1
1
import { async , TestBed } from '@angular/core/testing' ;
2
- import { Component } from '@angular/core' ;
2
+ import { Component , ViewChild } from '@angular/core' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
5
- import { MatExpansionModule } from './index' ;
5
+ import { MatExpansionModule , MatAccordion } from './index' ;
6
6
7
7
8
8
describe ( 'CdkAccordion' , ( ) => {
@@ -45,6 +45,45 @@ describe('CdkAccordion', () => {
45
45
expect ( panels [ 0 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
46
46
expect ( panels [ 1 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
47
47
} ) ;
48
+
49
+ it ( 'should expand or collapse all enabled items' , ( ) => {
50
+ const fixture = TestBed . createComponent ( SetOfItems ) ;
51
+ const panels = fixture . debugElement . queryAll ( By . css ( '.mat-expansion-panel' ) ) ;
52
+
53
+ fixture . componentInstance . multi = true ;
54
+ fixture . componentInstance . secondPanelExpanded = true ;
55
+ fixture . detectChanges ( ) ;
56
+ expect ( panels [ 0 ] . classes [ 'mat-expanded' ] ) . toBeFalsy ( ) ;
57
+ expect ( panels [ 1 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
58
+
59
+ fixture . componentInstance . accordion . openAll ( ) ;
60
+ fixture . detectChanges ( ) ;
61
+ expect ( panels [ 0 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
62
+ expect ( panels [ 1 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
63
+
64
+ fixture . componentInstance . accordion . closeAll ( ) ;
65
+ fixture . detectChanges ( ) ;
66
+ expect ( panels [ 0 ] . classes [ 'mat-expanded' ] ) . toBeFalsy ( ) ;
67
+ expect ( panels [ 1 ] . classes [ 'mat-expanded' ] ) . toBeFalsy ( ) ;
68
+ } ) ;
69
+
70
+ it ( 'should not expand or collapse disabled items' , ( ) => {
71
+ const fixture = TestBed . createComponent ( SetOfItems ) ;
72
+ const panels = fixture . debugElement . queryAll ( By . css ( '.mat-expansion-panel' ) ) ;
73
+
74
+ fixture . componentInstance . multi = true ;
75
+ fixture . componentInstance . secondPanelDisabled = true ;
76
+ fixture . detectChanges ( ) ;
77
+ fixture . componentInstance . accordion . openAll ( ) ;
78
+ fixture . detectChanges ( ) ;
79
+ expect ( panels [ 0 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
80
+ expect ( panels [ 1 ] . classes [ 'mat-expanded' ] ) . toBeFalsy ( ) ;
81
+
82
+ fixture . componentInstance . accordion . closeAll ( ) ;
83
+ fixture . detectChanges ( ) ;
84
+ expect ( panels [ 0 ] . classes [ 'mat-expanded' ] ) . toBeFalsy ( ) ;
85
+ expect ( panels [ 1 ] . classes [ 'mat-expanded' ] ) . toBeFalsy ( ) ;
86
+ } ) ;
48
87
} ) ;
49
88
50
89
@@ -54,13 +93,16 @@ describe('CdkAccordion', () => {
54
93
<mat-expansion-panel-header>Summary</mat-expansion-panel-header>
55
94
<p>Content</p>
56
95
</mat-expansion-panel>
57
- <mat-expansion-panel [expanded]="secondPanelExpanded">
96
+ <mat-expansion-panel [expanded]="secondPanelExpanded" [disabled]="secondPanelDisabled" >
58
97
<mat-expansion-panel-header>Summary</mat-expansion-panel-header>
59
98
<p>Content</p>
60
99
</mat-expansion-panel>
61
100
</mat-accordion>` } )
62
101
class SetOfItems {
102
+ @ViewChild ( MatAccordion ) accordion : MatAccordion ;
103
+
63
104
multi : boolean = false ;
64
105
firstPanelExpanded : boolean = false ;
65
106
secondPanelExpanded : boolean = false ;
107
+ secondPanelDisabled : boolean = false ;
66
108
}
0 commit comments