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

Commit 9a844d1

Browse files
committed
Added cross-sortable sorting tests.
1 parent 6f92022 commit 9a844d1

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test/sortable.spec.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,33 @@ describe('uiSortable', function() {
154154

155155
it('should update model when sorting between sortables', function() {
156156
inject(function($compile, $rootScope) {
157-
// TODO
157+
var elementTop, elementBottom;
158+
elementTop = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li></ul>')($rootScope);
159+
elementBottom = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li></ul>')($rootScope);
160+
$rootScope.$apply(function() {
161+
$rootScope.itemsTop = ["Top One", "Top Two", "Top Three"];
162+
$rootScope.itemsBottom = ["Bottom One", "Bottom Two", "Bottom Three"];
163+
$rootScope.opts = { connectWith: ".cross-sortable" };
164+
});
165+
166+
host.append(elementTop).append(elementBottom);
167+
168+
var li1 = elementTop.find(':eq(0)');
169+
var li2 = elementBottom.find(':eq(0)');
170+
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
171+
li1.simulate('drag', { dy: dy });
172+
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
173+
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
174+
175+
li1 = elementBottom.find(':eq(1)');
176+
li2 = elementTop.find(':eq(1)');
177+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
178+
li1.simulate('drag', { dy: dy });
179+
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
180+
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
181+
182+
$(elementTop).remove();
183+
$(elementBottom).remove();
158184
});
159185
});
160186

0 commit comments

Comments
 (0)