@@ -42,6 +42,7 @@ describe('MDCIconButtonToggleFoundation', () => {
42
42
'addClass' ,
43
43
'removeClass' ,
44
44
'hasClass' ,
45
+ 'getAttr' ,
45
46
'setAttr' ,
46
47
'notifyChange' ,
47
48
] ) ;
@@ -53,15 +54,15 @@ describe('MDCIconButtonToggleFoundation', () => {
53
54
return { foundation, mockAdapter} ;
54
55
} ;
55
56
56
- it ( `isOn is false if hasClass(${ cssClasses . ICON_BUTTON_ON } ) returns false` ,
57
+ it ( `# isOn is false if hasClass(${ cssClasses . ICON_BUTTON_ON } ) returns false` ,
57
58
( ) => {
58
59
const { foundation, mockAdapter} = setupTest ( ) ;
59
60
mockAdapter . hasClass . withArgs ( cssClasses . ICON_BUTTON_ON )
60
61
. and . returnValue ( false ) ;
61
62
expect ( foundation . isOn ( ) ) . toBe ( false ) ;
62
63
} ) ;
63
64
64
- it ( `isOn is true if hasClass(${ cssClasses . ICON_BUTTON_ON } ) returns true` ,
65
+ it ( `# isOn is true if hasClass(${ cssClasses . ICON_BUTTON_ON } ) returns true` ,
65
66
( ) => {
66
67
const { foundation, mockAdapter} = setupTest ( ) ;
67
68
mockAdapter . hasClass . withArgs ( cssClasses . ICON_BUTTON_ON )
@@ -133,4 +134,60 @@ describe('MDCIconButtonToggleFoundation', () => {
133
134
. toHaveBeenCalledWith ( strings . ARIA_PRESSED , 'false' ) ;
134
135
expect ( mockAdapter . setAttr ) . toHaveBeenCalledTimes ( 1 ) ;
135
136
} ) ;
137
+
138
+ describe ( 'Variant with toggled aria label' , ( ) => {
139
+ it ( '#init throws an error if `aria-label-on` and `aria-label-off` are ' +
140
+ 'set, but `aria-pressed` is also set' ,
141
+ ( ) => {
142
+ const { foundation, mockAdapter} = setupTest ( ) ;
143
+
144
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_ON )
145
+ . and . returnValue ( 'on label' ) ;
146
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_OFF )
147
+ . and . returnValue ( 'off label' ) ;
148
+ mockAdapter . getAttr . withArgs ( strings . ARIA_PRESSED )
149
+ . and . returnValue ( 'false' ) ;
150
+
151
+ expect ( foundation . init ) . toThrow ( ) ;
152
+ } ) ;
153
+
154
+ it ( '#toggle sets aria label correctly when toggled on' , ( ) => {
155
+ const { foundation, mockAdapter} = initWithToggledAriaLabel ( { isOn : false } ) ;
156
+
157
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_ON )
158
+ . and . returnValue ( 'on label' ) ;
159
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_OFF )
160
+ . and . returnValue ( 'off label' ) ;
161
+ foundation . toggle ( true ) ;
162
+ expect ( mockAdapter . setAttr )
163
+ . toHaveBeenCalledWith ( strings . ARIA_LABEL , 'on label' ) ;
164
+ } ) ;
165
+
166
+ it ( '#toggle sets aria label correctly when toggled off' , ( ) => {
167
+ const { foundation, mockAdapter} = initWithToggledAriaLabel ( { isOn : false } ) ;
168
+
169
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_ON )
170
+ . and . returnValue ( 'on label' ) ;
171
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_OFF )
172
+ . and . returnValue ( 'off label' ) ;
173
+ foundation . toggle ( false ) ;
174
+ expect ( mockAdapter . setAttr )
175
+ . toHaveBeenCalledWith ( strings . ARIA_LABEL , 'off label' ) ;
176
+ } ) ;
177
+
178
+ const initWithToggledAriaLabel = ( { isOn} : { isOn : boolean } ) => {
179
+ const { foundation, mockAdapter} = setupTest ( ) ;
180
+
181
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_ON )
182
+ . and . returnValue ( 'on label' ) ;
183
+ mockAdapter . getAttr . withArgs ( strings . DATA_ARIA_LABEL_OFF )
184
+ . and . returnValue ( 'off label' ) ;
185
+ mockAdapter . getAttr . withArgs ( strings . ARIA_PRESSED ) . and . returnValue ( null ) ;
186
+ mockAdapter . hasClass . withArgs ( cssClasses . ICON_BUTTON_ON )
187
+ . and . returnValue ( isOn ) ;
188
+ foundation . init ( ) ;
189
+
190
+ return { foundation, mockAdapter} ;
191
+ } ;
192
+ } ) ;
136
193
} ) ;
0 commit comments