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

test(sortable): test sorting from between different scopes #300

Merged
merged 1 commit into from
Nov 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/sortable.e2e.multi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,45 @@ describe('uiSortable', function() {
});
});

it('should update model when sorting between sortables of different scopes', function() {
inject(function($compile, $rootScope) {
var elementTop, elementBottom,
wrapperTop, wrapperBottom,
itemsTop, itemsBottom;
wrapperTop = $compile('<div ng-controller="dummyController"><ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li></ul></div>')($rootScope);
wrapperBottom = $compile('<div ng-controller="dummyController"><ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li></ul></div>')($rootScope);

host.append(wrapperTop).append(wrapperBottom).append('<div class="clear"></div>');
$rootScope.$apply(function() {
wrapperTop.scope().itemsTop = itemsTop = ['Top One', 'Top Two', 'Top Three'];
wrapperBottom.scope().itemsBottom = itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
$rootScope.opts = { connectWith: '.cross-sortable' };
});

elementTop = wrapperTop.find('> [ui-sortable]');
elementBottom = wrapperBottom.find('> [ui-sortable]');

var li1 = elementTop.find(':eq(0)');
var li2 = elementBottom.find(':eq(0)');
simulateElementDrag(li1, li2, 'below');
expect(itemsTop).toEqual(['Top Two', 'Top Three']);
expect(itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
expect(itemsTop).toEqual(listContent(elementTop));
expect(itemsBottom).toEqual(listContent(elementBottom));

li1 = elementBottom.find(':eq(1)');
li2 = elementTop.find(':eq(1)');
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -10 });
expect(itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
expect(itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
expect(itemsTop).toEqual(listContent(elementTop));
expect(itemsBottom).toEqual(listContent(elementBottom));

$(elementTop).remove();
$(elementBottom).remove();
});
});

it('should update model when sorting a "falsy" item between sortables', function() {
inject(function($compile, $rootScope) {
var elementTop, elementBottom;
Expand Down
3 changes: 3 additions & 0 deletions test/sortable.test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ angular.module('ui.sortable.testHelper', [])
simulateElementDrag: simulateElementDrag,
hasUndefinedProperties: hasUndefinedProperties
};
})
.controller('dummyController', function ($scope) {
$scope.testItems = ['One', 'Two', 'Three'];
});