11import { async , TestBed } from '@angular/core/testing' ;
2- import { Component } from '@angular/core' ;
2+ import { Component , ViewChild } from '@angular/core' ;
33import { By } from '@angular/platform-browser' ;
44import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
5- import { MatExpansionModule } from './index' ;
5+ import { MatExpansionModule , MatAccordion } from './index' ;
66
77
88describe ( 'CdkAccordion' , ( ) => {
@@ -45,6 +45,45 @@ describe('CdkAccordion', () => {
4545 expect ( panels [ 0 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
4646 expect ( panels [ 1 ] . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
4747 } ) ;
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+ } ) ;
4887} ) ;
4988
5089
@@ -54,13 +93,16 @@ describe('CdkAccordion', () => {
5493 <mat-expansion-panel-header>Summary</mat-expansion-panel-header>
5594 <p>Content</p>
5695 </mat-expansion-panel>
57- <mat-expansion-panel [expanded]="secondPanelExpanded">
96+ <mat-expansion-panel [expanded]="secondPanelExpanded" [disabled]="secondPanelDisabled" >
5897 <mat-expansion-panel-header>Summary</mat-expansion-panel-header>
5998 <p>Content</p>
6099 </mat-expansion-panel>
61100 </mat-accordion>` } )
62101class SetOfItems {
102+ @ViewChild ( MatAccordion ) accordion : MatAccordion ;
103+
63104 multi : boolean = false ;
64105 firstPanelExpanded : boolean = false ;
65106 secondPanelExpanded : boolean = false ;
107+ secondPanelDisabled : boolean = false ;
66108}
0 commit comments