aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/sortable
diff options
context:
space:
mode:
authorRichard Worth <rdworth@gmail.com>2009-01-07 03:31:15 +0000
committerRichard Worth <rdworth@gmail.com>2009-01-07 03:31:15 +0000
commitb792bd46ec9b1b55bf2289faedd4ab3614c9319a (patch)
tree4b1736c703d392ec07fd4a5ae3390151470ae933 /tests/unit/sortable
parent4707debd645e63ea22d7a076e97a34eb3d310ebc (diff)
downloadjquery-ui-b792bd46ec9b1b55bf2289faedd4ab3614c9319a.tar.gz
jquery-ui-b792bd46ec9b1b55bf2289faedd4ab3614c9319a.zip
restructured unit tests folder
Diffstat (limited to 'tests/unit/sortable')
-rw-r--r--tests/unit/sortable/sortable.html30
-rw-r--r--tests/unit/sortable/sortable.js148
2 files changed, 178 insertions, 0 deletions
diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html
new file mode 100644
index 000000000..5c45144bc
--- /dev/null
+++ b/tests/unit/sortable/sortable.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <title>jQuery UI Sortable Test Suite</title>
+
+ <script type="text/javascript" src="../../../jquery-1.3pre.js"></script>
+ <script type="text/javascript" src="../../../ui/ui.core.js"></script>
+ <script type="text/javascript" src="../../../ui/ui.sortable.js"></script>
+
+ <link type="text/css" href="../testsuite.css" rel="stylesheet" />
+ <script type="text/javascript" src="../testsuite.js"></script>
+ <script type="text/javascript" src="../../../external/qunit/testrunner.js"></script>
+ <script type="text/javascript" src="../../../external/simulate/jquery.simulate.js"></script>
+
+ <script type="text/javascript" src="sortable.js"></script>
+</head>
+<body>
+
+<div id="main">
+ <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/unit/sortable/sortable.js b/tests/unit/sortable/sortable.js
new file mode 100644
index 000000000..c913ed86d
--- /dev/null
+++ b/tests/unit/sortable/sortable.js
@@ -0,0 +1,148 @@
+/*
+ * sortable unit tests
+ */
+(function($) {
+//
+// Sortable Test Helper Functions
+//
+
+var defaults = {
+ appendTo: "parent",
+ cancel: ":input",
+ delay: 0,
+ disabled: false,
+ distance: 1,
+ dropOnEmpty: true,
+ helper: "original",
+ items: "> *",
+ scroll: true,
+ scrollSensitivity: 20,
+ scrollSpeed: 20,
+ tolerance: "guess",
+ zIndex: 1000
+};
+
+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);
+
+ $("<div></div>").appendTo('body').sortable().remove();
+ ok(true, '.sortable() called on element');
+
+ $([]).sortable();
+ ok(true, '.sortable() called on empty collection');
+
+ $("<div></div>").sortable();
+ ok(true, '.sortable() called on disconnected DOMElement');
+
+ $("<div></div>").sortable().sortable("foo");
+ ok(true, 'arbitrary method called after init');
+
+ $("<div></div>").sortable().data("foo.sortable");
+ ok(true, 'arbitrary option getter after init');
+
+ $("<div></div>").sortable().data("foo.sortable", "bar");
+ ok(true, 'arbitrary option setter after init');
+});
+
+test("destroy", function() {
+ expect(6);
+
+ $("<div></div>").appendTo('body').sortable().sortable("destroy").remove();
+ ok(true, '.sortable("destroy") called on element');
+
+ $([]).sortable().sortable("destroy");
+ ok(true, '.sortable("destroy") called on empty collection');
+
+ $("<div></div>").sortable().sortable("destroy");
+ ok(true, '.sortable("destroy") called on disconnected DOMElement');
+
+ $("<div></div>").sortable().sortable("destroy").sortable("foo");
+ ok(true, 'arbitrary method called after destroy');
+
+ $("<div></div>").sortable().sortable("destroy").data("foo.sortable");
+ ok(true, 'arbitrary option getter after destroy');
+
+ $("<div></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, 40, 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, 40, 2, '.data("disabled.sortable", false)');
+});
+
+test("disable", function() {
+ expect(5);
+ el = $("#sortable").sortable({ disabled: false });
+ sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');
+
+ el.sortable("disable");
+ sort($("li", el)[0], 0, 40, 0, 'disabled.sortable getter');
+
+ el.sortable("destroy");
+
+ el.sortable({ disabled: false });
+ sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');
+ el.data("disabled.sortable", true);
+ equals(el.data("disabled.sortable"), true, "disabled.sortable setter");
+ sort($("li", el)[0], 0, 40, 0, '.data("disabled.sortable", true)');
+});
+
+test("defaults", function() {
+ el = $('<div></div>').sortable();
+ $.each(defaults, function(key, val) {
+ var actual = el.data(key + ".sortable"), expected = val;
+ same(actual, expected, key);
+ });
+ el.remove();
+});
+
+test("#3019: Stop fires too early", function() {
+
+ var helper = null;
+ el = $("#sortable").sortable({ stop: function(event, ui) {
+ helper = ui.helper;
+ }});
+
+ sort($("li", el)[0], 0, 40, 2, 'Dragging the sortable');
+ equals(helper, null, "helper should be false");
+
+});
+
+
+})(jQuery);