2008-06-13 12:42:44 +00:00
|
|
|
/*
|
2008-08-18 10:38:23 +00:00
|
|
|
* sortable unit tests
|
2008-06-13 12:42:44 +00:00
|
|
|
*/
|
|
|
|
(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 });
|
|
|
|
|
2008-06-21 10:04:40 +00:00
|
|
|
sort($("li", el)[0], 0, 40, 0, '.sortable({ disabled: true })');
|
2008-06-13 12:42:44 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2008-06-21 10:04:40 +00:00
|
|
|
sort($("li", el)[0], 0, 40, 2, '.data("disabled.sortable", false)');
|
2008-06-13 12:42:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("disable", function() {
|
|
|
|
expect(5);
|
|
|
|
el = $("#sortable").sortable({ disabled: false });
|
2008-06-21 10:05:29 +00:00
|
|
|
sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');
|
2008-06-13 12:42:44 +00:00
|
|
|
|
|
|
|
el.sortable("disable");
|
2008-06-21 10:05:29 +00:00
|
|
|
sort($("li", el)[0], 0, 40, 0, 'disabled.sortable getter');
|
2008-06-13 12:42:44 +00:00
|
|
|
|
|
|
|
el.sortable("destroy");
|
|
|
|
|
|
|
|
el.sortable({ disabled: false });
|
2008-06-21 10:05:29 +00:00
|
|
|
sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');
|
2008-06-13 12:42:44 +00:00
|
|
|
el.data("disabled.sortable", true);
|
|
|
|
equals(el.data("disabled.sortable"), true, "disabled.sortable setter");
|
2008-06-21 10:05:29 +00:00
|
|
|
sort($("li", el)[0], 0, 40, 0, '.data("disabled.sortable", true)');
|
2008-06-13 12:42:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("defaults", function() {
|
|
|
|
el = $("#sortable").sortable();
|
|
|
|
|
2008-09-16 12:40:48 +00:00
|
|
|
equals(el.data("helper.sortable"), "original", "helper");
|
2008-06-13 12:42:44 +00:00
|
|
|
equals(el.data("tolerance.sortable"), "guess", "tolerance");
|
2008-06-24 14:30:26 +00:00
|
|
|
equals(el.data("distance.sortable"), 1, "distance");
|
2008-06-13 12:42:44 +00:00
|
|
|
equals(el.data("disabled.sortable"), false, "disabled");
|
|
|
|
equals(el.data("delay.sortable"), 0, "delay");
|
2008-06-24 13:17:02 +00:00
|
|
|
equals(el.data("scroll.sortable"), true, "scroll");
|
|
|
|
equals(el.data("scrollSensitivity.sortable"), 20, "scrollSensitivity");
|
|
|
|
equals(el.data("scrollSpeed.sortable"), 20, "scrollSpeed");
|
2008-06-26 10:23:38 +00:00
|
|
|
equals(el.data("cancel.sortable"), ":input", "cancel");
|
2008-06-13 12:42:44 +00:00
|
|
|
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");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2008-06-24 11:47:42 +00:00
|
|
|
test("#3019: Stop fires too early", function() {
|
|
|
|
|
|
|
|
var helper = null;
|
|
|
|
el = $("#sortable").sortable({ stop: function(e, ui) {
|
|
|
|
helper = ui.helper;
|
|
|
|
}});
|
|
|
|
|
|
|
|
sort($("li", el)[0], 0, 40, 2, 'Dragging the sortable');
|
|
|
|
equals(helper, null, "helper should be false");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2008-06-13 12:42:44 +00:00
|
|
|
|
|
|
|
})(jQuery);
|