@@ -13,6 +13,14 @@ test('creates foundation', () => {
13
13
assert . exists ( wrapper . instance ( ) . foundation ) ;
14
14
} ) ;
15
15
16
+ test ( '#componentWillUnmount destroys foundation' , ( ) => {
17
+ const wrapper = shallow < Chip > ( < Chip id = '2' /> ) ;
18
+ const foundation = wrapper . instance ( ) . foundation ;
19
+ foundation . destroy = td . func ( ) ;
20
+ wrapper . unmount ( ) ;
21
+ td . verify ( foundation . destroy ( ) , { times : 1 } ) ;
22
+ } ) ;
23
+
16
24
test ( 'calls setSelected if props.selected is true (#foundation.setSelected)' , ( ) => {
17
25
const wrapper = mount < Chip > (
18
26
< Chip id = '1' selected >
@@ -22,6 +30,36 @@ test('calls setSelected if props.selected is true (#foundation.setSelected)', ()
22
30
assert . isTrue ( wrapper . state ( ) . classList . has ( 'mdc-chip--selected' ) ) ;
23
31
} ) ;
24
32
33
+
34
+ test ( 'renders a Chip with foundation.shouldRemoveOnTrailingIconClick set to true' , ( ) => {
35
+ const wrapper = shallow < Chip > ( < Chip id = '3' /> ) ;
36
+ assert . isTrue ( wrapper . instance ( ) . foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
37
+ } ) ;
38
+
39
+ test ( '#componentDidMount sets #foundation.shouldRemoveOnTrailingIconClick to false if prop false' , ( ) => {
40
+ const wrapper = shallow < Chip > ( < Chip id = '4' shouldRemoveOnTrailingIconClick = { false } /> ) ;
41
+ assert . isFalse ( wrapper . instance ( ) . foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
42
+ } ) ;
43
+
44
+ test ( 'when props.shouldRemoveOnTrailingIconClick updates to false, ' +
45
+ ' #foundation.setShouldRemoveOnTrailingIconClick is called ' , ( ) => {
46
+ const wrapper = shallow < Chip > ( < Chip id = '5' shouldRemoveOnTrailingIconClick /> ) ;
47
+ assert . isTrue ( wrapper . instance ( ) . foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
48
+ wrapper . instance ( ) . foundation . setShouldRemoveOnTrailingIconClick = td . func ( ) ;
49
+ wrapper . setProps ( { shouldRemoveOnTrailingIconClick : false } ) ;
50
+ td . verify ( wrapper . instance ( ) . foundation . setShouldRemoveOnTrailingIconClick ( false ) , { times : 1 } ) ;
51
+ } ) ;
52
+
53
+
54
+ test ( 'when props.shouldRemoveOnTrailingIconClick updates to true, ' +
55
+ ' #foundation.setShouldRemoveOnTrailingIconClick is called ' , ( ) => {
56
+ const wrapper = shallow < Chip > ( < Chip id = '6' shouldRemoveOnTrailingIconClick = { false } /> ) ;
57
+ assert . isFalse ( wrapper . instance ( ) . foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
58
+ wrapper . instance ( ) . foundation . setShouldRemoveOnTrailingIconClick = td . func ( ) ;
59
+ wrapper . setProps ( { shouldRemoveOnTrailingIconClick : true } ) ;
60
+ td . verify ( wrapper . instance ( ) . foundation . setShouldRemoveOnTrailingIconClick ( true ) , { times : 1 } ) ;
61
+ } ) ;
62
+
25
63
test ( 'classNames adds classes' , ( ) => {
26
64
const wrapper = shallow ( < Chip id = '1' className = 'test-class-name' /> ) ;
27
65
assert . isTrue ( wrapper . hasClass ( 'test-class-name' ) ) ;
@@ -139,6 +177,13 @@ test('#adapter.notifySelection calls #props.handleSelect w/ chipId and selected
139
177
td . verify ( handleSelect ( '123' , true ) , { times : 1 } ) ;
140
178
} ) ;
141
179
180
+ test ( '#adapter.notifyTrailingIconInteraction calls #props.handleTrailingIconInteraction w/ chipId' , ( ) => {
181
+ const handleTrailingIconInteraction = coerceForTesting < ( id : string ) => void > ( td . func ( ) ) ;
182
+ const wrapper = shallow < Chip > ( < Chip id = '123' handleTrailingIconInteraction = { handleTrailingIconInteraction } /> ) ;
183
+ wrapper . instance ( ) . foundation . adapter_ . notifyTrailingIconInteraction ( ) ;
184
+ td . verify ( handleTrailingIconInteraction ( '123' ) , { times : 1 } ) ;
185
+ } ) ;
186
+
142
187
test ( 'on click calls #props.onClick' , ( ) => {
143
188
const onClick = coerceForTesting < ( event : React . MouseEvent ) => void > ( td . func ( ) ) ;
144
189
const wrapper = shallow < Chip > ( < Chip id = '1' onClick = { onClick } /> ) ;
@@ -229,9 +274,9 @@ test('renders leadingIcon with state.leadingIconClassList', () => {
229
274
) ;
230
275
} ) ;
231
276
232
- test ( 'renders remove icon' , ( ) => {
233
- const removeIcon = < i className = 'remove-icon' /> ;
234
- const wrapper = shallow ( < Chip id = '1' removeIcon = { removeIcon } /> ) ;
277
+ test ( 'renders trailing icon' , ( ) => {
278
+ const trailingIcon = < i className = 'remove-icon' /> ;
279
+ const wrapper = shallow ( < Chip id = '1' trailingIcon = { trailingIcon } /> ) ;
235
280
assert . equal (
236
281
wrapper
237
282
. children ( )
@@ -241,9 +286,9 @@ test('renders remove icon', () => {
241
286
) ;
242
287
} ) ;
243
288
244
- test ( 'renders remove icon with class name' , ( ) => {
245
- const removeIcon = < i className = 'remove-icon' /> ;
246
- const wrapper = shallow ( < Chip id = '1' removeIcon = { removeIcon } /> ) ;
289
+ test ( 'renders trailing icon with class name' , ( ) => {
290
+ const trailingIcon = < i className = 'remove-icon' /> ;
291
+ const wrapper = shallow ( < Chip id = '1' trailingIcon = { trailingIcon } /> ) ;
247
292
assert . isTrue (
248
293
wrapper
249
294
. children ( )
@@ -252,9 +297,9 @@ test('renders remove icon with class name', () => {
252
297
) ;
253
298
} ) ;
254
299
255
- test ( 'renders remove icon with base class names' , ( ) => {
256
- const removeIcon = < i className = 'remove-icon' /> ;
257
- const wrapper = shallow ( < Chip id = '1' removeIcon = { removeIcon } /> ) ;
300
+ test ( 'renders trailing icon with base class names' , ( ) => {
301
+ const trailingIcon = < i className = 'remove-icon' /> ;
302
+ const wrapper = shallow ( < Chip id = '1' trailingIcon = { trailingIcon } /> ) ;
258
303
assert . isTrue (
259
304
wrapper
260
305
. children ( )
@@ -269,9 +314,9 @@ test('renders remove icon with base class names', () => {
269
314
) ;
270
315
} ) ;
271
316
272
- test ( 'remove icon click calls #foundation.handleTrailingIconInteraction' , ( ) => {
273
- const removeIcon = < i className = 'remove-icon' /> ;
274
- const wrapper = shallow < Chip > ( < Chip id = '1' removeIcon = { removeIcon } /> ) ;
317
+ test ( 'trailing icon click calls #foundation.handleTrailingIconInteraction' , ( ) => {
318
+ const trailingIcon = < i className = 'remove-icon' /> ;
319
+ const wrapper = shallow < Chip > ( < Chip id = '1' trailingIcon = { trailingIcon } /> ) ;
275
320
wrapper . instance ( ) . foundation . handleTrailingIconInteraction = td . func ( ) ;
276
321
const evt = { } ;
277
322
wrapper
@@ -283,9 +328,9 @@ test('remove icon click calls #foundation.handleTrailingIconInteraction', () =>
283
328
} ) ;
284
329
} ) ;
285
330
286
- test ( 'remove icon keydown calls #foundation.handleTrailingIconInteraction' , ( ) => {
287
- const removeIcon = < i className = 'remove-icon' /> ;
288
- const wrapper = shallow < Chip > ( < Chip id = '1' removeIcon = { removeIcon } /> ) ;
331
+ test ( 'trailing icon keydown calls #foundation.handleTrailingIconInteraction' , ( ) => {
332
+ const trailingIcon = < i className = 'remove-icon' /> ;
333
+ const wrapper = shallow < Chip > ( < Chip id = '1' trailingIcon = { trailingIcon } /> ) ;
289
334
wrapper . instance ( ) . foundation . handleTrailingIconInteraction = td . func ( ) ;
290
335
const evt = { } ;
291
336
wrapper
@@ -297,6 +342,7 @@ test('remove icon keydown calls #foundation.handleTrailingIconInteraction', () =
297
342
} ) ;
298
343
} ) ;
299
344
345
+
300
346
test ( 'calls #foundation.handleTransitionEnd on transitionend event' , ( ) => {
301
347
const wrapper = shallow < Chip > ( < Chip id = '1' /> ) ;
302
348
wrapper . instance ( ) . foundation . handleTransitionEnd = td . func ( ) ;
0 commit comments