|
| 1 | +/* |
| 2 | + * draggable unit tests |
| 3 | + */ |
| 4 | +(function($) { |
| 5 | +// |
| 6 | +// Sortable Test Helper Functions |
| 7 | +// |
| 8 | +var el, offsetBefore, offsetAfter, dragged; |
| 9 | + |
| 10 | +var drag = function(handle, dx, dy) { |
| 11 | + offsetBefore = $(handle).offset(); |
| 12 | + $(handle).simulate("drag", { |
| 13 | + dx: dx || 0, |
| 14 | + dy: dy || 0 |
| 15 | + });
93D4
span> |
| 16 | + dragged = { dx: dx, dy: dy }; |
| 17 | + offsetAfter = $(handle).offset(); |
| 18 | +} |
| 19 | + |
| 20 | +var sort = function(handle, dx, dy, index, msg) { |
| 21 | + drag(handle, dx, dy); |
| 22 | + equals($(handle).parent().children().index(handle), index, msg); |
| 23 | +} |
| 24 | + |
| 25 | +var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } |
| 26 | +var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } |
| 27 | + |
| 28 | +// Sortable Tests |
| 29 | +module("sortable"); |
| 30 | + |
| 31 | +test("init", function() { |
| 32 | + expect(6); |
| 33 | + |
| 34 | + el = $("#sortable").sortable(); |
| 35 | + ok(true, '.sortable() called on element'); |
| 36 | + |
| 37 | + $([]).sortable(); |
| 38 | + ok(true, '.sortable() called on empty collection'); |
| 39 | + |
| 40 | + $("<div/>").sortable(); |
| 41 | + ok(true, '.sortable() called on disconnected DOMElement'); |
| 42 | + |
| 43 | + $("<div/>").sortable().sortable("foo"); |
| 44 | + ok(true, 'arbitrary method called after init'); |
| 45 | + |
| 46 | + $("<div/>").sortable().data("foo.sortable"); |
| 47 | + ok(true, 'arbitrary option getter after init'); |
| 48 | + |
| 49 | + $("<div/>").sortable().data("foo.sortable", "bar"); |
| 50 | + ok(true, 'arbitrary option setter after init'); |
| 51 | +}); |
| 52 | + |
| 53 | +test("destroy", function() { |
| 54 | + expect(6); |
| 55 | + |
| 56 | + $("#sortable").sortable().sortable("destroy"); |
| 57 | + ok(true, '.sortable("destroy") called on element'); |
| 58 | + |
| 59 | + $([]).sortable().sortable("destroy"); |
| 60 | + ok(true, '.sortable("destroy") called on empty collection'); |
| 61 | + |
| 62 | + $("<div/>").sortable().sortable("destroy"); |
| 63 | + ok(true, '.sortable("destroy") called on disconnected DOMElement'); |
| 64 | + |
| 65 | + $("<div/>").sortable().sortable("destroy").sortable("foo"); |
| 66 | + ok(true, 'arbitrary method called after destroy'); |
| 67 | + |
| 68 | + $("<div/>").sortable().sortable("destroy").data("foo.sortable"); |
| 69 | + ok(true, 'arbitrary option getter after destroy'); |
| 70 | + |
| 71 | + $("<div/>").sortable().sortable("destroy").data("foo.sortable", "bar"); |
| 72 | + ok(true, 'arbitrary option setter after destroy'); |
| 73 | +}); |
| 74 | + |
| 75 | +test("enable", function() { |
| 76 | + expect(4); |
| 77 | + el = $("#sortable").sortable({ disabled: true }); |
| 78 | + |
| 79 | + sort($("li", el)[0], 0, 50, 0, '.sortable({ disabled: true })'); |
| 80 | + |
| 81 | + el.sortable("enable"); |
| 82 | + equals(el.data("disabled.sortable"), false, "disabled.sortable getter"); |
| 83 | + |
| 84 | + el.sortable("destroy"); |
| 85 | + el.sortable({ disabled: true }); |
| 86 | + el.data("disabled.sortable", false); |
| 87 | + equals(el.data("disabled.sortable"), false, "disabled.sortable setter"); |
| 88 | + |
| 89 | + sort($("li", el)[0], 0, 20, 2, '.data("disabled.sortable", false)'); |
| 90 | +}); |
| 91 | + |
| 92 | +test("disable", function() { |
| 93 | + expect(5); |
| 94 | + el = $("#sortable").sortable({ disabled: false }); |
| 95 | + sort($("li", el)[0], 0, 20, 2, '.sortable({ disabled: false })'); |
| 96 | + |
| 97 | + el.sortable("disable"); |
| 98 | + sort($("li", el)[0], 0, 20, 0, 'disabled.sortable getter'); |
| 99 | + |
| 100 | + el.sortable("destroy"); |
| 101 | + |
| 102 | + el.sortable({ disabled: false }); |
| 103 | + sort($("li", el)[0], 0, 20, 2, '.sortable({ disabled: false })'); |
| 104 | + el.data("disabled.sortable", true); |
| 105 | + equals(el.data("disabled.sortable"), true, "disabled.sortable setter"); |
| 106 | + sort($("li", el)[0], 0, 20, 0, '.data("disabled.sortable", true)'); |
| 107 | +}); |
| 108 | + |
| 109 | +test("defaults", function() { |
| 110 | + el = $("#sortable").sortable(); |
| 111 | + |
| 112 | + equals(el.data("helper.sortable"), "clone", "helper"); |
| 113 | + equals(el.data("tolerance.sortable"), "guess", "tolerance"); |
| 114 | + equals(el.data("distance.sortable"), 0, "distance"); |
| 115 | + equals(el.data("disabled.sortable"), false, "disabled"); |
| 116 | + equals(el.data("delay.sortable"), 0, "delay"); |
| 117 | + equals(el.data("cancel.sortable"), ":input,button", "cancel"); |
| 118 | + equals(el.data("items.sortable"), "> *", "items"); |
| 119 | + equals(el.<
133E
span class=pl-en>data("zIndex.sortable"), 1000, "zIndex"); |
| 120 | + equals(el.data("dropOnEmpty.sortable"), true, "dropOnEmpty"); |
| 121 | + equals(el.data("appendTo.sortable"), "parent", "appendTo"); |
| 122 | + |
| 123 | +}); |
| 124 | + |
| 125 | + |
| 126 | +})(jQuery); |
0 commit comments