@@ -3,6 +3,17 @@ describe('uiSortable', function() {
3
3
// Ensure the sortable angular module is loaded
4
4
beforeEach ( module ( 'ui.sortable' ) ) ;
5
5
6
+ beforeEach ( function ( ) {
7
+ this . addMatchers ( {
8
+ toEqualListContent : function ( list ) {
9
+ if ( list && list . length ) {
10
+ return list . children ( ) . map ( function ( ) { return this . innerHTML ; } ) . toArray ( ) ;
11
+ }
12
+ return [ ] ;
13
+ }
14
+ } ) ;
15
+ } ) ;
16
+
6
17
var EXTRA_DY_PERCENTAGE = 0.25 ;
7
18
8
19
describe ( 'Simple use' , function ( ) {
@@ -60,11 +71,13 @@ describe('uiSortable', function() {
60
71
var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
61
72
li . simulate ( 'drag' , { dy : dy } ) ;
62
73
expect ( $rootScope . items ) . toEqual ( [ "One" , "Three" , "Two" ] ) ;
74
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
63
75
64
76
li = element . find ( ':eq(1)' ) ;
65
77
dy = - ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
66
78
li . simulate ( 'drag' , { dy : dy } ) ;
67
79
expect ( $rootScope . items ) . toEqual ( [ "Three" , "One" , "Two" ] ) ;
80
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
68
81
69
82
$ ( element ) . remove ( ) ;
70
83
} ) ;
@@ -92,21 +105,25 @@ describe('uiSortable', function() {
92
105
var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
93
106
li . simulate ( 'drag' , { dy : dy } ) ;
94
107
expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqual ( [ "One" , "Two" , "Three" , "Four" ] ) ;
108
+ expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqualListContent ( element ) ;
95
109
96
110
li = element . find ( ':eq(1)' ) ;
97
111
dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
98
112
li . simulate ( 'drag' , { dy : dy } ) ;
99
113
expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqual ( [ "One" , "Three" , "Four" , "Two" ] ) ;
114
+ expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqualListContent ( element ) ;
100
115
101
116
li = element . find ( ':eq(2)' ) ;
102
117
dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
103
118
li . simulate ( 'drag' , { dy : dy } ) ;
104
119
expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqual ( [ "Four" , "One" , "Three" , "Two" ] ) ;
120
+ expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqualListContent ( element ) ;
105
121
106
122
li = element . find ( ':eq(3)' ) ;
107
123
dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
108
124
li . simulate ( 'drag' , { dy : dy } ) ;
109
125
expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqual ( [ "Four" , "Two" , "One" , "Three" ] ) ;
126
+ expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqualListContent ( element ) ;
110
127
111
128
// also placing right above the locked node seems a bit harder !?!?
112
129
@@ -131,11 +148,13 @@ describe('uiSortable', function() {
131
148
var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
132
149
li . simulate ( 'drag' , { dy : dy } ) ;
133
150
expect ( $rootScope . items ) . toEqual ( [ "One" , "Three" , "Two" ] ) ;
151
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
134
152
135
153
li = element . find ( ':eq(1)' ) ;
136
154
dy = - ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
137
155
li . simulate ( 'drag' , { dy : dy } ) ;
138
156
expect ( $rootScope . items ) . toEqual ( [ "Three" , "One" , "Two" ] ) ;
157
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
139
158
140
159
$ ( element ) . remove ( ) ;
141
160
} ) ;
@@ -158,11 +177,13 @@ describe('uiSortable', function() {
158
177
var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
159
178
li . simulate ( 'drag' , { dy : dy } ) ;
160
179
expect ( $rootScope . items ) . toEqual ( [ "One" , "Three" , "Two" ] ) ;
180
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
161
181
162
182
li = element . find ( ':eq(1)' ) ;
163
183
dy = - ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
164
184
li . simulate ( 'drag' , { dy : dy } ) ;
165
185
expect ( $rootScope . items ) . toEqual ( [ "Three" , "One" , "Two" ] ) ;
186
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
166
187
167
188
$ ( element ) . remove ( ) ;
168
189
} ) ;
@@ -203,13 +224,17 @@ describe('uiSortable', function() {
203
224
li1 . simulate ( 'drag' , { dy : dy } ) ;
204
225
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top Three" ] ) ;
205
226
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Top One" , "Bottom Two" , "Bottom Three" ] ) ;
227
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
228
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
206
229
207
230
li1 = elementBottom . find ( ':eq(1)' ) ;
208
231
li2 = elementTop . find ( ':eq(1)' ) ;
209
232
dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
210
233
li1 . simulate ( 'drag' , { dy : dy } ) ;
211
234
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top One" , "Top Three" ] ) ;
212
235
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
236
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
237
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
213
238
214
239
$ ( elementTop ) . remove ( ) ;
215
240
$ ( elementBottom ) . remove ( ) ;
@@ -238,13 +263,17 @@ describe('uiSortable', function() {
238
263
li1 . simulate ( 'drag' , { dy : dy } ) ;
239
264
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top Three" ] ) ;
240
265
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Top One" , "Bottom Two" , "Bottom Three" ] ) ;
266
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
267
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
241
268
242
269
li1 = elementBottom . find ( ':eq(1)' ) ;
243
270
li2 = elementTop . find ( ':eq(1)' ) ;
244
271
dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
245
272
li1 . simulate ( 'drag' , { dy : dy } ) ;
246
273
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top One" , "Top Three" ] ) ;
247
274
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
275
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
276
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
248
277
249
278
$ ( elementTop ) . remove ( ) ;
250
279
$ ( elementBottom ) . remove ( ) ;
@@ -273,13 +302,17 @@ describe('uiSortable', function() {
273
302
li1 . simulate ( 'drag' , { dy : dy } ) ;
274
303
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top Three" ] ) ;
275
304
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Top One" , "Bottom Two" , "Bottom Three" ] ) ;
305
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
306
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
276
307
277
308
li1 = elementBottom . find ( ':eq(1)' ) ;
278
309
li2 = elementTop . find ( ':eq(1)' ) ;
279
310
dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
280
311
li1 . simulate ( 'drag' , { dy : dy } ) ;
281
312
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top One" , "Top Three" ] ) ;
282
313
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
314
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
315
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
283
316
284
317
$ ( elementTop ) . remove ( ) ;
285
318
$ ( elementBottom ) . remove ( ) ;
@@ -324,16 +357,19 @@ describe('uiSortable', function() {
324
357
var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
325
358
li . simulate ( 'drag' , { dy : dy } ) ;
326
359
expect ( $rootScope . items ) . toEqual ( [ "One" , "Two" , "Three" ] ) ;
360
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
327
361
328
362
li = element . find ( ':eq(0)' ) ;
329
363
dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
330
364
li . simulate ( 'drag' , { dy : dy } ) ;
331
365
expect ( $rootScope . items ) . toEqual ( [ "Two" , "Three" , "One" ] ) ;
366
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
332
367
333
368
li = element . find ( ':eq(2)' ) ;
334
369
dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
335
370
li . simulate ( 'drag' , { dy : dy } ) ;
336
371
expect ( $rootScope . items ) . toEqual ( [ "One" , "Two" , "Three" ] ) ;
372
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
337
373
338
374
$ ( element ) . remove ( ) ;
339
375
} ) ;
@@ -367,27 +403,35 @@ describe('uiSortable', function() {
367
403
li1 . simulate ( 'drag' , { dy : dy } ) ;
368
404
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top One" , "Top Two" , "Top Three" ] ) ;
369
405
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
406
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
407
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
370
408
371
409
li1 = elementBottom . find ( ':eq(1)' ) ;
372
410
li2 = elementTop . find ( ':eq(1)' ) ;
373
411
dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
374
412
li1 . simulate ( 'drag' , { dy : dy } ) ;
375
413
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top One" , "Top Two" , "Top Three" ] ) ;
376
414
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
415
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
416
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
377
417
378
418
li1 = elementTop . find ( ':eq(0)' ) ;
379
419
li2 = elementBottom . find ( ':eq(0)' ) ;
380
420
dy = EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) + ( li2 . position ( ) . top - li1 . position ( ) . top ) ;
381
421
li1 . simulate ( 'drag' , { dy : dy } ) ;
382
422
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top Three" ] ) ;
383
423
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Top One" , "Bottom Two" , "Bottom Three" ] ) ;
424
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
425
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
384
426
385
427
li1 = elementBottom . find ( ':eq(1)' ) ;
386
428
li2 = elementTop . find ( ':eq(1)' ) ;
387
429
dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
388
430
li1 . simulate ( 'drag' , { dy : dy } ) ;
389
431
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top One" , "Top Three" ] ) ;
390
432
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
433
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
434
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
391
435
392
436
$ ( elementTop ) . remove ( ) ;
393
437
$ ( elementBottom ) . remove ( ) ;
@@ -416,7 +460,8 @@ describe('uiSortable', function() {
416
460
li . simulate ( 'drag' , { dy : dy } ) ;
417
461
expect ( $rootScope . items ) . toEqual ( [ "One" , "Three" , "Two" ] ) ;
418
462
expect ( $rootScope . logs ) . toEqual ( [ "Moved element Two" ] ) ;
419
- expect ( logsElement . find ( 'li' ) . html ( ) ) . toEqual ( "Moved element Two" ) ;
463
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
464
+ expect ( $rootScope . logs ) . toEqualListContent ( logsElement ) ;
420
465
421
466
$ ( element ) . remove ( ) ;
422
467
$ ( logsElement ) . remove ( ) ;
@@ -446,7 +491,8 @@ describe('uiSortable', function() {
446
491
li . simulate ( 'drag' , { dy : dy } ) ;
447
492
expect ( $rootScope . items ) . toEqual ( [ "One" , "Three" , "Two" ] ) ;
448
493
expect ( $rootScope . logs ) . toEqual ( [ "Moved element Two" ] ) ;
449
- expect ( logsElement . find ( 'li' ) . html ( ) ) . toEqual ( "Moved element Two" ) ;
494
+ expect ( $rootScope . items ) . toEqualListContent ( element ) ;
495
+ expect ( $rootScope . logs ) . toEqualListContent ( logsElement ) ;
450
496
451
497
$ ( element ) . remove ( ) ;
452
498
$ ( logsElement ) . remove ( ) ;
0 commit comments