@@ -6,15 +6,13 @@ const SortableFake = {
6
6
destroy : jest . fn ( ) ,
7
7
option : jest . fn ( )
8
8
} ;
9
- const SortableFake2 = {
10
- destroy : jest . fn ( ) ,
11
- option : jest . fn ( )
12
- } ;
13
- Sortable . mockImplementationOnce ( ( ) => SortableFake )
14
- . mockImplementationOnce ( ( ) => SortableFake2 ) ;
9
+ Sortable . mockImplementation ( ( ) => SortableFake ) ;
15
10
16
11
import Vue from "vue" ;
17
12
import DraggableWithList from "./helper/DraggableWithList"
13
+ import DraggableWithModel from "./helper/DraggableWithList"
14
+ import DraggableWithTransition from "./helper/DraggableWithTransition"
15
+
18
16
import draggable from "@/vuedraggable" ;
19
17
20
18
let wrapper ;
@@ -25,51 +23,62 @@ function getEvent(name) {
25
23
return Sortable . mock . calls [ 0 ] [ 1 ] [ name ] ;
26
24
}
27
25
28
- describe ( "draggable.vue when working list" , ( ) => {
29
- beforeEach ( ( ) => {
30
- jest . resetAllMocks ( ) ;
31
- wrapper = mount ( DraggableWithList , {
32
- attachToDocument : true
33
- } ) ;
34
- vm = wrapper . vm ;
35
- element = wrapper . element ;
36
- } ) ;
37
-
38
- describe ( "when handling sort" , ( ) => {
39
- let item ;
26
+ const expectedArray = [ 0 , 1 , 3 , 4 , 5 , 6 , 7 , 2 , 8 , 9 ] ;
27
+ const expectedDomNoTransition = `<span>${ expectedArray . map ( nu => `<div>${ nu } </div>` ) . join ( '' ) } </span>` ;
28
+ const expectedDomTransition = `<div>${ expectedDomNoTransition } </div>` ;
40
29
41
- beforeEach ( async ( ) => {
42
- item = element . children [ 2 ] ;
43
- const startEvt = { item } ;
44
- getEvent ( "onStart" ) ( startEvt ) ;
45
- await Vue . nextTick ( ) ;
30
+ describe . each ( [
31
+ [ DraggableWithList , "draggable with list" , expectedDomNoTransition ] ,
32
+ [ DraggableWithModel , "draggable with model" , expectedDomNoTransition ] ,
33
+ [ DraggableWithTransition , "draggable with transition" , expectedDomTransition ]
34
+ ] )
35
+ (
36
+ "should update list with component: %s %s" ,
37
+ ( component , _ , expectedDom ) => {
46
38
47
- const firstDraggable = element . children [ 1 ] ;
48
- element . removeChild ( item ) ;
49
- element . insertBefore ( item , firstDraggable ) ;
50
- getEvent ( "onUpdate" ) ( {
51
- item,
52
- oldIndex : 2 ,
53
- newIndex : 7 ,
54
- from : element
39
+ beforeEach ( ( ) => {
40
+ jest . resetAllMocks ( ) ;
41
+ wrapper = mount ( component , {
42
+ attachToDocument : true
43
+ } ) ;
44
+ vm = wrapper . vm ;
45
+ element = wrapper . find ( 'span' ) . element ;
55
46
} ) ;
56
- await Vue . nextTick ( ) ;
57
- } )
58
47
59
- it ( "sends a change event" , async ( ) => {
60
- const draggableWrapper = wrapper . find ( draggable ) ;
61
- const expectedEvt = { moved : { element : 2 , oldIndex : 2 , newIndex : 7 } } ;
62
- expect ( draggableWrapper . emitted ( ) . change ) . toEqual ( [ [ expectedEvt ] ] ) ;
63
- } ) ;
48
+ describe ( "when handling sort" , ( ) => {
49
+ let item ;
64
50
65
- it ( "update list" , async ( ) => {
66
- expect ( wrapper . vm . array ) . toEqual ( [ 0 , 1 , 3 , 4 , 5 , 6 , 7 , 2 , 8 , 9 ] ) ;
67
- } ) ;
51
+ beforeEach ( async ( ) => {
52
+ item = element . children [ 2 ] ;
53
+ const startEvt = { item } ;
54
+ getEvent ( "onStart" ) ( startEvt ) ;
55
+ await Vue . nextTick ( ) ;
68
56
69
- it ( "updates DOM" , async ( ) => {
70
- const expectedArray = [ 0 , 1 , 3 , 4 , 5 , 6 , 7 , 2 , 8 , 9 ] ;
71
- const expectedDom = `<div>${ expectedArray . map ( nu => `<div>${ nu } </div>` ) . join ( '' ) } </div>` ;
72
- expect ( wrapper . html ( ) ) . toEqual ( expectedDom ) ;
73
- } ) ;
74
- } ) ;
75
- } ) ;
57
+ const firstDraggable = element . children [ 1 ] ;
58
+ element . removeChild ( item ) ;
59
+ element . insertBefore ( item , firstDraggable ) ;
60
+ getEvent ( "onUpdate" ) ( {
61
+ item,
62
+ oldIndex : 2 ,
63
+ newIndex : 7 ,
64
+ from : element
65
+ } ) ;
66
+ await Vue . nextTick ( ) ;
67
+ } )
68
+
69
+ it ( "sends a change event" , async ( ) => {
70
+ const draggableWrapper = wrapper . find ( draggable ) ;
71
+ const expectedEvt = { moved : { element : 2 , oldIndex : 2 , newIndex : 7 } } ;
72
+ expect ( draggableWrapper . emitted ( ) . change ) . toEqual ( [ [ expectedEvt ] ] ) ;
73
+ } ) ;
74
+
75
+ it ( "update list" , async ( ) => {
76
+ expect ( vm . array ) . toEqual ( expectedArray ) ;
77
+ } ) ;
78
+
79
+ it ( "updates DOM" , async ( ) => {
80
+ expect ( wrapper . html ( ) ) . toEqual ( expectedDom ) ;
81
+ } ) ;
82
+ } ) ;
83
+ }
84
+ )
0 commit comments