@@ -149,19 +149,21 @@ test(`#beginExit adds ${cssClasses.CHIP_EXIT} class`, () => {
149149 td . verify ( mockAdapter . addClass ( cssClasses . CHIP_EXIT ) ) ;
150150} ) ;
151151
152- test ( '#handleKeydown does not emit event on invalid key' , ( ) => {
152+ test ( '#handleInteraction does not emit event on invalid key' , ( ) => {
153153 const { foundation, mockAdapter} = setupTest ( ) ;
154- const mockKeydown = {
154+ const mockEvt = {
155155 type : 'keydown' ,
156156 key : 'Shift' ,
157157 } ;
158158
159- foundation . handleKeydown ( mockKeydown ) ;
159+ foundation . handleInteraction ( mockEvt ) ;
160160 td . verify ( mockAdapter . notifyInteraction ( ) , { times : 0 } ) ;
161161} ) ;
162162
163163const validEvents = [
164164 {
165+ type : 'click' ,
166+ } , {
165167 type : 'keydown' ,
166168 key : 'Enter' ,
167169 } , {
@@ -171,39 +173,23 @@ const validEvents = [
171173] ;
172174
173175validEvents . forEach ( ( evt ) => {
174- test ( `#handleKeydown (${ evt } ) notifies interaction` , ( ) => {
176+ test ( `#handleInteraction (${ evt } ) notifies interaction` , ( ) => {
175177 const { foundation, mockAdapter} = setupTest ( ) ;
176178
177- foundation . handleKeydown ( evt ) ;
179+ foundation . handleInteraction ( evt ) ;
178180 td . verify ( mockAdapter . notifyInteraction ( ) ) ;
179181 } ) ;
180182
181- test ( `#handleKeydown (${ evt } ) focuses the primary action` , ( ) => {
183+ test ( `#handleInteraction (${ evt } ) focuses the primary action` , ( ) => {
182184 const { foundation, mockAdapter} = setupTest ( ) ;
183185
184- foundation . handleKeydown ( evt ) ;
186+ foundation . handleInteraction ( evt ) ;
185187 td . verify ( mockAdapter . setPrimaryActionAttr ( strings . TAB_INDEX , '0' ) ) ;
186188 td . verify ( mockAdapter . setTrailingActionAttr ( strings . TAB_INDEX , '-1' ) ) ;
187189 td . verify ( mockAdapter . focusPrimaryAction ( ) ) ;
188190 } ) ;
189191} ) ;
190192
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-
207193test ( '#handleTransitionEnd notifies removal of chip on width transition end' , ( ) => {
208194 const { foundation, mockAdapter} = setupTest ( ) ;
209195 const mockEvt = {
@@ -318,106 +304,62 @@ test('#handleTransitionEnd does nothing for width property when not exiting', ()
318304 td . verify ( mockAdapter . removeClassFromLeadingIcon ( cssClasses . HIDDEN_LEADING_ICON ) , { times : 0 } ) ;
319305} ) ;
320306
321- test ( '#handleKeydown emits no custom event on invalid keys' , ( ) => {
307+ test ( '#handleTrailingIconInteraction emits no event on invalid keys' , ( ) => {
322308 const { foundation, mockAdapter} = setupTest ( ) ;
323309 const mockEvt = {
324- type : 'keydown ' ,
310+ type : 'keydowb ' ,
325311 key : 'Shift' ,
326312 stopPropagation : td . func ( 'stopPropagation' ) ,
327- target : { } ,
328313 } ;
329314
330- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
331-
332- foundation . handleKeydown ( mockEvt ) ;
315+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
333316 td . verify ( mockAdapter . notifyTrailingIconInteraction ( ) , { times : 0 } ) ;
334317} ) ;
335318
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' , ( ) => {
359320 const { foundation, mockAdapter} = setupTest ( ) ;
360321 const mockEvt = {
361322 type : 'click' ,
362323 stopPropagation : td . func ( 'stopPropagation' ) ,
363- target : { } ,
364324 } ;
365325
366- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
367-
368- foundation . handleClick ( mockEvt ) ;
326+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
369327 td . verify ( mockAdapter . notifyTrailingIconInteraction ( ) , { times : 1 } ) ;
370328 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 } ) ;
371337} ) ;
372338
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 ` , ( ) => {
374340 const { foundation, mockAdapter} = setupTest ( ) ;
375341 const mockEvt = {
376342 type : 'click' ,
377343 stopPropagation : td . func ( 'stopPropagation' ) ,
378- target : { } ,
379344 } ;
380345
381- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
346+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
382347
383- foundation . handleClick ( mockEvt ) ;
384348 assert . isTrue ( foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
385349 td . verify ( mockAdapter . addClass ( cssClasses . CHIP_EXIT ) ) ;
386350 td . verify ( mockEvt . stopPropagation ( ) ) ;
387351} ) ;
388352
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 ` +
409354 'if shouldRemoveOnTrailingIconClick_ is false' , ( ) => {
410355 const { foundation, mockAdapter} = setupTest ( ) ;
411356 const mockEvt = {
412357 type : 'click' ,
413358 stopPropagation : td . func ( 'stopPropagation' ) ,
414- target : { } ,
415359 } ;
416360
417- td . when ( mockAdapter . eventTargetHasClass ( mockEvt . target , cssClasses . TRAILING_ICON ) ) . thenReturn ( true ) ;
418-
419361 foundation . setShouldRemoveOnTrailingIconClick ( false ) ;
420- foundation . handleClick ( mockEvt ) ;
362+ foundation . handleTrailingIconInteraction ( mockEvt ) ;
421363
422364 assert . isFalse ( foundation . getShouldRemoveOnTrailingIconClick ( ) ) ;
423365 td . verify ( mockAdapter . addClass ( cssClasses . CHIP_EXIT ) , { times : 0 } ) ;
0 commit comments