--- /dev/null
+/*\r
+ * selectable unit tests\r
+ */\r
+\r
+//\r
+// Selectable Test Helper Functions\r
+//\r
+var el;\r
+\r
+var drag = function(dx, dy) {\r
+ var off = el.offset(), pos = { clientX: off.left, clientY: off.top };\r
+ el.simulate("mousedown", pos);\r
+ $(document).simulate("mousemove", pos);\r
+ pos.clientX += dx;\r
+ pos.clientY += dy;\r
+ $(document).simulate("mousemove", pos);\r
+ $(document).simulate("mouseup", pos);\r
+}\r
+\r
+var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }\r
+\r
+var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }\r
+\r
+// Selectable Tests\r
+module("selectable");\r
+\r
+test("init", function() {\r
+ expect(6);\r
+\r
+ $("#selectable1").selectable().remove();\r
+ ok(true, '.selectable() called on element');\r
+\r
+ $([]).selectable().remove();\r
+ ok(true, '.selectable() called on empty collection');\r
+\r
+ $("<div/>").selectable().remove();\r
+ ok(true, '.selectable() called on disconnected DOMElement');\r
+\r
+ $("<div/>").selectable().selectable("foo").remove();\r
+ ok(true, 'arbitrary method called after init');\r
+\r
+ el = $("<div/>").selectable()\r
+ var foo = el.data("foo.selectable");\r
+ el.remove();\r
+ ok(true, 'arbitrary option getter after init');\r
+\r
+ $("<div/>").selectable().data("foo.selectable", "bar").remove();\r
+ ok(true, 'arbitrary option setter after init');\r
+});\r
+\r
+test("destroy", function() {\r
+ expect(6);\r
+\r
+ $("#selectable1").selectable().selectable("destroy").remove();\r
+ ok(true, '.selectable("destroy") called on element');\r
+\r
+ $([]).selectable().selectable("destroy").remove();\r
+ ok(true, '.selectable("destroy") called on empty collection');\r
+\r
+ $("<div/>").selectable().selectable("destroy").remove();\r
+ ok(true, '.selectable("destroy") called on disconnected DOMElement');\r
+\r
+ $("<div/>").selectable().selectable("destroy").selectable("foo").remove();\r
+ ok(true, 'arbitrary method called after destroy');\r
+\r
+ el = $("<div/>").selectable();\r
+ var foo = el.selectable("destroy").data("foo.selectable");\r
+ el.remove();\r
+ ok(true, 'arbitrary option getter after destroy');\r
+\r
+ $("<div/>").selectable().selectable("destroy").data("foo.selectable", "bar").remove();\r
+ ok(true, 'arbitrary option setter after destroy');\r
+});\r
+\r
+test("defaults", function() {\r
+ el = $('#selectable1').selectable();\r
+ var defaults = {\r
+ autoRefresh: true,\r
+ filter: '*'\r
+ };\r
+ $.each(defaults, function(key, val) {\r
+ var actual = el.data(key + ".selectable"), expected = val,\r
+ method = (expected && expected.constructor == Object) ?\r
+ compare2 : equals;\r
+ method(actual, expected, key);\r
+ });\r
+ el.remove();\r
+});\r
+\r
+module("selectable: Options");\r
+\r
+test("autoRefresh", function() {\r
+ expect(3);\r
+ el = $("#selectable1");\r
+ var actual, sel = $("*", el), selected = function() { actual += 1 };\r
+\r
+ actual = 0;\r
+ el = $("#selectable1").selectable({ autoRefresh: false, selected: selected });\r
+ sel.hide();\r
+ drag(1000, 1000);\r
+ equals(actual, sel.length);\r
+ el.selectable("destroy");\r
+\r
+ actual = 0;\r
+ sel.show();\r
+ el = $("#selectable1").selectable({ autoRefresh: true, selected: selected });\r
+ sel.hide();\r
+ drag(1000, 1000);\r
+ equals(actual, 0);\r
+ sel.show();\r
+ drag(1000, 1000);\r
+ equals(actual, sel.length);\r
+ el.selectable("destroy");\r
+ sel.show();\r
+});\r
+\r
+test("filter", function() {\r
+ expect(2);\r
+ el = $("#selectable1");\r
+ var actual, sel = $("*", el), selected = function() { actual += 1 };\r
+\r
+ actual = 0;\r
+ el = $("#selectable1").selectable({ filter: '.special', selected: selected });\r
+ drag(1000, 1000);\r
+ ok(sel.length != 1, "this test assumes more than 1 selectee");\r
+ equals(actual, 1);\r
+ el.selectable("destroy");\r
+});\r
+\r
+module("selectable: Methods");\r
+\r
+test("disable", function() {\r
+ expect(2);\r
+ var fired = false;\r
+\r
+ el = $("#selectable1");\r
+ el.selectable({\r
+ disabled: false,\r
+ start: function() { fired = true; }\r
+ });\r
+ el.simulate("drag", 20, 20);\r
+ equals(fired, true, "start fired");\r
+ el.selectable("disable");\r
+ fired = false;\r
+ el.simulate("drag", 20, 20);\r
+ equals(fired, false, "start fired");\r
+ el.selectable("destroy");\r
+});\r
+\r
+test("enable", function() {\r
+ expect(2);\r
+ var fired = false;\r
+\r
+ el = $("#selectable1");\r
+ el.selectable({\r
+ disabled: true,\r
+ start: function() { fired = true; }\r
+ });\r
+ el.simulate("drag", 20, 20);\r
+ equals(fired, false, "start fired");\r
+ el.selectable("enable");\r
+ el.simulate("drag", 20, 20);\r
+ equals(fired, true, "start fired");\r
+ el.selectable("destroy");\r
+});\r
+\r
+test("toggle", function() {\r
+ expect(2);\r
+\r
+ el = $("#selectable1").selectable({ disabled: true }).selectable("toggle");\r
+ equals(el.data("disabled.selectable"), false, "disabled -> enabled");\r
+ el.selectable("destroy");\r
+\r
+ el = $("#selectable1").selectable({ disabled: false }).selectable("toggle");\r
+ equals(el.data("disabled.selectable"), true, "enabled -> disabled");\r
+ el.selectable("destroy");\r
+});\r
+\r
+module("selectable: Callbacks");\r
+\r
+test("start", function() {\r
+ expect(2);\r
+ el = $("#selectable1");\r
+ el.selectable({\r
+ start: function(ev, ui) {\r
+ ok(true, "drag fired start callback");\r
+ equals(this, el[0], "context of callback");\r
+ }\r
+ });\r
+ el.simulate("drag", 20, 20);\r
+});\r
+\r
+test("stop", function() {\r
+ expect(2);\r
+ el = $("#selectable1");\r
+ el.selectable({\r
+ start: function(ev, ui) {\r
+ ok(true, "drag fired stop callback");\r
+ equals(this, el[0], "context of callback");\r
+ }\r
+ });\r
+ el.simulate("drag", 20, 20);\r
+});\r
+\r
+module("selectable: Tickets");\r