Skip to content

Commit 4484c52

Browse files
committed
Sortable Tests: Add tests for axis option and recent axis option bugs.
1 parent 44d0717 commit 4484c52

File tree

1 file changed

+85
-8
lines changed

1 file changed

+85
-8
lines changed

tests/unit/sortable/sortable_options.js

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,100 @@ test("{ appendTo: 'parent' }, default", function() {
1313
test("{ appendTo: Selector }", function() {
1414
ok(false, "missing test - untested code is broken code.");
1515
});
16+
*/
1617

17-
test("{ axis: false }, default", function() {
18-
ok(false, "missing test - untested code is broken code.");
18+
test( "{ axis: false }, default", function() {
19+
expect( 2 );
20+
21+
var offsetAfter,
22+
element = $( "#sortable" ).sortable({
23+
axis: false,
24+
change: function() {
25+
offsetAfter = item.offset();
26+
notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: false" );
27+
notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: false" );
28+
}
29+
}),
30+
item = element.find( "li" ).eq( 0 ),
31+
offsetBefore = item.offset();
32+
33+
item.simulate( "drag", {
34+
dx: 50,
35+
dy: 25,
36+
moves: 1
37+
});
1938
});
2039

21-
test("{ axis: 'x' }", function() {
22-
ok(false, "missing test - untested code is broken code.");
40+
test( "{ axis: 'x' }", function() {
41+
expect( 2 );
42+
43+
var offsetAfter,
44+
element = $( "#sortable" ).sortable({
45+
axis: "x",
46+
change: function() {
47+
offsetAfter = item.offset();
48+
notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: x" );
49+
equal( offsetAfter.top, offsetBefore.top, "y axis constrained when axis: x" );
50+
}
51+
}),
52+
item = element.find( "li" ).eq( 0 ),
53+
offsetBefore = item.offset();
54+
55+
item.simulate( "drag", {
56+
dx: 50,
57+
dy: 25,
58+
moves: 1
59+
});
2360
});
2461

25-
test("{ axis: 'y' }", function() {
26-
ok(false, "missing test - untested code is broken code.");
62+
test( "{ axis: 'y' }", function() {
63+
expect( 2 );
64+
65+
var offsetAfter,
66+
element = $( "#sortable" ).sortable({
67+
axis: "y",
68+
change: function() {
69+
offsetAfter = item.offset();
70+
equal( offsetAfter.left, offsetBefore.left, "x axis constrained when axis: y" );
71+
notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: y" );
72+
}
73+
}),
74+
item = element.find( "li" ).eq( 0 ),
75+
offsetBefore = item.offset();
76+
77+
item.simulate( "drag", {
78+
dx: 50,
79+
dy: 25,
80+
moves: 1
81+
});
2782
});
2883

29-
test("{ axis: ? }, unexpected", function() {
30-
ok(false, "missing test - untested code is broken code.");
84+
asyncTest( "#7415: Incorrect revert animation with axis: 'y'", function() {
85+
expect( 2 );
86+
var expectedLeft,
87+
element = $( "#sortable" ).sortable({
88+
axis: "y",
89+
revert: true,
90+
stop: start,
91+
sort: function() {
92+
expectedLeft = item.css( "left" );
93+
}
94+
}),
95+
item = element.find( "li" ).eq( 0 );
96+
97+
item.simulate( "drag", {
98+
dy: 300,
99+
dx: 50
100+
});
101+
102+
setTimeout(function() {
103+
var top = parseFloat( item.css( "top" ) );
104+
equal( item.css( "left" ), expectedLeft, "left not animated" );
105+
ok( top > 0 && top < 300, "top is animated" );
106+
}, 100 );
31107
});
32108

109+
/*
33110
test("{ cancel: 'input,textarea,button,select,option' }, default", function() {
34111
ok(false, "missing test - untested code is broken code.");
35112
});

0 commit comments

Comments
 (0)