--- /dev/null
+/*\r
+ * draggable unit tests\r
+ */\r
+(function($) {\r
+//\r
+// Sortable Test Helper Functions\r
+//\r
+var el, offsetBefore, offsetAfter, dragged;\r
+\r
+var drag = function(handle, dx, dy) {\r
+ offsetBefore = $(handle).offset();\r
+ $(handle).simulate("drag", {\r
+ dx: dx || 0,\r
+ dy: dy || 0\r
+ });\r
+ dragged = { dx: dx, dy: dy };\r
+ offsetAfter = $(handle).offset();\r
+}\r
+\r
+var sort = function(handle, dx, dy, index, msg) {\r
+ drag(handle, dx, dy);\r
+ equals($(handle).parent().children().index(handle), index, msg);\r
+}\r
+\r
+var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }\r
+var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }\r
+\r
+// Sortable Tests\r
+module("sortable");\r
+\r
+test("init", function() {\r
+ expect(6);\r
+\r
+ el = $("#sortable").sortable();\r
+ ok(true, '.sortable() called on element');\r
+\r
+ $([]).sortable();\r
+ ok(true, '.sortable() called on empty collection');\r
+\r
+ $("<div/>").sortable();\r
+ ok(true, '.sortable() called on disconnected DOMElement');\r
+\r
+ $("<div/>").sortable().sortable("foo");\r
+ ok(true, 'arbitrary method called after init');\r
+\r
+ $("<div/>").sortable().data("foo.sortable");\r
+ ok(true, 'arbitrary option getter after init');\r
+\r
+ $("<div/>").sortable().data("foo.sortable", "bar");\r
+ ok(true, 'arbitrary option setter after init');\r
+});\r
+\r
+test("destroy", function() {\r
+ expect(6);\r
+\r
+ $("#sortable").sortable().sortable("destroy"); \r
+ ok(true, '.sortable("destroy") called on element');\r
+\r
+ $([]).sortable().sortable("destroy");\r
+ ok(true, '.sortable("destroy") called on empty collection');\r
+\r
+ $("<div/>").sortable().sortable("destroy");\r
+ ok(true, '.sortable("destroy") called on disconnected DOMElement');\r
+\r
+ $("<div/>").sortable().sortable("destroy").sortable("foo");\r
+ ok(true, 'arbitrary method called after destroy');\r
+\r
+ $("<div/>").sortable().sortable("destroy").data("foo.sortable");\r
+ ok(true, 'arbitrary option getter after destroy');\r
+\r
+ $("<div/>").sortable().sortable("destroy").data("foo.sortable", "bar");\r
+ ok(true, 'arbitrary option setter after destroy');\r
+});\r
+\r
+test("enable", function() {\r
+ expect(4);\r
+ el = $("#sortable").sortable({ disabled: true });\r
+\r
+ sort($("li", el)[0], 0, 50, 0, '.sortable({ disabled: true })');\r
+ \r
+ el.sortable("enable");\r
+ equals(el.data("disabled.sortable"), false, "disabled.sortable getter");\r
+\r
+ el.sortable("destroy");\r
+ el.sortable({ disabled: true });\r
+ el.data("disabled.sortable", false);\r
+ equals(el.data("disabled.sortable"), false, "disabled.sortable setter");\r
+ \r
+ sort($("li", el)[0], 0, 20, 2, '.data("disabled.sortable", false)');\r
+});\r
+\r
+test("disable", function() {\r
+ expect(5);\r
+ el = $("#sortable").sortable({ disabled: false });\r
+ sort($("li", el)[0], 0, 20, 2, '.sortable({ disabled: false })');\r
+\r
+ el.sortable("disable");\r
+ sort($("li", el)[0], 0, 20, 0, 'disabled.sortable getter');\r
+\r
+ el.sortable("destroy");\r
+\r
+ el.sortable({ disabled: false });\r
+ sort($("li", el)[0], 0, 20, 2, '.sortable({ disabled: false })');\r
+ el.data("disabled.sortable", true);\r
+ equals(el.data("disabled.sortable"), true, "disabled.sortable setter");\r
+ sort($("li", el)[0], 0, 20, 0, '.data("disabled.sortable", true)');\r
+});\r
+\r
+test("defaults", function() {\r
+ el = $("#sortable").sortable();\r
+\r
+ equals(el.data("helper.sortable"), "clone", "helper");\r
+ equals(el.data("tolerance.sortable"), "guess", "tolerance");\r
+ equals(el.data("distance.sortable"), 0, "distance");\r
+ equals(el.data("disabled.sortable"), false, "disabled");\r
+ equals(el.data("delay.sortable"), 0, "delay");\r
+ equals(el.data("cancel.sortable"), ":input,button", "cancel");\r
+ equals(el.data("items.sortable"), "> *", "items");\r
+ equals(el.data("zIndex.sortable"), 1000, "zIndex"); \r
+ equals(el.data("dropOnEmpty.sortable"), true, "dropOnEmpty");\r
+ equals(el.data("appendTo.sortable"), "parent", "appendTo");\r
+\r
+});\r
+\r
+\r
+})(jQuery);\r