]> source.dussan.org Git - jquery-ui.git/commitdiff
tests: initial version of sortable tests/
authorPaul Bakaus <paul.bakaus@googlemail.com>
Fri, 13 Jun 2008 12:42:44 +0000 (12:42 +0000)
committerPaul Bakaus <paul.bakaus@googlemail.com>
Fri, 13 Jun 2008 12:42:44 +0000 (12:42 +0000)
sortable: added default value for helper ("clone")

tests/sortable.html [new file with mode: 0644]
tests/sortable.js [new file with mode: 0644]
ui/ui.sortable.js

diff --git a/tests/sortable.html b/tests/sortable.html
new file mode 100644 (file)
index 0000000..1a8aad7
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>\r
+<html lang="en">\r
+<head>\r
+       <title>jQuery UI Draggable Test Suite</title>\r
+\r
+       <link rel="stylesheet" href="qunit/testsuite.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.sortable.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="sortable.js"></script>\r
+       \r
+       <style type="text/css">\r
+               html { border: 0; }\r
+               #main {\r
+                       position:absolute !important;\r
+                       top: -1000px !important;\r
+                       left: -1000px !important;\r
+               }\r
+       </style>\r
+</head>\r
+<body>\r
+\r
+<h1 id="header">jQuery UI Draggable 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="border: 1px solid black; padding: 10px; margin: 10px;">\r
+       <ul id="sortable">\r
+               <li>Item 1<li>\r
+               <li>Item 2<li>\r
+               <li>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/sortable.js b/tests/sortable.js
new file mode 100644 (file)
index 0000000..acfd8d9
--- /dev/null
@@ -0,0 +1,126 @@
+/*\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
index 7d9c5cd9e4c0ab2c00bb67d75a6d0de7c3f49653..43d962bc0b8bf6c612aeb24946745cbe36ea8725 100644 (file)
@@ -570,6 +570,7 @@ $.widget("ui.sortable", $.extend($.ui.mouse, {
 $.extend($.ui.sortable, {
        getter: "serialize toArray",
        defaults: {
+               helper: "clone",
                tolerance: "guess",
                distance: 0,
                delay: 0,