|
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import { NgxMaskModule } from '../ngx-mask.module'; |
| 3 | +import { ReactiveFormsModule } from '@angular/forms'; |
| 4 | +import { TestMaskComponent } from './utils/test-component.component'; |
| 5 | +import { equal } from './utils/test-functions.component'; |
| 6 | + |
| 7 | +describe('Directive: Mask', () => { |
| 8 | + let fixture: ComponentFixture<TestMaskComponent>; |
| 9 | + let component: TestMaskComponent; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + TestBed.configureTestingModule({ |
| 13 | + declarations: [TestMaskComponent], |
| 14 | + imports: [ReactiveFormsModule, NgxMaskModule.forRoot()], |
| 15 | + }); |
| 16 | + fixture = TestBed.createComponent(TestMaskComponent); |
| 17 | + component = fixture.componentInstance; |
| 18 | + fixture.detectChanges(); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should display the default placeholder when not configured', () => { |
| 22 | + component.mask = '(000) 000-0000'; |
| 23 | + component.showMaskTyped = true; |
| 24 | + equal('', '(___) ___-____', fixture); |
| 25 | + equal('2345678', '(234) 567-8___', fixture); |
| 26 | + |
| 27 | + component.prefix = '+7'; |
| 28 | + component.showMaskTyped = true; |
| 29 | + equal('', '+7(___) ___-____', fixture); |
| 30 | + equal('2345678', '+7(234) 567-8___', fixture); |
| 31 | + |
| 32 | + component.mask = 'IP'; |
| 33 | + component.prefix = ''; |
| 34 | + component.showMaskTyped = true; |
| 35 | + equal('', '_._._._', fixture); |
| 36 | + equal('1921681', '192.168.1_', fixture); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should display the modified placeholder when configured', () => { |
| 40 | + component.mask = '(000) 000-0000'; |
| 41 | + component.showMaskTyped = true; |
| 42 | + component.placeHolderCharacter = '*'; |
| 43 | + equal('', '(***) ***-****', fixture); |
| 44 | + equal('2345678', '(234) 567-8***', fixture); |
| 45 | + |
| 46 | + component.prefix = '+7'; |
| 47 | + component.showMaskTyped = true; |
| 48 | + equal('', '+7(***) ***-****', fixture); |
| 49 | + equal('2345678', '+7(234) 567-8***', fixture); |
| 50 | + |
| 51 | + component.mask = 'IP'; |
| 52 | + component.prefix = ''; |
| 53 | + component.showMaskTyped = true; |
| 54 | + equal('', '*.*.*.*', fixture); |
| 55 | + equal('1921681', '192.168.1*', fixture); |
| 56 | + }); |
| 57 | +}); |
0 commit comments