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

Commit 7824aab

Browse files
committed
Merge pull request #300 from thgreasi/differentScopeTest
test(sortable): test sorting between different scopes
2 parents e20710b + 0ce0a05 commit 7824aab

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

test/sortable.e2e.multi.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,45 @@ describe('uiSortable', function() {
6464
});
6565
});
6666

67+
it('should update model when sorting between sortables of different scopes', function() {
68+
inject(function($compile, $rootScope) {
69+
var elementTop, elementBottom,
70+
wrapperTop, wrapperBottom,
71+
itemsTop, itemsBottom;
72+
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);
73+
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);
74+
75+
host.append(wrapperTop).append(wrapperBottom).append('<div class="clear"></div>');
76+
$rootScope.$apply(function() {
77+
wrapperTop.scope().itemsTop = itemsTop = ['Top One', 'Top Two', 'Top Three'];
78+
wrapperBottom.scope().itemsBottom = itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
79+
$rootScope.opts = { connectWith: '.cross-sortable' };
80+
});
81+
82+
elementTop = wrapperTop.find('> [ui-sortable]');
83+
elementBottom = wrapperBottom.find('> [ui-sortable]');
84+
85+
var li1 = elementTop.find(':eq(0)');
86+
var li2 = elementBottom.find(':eq(0)');
87+
simulateElementDrag(li1, li2, 'below');
88+
expect(itemsTop).toEqual(['Top Two', 'Top Three']);
89+
expect(itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
90+
expect(itemsTop).toEqual(listContent(elementTop));
91+
expect(itemsBottom).toEqual(listContent(elementBottom));
92+
93+
li1 = elementBottom.find(':eq(1)');
94+
li2 = elementTop.find(':eq(1)');
95+
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -10 });
96+
expect(itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
97+
expect(itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
98+
expect(itemsTop).toEqual(listContent(elementTop));
99+
expect(itemsBottom).toEqual(listContent(elementBottom));
100+
101+
$(elementTop).remove();
102+
$(elementBottom).remove();
103+
});
104+
});
105+
67106
it('should update model when sorting a "falsy" item between sortables', function() {
68107
inject(function($compile, $rootScope) {
69108
var elementTop, elementBottom;

test/sortable.test-helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,7 @@ angular.module('ui.sortable.testHelper', [])
7878
simulateElementDrag: simulateElementDrag,
7979
hasUndefinedProperties: hasUndefinedProperties
8080
};
81+
})
82+
.controller('dummyController', function ($scope) {
83+
$scope.testItems = ['One', 'Two', 'Three'];
8184
});

0 commit comments

Comments
 (0)