@@ -6,13 +6,14 @@ describe('uiSortable', function() {
6
6
beforeEach ( module ( 'ui.sortable' ) ) ;
7
7
beforeEach ( module ( 'ui.sortable.testHelper' ) ) ;
8
8
9
- var EXTRA_DY_PERCENTAGE , listContent , listInnerContent , simulateElementDrag ;
9
+ var EXTRA_DY_PERCENTAGE , listContent , listInnerContent , simulateElementDrag , hasUndefinedProperties ;
10
10
11
11
beforeEach ( inject ( function ( sortableTestHelper ) {
12
12
EXTRA_DY_PERCENTAGE = sortableTestHelper . EXTRA_DY_PERCENTAGE ;
13
13
listContent = sortableTestHelper . listContent ;
14
14
listInnerContent = sortableTestHelper . listInnerContent ;
15
15
simulateElementDrag = sortableTestHelper . simulateElementDrag ;
16
+ hasUndefinedProperties = sortableTestHelper . hasUndefinedProperties ;
16
17
} ) ) ;
17
18
18
19
describe ( 'Multiple sortables related' , function ( ) {
@@ -470,6 +471,83 @@ describe('uiSortable', function() {
470
471
} ) ;
471
472
} ) ;
472
473
474
+ it ( 'should properly free ui.item.sortable object' , function ( ) {
475
+ inject ( function ( $compile , $rootScope ) {
476
+ var elementTop , elementBottom , uiItem , uiItemSortable_Destroy ;
477
+ elementTop = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
478
+ elementBottom = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
479
+ $rootScope . $apply ( function ( ) {
480
+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
481
+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
482
+ $rootScope . opts = {
483
+ connectWith : '.cross-sortable' ,
484
+ start : function ( e , ui ) {
485
+ uiItem = ui . item ;
486
+ spyOn ( ui . item . sortable , '_destroy' ) . andCallThrough ( ) ;
487
+ uiItemSortable_Destroy = ui . item . sortable . _destroy ;
488
+ } ,
489
+ update : function ( e , ui ) {
490
+ uiItem . sortable = ui . item . sortable ;
491
+ if ( ui . item . scope ( ) &&
492
+ ( typeof ui . item . scope ( ) . item === 'string' ) &&
493
+ ui . item . scope ( ) . item . indexOf ( 'Two' ) >= 0 ) {
494
+ ui . item . sortable . cancel ( ) ;
495
+ }
496
+ }
497
+ } ;
498
+ } ) ;
499
+
500
+ host . append ( elementTop ) . append ( elementBottom ) . append ( '<div class="clear"></div>' ) ;
501
+
502
+ var li1 = elementTop . find ( ':eq(1)' ) ;
503
+ var li2 = elementBottom . find ( ':eq(0)' ) ;
504
+ simulateElementDrag ( li1 , li2 , 'below' ) ;
505
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
506
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
507
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
508
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
509
+ expect ( uiItemSortable_Destroy ) . toHaveBeenCalled ( ) ;
510
+ expect ( hasUndefinedProperties ( uiItem . sortable ) ) . toBe ( true ) ;
511
+ uiItem = uiItemSortable_Destroy = undefined ;
512
+
513
+ li1 = elementBottom . find ( ':eq(1)' ) ;
514
+ li2 = elementTop . find ( ':eq(1)' ) ;
515
+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
516
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
517
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
518
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
519
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
520
+ expect ( uiItemSortable_Destroy ) . toHaveBeenCalled ( ) ;
521
+ expect ( hasUndefinedProperties ( uiItem . sortable ) ) . toBe ( true ) ;
522
+ uiItem = uiItemSortable_Destroy = undefined ;
523
+
524
+ li1 = elementTop . find ( ':eq(0)' ) ;
525
+ li2 = elementBottom . find ( ':eq(0)' ) ;
526
+ simulateElementDrag ( li1 , li2 , 'below' ) ;
527
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
528
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Top One' , 'Bottom Two' , 'Bottom Three' ] ) ;
529
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
530
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
531
+ expect ( uiItemSortable_Destroy ) . toHaveBeenCalled ( ) ;
532
+ expect ( hasUndefinedProperties ( uiItem . sortable ) ) . toBe ( true ) ;
533
+ uiItem = uiItemSortable_Destroy = undefined ;
534
+
535
+ li1 = elementBottom . find ( ':eq(1)' ) ;
536
+ li2 = elementTop . find ( ':eq(1)' ) ;
537
+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
538
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
539
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
540
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
541
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
542
+ expect ( uiItemSortable_Destroy ) . toHaveBeenCalled ( ) ;
543
+ expect ( hasUndefinedProperties ( uiItem . sortable ) ) . toBe ( true ) ;
544
+ uiItem = uiItemSortable_Destroy = undefined ;
545
+
546
+ $ ( elementTop ) . remove ( ) ;
547
+ $ ( elementBottom ) . remove ( ) ;
548
+ } ) ;
549
+ } ) ;
550
+
473
551
} ) ;
474
552
475
553
} ) ;
0 commit comments