-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(1009): decimalMarker not locale default (#1052)
* fix(1009): decimalMarker not locale default note: manually tested with added showcase "Decimal separator with existing value" of course, if someone finds a way to mock/set the locale in the tests, I'll gladly add a unit test for that :) to test: set browser locale to German for instance (so that decimal marker defaults to ',') before fix: 1234.56 shows as 1234.5 after fix: 1234.56 shows as 1234.56 * test(1009): test non EN locale e.g. FR locale uses comma (,) as decimal marker
- Loading branch information
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
projects/ngx-mask-lib/src/test/separator-non-en-locale.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { LOCALE_ID } from '@angular/core'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { TestMaskComponent } from './utils/test-component.component'; | ||
import { equal, typeTest } from './utils/test-functions.component'; | ||
import { provideNgxMask } from '../lib/ngx-mask.providers'; | ||
import { NgxMaskDirective } from '../lib/ngx-mask.directive'; | ||
|
||
// FR locale uses comma as decimal marker | ||
describe('Separator: Mask with FR locale', () => { | ||
let fixture: ComponentFixture<TestMaskComponent>; | ||
let component: TestMaskComponent; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [TestMaskComponent], | ||
imports: [ReactiveFormsModule, NgxMaskDirective], | ||
providers: [provideNgxMask(), { provide: LOCALE_ID, useValue: 'fr' }], | ||
}); | ||
fixture = TestBed.createComponent(TestMaskComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('Should work right when reset decimalMarker', () => { | ||
component.mask = 'separator.2'; | ||
component.decimalMarker = '.'; | ||
equal('1000000.00', '1 000 000.00', fixture); | ||
}); | ||
|
||
it('separator precision 2 with thousandSeparator (.) decimalMarker (,) for 12345.67', () => { | ||
component.mask = 'separator.2'; | ||
component.thousandSeparator = ','; | ||
component.decimalMarker = '.'; | ||
equal('12,345.67', '12,345.67', fixture); | ||
}); | ||
|
||
it('separator precision 2 with thousandSeparator (.) decimalMarker (,) for 12345.67', () => { | ||
component.mask = 'separator.2'; | ||
component.thousandSeparator = ','; | ||
component.decimalMarker = '.'; | ||
equal('12345.67', '12,345.67', fixture); | ||
}); | ||
|
||
it('check formControl value to be number when decimalMarker is dot', () => { | ||
component.mask = 'separator.2'; | ||
component.thousandSeparator = ' '; | ||
component.decimalMarker = '.'; | ||
|
||
typeTest('12 345.67', fixture); | ||
expect(component.form.value).toBe('12345.67'); | ||
}); | ||
|
||
it('check formControl value to be number when decimalMarker is array', () => { | ||
component.mask = 'separator.2'; | ||
component.thousandSeparator = ' '; | ||
component.decimalMarker = ['.', ',']; | ||
|
||
typeTest('12 345,67', fixture); | ||
expect(component.form.value).toBe('12345.67'); | ||
|
||
typeTest('123 456.78', fixture); | ||
expect(component.form.value).toBe('123456.78'); | ||
}); | ||
}); |