11import { Directionality } from '@angular/cdk/bidi' ;
2- import { BACKSPACE , DELETE } from '@angular/cdk/keycodes' ;
2+ import { BACKSPACE , DELETE , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
33import {
44 createKeyboardEvent ,
55 createFakeEvent ,
@@ -9,14 +9,15 @@ import {Component, DebugElement, ViewChild} from '@angular/core';
99import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
1010import { By } from '@angular/platform-browser' ;
1111import { Subject } from 'rxjs' ;
12- import { MatChipEvent , MatChipGrid , MatChipRow , MatChipsModule } from './index' ;
12+ import { MatChipEvent , MatChipGrid , MatChipRemove , MatChipRow , MatChipsModule } from './index' ;
1313
1414
1515describe ( 'MDC-based Row Chips' , ( ) => {
1616 let fixture : ComponentFixture < any > ;
1717 let chipDebugElement : DebugElement ;
1818 let chipNativeElement : HTMLElement ;
1919 let chipInstance : MatChipRow ;
20+ let removeIconInstance : MatChipRemove ;
2021
2122 let dir = 'ltr' ;
2223
@@ -46,6 +47,9 @@ describe('MDC-based Row Chips', () => {
4647 chipNativeElement = chipDebugElement . nativeElement ;
4748 chipInstance = chipDebugElement . injector . get < MatChipRow > ( MatChipRow ) ;
4849 testComponent = fixture . debugElement . componentInstance ;
50+
51+ const removeIconDebugElement = fixture . debugElement . query ( By . directive ( MatChipRemove ) ) ! ;
52+ removeIconInstance = removeIconDebugElement . injector . get < MatChipRemove > ( MatChipRemove ) ;
4953 } ) ;
5054
5155 describe ( 'basic behaviors' , ( ) => {
@@ -135,6 +139,21 @@ describe('MDC-based Row Chips', () => {
135139
136140 expect ( testComponent . chipRemove ) . toHaveBeenCalled ( ) ;
137141 } ) ;
142+
143+ it ( 'arrow key navigation does not emit the (removed) event' , ( ) => {
144+ const ARROW_KEY_EVENT = createKeyboardEvent ( 'keydown' , RIGHT_ARROW ) as KeyboardEvent ;
145+
146+ spyOn ( testComponent , 'chipRemove' ) ;
147+
148+ removeIconInstance . interaction . next ( ARROW_KEY_EVENT ) ;
149+ fixture . detectChanges ( ) ;
150+
151+ const fakeEvent = createFakeEvent ( 'transitionend' ) ;
152+ ( fakeEvent as any ) . propertyName = 'width' ;
153+ chipNativeElement . dispatchEvent ( fakeEvent ) ;
154+
155+ expect ( testComponent . chipRemove ) . not . toHaveBeenCalled ( ) ;
156+ } ) ;
138157 } ) ;
139158
140159 describe ( 'when removable is false' , ( ) => {
@@ -219,6 +238,7 @@ describe('MDC-based Row Chips', () => {
219238 (focus)="chipFocus($event)" (destroyed)="chipDestroy($event)"
220239 (removed)="chipRemove($event)">
221240 {{name}}
241+ <button matChipRemove>x</button>
222242 </mat-chip-row>
223243 <input matInput [matChipInputFor]="chipGrid">
224244 </div>
0 commit comments