@@ -520,47 +520,52 @@ describe("draggable.vue when initialized with list", () => {
520
520
} )
521
521
} )
522
522
523
- describe ( "when update is called" , ( ) => {
524
- beforeEach ( ( ) => {
525
- const firstDraggable = element . children [ 1 ] ;
526
- element . removeChild ( item ) ;
527
- element . insertBefore ( item , firstDraggable ) ;
528
- const update = getEvent ( "onUpdate" ) ;
529
- update ( {
530
- item,
531
- oldIndex : 2 ,
532
- newIndex : 1 ,
533
- from : element
523
+ describe . each ( [
524
+ [ 1 , [ "b" , "a" , "c" ] ] ,
525
+ [ 3 , [ "a" , "c" , "b" ] ]
526
+ ] )
527
+ ( "when update is called with new index being %i" ,
528
+ ( index , expectedList ) => {
529
+ beforeEach ( ( ) => {
530
+ const firstDraggable = element . children [ index ] ;
531
+ element . removeChild ( item ) ;
532
+ element . insertBefore ( item , firstDraggable ) ;
533
+ const update = getEvent ( "onUpdate" ) ;
534
+ update ( {
535
+ item,
536
+ oldIndex : 2 ,
537
+ newIndex : index ,
538
+ from : element
539
+ } ) ;
540
+ } )
541
+
542
+ it ( "DOM changes should be reverted" , async ( ) => {
543
+ await Vue . nextTick ( ) ;
544
+ expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
545
+ } )
546
+
547
+ it ( "list should be updated" , async ( ) => {
548
+ await Vue . nextTick ( ) ;
549
+ expect ( vm . list ) . toEqual ( expectedList ) ;
550
+ } )
551
+
552
+ it ( "sends a update event" , async ( ) => {
553
+ await Vue . nextTick ( ) ;
554
+ const expectedEvt = {
555
+ item,
556
+ oldIndex : 2 ,
557
+ newIndex : index ,
558
+ from : element
559
+ } ;
560
+ expect ( wrapper . emitted ( ) . update ) . toEqual ( [ [ expectedEvt ] ] ) ;
561
+ } )
562
+
563
+ it ( "sends a change event" , async ( ) => {
564
+ await Vue . nextTick ( ) ;
565
+ const expectedEvt = { moved : { element : "b" , oldIndex : 1 , newIndex : index - 1 } } ;
566
+ expect ( wrapper . emitted ( ) . change ) . toEqual ( [ [ expectedEvt ] ] ) ;
567
+ } )
534
568
} ) ;
535
- } )
536
-
537
- it ( "DOM changes should be reverted" , async ( ) => {
538
- await Vue . nextTick ( ) ;
539
- expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
540
- } )
541
-
542
- it ( "list should be updated" , async ( ) => {
543
- await Vue . nextTick ( ) ;
544
- expect ( vm . list ) . toEqual ( [ "b" , "a" , "c" ] ) ;
545
- } )
546
-
547
- it ( "sends a update event" , async ( ) => {
548
- await Vue . nextTick ( ) ;
549
- const expectedEvt = {
550
- item,
551
- oldIndex : 2 ,
552
- newIndex : 1 ,
553
- from : element
554
- } ;
555
- expect ( wrapper . emitted ( ) . update ) . toEqual ( [ [ expectedEvt ] ] ) ;
556
- } )
557
-
558
- it ( "sends a change event" , async ( ) => {
559
- await Vue . nextTick ( ) ;
560
- const expectedEvt = { moved : { element : "b" , oldIndex : 1 , newIndex : 0 } } ;
561
- expect ( wrapper . emitted ( ) . change ) . toEqual ( [ [ expectedEvt ] ] ) ;
562
- } )
563
- } ) ;
564
569
565
570
describe ( "when sending DragEnd" , ( ) => {
566
571
let endEvt ;
0 commit comments