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

Added cross-sortable sorting tests. Changed bower to use angular 1.0.x. #52

Merged
merged 2 commits into from
Nov 17, 2013
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
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"package.json"
],
"dependencies": {
"angular": "~1.x",
"angular": "~1.0.x",
"jquery-ui": ">= 1.9",
"jquery-simulate": "latest"
},
"devDependencies": {
"angular-mocks": "~1.x"
"angular-mocks": "~1.0.x"
}
}
52 changes: 40 additions & 12 deletions test/sortable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ describe('uiSortable', function() {
li.simulate('drag', { dy: dy });
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["One", "Three", "Four", "Two"]);

// // fails on angular 1.2
// li = element.find(':eq(2)');
// dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
// li.simulate('drag', { dy: dy });
// expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "One", "Three", "Two"]);

// // fails on angular 1.2
// li = element.find(':eq(3)');
// dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
// li.simulate('drag', { dy: dy });
// expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "Two", "One", "Three"]);
// fails on angular 1.2
li = element.find(':eq(2)');
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
li.simulate('drag', { dy: dy });
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "One", "Three", "Two"]);

// fails on angular 1.2
li = element.find(':eq(3)');
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
li.simulate('drag', { dy: dy });
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "Two", "One", "Three"]);

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

Expand All @@ -154,7 +154,35 @@ describe('uiSortable', function() {

it('should update model when sorting between sortables', function() {
inject(function($compile, $rootScope) {
// TODO
var elementTop, elementBottom;
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);
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);
$rootScope.$apply(function() {
$rootScope.itemsTop = ["Top One", "Top Two", "Top Three"];
$rootScope.itemsBottom = ["Bottom One", "Bottom Two", "Bottom Three"];
$rootScope.opts = { connectWith: ".cross-sortable" };
});

host.append(elementTop).append(elementBottom);

// fails on angular 1.2
var li1 = elementTop.find(':eq(0)');
var li2 = elementBottom.find(':eq(0)');
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
li1.simulate('drag', { dy: dy });
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);

// fails on angular 1.2
li1 = elementBottom.find(':eq(1)');
li2 = elementTop.find(':eq(1)');
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
li1.simulate('drag', { dy: dy });
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);

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

Expand Down