@@ -27,7 +27,7 @@ describe('igxMask', () => {
27
27
OneWayBindComponent ,
28
28
PipesMaskComponent ,
29
29
PlaceholderMaskComponent ,
30
- EmptyMaskTestComponent ,
30
+ MaskTestComponent ,
31
31
ReadonlyMaskTestComponent
32
32
] ,
33
33
imports : [
@@ -378,7 +378,7 @@ describe('igxMask', () => {
378
378
} ) ) ;
379
379
380
380
it ( 'Should display mask on dragenter and remove it on dragleave' , fakeAsync ( ( ) => {
381
- const fixture = TestBed . createComponent ( EmptyMaskTestComponent ) ;
381
+ const fixture = TestBed . createComponent ( MaskTestComponent ) ;
382
382
fixture . detectChanges ( ) ;
383
383
const input = fixture . componentInstance . input ;
384
384
@@ -390,6 +390,17 @@ describe('igxMask', () => {
390
390
391
391
input . nativeElement . dispatchEvent ( new DragEvent ( 'dragleave' ) ) ;
392
392
expect ( input . nativeElement . value ) . toEqual ( '' ) ;
393
+
394
+ // should preserve state on dragenter
395
+ input . nativeElement . dispatchEvent ( new Event ( 'focus' ) ) ;
396
+ UIInteractions . simulatePaste ( '76' , fixture . debugElement . query ( By . css ( '.igx-input-group__input' ) ) , 3 , 3 ) ;
397
+ fixture . detectChanges ( ) ;
398
+
399
+ input . nativeElement . dispatchEvent ( new Event ( 'blur' ) ) ;
400
+ expect ( input . nativeElement . value ) . toEqual ( '___76_____' ) ;
401
+
402
+ input . nativeElement . dispatchEvent ( new DragEvent ( 'dragenter' ) ) ;
403
+ expect ( input . nativeElement . value ) . toEqual ( '___76_____' ) ;
393
404
} ) ) ;
394
405
395
406
it ( 'Apply display and input pipes on blur and focus.' , fakeAsync ( ( ) => {
@@ -485,6 +496,29 @@ describe('igxMask', () => {
485
496
expect ( fixture . componentInstance . maskDirective . mask ) . toEqual ( '##.##' ) ;
486
497
expect ( input . nativeElement . placeholder ) . toEqual ( '##.##' ) ;
487
498
} ) ) ;
499
+
500
+ it ( 'should update input properly on selection with DELETE' , ( ) => {
501
+ const fixture = TestBed . createComponent ( MaskComponent ) ;
502
+ fixture . detectChanges ( ) ;
503
+ const inputElement = fixture . debugElement . query ( By . css ( 'input' ) ) ;
504
+ inputElement . triggerEventHandler ( 'focus' ) ;
505
+ UIInteractions . simulatePaste ( '1234567890' , inputElement , 1 , 1 ) ;
506
+ fixture . detectChanges ( ) ;
507
+ expect ( inputElement . nativeElement . value ) . toEqual ( '(123) 4567-890' ) ;
508
+
509
+ const inputHTMLElement = inputElement . nativeElement as HTMLInputElement ;
510
+ inputHTMLElement . setSelectionRange ( 6 , 8 ) ;
511
+ fixture . detectChanges ( ) ;
512
+ expect ( inputElement . nativeElement . selectionStart ) . toEqual ( 6 ) ;
513
+ expect ( inputElement . nativeElement . selectionEnd ) . toEqual ( 8 ) ;
514
+
515
+ UIInteractions . triggerEventHandlerKeyDown ( 'Delete' , inputElement ) ;
516
+ inputElement . triggerEventHandler ( 'input' , { inputType : 'test' } ) ;
517
+ fixture . detectChanges ( ) ;
518
+ expect ( inputElement . nativeElement . selectionStart ) . toEqual ( 8 ) ;
519
+ expect ( inputElement . nativeElement . selectionEnd ) . toEqual ( 8 ) ;
520
+ expect ( inputHTMLElement . value ) . toEqual ( '(123) __67-890' ) ;
521
+ } ) ;
488
522
} ) ;
489
523
490
524
describe ( 'igxMaskDirective ControlValueAccessor Unit' , ( ) => {
@@ -728,7 +762,7 @@ class PipesMaskComponent {
728
762
</igx-input-group>
729
763
`
730
764
} )
731
- class EmptyMaskTestComponent {
765
+ class MaskTestComponent {
732
766
@ViewChild ( 'input' , { static : true } )
733
767
public input : ElementRef ;
734
768
}
0 commit comments