Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 92cdc79

Browse files
thgreasidouglasduteil
authored andcommitted
Testing if sortable works after a reverted (not dropped) drag.
As per the case mentioned in #61. Created jquery.sumilate.dragandrevert to reduce complexiy.
1 parent 4ea1e3e commit 92cdc79

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/sortable.spec.js

+41
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,47 @@ describe('uiSortable', function() {
189189
});
190190
});
191191

192+
it('should continue to work after a drag is reverted', function() {
193+
inject(function($compile, $rootScope) {
194+
var element;
195+
element = $compile('<ul ui-sortable ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
196+
$rootScope.$apply(function() {
197+
$rootScope.opts = {
198+
placeholder: "sortable-item"
199+
};
200+
$rootScope.items = ["One", "Two", "Three"];
201+
});
202+
203+
host.append(element);
204+
205+
var li = element.find(':eq(0)');
206+
var dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
207+
li.simulate('dragAndRevert', { dy: dy });
208+
expect($rootScope.items).toEqual(["One", "Two", "Three"]);
209+
expect($rootScope.items).toEqualListContent(element);
210+
211+
li = element.find(':eq(0)');
212+
dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
213+
li.simulate('drag', { dy: dy });
214+
expect($rootScope.items).toEqual(["Two", "One", "Three"]);
215+
expect($rootScope.items).toEqualListContent(element);
216+
217+
li = element.find(':eq(1)');
218+
dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
219+
li.simulate('drag', { dy: dy });
220+
expect($rootScope.items).toEqual(["Two", "Three", "One"]);
221+
expect($rootScope.items).toEqualListContent(element);
222+
223+
li = element.find(':eq(1)');
224+
dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
225+
li.simulate('drag', { dy: dy });
226+
expect($rootScope.items).toEqual(["Two", "One", "Three"]);
227+
expect($rootScope.items).toEqualListContent(element);
228+
229+
$(element).remove();
230+
});
231+
});
232+
192233
});
193234

194235
describe('Multiple sortables related', function() {

0 commit comments

Comments
 (0)