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