@@ -77,6 +77,25 @@ describe('uiSortable', function() {
77
77
} ) ;
78
78
} ) ;
79
79
80
+ it ( 'should refresh sortable properly after an apply [data-* anotation]' , function ( ) {
81
+ inject ( function ( $compile , $rootScope , $timeout ) {
82
+ var element ;
83
+ var childScope = $rootScope . $new ( ) ;
84
+ element = $compile ( '<ul data-ui-sortable="opts" data-ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul>' ) ( childScope ) ;
85
+ $rootScope . $apply ( function ( ) {
86
+ childScope . items = [ 'One' , 'Two' , 'Three' ] ;
87
+ childScope . opts = { } ;
88
+ } ) ;
89
+
90
+ expect ( function ( ) {
91
+ $timeout . flush ( ) ;
92
+ } ) . not . toThrow ( ) ;
93
+
94
+ expect ( childScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
95
+ expect ( childScope . items ) . toEqual ( listContent ( element ) ) ;
96
+ } ) ;
97
+ } ) ;
98
+
80
99
it ( 'should not refresh sortable if destroyed' , function ( ) {
81
100
inject ( function ( $compile , $rootScope , $timeout ) {
82
101
var element ;
@@ -94,6 +113,24 @@ describe('uiSortable', function() {
94
113
} ) ;
95
114
} ) ;
96
115
116
+ it ( 'should not refresh sortable if destroyed [data-* anotation]' , function ( ) {
117
+ inject ( function ( $compile , $rootScope , $timeout ) {
118
+ var element ;
119
+ var childScope = $rootScope . $new ( ) ;
120
+ element = $compile ( '<div><ul data-ui-sortable="opts" data-ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul></div>' ) ( childScope ) ;
121
+ $rootScope . $apply ( function ( ) {
122
+ childScope . items = [ 'One' , 'Two' , 'Three' ] ;
123
+ childScope . opts = { } ;
124
+ } ) ;
125
+
126
+ element . remove ( element . firstChild ) ;
127
+ expect ( function ( ) {
128
+ $timeout . flush ( ) ;
129
+ } ) . not . toThrow ( ) ;
130
+
131
+ } ) ;
132
+ } ) ;
133
+
97
134
it ( 'should not try to apply options to a destroyed sortable' , function ( ) {
98
135
inject ( function ( $compile , $rootScope , $timeout ) {
99
136
var element ;
@@ -115,6 +152,27 @@ describe('uiSortable', function() {
115
152
} ) ;
116
153
} ) ;
117
154
155
+ it ( 'should not try to apply options to a destroyed sortable [data-* anotation]' , function ( ) {
156
+ inject ( function ( $compile , $rootScope , $timeout ) {
157
+ var element ;
158
+ var childScope = $rootScope . $new ( ) ;
159
+ element = $compile ( '<div><ul data-ui-sortable="opts" data-ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul></div>' ) ( childScope ) ;
160
+ $rootScope . $apply ( function ( ) {
161
+ childScope . items = [ 'One' , 'Two' , 'Three' ] ;
162
+ childScope . opts = {
163
+ update : function ( ) { }
164
+ } ;
165
+
166
+ element . remove ( element . firstChild ) ;
167
+ } ) ;
168
+
169
+ expect ( function ( ) {
170
+ $timeout . flush ( ) ;
171
+ } ) . not . toThrow ( ) ;
172
+
173
+ } ) ;
174
+ } ) ;
175
+
118
176
} ) ;
119
177
120
178
} ) ;
0 commit comments