@@ -31,45 +31,96 @@ describe('CdkAccordionItem', () => {
3131 . injector . get ( CdkAccordionItem ) ;
3232 } ) ;
3333
34- it ( 'should toggle its expanded state' , ( ) => {
35- expect ( item . expanded ) . toBeFalsy ( ) ;
36- item . toggle ( ) ;
37- expect ( item . expanded ) . toBeTruthy ( ) ;
38- item . toggle ( ) ;
39- expect ( item . expanded ) . toBeFalsy ( ) ;
34+ describe ( 'that is not disabled' , ( ) => {
35+ beforeEach ( ( ) => {
36+ item . disabled = false ;
37+ } ) ;
38+
39+ it ( 'should toggle its expanded state' , ( ) => {
40+ expect ( item . expanded ) . toBeFalsy ( ) ;
41+ item . toggle ( ) ;
42+ expect ( item . expanded ) . toBeTruthy ( ) ;
43+ item . toggle ( ) ;
44+ expect ( item . expanded ) . toBeFalsy ( ) ;
45+ } ) ;
46+
47+ it ( 'should set its expanded state to expanded' , ( ) => {
48+ item . expanded = false ;
49+ item . open ( ) ;
50+ expect ( item . expanded ) . toBeTruthy ( ) ;
51+ } ) ;
52+
53+ it ( 'should set its expanded state to closed' , ( ) => {
54+ item . expanded = true ;
55+ item . close ( ) ;
56+ expect ( item . expanded ) . toBeFalsy ( ) ;
57+ } ) ;
58+
59+ it ( 'should emit a closed event' , ( ) => {
60+ spyOn ( item . closed , 'emit' ) ;
61+ item . close ( ) ;
62+ fixture . detectChanges ( ) ;
63+ expect ( item . closed . emit ) . toHaveBeenCalledWith ( ) ;
64+ } ) ;
65+
66+ it ( 'should emit an opened event' , ( ) => {
67+ spyOn ( item . opened , 'emit' ) ;
68+ item . open ( ) ;
69+ fixture . detectChanges ( ) ;
70+ expect ( item . opened . emit ) . toHaveBeenCalledWith ( ) ;
71+ } ) ;
72+
73+ it ( 'should emit a destroyed event' , ( ) => {
74+ spyOn ( item . destroyed , 'emit' ) ;
75+ item . ngOnDestroy ( ) ;
76+ fixture . detectChanges ( ) ;
77+ expect ( item . destroyed . emit ) . toHaveBeenCalledWith ( ) ;
78+ } ) ;
4079 } ) ;
4180
42- it ( 'should set its expanded state to expanded' , ( ) => {
43- item . expanded = false ;
44- item . open ( ) ;
45- expect ( item . expanded ) . toBeTruthy ( ) ;
46- } ) ;
47-
48- it ( 'should set its expanded state to closed' , ( ) => {
49- item . expanded = true ;
50- item . close ( ) ;
51- expect ( item . expanded ) . toBeFalsy ( ) ;
52- } ) ;
53-
54- it ( 'should emit a closed event' , ( ) => {
55- spyOn ( item . closed , 'emit' ) ;
56- item . close ( ) ;
57- fixture . detectChanges ( ) ;
58- expect ( item . closed . emit ) . toHaveBeenCalledWith ( ) ;
59- } ) ;
60-
61- it ( 'should emit an opened event' , ( ) => {
62- spyOn ( item . opened , 'emit' ) ;
63- item . open ( ) ;
64- fixture . detectChanges ( ) ;
65- expect ( item . opened . emit ) . toHaveBeenCalledWith ( ) ;
66- } ) ;
67-
68- it ( 'should emit an destroyed event' , ( ) => {
69- spyOn ( item . destroyed , 'emit' ) ;
70- item . ngOnDestroy ( ) ;
71- fixture . detectChanges ( ) ;
72- expect ( item . destroyed . emit ) . toHaveBeenCalledWith ( ) ;
81+ describe ( 'that is disabled' , ( ) => {
82+ beforeEach ( ( ) => {
83+ item . disabled = true ;
84+ } ) ;
85+
86+ it ( 'should not toggle its expanded state' , ( ) => {
87+ expect ( item . expanded ) . toBeFalsy ( ) ;
88+ item . toggle ( ) ;
89+ expect ( item . expanded ) . toBeFalsy ( ) ;
90+ } ) ;
91+
92+ it ( 'should not set its expanded state to expanded' , ( ) => {
93+ item . expanded = false ;
94+ item . open ( ) ;
95+ expect ( item . expanded ) . toBeFalsy ( ) ;
96+ } ) ;
97+
98+ it ( 'should not set its expanded state to closed' , ( ) => {
99+ item . expanded = true ;
100+ item . close ( ) ;
101+ expect ( item . expanded ) . toBeTruthy ( ) ;
102+ } ) ;
103+
104+ it ( 'should not emit a closed event' , ( ) => {
105+ spyOn ( item . closed , 'emit' ) ;
106+ item . close ( ) ;
107+ fixture . detectChanges ( ) ;
108+ expect ( item . closed . emit ) . not . toHaveBeenCalled ( ) ;
109+ } ) ;
110+
111+ it ( 'should not emit an opened event' , ( ) => {
112+ spyOn ( item . opened , 'emit' ) ;
113+ item . open ( ) ;
114+ fixture . detectChanges ( ) ;
115+ expect ( item . opened . emit ) . not . toHaveBeenCalled ( ) ;
116+ } ) ;
117+
118+ it ( 'should emit a destroyed event' , ( ) => {
119+ spyOn ( item . destroyed , 'emit' ) ;
120+ item . ngOnDestroy ( ) ;
121+ fixture . detectChanges ( ) ;
122+ expect ( item . destroyed . emit ) . toHaveBeenCalledWith ( ) ;
123+ } ) ;
73124 } ) ;
74125 } ) ;
75126
@@ -99,6 +150,20 @@ describe('CdkAccordionItem', () => {
99150 expect ( firstItem . expanded ) . toBeTruthy ( ) ;
100151 expect ( secondItem . expanded ) . toBeTruthy ( ) ;
101152 } ) ;
153+
154+ it ( 'should not change expanded state for disabled items' , ( ) => {
155+ firstItem . disabled = true ;
156+ expect ( firstItem . expanded ) . toBeFalsy ( ) ;
157+ expect ( secondItem . expanded ) . toBeFalsy ( ) ;
158+ firstItem . open ( ) ;
159+ fixture . detectChanges ( ) ;
160+ expect ( firstItem . expanded ) . toBeFalsy ( ) ;
161+ expect ( secondItem . expanded ) . toBeFalsy ( ) ;
162+ secondItem . open ( ) ;
163+ fixture . detectChanges ( ) ;
164+ expect ( firstItem . expanded ) . toBeFalsy ( ) ;
165+ expect ( secondItem . expanded ) . toBeTruthy ( ) ;
166+ } ) ;
102167 } ) ;
103168
104169
0 commit comments