diff options
author | Paul Bakaus <paul.bakaus@googlemail.com> | 2008-06-13 12:42:44 +0000 |
---|---|---|
committer | Paul Bakaus <paul.bakaus@googlemail.com> | 2008-06-13 12:42:44 +0000 |
commit | abdda174f2b0068cc9c828becbf941f6e5362633 (patch) | |
tree | 4b369381db89135906ac1283e25a76f7cd53da81 /tests | |
parent | 854d60dc83641f7ea2ae92faf0f092f954e045f3 (diff) | |
download | jquery-ui-abdda174f2b0068cc9c828becbf941f6e5362633.tar.gz jquery-ui-abdda174f2b0068cc9c828becbf941f6e5362633.zip |
tests: initial version of sortable tests/
sortable: added default value for helper ("clone")
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sortable.html | 45 | ||||
-rw-r--r-- | tests/sortable.js | 126 |
2 files changed, 171 insertions, 0 deletions
diff --git a/tests/sortable.html b/tests/sortable.html new file mode 100644 index 000000000..1a8aad730 --- /dev/null +++ b/tests/sortable.html @@ -0,0 +1,45 @@ +<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>jQuery UI Draggable Test Suite</title>
+
+ <link rel="stylesheet" href="qunit/testsuite.css" type="text/css" media="screen">
+
+ <script type="text/javascript" src="../jquery-1.2.6.js"></script>
+ <script type="text/javascript" src="../ui/ui.core.js"></script>
+ <script type="text/javascript" src="../ui/ui.sortable.js"></script>
+
+ <script type="text/javascript" src="qunit/testrunner.js"></script>
+ <script type="text/javascript" src="simulate/jquery.simulate.js"></script>
+
+ <script type="text/javascript" src="sortable.js"></script>
+
+ <style type="text/css">
+ html { border: 0; }
+ #main {
+ position:absolute !important;
+ top: -1000px !important;
+ left: -1000px !important;
+ }
+ </style>
+</head>
+<body>
+
+<h1 id="header">jQuery UI Draggable Test Suite</h1>
+<h2 id="banner"></h2>
+<h2 id="userAgent"></h2>
+
+<ol id="tests"></ol>
+
+<div id="main" style="border: 1px solid black; padding: 10px; margin: 10px;">
+ <ul id="sortable">
+ <li>Item 1<li>
+ <li>Item 2<li>
+ <li>Item 3<li>
+ <li>Item 4<li>
+ <li>Item 5<li>
+ </ul>
+</div>
+
+</body>
+</html>
diff --git a/tests/sortable.js b/tests/sortable.js new file mode 100644 index 000000000..acfd8d9df --- /dev/null +++ b/tests/sortable.js @@ -0,0 +1,126 @@ +/*
+ * draggable unit tests
+ */
+(function($) {
+//
+// Sortable Test Helper Functions
+//
+var el, offsetBefore, offsetAfter, dragged;
+
+var drag = function(handle, dx, dy) {
+ offsetBefore = $(handle).offset();
+ $(handle).simulate("drag", {
+ dx: dx || 0,
+ dy: dy || 0
+ });
+ dragged = { dx: dx, dy: dy };
+ offsetAfter = $(handle).offset();
+}
+
+var sort = function(handle, dx, dy, index, msg) {
+ drag(handle, dx, dy);
+ equals($(handle).parent().children().index(handle), index, msg);
+}
+
+var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }
+var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }
+
+// Sortable Tests
+module("sortable");
+
+test("init", function() {
+ expect(6);
+
+ el = $("#sortable").sortable();
+ ok(true, '.sortable() called on element');
+
+ $([]).sortable();
+ ok(true, '.sortable() called on empty collection');
+
+ $("<div/>").sortable();
+ ok(true, '.sortable() called on disconnected DOMElement');
+
+ $("<div/>").sortable().sortable("foo");
+ ok(true, 'arbitrary method called after init');
+
+ $("<div/>").sortable().data("foo.sortable");
+ ok(true, 'arbitrary option getter after init');
+
+ $("<div/>").sortable().data("foo.sortable", "bar");
+ ok(true, 'arbitrary option setter after init');
+});
+
+test("destroy", function() {
+ expect(6);
+
+ $("#sortable").sortable().sortable("destroy");
+ ok(true, '.sortable("destroy") called on element');
+
+ $([]).sortable().sortable("destroy");
+ ok(true, '.sortable("destroy") called on empty collection');
+
+ $("<div/>").sortable().sortable("destroy");
+ ok(true, '.sortable("destroy") called on disconnected DOMElement');
+
+ $("<div/>").sortable().sortable("destroy").sortable("foo");
+ ok(true, 'arbitrary method called after destroy');
+
+ $("<div/>").sortable().sortable("destroy").data("foo.sortable");
+ ok(true, 'arbitrary option getter after destroy');
+
+ $("<div/>").sortable().sortable("destroy").data("foo.sortable", "bar");
+ ok(true, 'arbitrary option setter after destroy');
+});
+
+test("enable", function() {
+ expect(4);
+ el = $("#sortable").sortable({ disabled: true });
+
+ sort($("li", el)[0], 0, 50, 0, '.sortable({ disabled: true })');
+
+ el.sortable("enable");
+ equals(el.data("disabled.sortable"), false, "disabled.sortable getter");
+
+ el.sortable("destroy");
+ el.sortable({ disabled: true });
+ el.data("disabled.sortable", false);
+ equals(el.data("disabled.sortable"), false, "disabled.sortable setter");
+
+ sort($("li", el)[0], 0, 20, 2, '.data("disabled.sortable", false)');
+});
+
+test("disable", function() {
+ expect(5);
+ el = $("#sortable").sortable({ disabled: false });
+ sort($("li", el)[0], 0, 20, 2, '.sortable({ disabled: false })');
+
+ el.sortable("disable");
+ sort($("li", el)[0], 0, 20, 0, 'disabled.sortable getter');
+
+ el.sortable("destroy");
+
+ el.sortable({ disabled: false });
+ sort($("li", el)[0], 0, 20, 2, '.sortable({ disabled: false })');
+ el.data("disabled.sortable", true);
+ equals(el.data("disabled.sortable"), true, "disabled.sortable setter");
+ sort($("li", el)[0], 0, 20, 0, '.data("disabled.sortable", true)');
+});
+
+test("defaults", function() {
+ el = $("#sortable").sortable();
+
+ equals(el.data("helper.sortable"), "clone", "helper");
+ equals(el.data("tolerance.sortable"), "guess", "tolerance");
+ equals(el.data("distance.sortable"), 0, "distance");
+ equals(el.data("disabled.sortable"), false, "disabled");
+ equals(el.data("delay.sortable"), 0, "delay");
+ equals(el.data("cancel.sortable"), ":input,button", "cancel");
+ equals(el.data("items.sortable"), "> *", "items");
+ equals(el.data("zIndex.sortable"), 1000, "zIndex");
+ equals(el.data("dropOnEmpty.sortable"), true, "dropOnEmpty");
+ equals(el.data("appendTo.sortable"), "parent", "appendTo");
+
+});
+
+
+})(jQuery);
|