@@ -68,6 +68,77 @@ describe('uiSortable', function() {
68
68
li . simulate ( 'drag' , { dy : dy } ) ;
69
69
expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
70
70
expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
71
+ // try again
72
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
73
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
74
+ li . simulate ( 'drag' , { dy : dy } ) ;
75
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
76
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
77
+ // try again
78
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
79
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
80
+ li . simulate ( 'drag' , { dy : dy } ) ;
81
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
82
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
83
+
84
+ li = element . find ( '[ng-repeat]:eq(0)' ) ;
85
+ dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
86
+ li . simulate ( 'drag' , { dy : dy } ) ;
87
+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
88
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
89
+
90
+ li = element . find ( '[ng-repeat]:eq(2)' ) ;
91
+ dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
92
+ li . simulate ( 'drag' , { dy : dy } ) ;
93
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
94
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
95
+
96
+ $ ( element ) . remove ( ) ;
97
+ } ) ;
98
+ } ) ;
99
+
100
+ it ( 'should cancel sorting of node "Two" and "helper: function" that returns an element is used' , function ( ) {
101
+ inject ( function ( $compile , $rootScope ) {
102
+ var element ;
103
+ element = $compile ( '' . concat (
104
+ '<ul ui-sortable="opts" ng-model="items">' ,
105
+ beforeLiElement ,
106
+ '<li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li>' ,
107
+ afterLiElement +
108
+ '</ul>' ) ) ( $rootScope ) ;
109
+ $rootScope . $apply ( function ( ) {
110
+ $rootScope . opts = {
111
+ helper : function ( e , item ) {
112
+ return item . clone ( ) ;
113
+ } ,
114
+ update : function ( e , ui ) {
115
+ if ( ui . item . sortable . model === 'Two' ) {
116
+ ui . item . sortable . cancel ( ) ;
117
+ }
118
+ }
119
+ } ;
120
+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
121
+ } ) ;
122
+
123
+ host . append ( element ) ;
124
+
125
+ var li = element . find ( '[ng-repeat]:eq(1)' ) ;
126
+ var 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
+ // try again
131
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
132
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
133
+ li . simulate ( 'drag' , { dy : dy } ) ;
134
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
135
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
136
+ // try again
137
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
138
+ dy = ( 1 + 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 ) ) ;
71
142
72
143
li = element . find ( '[ng-repeat]:eq(0)' ) ;
73
144
dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
@@ -115,6 +186,18 @@ describe('uiSortable', function() {
115
186
li . simulate ( 'drag' , { dy : dy } ) ;
116
187
expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
117
188
expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
189
+ // try again
190
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
191
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
192
+ li . simulate ( 'drag' , { dy : dy } ) ;
193
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
194
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
195
+ // try again
196
+ li = element . find ( '[ng-repeat]:eq(1)' ) ;
197
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
198
+ li . simulate ( 'drag' , { dy : dy } ) ;
199
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
200
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
118
201
119
202
li = element . find ( '[ng-repeat]:eq(0)' ) ;
120
203
dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
0 commit comments