@@ -947,6 +947,92 @@ describe('uiSortable', function() {
947
947
} ) ;
948
948
} ) ;
949
949
950
+ it ( 'should properly set ui.item.sortable.droptargetModel when using data-ui-sortable' , function ( ) {
951
+ inject ( function ( $compile , $rootScope ) {
952
+ var elementTop , elementBottom , updateCallbackExpectations ;
953
+ elementTop = $compile ( '' . concat (
954
+ '<ul data-ui-sortable="opts" class="cross-sortable" data-ng-model="itemsTop">' ,
955
+ beforeLiElement ,
956
+ '<li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li>' ,
957
+ afterLiElement ,
958
+ '</ul>' ) ) ( $rootScope ) ;
959
+ elementBottom = $compile ( '' . concat (
960
+ '<ul data-ui-sortable="opts" class="cross-sortable" data-ng-model="itemsBottom">' ,
961
+ beforeLiElement ,
962
+ '<li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li>' ,
963
+ afterLiElement ,
964
+ '</ul>' ) ) ( $rootScope ) ;
965
+ $rootScope . $apply ( function ( ) {
966
+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
967
+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
968
+ $rootScope . opts = {
969
+ connectWith : '.cross-sortable' ,
970
+ update : function ( e , ui ) {
971
+ if ( ui . item . sortable . model &&
972
+ ( typeof ui . item . sortable . model === 'string' ) &&
973
+ ui . item . sortable . model . indexOf ( 'Two' ) >= 0 ) {
974
+ ui . item . sortable . cancel ( ) ;
975
+ }
976
+ updateCallbackExpectations ( ui . item . sortable ) ;
977
+ }
978
+ } ;
979
+ } ) ;
980
+
981
+ host . append ( elementTop ) . append ( elementBottom ) . append ( '<div class="clear"></div>' ) ;
982
+
983
+ var li1 = elementTop . find ( '[ng-repeat]:eq(1)' ) ;
984
+ var li2 = elementBottom . find ( '[ng-repeat]:eq(0)' ) ;
985
+ updateCallbackExpectations = function ( uiItemSortable ) {
986
+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsBottom ) ;
987
+ } ;
988
+ simulateElementDrag ( li1 , li2 , { place : 'below' , extradx : - 20 , extrady : - 11 } ) ;
989
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
990
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
991
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
992
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
993
+ updateCallbackExpectations = undefined ;
994
+
995
+ li1 = elementBottom . find ( '[ng-repeat]:eq(1)' ) ;
996
+ li2 = elementTop . find ( '[ng-repeat]:eq(1)' ) ;
997
+ updateCallbackExpectations = function ( uiItemSortable ) {
998
+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsTop ) ;
999
+ } ;
1000
+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 11 } ) ;
1001
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
1002
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
1003
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
1004
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
1005
+ updateCallbackExpectations = undefined ;
1006
+
1007
+ li1 = elementTop . find ( '[ng-repeat]:eq(0)' ) ;
1008
+ li2 = elementBottom . find ( '[ng-repeat]:eq(0)' ) ;
1009
+ updateCallbackExpectations = function ( uiItemSortable ) {
1010
+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsBottom ) ;
1011
+ } ;
1012
+ simulateElementDrag ( li1 , li2 , 'below' ) ;
1013
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
1014
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Top One' , 'Bottom Two' , 'Bottom Three' ] ) ;
1015
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
1016
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
1017
+ updateCallbackExpectations = undefined ;
1018
+
1019
+ li1 = elementBottom . find ( '[ng-repeat]:eq(1)' ) ;
1020
+ li2 = elementTop . find ( '[ng-repeat]:eq(1)' ) ;
1021
+ updateCallbackExpectations = function ( uiItemSortable ) {
1022
+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsTop ) ;
1023
+ } ;
1024
+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 11 } ) ;
1025
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
1026
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
1027
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
1028
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
1029
+ updateCallbackExpectations = undefined ;
1030
+
1031
+ $ ( elementTop ) . remove ( ) ;
1032
+ $ ( elementBottom ) . remove ( ) ;
1033
+ } ) ;
1034
+ } ) ;
1035
+
950
1036
it ( 'should properly set ui.item.sortable.droptargetModel when sorting between different scopes' , function ( ) {
951
1037
inject ( function ( $compile , $rootScope ) {
952
1038
var elementTop , elementBottom ,
0 commit comments