@@ -98,8 +98,8 @@ describe('uiSortable', function() {
98
98
expect ( itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
99
99
expect ( itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
100
100
101
- $ ( elementTop ) . remove ( ) ;
102
- $ ( elementBottom ) . remove ( ) ;
101
+ $ ( wrapperBottom ) . remove ( ) ;
102
+ $ ( wrapperTop ) . remove ( ) ;
103
103
} ) ;
104
104
} ) ;
105
105
@@ -725,6 +725,88 @@ describe('uiSortable', function() {
725
725
} ) ;
726
726
} ) ;
727
727
728
+ it ( 'should properly set ui.item.sortable.droptargetModel when sorting between different scopes' , function ( ) {
729
+ inject ( function ( $compile , $rootScope ) {
730
+ var elementTop , elementBottom ,
731
+ wrapperTop , wrapperBottom ,
732
+ itemsTop , itemsBottom ,
733
+ updateCallbackExpectations ;
734
+ wrapperTop = $compile ( '<div ng-controller="dummyController"><ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li></ul></div>' ) ( $rootScope ) ;
735
+ wrapperBottom = $compile ( '<div ng-controller="dummyController"><ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li></ul></div>' ) ( $rootScope ) ;
736
+
737
+ host . append ( wrapperTop ) . append ( wrapperBottom ) . append ( '<div class="clear"></div>' ) ;
738
+ $rootScope . $apply ( function ( ) {
739
+ wrapperTop . scope ( ) . itemsTop = itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
740
+ wrapperBottom . scope ( ) . itemsBottom = itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
741
+ $rootScope . opts = {
742
+ connectWith : '.cross-sortable' ,
743
+ update : function ( e , ui ) {
744
+ if ( ui . item . scope ( ) &&
745
+ ( typeof ui . item . scope ( ) . item === 'string' ) &&
746
+ ui . item . scope ( ) . item . indexOf ( 'Two' ) >= 0 ) {
747
+ ui . item . sortable . cancel ( ) ;
748
+ }
749
+ updateCallbackExpectations ( ui . item . sortable ) ;
750
+ }
751
+ } ;
752
+ } ) ;
753
+
754
+ elementTop = wrapperTop . find ( '> [ui-sortable]' ) ;
755
+ elementBottom = wrapperBottom . find ( '> [ui-sortable]' ) ;
756
+
757
+ var li1 = elementTop . find ( ':eq(1)' ) ;
758
+ var li2 = elementBottom . find ( ':eq(0)' ) ;
759
+ updateCallbackExpectations = function ( uiItemSortable ) {
760
+ expect ( uiItemSortable . droptargetModel ) . toBe ( itemsBottom ) ;
761
+ } ;
762
+ simulateElementDrag ( li1 , li2 , { place : 'below' , extradx : - 20 , extrady : - 10 } ) ;
763
+ expect ( itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
764
+ expect ( itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
765
+ expect ( itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
766
+ expect ( itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
767
+ updateCallbackExpectations = undefined ;
768
+
769
+ li1 = elementBottom . find ( ':eq(1)' ) ;
770
+ li2 = elementTop . find ( ':eq(1)' ) ;
771
+ updateCallbackExpectations = function ( uiItemSortable ) {
772
+ expect ( uiItemSortable . droptargetModel ) . toBe ( itemsTop ) ;
773
+ } ;
774
+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
775
+ expect ( itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
776
+ expect ( itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
777
+ expect ( itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
778
+ expect ( itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
779
+ updateCallbackExpectations = undefined ;
780
+
781
+ li1 = elementTop . find ( ':eq(0)' ) ;
782
+ li2 = elementBottom . find ( ':eq(0)' ) ;
783
+ updateCallbackExpectations = function ( uiItemSortable ) {
784
+ expect ( uiItemSortable . droptargetModel ) . toBe ( itemsBottom ) ;
785
+ } ;
786
+ simulateElementDrag ( li1 , li2 , 'below' ) ;
787
+ expect ( itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
788
+ expect ( itemsBottom ) . toEqual ( [ 'Bottom One' , 'Top One' , 'Bottom Two' , 'Bottom Three' ] ) ;
789
+ expect ( itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
790
+ expect ( itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
791
+ updateCallbackExpectations = undefined ;
792
+
793
+ li1 = elementBottom . find ( ':eq(1)' ) ;
794
+ li2 = elementTop . find ( ':eq(1)' ) ;
795
+ updateCallbackExpectations = function ( uiItemSortable ) {
796
+ expect ( uiItemSortable . droptargetModel ) . toBe ( itemsTop ) ;
797
+ } ;
798
+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
799
+ expect ( itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
800
+ expect ( itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
801
+ expect ( itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
802
+ expect ( itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
803
+ updateCallbackExpectations = undefined ;
804
+
805
+ $ ( wrapperTop ) . remove ( ) ;
806
+ $ ( wrapperBottom ) . remove ( ) ;
807
+ } ) ;
808
+ } ) ;
809
+
728
810
it ( 'should properly free ui.item.sortable object' , function ( ) {
729
811
inject ( function ( $compile , $rootScope ) {
730
812
var elementTop , elementBottom , uiItem , uiItemSortable_Destroy ;
0 commit comments