@@ -6,11 +6,12 @@ describe('uiSortable', function() {
6
6
beforeEach ( module ( 'ui.sortable' ) ) ;
7
7
beforeEach ( module ( 'ui.sortable.testHelper' ) ) ;
8
8
9
- var EXTRA_DY_PERCENTAGE , listContent ;
9
+ var EXTRA_DY_PERCENTAGE , listContent , listInnerContent ;
10
10
11
11
beforeEach ( inject ( function ( sortableTestHelper ) {
12
12
EXTRA_DY_PERCENTAGE = sortableTestHelper . EXTRA_DY_PERCENTAGE ;
13
13
listContent = sortableTestHelper . listContent ;
14
+ listInnerContent = sortableTestHelper . listInnerContent ;
14
15
} ) ) ;
15
16
16
17
describe ( 'Multiple sortables related' , function ( ) {
@@ -346,6 +347,66 @@ describe('uiSortable', function() {
346
347
} ) ;
347
348
} ) ;
348
349
350
+ it ( 'should update model when sorting between nested sortables' , function ( ) {
351
+ inject ( function ( $compile , $rootScope ) {
352
+ var elementTree ;
353
+
354
+ elementTree = $compile ( '' . concat (
355
+ '<ul ui-sortable="sortableOptions" ng-model="items" class="apps-container outterList" style="float: left;margin-left: 10px;padding-bottom: 10px;">' ,
356
+ '<li ng-repeat="item in items track by $index">' ,
357
+ '<div>' ,
358
+ '<span class="itemContent lvl1ItemContent">{{item.text}}</span>' ,
359
+ '<ul ui-sortable="sortableOptions" ng-model="item.items" class="apps-container innerList" style="float: left;margin-left: 10px;padding-bottom: 10px;">' ,
360
+ '<li ng-repeat="i in item.items track by $index">' ,
361
+ '<span class="itemContent lvl2ItemContent">{{i.text}}</span>' ,
362
+ '</li>' ,
363
+ '</ul>' ,
364
+ '</div>' ,
365
+ '</li>' ,
366
+ '</ul>' ,
367
+ '<div style="clear: both;"></div>' ) ) ( $rootScope ) ;
368
+
369
+ $rootScope . $apply ( function ( ) {
370
+ $rootScope . items = [
371
+ {
372
+ text : 'Item 1' ,
373
+ items : [ ]
374
+ } ,
375
+ {
376
+ text : 'Item 2' ,
377
+ items : [
378
+ { text : 'Item 2.1' } ,
379
+ { text : 'Item 2.2' }
380
+ ]
381
+ }
382
+ ] ;
383
+
384
+ $rootScope . sortableOptions = {
385
+ connectWith : '.apps-container'
386
+ } ;
387
+ } ) ;
388
+
389
+ host . append ( elementTree ) ;
390
+
391
+ var li = elementTree . find ( '.innerList:last' ) . find ( ':last' ) ;
392
+ li . simulate ( 'drag' , { dx : - 200 , moves : 30 } ) ;
393
+ expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) )
394
+ . toEqual ( [ 'Item 1' , 'Item 2' ] ) ;
395
+ expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) )
396
+ . toEqual ( listInnerContent ( elementTree , '.lvl1ItemContent' ) ) ;
397
+ expect ( $rootScope . items [ 0 ] . items . map ( function ( x ) { return x . text ; } ) )
398
+ . toEqual ( [ ] ) ;
399
+ expect ( $rootScope . items [ 0 ] . items . map ( function ( x ) { return x . text ; } ) )
400
+ . toEqual ( listInnerContent ( elementTree . find ( '.innerList:eq(0)' ) , '.lvl2ItemContent' ) ) ;
401
+ expect ( $rootScope . items [ 1 ] . items . map ( function ( x ) { return x . text ; } ) )
402
+ . toEqual ( [ 'Item 2.1' , 'Item 2.2' ] ) ;
403
+ expect ( $rootScope . items [ 1 ] . items . map ( function ( x ) { return x . text ; } ) )
404
+ . toEqual ( listInnerContent ( elementTree . find ( '.innerList:eq(1)' ) , '.lvl2ItemContent' ) ) ;
405
+
406
+ $ ( elementTree ) . remove ( ) ;
407
+ } ) ;
408
+ } ) ;
409
+
349
410
} ) ;
350
411
351
412
} ) ;
0 commit comments