1 |
/* |
2 |
* sortable_methods.js |
3 |
*/ |
4 |
(function($) { |
5 |
|
6 |
module("sortable: methods"); |
7 |
|
8 |
test("init", function() { |
9 |
expect(5); |
10 |
|
11 |
$("<div></div>").appendTo("body").sortable().remove(); |
12 |
ok(true, ".sortable() called on element"); |
13 |
|
14 |
$([]).sortable(); |
15 |
ok(true, ".sortable() called on empty collection"); |
16 |
|
17 |
$("<div></div>").sortable(); |
18 |
ok(true, ".sortable() called on disconnected DOMElement"); |
19 |
|
20 |
$("<div></div>").sortable().sortable("option", "foo"); |
21 |
ok(true, "arbitrary option getter after init"); |
22 |
|
23 |
$("<div></div>").sortable().sortable("option", "foo", "bar"); |
24 |
ok(true, "arbitrary option setter after init"); |
25 |
}); |
26 |
|
27 |
test("destroy", function() { |
28 |
expect(4); |
29 |
$("<div></div>").appendTo("body").sortable().sortable("destroy").remove(); |
30 |
ok(true, ".sortable('destroy') called on element"); |
31 |
|
32 |
$([]).sortable().sortable("destroy"); |
33 |
ok(true, ".sortable('destroy') called on empty collection"); |
34 |
|
35 |
$("<div></div>").sortable().sortable("destroy"); |
36 |
ok(true, ".sortable('destroy') called on disconnected DOMElement"); |
37 |
|
38 |
var expected = $("<div></div>").sortable(), |
39 |
actual = expected.sortable("destroy"); |
40 |
equal(actual, expected, "destroy is chainable"); |
41 |
}); |
42 |
|
43 |
test("enable", function() { |
44 |
expect(5); |
45 |
|
46 |
var el, actual, expected; |
47 |
|
48 |
el = $("#sortable").sortable({ disabled: true }); |
49 |
|
50 |
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, ".sortable({ disabled: true })"); |
51 |
|
52 |
el.sortable("enable"); |
53 |
equal(el.sortable("option", "disabled"), false, "disabled option getter"); |
54 |
|
55 |
el.sortable("destroy"); |
56 |
el.sortable({ disabled: true }); |
57 |
el.sortable("option", "disabled", false); |
58 |
equal(el.sortable("option", "disabled"), false, "disabled option setter"); |
59 |
|
60 |
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, ".sortable('option', 'disabled', false)"); |
61 |
|
62 |
expected = $("<div></div>").sortable(), |
63 |
actual = expected.sortable("enable"); |
64 |
equal(actual, expected, "enable is chainable"); |
65 |
}); |
66 |
|
67 |
test("disable", function() { |
68 |
expect(7); |
69 |
|
70 |
var el, actual, expected; |
71 |
|
72 |
el = $("#sortable").sortable({ disabled: false }); |
73 |
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, ".sortable({ disabled: false })"); |
74 |
|
75 |
el.sortable("disable"); |
76 |
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, "disabled.sortable getter"); |
77 |
|
78 |
el.sortable("destroy"); |
79 |
|
80 |
el.sortable({ disabled: false }); |
81 |
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, ".sortable({ disabled: false })"); |
82 |
el.sortable("option", "disabled", true); |
83 |
equal(el.sortable("option", "disabled"), true, "disabled option setter"); |
84 |
ok(el.sortable("widget").is(":not(.ui-state-disabled)"), "sortable element does not get ui-state-disabled since it's an interaction"); |
85 |
TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, ".sortable('option', 'disabled', true)"); |
86 |
|
87 |
expected = $("<div></div>").sortable(), |
88 |
actual = expected.sortable("disable"); |
89 |
equal(actual, expected, "disable is chainable"); |
90 |
}); |
91 |
|
92 |
})(jQuery); |