@@ -15,12 +15,18 @@ let props;
15
15
let items ;
16
16
let element ;
17
17
let input ;
18
+ const initialRender = "<div><header></header><div>a</div><div>b</div><div>c</div><footer></footer></div>" ;
19
+
20
+ function getEvent ( name ) {
21
+ return Sortable . mock . calls [ 0 ] [ 1 ] [ name ] ;
22
+ }
18
23
19
24
describe ( "draggable.vue" , ( ) => {
20
25
beforeEach ( ( ) => {
21
26
Sortable . mockClear ( ) ;
22
27
items = [ "a" , "b" , "c" ] ;
23
28
wrapper = shallowMount ( draggable , {
29
+ attachToDocument : true ,
24
30
propsData : {
25
31
list : items
26
32
} ,
@@ -110,6 +116,10 @@ describe("draggable.vue", () => {
110
116
expect ( wrapper . html ( ) ) . toContain ( "<div>a</div><div>b</div><div>c</div>" ) ;
111
117
} )
112
118
119
+ it ( "renders correctly" , ( ) => {
120
+ expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
121
+ } )
122
+
113
123
test . each ( [
114
124
"ul" ,
115
125
"span" ,
@@ -189,7 +199,7 @@ describe("draggable.vue", () => {
189
199
) (
190
200
"when event %s is emitted from sortable" ,
191
201
async ( evt , vueEvt ) => {
192
- const callBack = Sortable . mock . calls [ 0 ] [ 1 ] [ evt ] ;
202
+ const callBack = getEvent ( evt ) ;
193
203
const evtInfo = {
194
204
data : { }
195
205
} ;
@@ -200,4 +210,63 @@ describe("draggable.vue", () => {
200
210
} ) ;
201
211
}
202
212
) ;
213
+
214
+ describe ( "when initiating a drag operation" , ( ) => {
215
+ let evt ;
216
+ let item ;
217
+ beforeEach ( ( ) => {
218
+ item = element . children [ 2 ] ;
219
+ evt = { item } ;
220
+ const start = getEvent ( "onStart" ) ;
221
+ start ( evt ) ;
222
+ } ) ;
223
+
224
+ it ( "sends a start event" , async ( ) => {
225
+ await Vue . nextTick ( ) ;
226
+ expect ( wrapper . emitted ( ) ) . toEqual ( {
227
+ start : [ [ evt ] ]
228
+ } ) ;
229
+ } )
230
+
231
+ it ( "sets context" , async ( ) => {
232
+ await Vue . nextTick ( ) ;
233
+ expect ( vm . context ) . toEqual ( {
234
+ element : "b" ,
235
+ index : 1
236
+ } ) ;
237
+ } )
238
+
239
+ describe ( "when remove is called" , ( ) => {
240
+ beforeEach ( ( ) => {
241
+ element . removeChild ( item ) ;
242
+ const remove = getEvent ( "onRemove" ) ;
243
+ remove ( {
244
+ item,
245
+ oldIndex : 2
246
+ } ) ;
247
+ } )
248
+
249
+ it ( "DOM changes should be reverted" , async ( ) => {
250
+ await Vue . nextTick ( ) ;
251
+ expect ( wrapper . html ( ) ) . toEqual ( initialRender ) ;
252
+ } )
253
+
254
+ it ( "list should be updated" , async ( ) => {
255
+ await Vue . nextTick ( ) ;
256
+ expect ( vm . list ) . toEqual ( [ "a" , "c" ] ) ;
257
+ } )
258
+
259
+ it ( "sends a remove event" , async ( ) => {
260
+ await Vue . nextTick ( ) ;
261
+ const expectedEvt = { item, oldIndex : 2 } ;
262
+ expect ( wrapper . emitted ( ) . remove ) . toEqual ( [ [ expectedEvt ] ] ) ;
263
+ } )
264
+
265
+ it ( "sends a change event" , async ( ) => {
266
+ await Vue . nextTick ( ) ;
267
+ const expectedEvt = { removed : { element : "b" , oldIndex : 1 } } ;
268
+ expect ( wrapper . emitted ( ) . change ) . toEqual ( [ [ expectedEvt ] ] ) ;
269
+ } )
270
+ } )
271
+ } ) ;
203
272
} ) ;
0 commit comments