@@ -149,19 +149,21 @@ test(`#beginExit adds ${cssClasses.CHIP_EXIT} class`, () => {
149
149
td . verify ( mockAdapter . addClass ( cssClasses . CHIP_EXIT ) ) ;
150
150
} ) ;
151
151
152
- test ( '#handleKeydown does not emit event on invalid key' , ( ) => {
152
+ test ( '#handleInteraction does not emit event on invalid key' , ( ) => {
153
153
const { foundation, mockAdapter} = setupTest ( ) ;
154
- const mockKeydown = {
154
+ const mockEvt = {
155
155
type : 'keydown' ,
156
156
key : 'Shift' ,
157
157
} ;
158
158
159
- foundation . handleKeydown ( mockKeydown ) ;
159
+ foundation . handleInteraction ( mockEvt ) ;
160
160
td . verify ( mockAdapter . notifyInteraction ( ) , { times : 0 } ) ;
161
161
} ) ;
162
162
163
163
const validEvents = [
164
164
{
165
+ type : 'click' ,
166
+ } , {
165
167
type : 'keydown' ,
166
168
key : 'Enter' ,
167
169
} , {
@@ -171,39 +173,23 @@ const validEvents = [
171
173
] ;
172
174
173
175
validEvents . forEach ( ( evt ) => {
174
- test ( `#handleKeydown (${ evt } ) notifies interaction` , ( ) => {
176
+ test ( `#handleInteraction (${ evt } ) notifies interaction` , ( ) => {
175
177
const { foundation, mockAdapter} = setupTest ( ) ;
176
178
177
- foundation . handleKeydown ( evt ) ;
179
+ foundation . handleInteraction ( evt ) ;
178
180
td . verify ( mockAdapter . notifyInteraction ( ) ) ;
179
181
} ) ;
180
182
181
- test ( `#handleKeydown (${ evt } ) focuses the primary action` , ( ) => {
183
+ test ( `#handleInteraction (${ evt } ) focuses the primary action` , ( ) => {
182
184
const { foundation, mockAdapter} = setupTest ( ) ;
183
185
184
- foundation . handleKeydown ( evt ) ;
186
+ foundation . handleInteraction ( evt ) ;
185
187
td . verify ( mockAdapter . setPrimaryActionAttr ( strings . TAB_INDEX , '0' ) ) ;
186
188
td . verify ( mockAdapter . setTrailingActionAttr ( strings . TAB_INDEX , '-1' ) ) ;
187
189
td . verify ( mockAdapter . focusPrimaryAction ( ) ) ;
188
190
} ) ;
189
191
} ) ;
190
192
191
- test ( '#handleClick(evt) notifies interaction' , ( ) => {
192
- const { foundation, mockAdapter} = setupTest ( ) ;
193
-
194
- foundation . handleClick ( { type : 'click' } ) ;
195
- td . verify ( mockAdapter . notifyInteraction ( ) ) ;
196
- } ) ;
197
-
198
- test ( '#handleClick(evt) focuses the primary action' , ( ) => {
199
- const { foundation, mockAdapter} = setupTest ( ) ;
200
-
201
- foundation . handleClick ( { type : 'click' } ) ;
202
- td . verify ( mockAdapter . setPrimaryActionAttr ( strings . TAB_INDEX , '0' ) ) ;
203
- td . verify ( mockAdapter . setTrailingActionAttr ( strings . TAB_INDEX , '-1' ) ) ;
204
- td . verify ( mockAdapter . focusPrimaryAction ( ) ) ;
205
- } ) ;
206
-
207
193
test ( '#handleTransitionEnd notifies removal of chip on width transition end' , ( ) => {
208
194
const { foundation, mockAdapter} = setupTest ( ) ;
209
195
const mockEvt = {
@@ -318,106 +304,62 @@ test('#handleTransitionEnd does nothing for width property when not exiting', ()
318
304
td . verify ( mockAdapter . removeClassFromLeadingIcon ( cssClasses . HIDDEN_LEADING_ICON ) , { times : 0 } ) ;
319
305
} ) ;
320
306
321
- test ( '#handleKeydown emits no custom event on invalid keys' , ( ) => {
307
+ test ( '#handleTrailingIconInteraction emits no event on invalid keys' , ( ) => {
322
308
const { foundation, mockAdapter} = setupTest ( ) ;
323
309
const mockEvt = {
324
- type : 'keydown ' ,
310
+ type : 'keydowb ' ,
325
311
key : 'Shift' ,
326
312
stopPropagation : td . func ( 'stopPropagation' ) ,
327
- target : { } ,
328
313
} ;
329
314
330
- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
331
-
332
- foundation . handleKeydown ( mockEvt ) ;
315
+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
333
316
td . verify ( mockAdapter . notifyTrailingIconInteraction ( ) , { times : 0 } ) ;
334
317
} ) ;
335
318
336
- const validKeys = [
337
- ' ' , // Space
338
- 'Enter' ,
339
- ] ;
340
-
341
- validKeys . forEach ( ( key ) => {
342
- test ( `#handleKeydown() from trailing icon emits custom event on "${ key } "` , ( ) => {
343
- const { foundation, mockAdapter} = setupTest ( ) ;
344
- const mockEvt = {
345
- type : 'keydown' ,
346
- stopPropagation : td . func ( 'stopPropagation' ) ,
347
- target : { } ,
348
- key,
349
- } ;
350
-
351
- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
352
-
353
- foundation . handleKeydown ( mockEvt ) ;
354
- td . verify ( mockAdapter . notifyTrailingIconInteraction ( ) , { times : 1 } ) ;
355
- } ) ;
356
- } ) ;
357
-
358
- test ( '#handleClick() from trailing icon emits custom event' , ( ) => {
319
+ test ( '#handleTrailingIconInteraction emits custom event on click or enter key in trailing icon' , ( ) => {
359
320
const { foundation, mockAdapter} = setupTest ( ) ;
360
321
const mockEvt = {
361
322
type : 'click' ,
362
323
stopPropagation : td . func ( 'stopPropagation' ) ,
363
- target : { } ,
364
324
} ;
365
325
366
- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
367
-
368
- foundation . handleClick ( mockEvt ) ;
326
+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
369
327
td . verify ( mockAdapter . notifyTrailingIconInteraction ( ) , { times : 1 } ) ;
370
328
td . verify ( mockEvt . stopPropagation ( ) , { times : 1 } ) ;
329
+
330
+ foundation . handleTrailingIconInteraction ( Object . assign ( mockEvt , { type : 'keydown' , key : ' ' } ) ) ;
331
+ td . verify ( mockAdapter . notifyTrailingIconInteraction ( ) , { times : 2 } ) ;
332
+ td . verify ( mockEvt . stopPropagation ( ) , { times : 2 } ) ;
333
+
334
+ foundation . handleTrailingIconInteraction ( Object . assign ( mockEvt , { type : 'keydown' , key : 'Enter' } ) ) ;
335
+ td . verify ( mockAdapter . notifyTrailingIconInteraction ( ) , { times : 3 } ) ;
336
+ td . verify ( mockEvt . stopPropagation ( ) , { times : 3 } ) ;
371
337
} ) ;
372
338
373
- test ( `#handleClick() from trailing icon adds ${ cssClasses . CHIP_EXIT } class by default` , ( ) => {
339
+ test ( `#handleTrailingIconInteraction adds ${ cssClasses . CHIP_EXIT } class by default on click in trailing icon ` , ( ) => {
374
340
const { foundation, mockAdapter} = setupTest ( ) ;
375
341
const mockEvt = {
376
342
type : 'click' ,
377
343
stopPropagation : td . func ( 'stopPropagation' ) ,
378
- target : { } ,
379
344
} ;
380
345
381
- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
346
+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
382
347
383
- foundation . handleClick ( mockEvt ) ;
384
348
assert . isTrue ( foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
385
349
td . verify ( mockAdapter . addClass ( cssClasses . CHIP_EXIT ) ) ;
386
350
td . verify ( mockEvt . stopPropagation ( ) ) ;
387
351
} ) ;
388
352
389
- validKeys . forEach ( ( key ) => {
390
- test ( `#handleKeydown({key: "${ key } "}) from trailing icon adds ${ cssClasses . CHIP_EXIT } class by default` , ( ) => {
391
- const { foundation, mockAdapter} = setupTest ( ) ;
392
- const mockEvt = {
393
- type : 'keydown' ,
394
- stopPropagation : td . func ( 'stopPropagation' ) ,
395
- target : { } ,
396
- key,
397
- } ;
398
-
399
- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
400
-
401
- foundation . handleKeydown ( mockEvt ) ;
402
- assert . isTrue ( foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
403
- td . verify ( mockAdapter . addClass ( cssClasses . CHIP_EXIT ) ) ;
404
- td . verify ( mockEvt . stopPropagation ( ) ) ;
405
- } ) ;
406
- } ) ;
407
-
408
- test ( `#handleClick() from trailing icon does not add ${ cssClasses . CHIP_EXIT } class to trailing icon ` +
353
+ test ( `#handleTrailingIconInteraction does not add ${ cssClasses . CHIP_EXIT } class on click in trailing icon ` +
409
354
'if shouldRemoveOnTrailingIconClick_ is false' , ( ) => {
410
355
const { foundation, mockAdapter} = setupTest ( ) ;
411
356
const mockEvt = {
412
357
type : 'click' ,
413
358
stopPropagation : td . func ( 'stopPropagation' ) ,
414
- target : { } ,
415
359
} ;
416
360
417
- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
418
-
419
361
foundation . setShouldRemoveOnTrailingIconClick ( false ) ;
420
- foundation . handleClick ( mockEvt ) ;
362
+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
421
363
422
364
assert . isFalse ( foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
423
365
td . verify ( mockAdapter . addClass ( cssClasses . CHIP_EXIT ) , { times : 0 } ) ;
0 commit comments