@@ -294,143 +294,36 @@ describe('CategoryOptions', () => {
294294 } ) ;
295295
296296 describe ( 'interactions' , ( ) => {
297- it ( 'when user checks an item, only that item is added to the chips ' , ( ) => {
297+ it ( 'when user checks an item, that is emitted to the parent component ' , ( ) => {
298298 const wrapper = shallowMount ( CategoryOptions ) ;
299- const items = [ 'PbGoe2MV' ] ;
300- const item = 'PbGoe2MV' ;
301- wrapper . vm . handleCheckboxItem ( item , items ) ;
299+ const item = 'abcd' ;
300+ wrapper . vm . $emit = jest . fn ( ) ;
301+ wrapper . vm . add ( item ) ;
302302
303- expect ( wrapper . vm . chipsSelected ) . toEqual ( items ) ;
303+ expect ( wrapper . vm . $emit . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'input' ) ;
304+ expect ( wrapper . vm . $emit . mock . calls [ 0 ] [ 1 ] ) . toEqual ( [ item ] ) ;
304305 } ) ;
305- it ( 'when user checks a grandchild item, that item and all its parents are added to the dropdown ' , ( ) => {
306+ it ( 'when user unchecks an item, that is emitted to the parent component ' , ( ) => {
306307 const wrapper = shallowMount ( CategoryOptions ) ;
307- const items = [ 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ] ;
308- const item = 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ;
309- const expectedDropdown = [ 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' , 'd&WXdXWF.e#RTW9E#' , 'd&WXdXWF' ] ;
310- wrapper . vm . handleCheckboxItem ( item , items ) ;
308+ const item = 'defj' ;
309+ wrapper . vm . $emit = jest . fn ( ) ;
310+ wrapper . vm . remove ( item ) ;
311311
312- expect ( wrapper . vm . dropdownSelected . length ) . toEqual ( expectedDropdown . length ) ;
313- } ) ;
314- it ( 'when user unchecks a grandchild item that has a sibling, only that item is removed from the chips' , ( ) => {
315- const wrapper = shallowMount ( CategoryOptions , {
316- data ( ) {
317- return {
318- chipsSelected : [
319- 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ,
320- 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ,
321- 'd&WXdXWF.5QAjgfv7.BUMJJBnS' ,
322- 'd&WXdXWF.5QAjgfv7.XsWznP4o' ,
323- ] ,
324- } ;
325- } ,
326- } ) ;
327- const items = [
328- 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ,
329- 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ,
330- 'd&WXdXWF.5QAjgfv7.BUMJJBnS' ,
331- ] ;
332- const item = 'd&WXdXWF.5QAjgfv7.BUMJJBnS' ;
333- const expectedChips = [
334- 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ,
335- 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ,
336- 'd&WXdXWF.5QAjgfv7.BUMJJBnS' ,
337- ] ;
338- const expectedDropdown = [
339- 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ,
340- 'd&WXdXWF.e#RTW9E#' ,
341- 'd&WXdXWF' ,
342- 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ,
343- 'd&WXdXWF.5QAjgfv7.BUMJJBnS' ,
344- 'd&WXdXWF.5QAjgfv7' ,
345- ] ;
346- wrapper . vm . handleCheckboxItem ( item , items ) ;
347-
348- expect ( wrapper . vm . chipsSelected . length ) . toEqual ( expectedChips . length ) ;
349- expect ( wrapper . vm . dropdownSelected . length ) . toEqual ( expectedDropdown . length ) ;
350- } ) ;
351- it ( 'when user unchecks a grandchild item that has no siblings and its parents have siblings, that item and its parent are removed from the chips ' , ( ) => {
352- const wrapper = shallowMount ( CategoryOptions , {
353- data ( ) {
354- return {
355- chipsSelected : [
356- 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ,
357- 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ,
358- 'd&WXdXWF.5QAjgfv7.BUMJJBnS' ,
359- ] ,
360- } ;
361- } ,
362- } ) ;
363- const items = [ 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' , 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ] ;
364- const item = 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ;
365- const expectedChips = [ 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' , 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ] ;
366- const expectedDropdown = [
367- 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' ,
368- 'd&WXdXWF.e#RTW9E#' ,
369- 'd&WXdXWF' ,
370- 'd&WXdXWF.e#RTW9E#.CfnlTDZ#' ,
371- ] ;
372- wrapper . vm . handleCheckboxItem ( item , items ) ;
373-
374- expect ( wrapper . vm . chipsSelected . length ) . toEqual ( expectedChips . length ) ;
375- expect ( wrapper . vm . dropdownSelected . length ) . toEqual ( expectedDropdown . length ) ;
376- } ) ;
377- it ( 'when user unchecks a grandchild item that has no siblings and its parents have no siblings, that item, its parent, and the root are removed from the chips ' , ( ) => {
378- const wrapper = shallowMount ( CategoryOptions , {
379- data ( ) {
380- return { chipsSelected : [ 'd&WXdXWF.e#RTW9E#.8ZoaPsVW' , 'BCG3&slG.wZ3EAedB' ] } ;
381- } ,
382- } ) ;
383- const items = [ 'BCG3&slG.wZ3EAedB' ] ;
384- const item = 'BCG3&slG.wZ3EAedB' ;
385- const expectedChips = [ 'BCG3&slG.wZ3EAedB' ] ;
386- const expectedDropdown = [ 'BCG3&slG.wZ3EAedB' , 'BCG3&slG' ] ;
387- wrapper . vm . handleCheckboxItem ( item , items ) ;
388-
389- expect ( wrapper . vm . chipsSelected . length ) . toEqual ( expectedChips . length ) ;
390- expect ( wrapper . vm . dropdownSelected . length ) . toEqual ( expectedDropdown . length ) ;
391- } ) ;
392- it ( 'when user unchecks an item that has children and its parents have no siblings, that item and all its children are removed from the chips ' , ( ) => {
393- const wrapper = shallowMount ( CategoryOptions , {
394- data ( ) {
395- return { chipsSelected : [ 'd&WXdXWF.5QAjgfv7.BUMJJBnS' ] } ;
396- } ,
397- } ) ;
398- const items = [ 'd&WXdXWF.5QAjgfv7.BUMJJBnS' , 'd&WXdXWF' ] ;
399- const item = 'd&WXdXWF' ;
400- const expectedChips = [ ] ;
401- const expectedDropdown = [ ] ;
402- wrapper . vm . handleCheckboxItem ( item , items ) ;
403-
404- expect ( wrapper . vm . chipsSelected . length ) . toEqual ( expectedChips . length ) ;
405- expect ( wrapper . vm . dropdownSelected . length ) . toEqual ( expectedDropdown . length ) ;
406- } ) ;
407- it ( 'when user checks grandchild of parent after parent item has already been checked, the grandchild replaces the parent chip' , ( ) => {
408- const wrapper = shallowMount ( CategoryOptions , {
409- data ( ) {
410- return { chipsSelected : [ 'd&WXdXWF' ] } ;
411- } ,
412- } ) ;
413- const items = [ 'd&WXdXWF' , 'd&WXdXWF.5QAjgfv7.XsWznP4o' ] ;
414- const item = 'd&WXdXWF.5QAjgfv7.XsWznP4o' ;
415- const expectedChips = [ 'd&WXdXWF.5QAjgfv7.XsWznP4o' ] ;
416- const expectedDropdown = [ 'd&WXdXWF.5QAjgfv7.XsWznP4o' , 'd&WXdXWF.5QAjgfv7' , 'd&WXdXWF' ] ;
417- wrapper . vm . handleCheckboxItem ( item , items ) ;
418-
419- expect ( wrapper . vm . chipsSelected . length ) . toEqual ( expectedChips . length ) ;
420- expect ( wrapper . vm . dropdownSelected . length ) . toEqual ( expectedDropdown . length ) ;
312+ expect ( wrapper . vm . $emit . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'input' ) ;
313+ expect ( wrapper . vm . $emit . mock . calls [ 0 ] [ 1 ] ) . toEqual ( [ ] ) ;
421314 } ) ;
422315 } ) ;
423316
424317 describe ( 'close button on chip interactions' , ( ) => {
425318 it ( 'in the autocomplete bar, the chip is removed when user clicks on its close button' , ( ) => {
426319 const wrapper = shallowMount ( CategoryOptions , {
427320 data ( ) {
428- return { chipsSelected : [ 'remove me' , 'abc' , 'def' , 'abc.' ] } ;
321+ return { selected : [ 'remove me' , 'abc' , 'def' , 'abc.' ] } ;
429322 } ,
430323 } ) ;
431- const originalChipsLength = wrapper . vm . chipsSelected . length ;
324+ const originalChipsLength = wrapper . vm . selected . length ;
432325 wrapper . vm . remove ( 'remove me' ) ;
433- const chips = wrapper . vm . chipsSelected ;
326+ const chips = wrapper . vm . selected ;
434327
435328 expect ( chips . length ) . toEqual ( originalChipsLength - 1 ) ;
436329 } ) ;
0 commit comments