1
1
import { Component , DebugElement , QueryList } from '@angular/core' ;
2
2
import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
3
+ import { CommonModule } from '@angular/common' ;
3
4
import { By } from '@angular/platform-browser' ;
4
5
import { MatChip , MatChipSet , MatChipsModule } from './index' ;
5
6
6
7
7
8
describe ( 'MatChipSet' , ( ) => {
8
- let fixture : ComponentFixture < any > ;
9
- let chipSetDebugElement : DebugElement ;
10
- let chipSetNativeElement : HTMLElement ;
11
- let chipSetInstance : MatChipSet ;
12
- let chips : QueryList < MatChip > ;
13
-
14
9
beforeEach ( async ( ( ) => {
15
10
TestBed . configureTestingModule ( {
16
- imports : [ MatChipsModule ] ,
17
- declarations : [ BasicChipSet ] ,
11
+ imports : [ MatChipsModule , CommonModule ] ,
12
+ declarations : [ BasicChipSet , IndirectDescendantsChipSet ] ,
18
13
} ) ;
19
14
20
15
TestBed . compileComponents ( ) ;
21
16
} ) ) ;
22
17
23
18
describe ( 'BasicChipSet' , ( ) => {
19
+ let fixture : ComponentFixture < any > ;
20
+ let chipSetDebugElement : DebugElement ;
21
+ let chipSetNativeElement : HTMLElement ;
22
+ let chipSetInstance : MatChipSet ;
23
+ let chips : QueryList < MatChip > ;
24
+
24
25
describe ( 'basic behaviors' , ( ) => {
25
26
beforeEach ( ( ) => {
26
27
fixture = TestBed . createComponent ( BasicChipSet ) ;
@@ -71,6 +72,28 @@ describe('MatChipSet', () => {
71
72
} ) ;
72
73
} ) ;
73
74
} ) ;
75
+
76
+ it ( 'should sync the disabled state to indirect descendant chips' , ( ) => {
77
+ const fixture = TestBed . createComponent ( IndirectDescendantsChipSet ) ;
78
+ fixture . detectChanges ( ) ;
79
+
80
+ const chipSetDebugElement = fixture . debugElement . query ( By . directive ( MatChipSet ) ) ! ;
81
+ const chipSetInstance = chipSetDebugElement . componentInstance ;
82
+ const chips : QueryList < MatChip > = chipSetInstance . _chips ;
83
+
84
+ expect ( chips . toArray ( ) . every ( chip => chip . disabled ) ) . toBe ( false ) ;
85
+
86
+ chipSetInstance . disabled = true ;
87
+ fixture . detectChanges ( ) ;
88
+
89
+ expect ( chips . toArray ( ) . every ( chip => chip . disabled ) ) . toBe ( true ) ;
90
+
91
+ chipSetInstance . disabled = false ;
92
+ fixture . detectChanges ( ) ;
93
+
94
+ expect ( chips . toArray ( ) . every ( chip => chip . disabled ) ) . toBe ( false ) ;
95
+ } ) ;
96
+
74
97
} ) ;
75
98
76
99
@Component ( {
@@ -86,3 +109,17 @@ class BasicChipSet {
86
109
name : string = 'Test' ;
87
110
chips = [ 0 , 1 , 2 , 3 , 4 ] ;
88
111
}
112
+
113
+ @Component ( {
114
+ template : `
115
+ <mat-chip-set>
116
+ <ng-container [ngSwitch]="true">
117
+ <mat-chip *ngFor="let i of chips">
118
+ {{name}} {{i + 1}}
119
+ </mat-chip>
120
+ </ng-container>
121
+ </mat-chip-set>
122
+ `
123
+ } )
124
+ class IndirectDescendantsChipSet extends BasicChipSet {
125
+ }
0 commit comments