8000 Added test for sorting "falsy" items between sortables. · angular-ui/ui-sortable@1a853d9 · GitHub
[go: up one dir, main page]

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

Commit 1a853d9

Browse files
committed
Added test for sorting "falsy" items between sortables.
1 parent 931399b commit 1a853d9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/sortable.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,42 @@ describe('uiSortable', function() {
400400
});
401401
});
402402

403+
it('should update model when sorting a "falsy" item between sortables', function() {
404+
inject(function($compile, $rootScope) {
405+
var elementTop, elementBottom;
406+
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);
407+
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);
408+
$rootScope.$apply(function() {
409+
$rootScope.itemsTop = [0, 'Top Two', 'Top Three'];
410+
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
411+
$rootScope.opts = { connectWith: '.cross-sortable' };
412+
});
413+
414+
host.append(elementTop).append(elementBottom);
415+
416+
var li1 = elementTop.find(':eq(0)');
417+
var li2 = elementBottom.find(':eq(0)');
418+
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
419+
li1.simulate('drag', { dy: dy });
420+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
421+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 0, 'Bottom Two', 'Bottom Three']);
422+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
423+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
424+
425+
li1 = elementBottom.find(':eq(1)');
426+
li2 = elementTop.find(':eq(1)');
427+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
428+
li1.simulate('drag', { dy: dy });
429+
expect($rootScope.itemsTop).toEqual(['Top Two', 0, 'Top Three']);
430+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
431+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
432+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
433+
434+
$(elementTop).remove();
435+
$(elementBottom).remove();
436+
});
437+
});
438+
403439
it('should work when "placeholder" option is used', function() {
404440
inject(function($compile, $rootScope) {
405441
var elementTop, elementBottom;

0 commit comments

Comments
 (0)
0