]> source.dussan.org Git - jquery-ui.git/commitdiff
tests - added selectable unit tests
authorRichard Worth <rdworth@gmail.com>
Mon, 9 Jun 2008 05:40:24 +0000 (05:40 +0000)
committerRichard Worth <rdworth@gmail.com>
Mon, 9 Jun 2008 05:40:24 +0000 (05:40 +0000)
tests/selectable.html [new file with mode: 0644]
tests/selectable.js [new file with mode: 0644]

diff --git a/tests/selectable.html b/tests/selectable.html
new file mode 100644 (file)
index 0000000..7f959ae
--- /dev/null
@@ -0,0 +1,46 @@
+<!DOCTYPE html>\r
+<html lang="en">\r
+<head>\r
+       <title>jQuery UI Selectable Test Suite</title>\r
+\r
+       <link rel="stylesheet" href="qunit/testsuite.css" type="text/css" media="screen">\r
+       <!--link rel="stylesheet" href="../themes/flora/flora.selectable.css" type="text/css" media="screen"-->\r
+       \r
+       <script type="text/javascript" src="../jquery-1.2.6.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.core.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.selectable.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.draggable.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.resizable.js"></script>\r
+       \r
+       <script type="text/javascript" src="qunit/testrunner.js"></script>\r
+       <script type="text/javascript" src="simulate/jquery.simulate.js"></script>\r
+       \r
+       <script type="text/javascript" src="selectable.js"></script>\r
+       \r
+       <style type="text/css">\r
+               html { border: 0; }\r
+       </style>\r
+\r
+\r
+\r
+</head>\r
+<body class="flora">\r
+\r
+<h1 id="header">jQuery UI Selectable Test Suite</h1>\r
+<h2 id="banner"></h2>\r
+<h2 id="userAgent"></h2>\r
+\r
+<ol id="tests"></ol>\r
+\r
+<div id="main" style="position: absolute; top: -10000px; border: 1px solid black; padding: 10px; margin: 10px;">\r
+       <ul id="selectable1">\r
+               <li>Item 1</li>\r
+               <li>Item 2</li>\r
+               <li class="special">Item 3</li>\r
+               <li>Item 4</li>\r
+               <li>Item 5</li>\r
+       </ul>\r
+</div>\r
+\r
+</body>\r
+</html>\r
diff --git a/tests/selectable.js b/tests/selectable.js
new file mode 100644 (file)
index 0000000..2c127b1
--- /dev/null
@@ -0,0 +1,205 @@
+/*\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