@@ -85,6 +85,65 @@ describe('uiSortable', function() {
85
85
} ) ;
86
86
} ) ;
87
87
88
+ it ( 'should cancel sorting of node "Two" and "helper: function" that returns an element is used' , function ( ) {
89
+ inject ( function ( $compile , $rootScope ) {
90
+ var element ;
91
+ element = $compile ( '' . concat (
92
+ '<ul ui-sortable="opts" ng-model="items">' ,
93
+ beforeLiElement ,
94
+ '<li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li>' ,
95
+ afterLiElement +
96
+ '</ul>' ) ) ( $rootScope ) ;
97
+ $rootScope . $apply ( function ( ) {
98
+ $rootScope . opts = {
99
+ helper : function ( e , item ) {
100
+ return item . clone ( ) ;
101
+ } ,
102
+ update : function ( e , ui ) {
103
+ if ( ui . item . sortable . model === 'Two' ) {
104
+ ui . item . sortable . cancel ( ) ;
105
+ }
106
+ }
107
+ } ;
108
+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
109
+ } ) ;
110
+
111
+ host . append ( element ) ;
112
+
113
+ var li = element . find ( '[ng-repeat]:eq(1)' ) ;
114
+ var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
115
+ li . simulate ( 'drag' , { dy : dy } ) ;
116
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
117
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
118
+ // try again
119
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
120
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
121
+ li . simulate ( 'drag' , { dy : dy } ) ;
122
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
123
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
124
+ // try again
125
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
126
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
127
+ li . simulate ( 'drag' , { dy : dy } ) ;
128
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
129
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
130
+
131
+ li = element . find ( '[ng-repeat]:eq(0)' ) ;
132
+ dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
133
+ li . simulate ( 'drag' , { dy : dy } ) ;
134
+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
135
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
136
+
137
+ li = element . find ( '[ng-repeat]:eq(2)' ) ;
138
+ dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
139
+ li . simulate ( 'drag' , { dy : dy } ) ;
140
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
141
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
142
+
143
+ $ ( element ) . remove ( ) ;
144
+ } ) ;
145
+ } ) ;
146
+
88
147
it ( 'should cancel sorting of node "Two" and "helper: function" that returns a list element is used' , function ( ) {
89
148
inject ( function ( $compile , $rootScope ) {
90
149
var element ;
0 commit comments