@@ -4,6 +4,7 @@ import {assert} from 'chai';
4
4
import { shallow } from 'enzyme' ;
5
5
import Icon from '../../../../packages/text-field/icon/index' ;
6
6
import MaterialIcon from '../../../../packages/material-icon/index' ;
7
+ import { coerceForTesting } from '../../helpers/types' ;
7
8
8
9
suite ( 'Text Field Icon' ) ;
9
10
@@ -59,7 +60,7 @@ test('#componentDidMount calls #foundation.setDisabled if disabled prop is true'
59
60
< i />
60
61
</ Icon >
61
62
) ;
62
- assert . equal ( wrapper . state ( ) . tabindex , undefined ) ;
63
+ assert . equal ( wrapper . state ( ) . tabindex , - 1 ) ; // foundation setDisabled sets tabIndex -1
63
64
assert . equal ( wrapper . state ( ) . role , undefined ) ;
64
65
} ) ;
65
66
@@ -73,6 +74,26 @@ test('#componentDidMount calls #foundation.setDisabled if disabled prop is true
73
74
assert . equal ( wrapper . state ( ) . role , undefined ) ;
74
75
} ) ;
75
76
77
+ test ( '#componentDidMount sets tabindex if prop not present but onSelect exists' , ( ) => {
78
+ // w/out tabindex onSelect will never fire && cursor: pointer is not applied
79
+ const wrapper = shallow < Icon > (
80
+ < Icon onSelect = { ( ) => { } } > < MaterialIcon icon = 'favorite' /> </ Icon > ) ;
81
+
82
+ assert . equal ( wrapper . state ( ) . tabindex , 0 ) ;
83
+ } ) ;
84
+
85
+ test (
86
+ '#componentDidUpdate will set tabindex if prop not present but updates ' +
87
+ 'with onSelect' ,
88
+ ( ) => {
89
+ const wrapper = shallow < Icon > ( < Icon > < MaterialIcon icon = 'favorite' /> </ Icon > ) ;
90
+
91
+ assert . equal ( wrapper . state ( ) . tabindex , - 1 ) ;
92
+ wrapper . setProps ( { onSelect : ( ) => { } } ) ;
93
+ assert . equal ( wrapper . state ( ) . tabindex , 0 ) ;
94
+ }
95
+ ) ;
96
+
76
97
test (
77
98
'#componentDidUpdate calls #foundation.setDisabled if ' +
78
99
'props.disabled updates' ,
@@ -201,6 +222,47 @@ test('#adapter.removeAttr for role works with Custom Component', () => {
201
222
assert . equal ( wrapper . state ( ) . role , undefined ) ;
202
223
} ) ;
203
224
225
+ test ( '#adapter.notifyIconAction calls props.onSelect' , ( ) => {
226
+ const onSelect = coerceForTesting < ( ) => void > ( td . func ( ) ) ;
227
+ const wrapper = shallow < Icon > (
228
+ < Icon onSelect = { onSelect } >
229
+ < MaterialIcon icon = 'favorite' role = 'button' />
230
+ </ Icon >
231
+ ) ;
232
+ wrapper . instance ( ) . foundation_ . adapter_ . notifyIconAction ( ) ;
233
+ td . verify ( onSelect ( ) , { times : 1 } ) ;
234
+ } ) ;
235
+
236
+ test ( 'onClick calls foundation.handleInteraction' , ( ) => {
237
+ const onSelect = coerceForTesting < ( ) => void > ( td . func ( ) ) ;
238
+ const wrapper = shallow < Icon > (
239
+ < Icon onSelect = { onSelect } >
240
+ < MaterialIcon icon = 'favorite' role = 'button' />
241
+ </ Icon >
242
+ ) ;
243
+ const evt = coerceForTesting < React . MouseEvent > ( { } ) ;
244
+ wrapper . instance ( ) . foundation_ . handleInteraction = td . func ( ) ;
245
+ wrapper . simulate ( 'click' , evt ) ;
246
+ td . verify ( wrapper . instance ( ) . foundation_ . handleInteraction ( evt ) , {
247
+ times : 1 ,
248
+ } ) ;
249
+ } ) ;
250
+
251
+ test ( 'onKeyDown call foundation.handleInteraction' , ( ) => {
252
+ const onSelect = coerceForTesting < ( ) => void > ( td . func ( ) ) ;
253
+ const wrapper = shallow < Icon > (
254
+ < Icon onSelect = { onSelect } >
255
+ < MaterialIcon icon = 'favorite' role = 'button' />
256
+ </ Icon >
257
+ ) ;
258
+ const evt = coerceForTesting < React . KeyboardEvent > ( { } ) ;
259
+ wrapper . instance ( ) . foundation_ . handleInteraction = td . func ( ) ;
260
+ wrapper . simulate ( 'keydown' , evt ) ;
261
+ td . verify ( wrapper . instance ( ) . foundation_ . handleInteraction ( evt ) , {
262
+ times : 1 ,
263
+ } ) ;
264
+ } ) ;
265
+
204
266
test ( 'updating the role reflects on DOM node' , ( ) => {
205
267
const wrapper = shallow (
206
268
< Icon >
0 commit comments