mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-19 01:21:19 +00:00
Enhancement: refactor monetary field (#6370)
This commit is contained in:
@@ -11,7 +11,6 @@ import { MonetaryComponent } from './monetary.component'
|
||||
describe('MonetaryComponent', () => {
|
||||
let component: MonetaryComponent
|
||||
let fixture: ComponentFixture<MonetaryComponent>
|
||||
let input: HTMLInputElement
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
@@ -24,37 +23,22 @@ describe('MonetaryComponent', () => {
|
||||
fixture.debugElement.injector.get(NG_VALUE_ACCESSOR)
|
||||
component = fixture.componentInstance
|
||||
fixture.detectChanges()
|
||||
input = component.inputField.nativeElement
|
||||
})
|
||||
|
||||
it('should set the currency code correctly', () => {
|
||||
expect(component.currencyCode).toEqual('USD') // default
|
||||
component.currencyCode = 'EUR'
|
||||
expect(component.currencyCode).toEqual('EUR')
|
||||
it('should set the currency code and monetary value correctly', () => {
|
||||
expect(component.currency).toEqual('USD') // default
|
||||
component.writeValue('G123.4')
|
||||
expect(component.currency).toEqual('G')
|
||||
|
||||
component.value = 'G123.4'
|
||||
jest
|
||||
.spyOn(document, 'activeElement', 'get')
|
||||
.mockReturnValue(component.currencyField.nativeElement)
|
||||
expect(component.currencyCode).toEqual('G')
|
||||
component.writeValue('EUR123.4')
|
||||
expect(component.currency).toEqual('EUR')
|
||||
expect(component.monetaryValue).toEqual('123.40')
|
||||
})
|
||||
|
||||
it('should parse monetary value only when out of focus', () => {
|
||||
component.monetaryValue = 10.5
|
||||
jest.spyOn(document, 'activeElement', 'get').mockReturnValue(null)
|
||||
it('should set monetary value to fixed decimals', () => {
|
||||
component.monetaryValue = '10.5'
|
||||
component.monetaryValueChange(true)
|
||||
expect(component.monetaryValue).toEqual('10.50')
|
||||
|
||||
component.value = 'GBP123.4'
|
||||
jest
|
||||
.spyOn(document, 'activeElement', 'get')
|
||||
.mockReturnValue(component.inputField.nativeElement)
|
||||
expect(component.monetaryValue).toEqual('123.4')
|
||||
})
|
||||
|
||||
it('should report value including currency code and monetary value', () => {
|
||||
component.currencyCode = 'EUR'
|
||||
component.monetaryValue = 10.5
|
||||
expect(component.value).toEqual('EUR10.50')
|
||||
})
|
||||
|
||||
it('should set the default currency code based on LOCALE_ID', () => {
|
||||
|
||||
Reference in New Issue
Block a user