@@ -27,7 +27,7 @@ describe('igxMask', () => {
2727 OneWayBindComponent ,
2828 PipesMaskComponent ,
2929 PlaceholderMaskComponent ,
30- EmptyMaskTestComponent ,
30+ MaskTestComponent ,
3131 ReadonlyMaskTestComponent
3232 ] ,
3333 imports : [
@@ -378,7 +378,7 @@ describe('igxMask', () => {
378378 } ) ) ;
379379
380380 it ( 'Should display mask on dragenter and remove it on dragleave' , fakeAsync ( ( ) => {
381- const fixture = TestBed . createComponent ( EmptyMaskTestComponent ) ;
381+ const fixture = TestBed . createComponent ( MaskTestComponent ) ;
382382 fixture . detectChanges ( ) ;
383383 const input = fixture . componentInstance . input ;
384384
@@ -390,6 +390,17 @@ describe('igxMask', () => {
390390
391391 input . nativeElement . dispatchEvent ( new DragEvent ( 'dragleave' ) ) ;
392392 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_____' ) ;
393404 } ) ) ;
394405
395406 it ( 'Apply display and input pipes on blur and focus.' , fakeAsync ( ( ) => {
@@ -485,6 +496,29 @@ describe('igxMask', () => {
485496 expect ( fixture . componentInstance . maskDirective . mask ) . toEqual ( '##.##' ) ;
486497 expect ( input . nativeElement . placeholder ) . toEqual ( '##.##' ) ;
487498 } ) ) ;
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+ } ) ;
488522} ) ;
489523
490524describe ( 'igxMaskDirective ControlValueAccessor Unit' , ( ) => {
@@ -728,7 +762,7 @@ class PipesMaskComponent {
728762 </igx-input-group>
729763 `
730764} )
731- class EmptyMaskTestComponent {
765+ class MaskTestComponent {
732766 @ViewChild ( 'input' , { static : true } )
733767 public input : ElementRef ;
734768}
0 commit comments