1
1
import { Directionality } from '@angular/cdk/bidi' ;
2
- import { BACKSPACE , DELETE } from '@angular/cdk/keycodes' ;
2
+ import { BACKSPACE , DELETE , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
3
3
import {
4
4
createKeyboardEvent ,
5
5
createFakeEvent ,
@@ -9,14 +9,15 @@ import {Component, DebugElement, ViewChild} from '@angular/core';
9
9
import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
10
10
import { By } from '@angular/platform-browser' ;
11
11
import { Subject } from 'rxjs' ;
12
- import { MatChipEvent , MatChipGrid , MatChipRow , MatChipsModule } from './index' ;
12
+ import { MatChipEvent , MatChipGrid , MatChipRemove , MatChipRow , MatChipsModule } from './index' ;
13
13
14
14
15
15
describe ( 'MDC-based Row Chips' , ( ) => {
16
16
let fixture : ComponentFixture < any > ;
17
17
let chipDebugElement : DebugElement ;
18
18
let chipNativeElement : HTMLElement ;
19
19
let chipInstance : MatChipRow ;
20
+ let removeIconInstance : MatChipRemove ;
20
21
21
22
let dir = 'ltr' ;
22
23
@@ -46,6 +47,9 @@ describe('MDC-based Row Chips', () => {
46
47
chipNativeElement = chipDebugElement . nativeElement ;
47
48
chipInstance = chipDebugElement . injector . get < MatChipRow > ( MatChipRow ) ;
48
49
testComponent = fixture . debugElement . componentInstance ;
50
+
51
+ const removeIconDebugElement = fixture . debugElement . query ( By . directive ( MatChipRemove ) ) ! ;
52
+ removeIconInstance = removeIconDebugElement . injector . get < MatChipRemove > ( MatChipRemove ) ;
49
53
} ) ;
50
54
51
55
describe ( 'basic behaviors' , ( ) => {
@@ -135,6 +139,21 @@ describe('MDC-based Row Chips', () => {
135
139
136
140
expect ( testComponent . chipRemove ) . toHaveBeenCalled ( ) ;
137
141
} ) ;
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
+ } ) ;
138
157
} ) ;
139
158
140
159
describe ( 'when removable is false' , ( ) => {
@@ -219,6 +238,7 @@ describe('MDC-based Row Chips', () => {
219
238
(focus)="chipFocus($event)" (destroyed)="chipDestroy($event)"
220
239
(removed)="chipRemove($event)">
221
240
{{name}}
241
+ <button matChipRemove>x</button>
222
242
</mat-chip-row>
223
243
<input matInput [matChipInputFor]="chipGrid">
224
244
</div>
0 commit comments