@@ -25,14 +25,17 @@ import {MDCIconToggle, MDCIconToggleFoundation} from '../../../packages/mdc-icon
25
25
import { MDCRipple } from '../../../packages/mdc-ripple' ;
26
26
import { cssClasses } from '../../../packages/mdc-ripple/constants' ;
27
27
28
- function setupTest ( { useInnerIconElement = false } = { } ) {
28
+ function setupTest ( { tabIndex = undefined , useInnerIconElement = false } = { } ) {
29
29
const root = document . createElement ( useInnerIconElement ? 'span' : 'i' ) ;
30
30
if ( useInnerIconElement ) {
31
31
const icon = document . createElement ( 'i' ) ;
32
32
icon . id = 'icon' ;
33
33
root . dataset . iconInnerSelector = `#${ icon . id } ` ;
34
34
root . appendChild ( icon ) ;
35
35
}
36
+ if ( tabIndex !== undefined ) {
37
+ root . tabIndex = tabIndex ;
38
+ }
36
39
const component = new MDCIconToggle ( root ) ;
37
40
return { root, component} ;
38
41
}
@@ -74,17 +77,40 @@ test('set/get on', () => {
74
77
assert . equal ( root . getAttribute ( 'aria-pressed' ) , 'false' ) ;
75
78
} ) ;
76
79
77
- test ( 'set/get disabled' , ( ) => {
78
- const { root, component} = setupTest ( ) ;
80
+ test ( 'set/get disabled to true' , ( ) => {
81
+ const { root, component} = setupTest ( { tabIndex : 0 } ) ;
82
+
79
83
component . disabled = true ;
80
84
assert . isOk ( component . disabled ) ;
81
85
assert . equal ( root . getAttribute ( 'aria-disabled' ) , 'true' ) ;
82
86
assert . isOk ( root . classList . contains ( MDCIconToggleFoundation . cssClasses . DISABLED ) ) ;
87
+ assert . equal ( root . tabIndex , - 1 ) ;
88
+ } ) ;
89
+
90
+ test ( 'set/get disabled to false' , ( ) => {
91
+ const { root, component} = setupTest ( { tabIndex : 0 } ) ;
83
92
84
93
component . disabled = false ;
85
94
assert . isNotOk ( component . disabled ) ;
86
95
assert . isNotOk ( root . hasAttribute ( 'aria-disabled' ) ) ;
87
96
assert . isNotOk ( root . classList . contains ( MDCIconToggleFoundation . cssClasses . DISABLED ) ) ;
97
+ assert . equal ( root . tabIndex , 0 , 'element\'s tabIndex should be the same value it already had' ) ;
98
+ } ) ;
99
+
100
+ test ( 'set/get disabled to true, then false' , ( ) => {
101
+ const { root, component} = setupTest ( { tabIndex : 0 } ) ;
102
+
103
+ component . disabled = true ;
104
+ assert . isOk ( component . disabled ) ;
105
+ assert . equal ( root . getAttribute ( 'aria-disabled' ) , 'true' ) ;
106
+ assert . isOk ( root . classList . contains ( MDCIconToggleFoundation . cssClasses . DISABLED ) ) ;
107
+ assert . equal ( root . tabIndex , - 1 ) ;
108
+
109
+ component . disabled = false ;
110
+ assert . isNotOk ( component . disabled ) ;
111
+ assert . isNotOk ( root . hasAttribute ( 'aria-disabled' ) ) ;
112
+ assert . isNotOk ( root . classList . contains ( MDCIconToggleFoundation . cssClasses . DISABLED ) ) ;
113
+ assert . equal ( root . tabIndex , 0 , 'element\'s tabIndex should be the same value it originally had' ) ;
88
114
} ) ;
89
115
90
116
test ( '#refreshToggleData proxies to foundation.refreshToggleData()' , ( ) => {
@@ -174,14 +200,12 @@ test('#adapter.setText sets the text content of the inner icon element when used
174
200
} ) ;
175
201
176
202
test ( '#adapter.getTabIndex returns the tabIndex of the element' , ( ) => {
177
- const { root, component} = setupTest ( ) ;
178
- root . tabIndex = 4 ;
203
+ const { component} = setupTest ( { tabIndex : 4 } ) ;
179
204
assert . equal ( component . getDefaultFoundation ( ) . adapter_ . getTabIndex ( ) , 4 ) ;
180
205
} ) ;
181
206
182
207
test ( '#adapter.setTabIndex sets the tabIndex of the element' , ( ) => {
183
- const { root, component} = setupTest ( ) ;
184
- root . tabIndex = 4 ;
208
+ const { root, component} = setupTest ( { tabIndex : 4 } ) ;
185
209
component . getDefaultFoundation ( ) . adapter_ . setTabIndex ( 2 ) ;
186
210
assert . equal ( root . tabIndex , 2 ) ;
187
211
} ) ;
0 commit comments