@@ -13,15 +13,18 @@ describe('uiSortable', function() {
13
13
beforeEach ( module ( 'ui.sortable.testHelper' ) ) ;
14
14
beforeEach ( module ( 'ui.sortable.testDirectives' ) ) ;
15
15
16
- var EXTRA_DY_PERCENTAGE , listContent , listFindContent , listInnerContent , beforeLiElement , afterLiElement ;
16
+ var EXTRA_DY_PERCENTAGE , listContent , listFindContent , listInnerContent , simulateElementDrag , beforeLiElement , afterLiElement , beforeDivElement , afterDivElement ;
17
17
18
18
beforeEach ( inject ( function ( sortableTestHelper ) {
19
19
EXTRA_DY_PERCENTAGE = sortableTestHelper . EXTRA_DY_PERCENTAGE ;
20
20
listContent = sortableTestHelper . listContent ;
21
21
listFindContent = sortableTestHelper . listFindContent ;
22
22
listInnerContent = sortableTestHelper . listInnerContent ;
23
+ simulateElementDrag = sortableTestHelper . simulateElementDrag ;
23
24
beforeLiElement = sortableTestHelper . extraElements && sortableTestHelper . extraElements . beforeLiElement ;
24
25
afterLiElement = sortableTestHelper . extraElements && sortableTestHelper . extraElements . afterLiElement ;
26
+ beforeDivElement = sortableTestHelper . extraElements && sortableTestHelper . extraElements . beforeDivElement ;
27
+ afterDivElement = sortableTestHelper . extraElements && sortableTestHelper . extraElements . afterDivElement ;
25
28
} ) ) ;
26
29
27
30
tests . description = 'Inner directives related' ;
@@ -35,6 +38,7 @@ describe('uiSortable', function() {
35
38
36
39
if ( ! useExtraElements ) {
37
40
beforeLiElement = afterLiElement = '' ;
41
+ beforeDivElement = afterDivElement = '' ;
38
42
}
39
43
} ) ) ;
40
44
@@ -215,6 +219,141 @@ describe('uiSortable', function() {
215
219
} ) ;
216
220
} ) ;
217
221
222
+ it ( 'should update model when the items are inside a transcluded directive and sorting between sortables' , function ( ) {
223
+ inject ( function ( $compile , $rootScope ) {
224
+ var elementTop , elementBottom ;
225
+ elementTop = $compile ( '' . concat (
226
+ '<div ui-sortable="opts" class="cross-sortable" ng-model="itemsTop">' ,
227
+ '<ui-sortable-transclusion-test-directive>' ,
228
+ beforeDivElement ,
229
+ '<div ng-repeat="item in itemsTop" id="s-top-{{$index}}" class="sortable-item">{{ item }}</div>' ,
230
+ afterDivElement ,
231
+ '</ui-sortable-simple-test-directive>' ,
232
+ '</div>' ) ) ( $rootScope ) ;
233
+ elementBottom = $compile ( '' . concat (
234
+ '<div ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom">' ,
235
+ '<ui-sortable-transclusion-test-directive>' ,
236
+ beforeDivElement ,
237
+ '<div ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}" class="sortable-item">{{ item }}</div>' ,
238
+ afterDivElement ,
239
+ '</ui-sortable-simple-test-directive>' ,
240
+ '</div>' ) ) ( $rootScope ) ;
241
+ $rootScope . $apply ( function ( ) {
242
+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
243
+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
244
+ $rootScope . opts = {
245
+ connectWith : '.cross-sortable' ,
246
+ items : '> * .sortable-item'
247
+ } ;
248
+ } ) ;
249
+
250
+ host . append ( elementTop ) . append ( elementBottom ) . append ( '<div class="clear"></div>' ) ;
251
+
252
+ var li1 = elementTop . find ( '.sortable-item:eq(0)' ) ;
253
+ var li2 = elementBottom . find ( '.sortable-item:eq(2)' ) ;
254
+ simulateElementDrag ( li1 , li2 , { place : 'above' , moves : 100 } ) ;
255
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
256
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Top One' , 'Bottom Three' ] ) ;
257
+ expect ( $rootScope . itemsTop ) . toEqual ( listFindContent ( elementTop ) ) ;
258
+ expect ( $rootScope . itemsBottom ) . toEqual ( listFindContent ( elementBottom ) ) ;
259
+
260
+ // it seems that it ony likes the last spot
261
+ li1 = elementBottom . find ( '.sortable-item:eq(2)' ) ;
262
+ li2 = elementTop . find ( '.sortable-item:eq(1)' ) ;
263
+ simulateElementDrag ( li1 , li2 , { place : 'below' , moves : 100 } ) ;
264
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' , 'Top One' ] ) ;
265
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
266
+ expect ( $rootScope . itemsTop ) . toEqual ( listFindContent ( elementTop ) ) ;
267
+ expect ( $rootScope . itemsBottom ) . toEqual ( listFindContent ( elementBottom ) ) ;
268
+
269
+ $ ( elementTop ) . remove ( ) ;
270
+ $ ( elementBottom ) . remove ( ) ;
271
+ } ) ;
272
+ } ) ;
273
+
274
+ it ( 'should properly cancel() when the items are inside a transcluded directive and sorting between sortables' , function ( ) {
275
+ inject ( function ( $compile , $rootScope ) {
276
+ var elementTop , elementBottom ;
277
+ elementTop = $compile ( '' . concat (
278
+ '<div ui-sortable="opts" class="cross-sortable" ng-model="itemsTop">' ,
279
+ '<ui-sortable-transclusion-test-directive>' ,
280
+ beforeDivElement ,
281
+ '<div ng-repeat="item in itemsTop" id="s-top-{{$index}}" class="sortable-item">{{ item }}</div>' ,
282
+ afterDivElement ,
283
+ '</ui-sortable-simple-test-directive>' ,
284
+ '</div>' ) ) ( $rootScope ) ;
285
+ elementBottom = $compile ( '' . concat (
286
+ '<div ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom">' ,
287
+ '<ui-sortable-transclusion-test-directive>' ,
288
+ beforeDivElement ,
289
+ '<div ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}" class="sortable-item">{{ item }}</div>' ,
290
+ afterDivElement ,
291
+ '</ui-sortable-simple-test-directive>' ,
292
+ '</div>' ) ) ( $rootScope ) ;
293
+ $rootScope . $apply ( function ( ) {
294
+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
295
+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
296
+ $rootScope . opts = {
297
+ connectWith : '.cross-sortable' ,
298
+ items : '> * .sortable-item' ,
299
+ update : function ( e , ui ) {
300
+ if ( ui . item . sortable . model &&
301
+ ( typeof ui . item . sortable . model === 'string' ) &&
302
+ ui . item . sortable . model . indexOf ( 'Two' ) >= 0 ) {
303
+ ui . item . sortable . cancel ( ) ;
304
+ }
305
+ }
306
+ } ;
307
+ } ) ;
308
+
309
+ host . append ( elementTop ) . append ( elementBottom ) . append ( '<div class="clear"></div>' ) ;
310
+
311
+ var li1 = elementTop . find ( '.sortable-item:eq(1)' ) ;
312
+ var li2 = elementBottom . find ( '.sortable-item:eq(0)' ) ;
313
+ simulateElementDrag ( li1 , li2 , { place : 'below' , moves : 100 } ) ;
314
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
315
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
316
+ expect ( $rootScope . itemsTop ) . toEqual ( listFindContent ( elementTop ) ) ;
317
+ expect ( $rootScope . itemsBottom ) . toEqual ( listFindContent ( elementBottom ) ) ;
318
+ // try again
319
+ li1 = elementBottom . find ( '.sortable-item:eq(1)' ) ;
320
+ li2 = elementTop . find ( '.sortable-item:eq(1)' ) ;
321
+ simulateElementDrag ( li1 , li2 , { place : 'above' , moves : 100 } ) ;
322
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
323
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
324
+ expect ( $rootScope . itemsTop ) . toEqual ( listFindContent ( elementTop ) ) ;
325
+ expect ( $rootScope . itemsBottom ) . toEqual ( listFindContent ( elementBottom ) ) ;
326
+ // try again
327
+ li1 = elementBottom . find ( '.sortable-item:eq(1)' ) ;
328
+ li2 = elementTop . find ( '.sortable-item:eq(1)' ) ;
329
+ simulateElementDrag ( li1 , li2 , { place : 'above' , moves : 100 } ) ;
330
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
331
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
332
+ expect ( $rootScope . itemsTop ) . toEqual ( listFindContent ( elementTop ) ) ;
333
+ expect ( $rootScope . itemsBottom ) . toEqual ( listFindContent ( elementBottom ) ) ;
334
+
335
+ li1 = elementTop . find ( '.sortable-item:eq(0)' ) ;
336
+ li2 = elementBottom . find ( '.sortable-item:eq(2)' ) ;
337
+ simulateElementDrag ( li1 , li2 , { place : 'above' , moves : 100 } ) ;
338
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
339
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Top One' , 'Bottom Three' ] ) ;
340
+ expect ( $rootScope . itemsTop ) . toEqual ( listFindContent ( elementTop ) ) ;
341
+ expect ( $rootScope . itemsBottom ) . toEqual ( listFindContent ( elementBottom ) ) ;
342
+
343
+ // it seems that it ony likes the last spot
344
+ li1 = elementBottom . find ( '.sortable-item:eq(2)' ) ;
345
+ li2 = elementTop . find ( '.sortable-item:eq(1)' ) ;
346
+ simulateElementDrag ( li1 , li2 , { place : 'below' , moves : 100 } ) ;
347
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' , 'Top One' ] ) ;
348
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
349
+ expect ( $rootScope . itemsTop ) . toEqual ( listFindContent ( elementTop ) ) ;
350
+ expect ( $rootScope . itemsBottom ) . toEqual ( listFindContent ( elementBottom ) ) ;
351
+
352
+ $ ( elementTop ) . remove ( ) ;
353
+ $ ( elementBottom ) . remove ( ) ;
354
+ } ) ;
355
+ } ) ;
356
+
218
357
}
219
358
220
359
[ 0 , 1 ] . forEach ( function ( useExtraElements ) {
0 commit comments