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

Commit 1171e41

Browse files
committed
Merge pull request #52 from thgreasi/tests
Added cross-sortable sorting tests. Changed bower to use angular 1.0.x.
2 parents 05d44b7 + b2f5964 commit 1171e41

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"angular": "~1.x",
19+
"angular": "~1.0.x",
2020
"jquery-ui": ">= 1.9",
2121
"jquery-simulate": "latest"
2222
},
2323
"devDependencies": {
24-
"angular-mocks": "~1.x"
24+
"angular-mocks": "~1.0.x"
2525
}
2626
}

test/sortable.spec.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ describe('uiSortable', function() {
134134
li.simulate('drag', { dy: dy });
135135
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["One", "Three", "Four", "Two"]);
136136

137-
// // fails on angular 1.2
138-
// li = element.find(':eq(2)');
139-
// dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
140-
// li.simulate('drag', { dy: dy });
141-
// expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "One", "Three", "Two"]);
142-
143-
// // fails on angular 1.2
144-
// li = element.find(':eq(3)');
145-
// dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
146-
// li.simulate('drag', { dy: dy });
147-
// expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "Two", "One", "Three"]);
137+
// fails on angular 1.2
138+
li = element.find(':eq(2)');
139+
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
140+
li.simulate('drag', { dy: dy });
141+
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "One", "Three", "Two"]);
142+
143+
// fails on angular 1.2
144+
li = element.find(':eq(3)');
145+
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
146+
li.simulate('drag', { dy: dy });
147+
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "Two", "One", "Three"]);
148148

149149
// also placing right above the locked node seems a bit harder !?!?
150150

@@ -154,7 +154,35 @@ 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+
// fails on angular 1.2
169+
var li1 = elementTop.find(':eq(0)');
170+
var li2 = elementBottom.find(':eq(0)');
171+
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
172+
li1.simulate('drag', { dy: dy });
173+
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
174+
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
175+
176+
// fails on angular 1.2
177+
li1 = elementBottom.find(':eq(1)');
178+
li2 = elementTop.find(':eq(1)');
179+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
180+
li1.simulate('drag', { dy: dy });
181+
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
182+
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
183+
184+
$(elementTop).remove();
185+
$(elementBottom).remove();
158186
});
159187
});
160188

0 commit comments

Comments
 (0)