@@ -38,6 +38,7 @@ import {MatFormFieldModule} from '../form-field';
38
38
import { MatInputModule } from '../input' ;
39
39
import { By } from '@angular/platform-browser' ;
40
40
import { MatChipEvent , MatChipGrid , MatChipInputEvent , MatChipRow , MatChipsModule } from './index' ;
41
+ import { MATERIAL_ANIMATIONS } from '../core' ;
41
42
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
42
43
43
44
describe ( 'MatChipGrid' , ( ) => {
@@ -121,27 +122,25 @@ describe('MatChipGrid', () => {
121
122
} ) ;
122
123
123
124
describe ( 'focus behaviors' , ( ) => {
124
- let fixture : ComponentFixture < StandardChipGrid > ;
125
-
126
- beforeEach ( ( ) => {
127
- fixture = createComponent ( StandardChipGrid ) ;
128
- } ) ;
129
-
130
125
it ( 'should focus the first chip on focus' , ( ) => {
126
+ const fixture = createComponent ( StandardChipGrid ) ;
131
127
chipGridInstance . focus ( ) ;
132
128
fixture . detectChanges ( ) ;
133
129
134
130
expect ( document . activeElement ) . toBe ( primaryActions [ 0 ] ) ;
135
131
} ) ;
136
132
137
133
it ( 'should focus the primary action when calling the `focus` method' , ( ) => {
134
+ const fixture = createComponent ( StandardChipGrid ) ;
138
135
chips . last . focus ( ) ;
139
136
fixture . detectChanges ( ) ;
140
137
141
138
expect ( document . activeElement ) . toBe ( primaryActions [ primaryActions . length - 1 ] ) ;
142
139
} ) ;
143
140
144
141
it ( 'should not be able to become focused when disabled' , ( ) => {
142
+ const fixture = createComponent ( StandardChipGrid ) ;
143
+
145
144
expect ( chipGridInstance . focused )
146
145
. withContext ( 'Expected grid to not be focused.' )
147
146
. toBe ( false ) ;
@@ -159,6 +158,7 @@ describe('MatChipGrid', () => {
159
158
} ) ;
160
159
161
160
it ( 'should remove the tabindex from the grid if it is disabled' , ( ) => {
161
+ const fixture = createComponent ( StandardChipGrid ) ;
162
162
expect ( chipGridNativeElement . getAttribute ( 'tabindex' ) ) . toBe ( '0' ) ;
163
163
164
164
chipGridInstance . disabled = true ;
@@ -170,6 +170,9 @@ describe('MatChipGrid', () => {
170
170
171
171
describe ( 'on chip destroy' , ( ) => {
172
172
it ( 'should focus the next item' , ( ) => {
173
+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
174
+ // It can indicate a deeper issue with the chips.
175
+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
173
176
const midItem = chips . get ( 2 ) ! ;
174
177
175
178
// Focus the middle item
@@ -185,6 +188,9 @@ describe('MatChipGrid', () => {
185
188
} ) ;
186
189
187
190
it ( 'should focus the previous item' , ( ) => {
191
+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
192
+ // It can indicate a deeper issue with the chips.
193
+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
188
194
// Focus the last item
189
195
chips . last . focus ( ) ;
190
196
@@ -198,6 +204,9 @@ describe('MatChipGrid', () => {
198
204
} ) ;
199
205
200
206
it ( 'should not focus if chip grid is not focused' , fakeAsync ( ( ) => {
207
+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
208
+ // It can indicate a deeper issue with the chips.
209
+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
201
210
const midItem = chips . get ( 2 ) ! ;
202
211
203
212
// Focus and blur the middle item
@@ -216,6 +225,9 @@ describe('MatChipGrid', () => {
216
225
} ) ) ;
217
226
218
227
it ( 'should focus the grid if the last focused item is removed' , ( ) => {
228
+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
229
+ // It can indicate a deeper issue with the chips.
230
+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
219
231
testComponent . chips = [ 0 ] ;
220
232
fixture . changeDetectorRef . markForCheck ( ) ;
221
233
@@ -232,6 +244,7 @@ describe('MatChipGrid', () => {
232
244
} ) ;
233
245
234
246
it ( 'should have a focus indicator' , ( ) => {
247
+ createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
235
248
const focusIndicators = chipGridNativeElement . querySelectorAll (
236
249
'.mat-mdc-chip-primary-focus-indicator' ,
237
250
) ;
@@ -488,14 +501,11 @@ describe('MatChipGrid', () => {
488
501
} ) ;
489
502
490
503
describe ( 'FormFieldChipGrid' , ( ) => {
491
- let fixture : ComponentFixture < FormFieldChipGrid > ;
492
-
493
- beforeEach ( ( ) => {
494
- fixture = createComponent ( FormFieldChipGrid ) ;
495
- } ) ;
496
-
497
504
describe ( 'keyboard behavior' , ( ) => {
498
505
it ( 'should maintain focus if the active chip is deleted' , ( ) => {
506
+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
507
+ // It can indicate a deeper issue with the chips.
508
+ const fixture = createComponent ( FormFieldChipGrid , undefined , [ NoopAnimationsModule ] ) ;
499
509
const secondChip = fixture . nativeElement . querySelectorAll ( '.mat-mdc-chip' ) [ 1 ] ;
500
510
const secondChipAction = secondChip . querySelector ( '.mdc-evolution-chip__action--primary' ) ;
501
511
@@ -512,6 +522,7 @@ describe('MatChipGrid', () => {
512
522
513
523
describe ( 'when the input has focus' , ( ) => {
514
524
it ( 'should not focus the last chip when press DELETE' , ( ) => {
525
+ const fixture = createComponent ( FormFieldChipGrid ) ;
515
526
let nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
516
527
517
528
// Focus the input
@@ -527,6 +538,7 @@ describe('MatChipGrid', () => {
527
538
} ) ;
528
539
529
540
it ( 'should focus the last chip when press BACKSPACE' , ( ) => {
541
+ const fixture = createComponent ( FormFieldChipGrid ) ;
530
542
let nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
531
543
532
544
// Focus the input
@@ -542,6 +554,7 @@ describe('MatChipGrid', () => {
542
554
} ) ;
543
555
544
556
it ( 'should not focus the last chip when pressing BACKSPACE on a non-empty input' , ( ) => {
557
+ const fixture = createComponent ( FormFieldChipGrid ) ;
545
558
const nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
546
559
nativeInput . value = 'hello' ;
547
560
nativeInput . focus ( ) ;
@@ -558,6 +571,7 @@ describe('MatChipGrid', () => {
558
571
} ) ;
559
572
560
573
it ( 'should complete the stateChanges stream on destroy' , ( ) => {
574
+ const fixture = createComponent ( FormFieldChipGrid ) ;
561
575
const spy = jasmine . createSpy ( 'stateChanges complete' ) ;
562
576
const subscription = chipGridInstance . stateChanges . subscribe ( { complete : spy } ) ;
563
577
@@ -568,18 +582,14 @@ describe('MatChipGrid', () => {
568
582
} ) ;
569
583
570
584
describe ( 'with chip remove' , ( ) => {
571
- let fixture : ComponentFixture < ChipGridWithRemove > ;
572
- let trailingActions : NodeListOf < HTMLElement > ;
573
-
574
- beforeEach ( fakeAsync ( ( ) => {
575
- fixture = createComponent ( ChipGridWithRemove ) ;
585
+ it ( 'should properly focus next item if chip is removed through click' , fakeAsync ( ( ) => {
586
+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
587
+ // It can indicate a deeper issue with the chips.
588
+ const fixture = createComponent ( ChipGridWithRemove , undefined , [ NoopAnimationsModule ] ) ;
576
589
flush ( ) ;
577
- trailingActions = chipGridNativeElement . querySelectorAll (
590
+ const trailingActions = chipGridNativeElement . querySelectorAll < HTMLElement > (
578
591
'.mdc-evolution-chip__action--trailing' ,
579
592
) ;
580
- } ) ) ;
581
-
582
- it ( 'should properly focus next item if chip is removed through click' , fakeAsync ( ( ) => {
583
593
const chip = chips . get ( 2 ) ! ;
584
594
chip . focus ( ) ;
585
595
fixture . detectChanges ( ) ;
@@ -1018,6 +1028,7 @@ describe('MatChipGrid', () => {
1018
1028
function createComponent < T > (
1019
1029
component : Type < T > ,
1020
1030
direction : Direction = 'ltr' ,
1031
+ additionalImports : Type < unknown > [ ] = [ ] ,
1021
1032
) : ComponentFixture < T > {
1022
1033
directionality = {
1023
1034
value : direction ,
@@ -1031,9 +1042,12 @@ describe('MatChipGrid', () => {
1031
1042
MatChipsModule ,
1032
1043
MatFormFieldModule ,
1033
1044
MatInputModule ,
1034
- NoopAnimationsModule ,
1045
+ ...additionalImports ,
1046
+ ] ,
1047
+ providers : [
1048
+ { provide : Directionality , useValue : directionality } ,
1049
+ { provide : MATERIAL_ANIMATIONS , useValue : { animationsDisabled : true } } ,
1035
1050
] ,
1036
- providers : [ { provide : Directionality , useValue : directionality } ] ,
1037
1051
declarations : [ component ] ,
1038
1052
} ) ;
1039
1053
0 commit comments