tests: cleanup and consistency with defaults tests

This commit is contained in:
Richard Worth 2008-11-12 02:52:31 +00:00
parent 7d946ec774
commit e47820f6ea
10 changed files with 355 additions and 224 deletions

View File

@ -115,48 +115,48 @@ module("dialog");
test("init", function() {
expect(6);
$("#dialog1").dialog().remove();
$("<div></div>").appendTo('body').dialog().remove();
ok(true, '.dialog() called on element');
$([]).dialog().remove();
ok(true, '.dialog() called on empty collection');
$('<div/>').dialog().remove();
$('<div></div>').dialog().remove();
ok(true, '.dialog() called on disconnected DOMElement');
$('<div/>').dialog().dialog("foo").remove();
$('<div></div>').dialog().dialog("foo").remove();
ok(true, 'arbitrary method called after init');
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
var foo = el.data("foo.dialog");
el.remove();
ok(true, 'arbitrary option getter after init');
$('<div/>').dialog().data("foo.dialog", "bar").remove();
$('<div></div>').dialog().data("foo.dialog", "bar").remove();
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(6);
$("#dialog1").dialog().dialog("destroy").remove();
$("<div></div>").appendTo('body').dialog().dialog("destroy").remove();
ok(true, '.dialog("destroy") called on element');
$([]).dialog().dialog("destroy").remove();
ok(true, '.dialog("destroy") called on empty collection');
$('<div/>').dialog().dialog("destroy").remove();
$('<div></div>').dialog().dialog("destroy").remove();
ok(true, '.dialog("destroy") called on disconnected DOMElement');
$('<div/>').dialog().dialog("destroy").dialog("foo").remove();
$('<div></div>').dialog().dialog("destroy").dialog("foo").remove();
ok(true, 'arbitrary method called after destroy');
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
var foo = el.dialog("destroy").data("foo.dialog");
el.remove();
ok(true, 'arbitrary option getter after destroy');
$('<div/>').dialog().dialog("destroy").data("foo.dialog", "bar").remove();
$('<div></div>').dialog().dialog("destroy").data("foo.dialog", "bar").remove();
ok(true, 'arbitrary option setter after destroy');
});
@ -183,7 +183,7 @@ test("element types", function() {
*/
test("defaults", function() {
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".dialog"), expected = val;
same(actual, expected, key);
@ -199,12 +199,12 @@ test("title id", function() {
// reset the uuid so we know what values to expect
$.ui.dialog.uuid = 0;
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
titleId = dlg().find('.ui-dialog-title').attr('id');
equals(titleId, 'ui-dialog-title-1', 'auto-numbered title id');
el.remove();
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
titleId = dlg().find('.ui-dialog-title').attr('id');
equals(titleId, 'ui-dialog-title-2', 'auto-numbered title id');
el.remove();
@ -220,11 +220,11 @@ module("dialog: Options");
test("autoOpen", function() {
expect(2);
el = $('<div/>').dialog({ autoOpen: false });
el = $('<div></div>').dialog({ autoOpen: false });
isNotOpen('.dialog({ autoOpen: false })');
el.remove();
el = $('<div/>').dialog({ autoOpen: true });
el = $('<div></div>').dialog({ autoOpen: true });
isOpen('.dialog({ autoOpen: true })');
el.remove();
});
@ -270,7 +270,7 @@ test("buttons", function() {
}
};
el = $('<div/>').dialog({ buttons: buttons });
el = $('<div></div>').dialog({ buttons: buttons });
var btn = $("button", dlg());
equals(btn.length, 2, "number of buttons");
@ -311,15 +311,15 @@ test("buttons", function() {
test("dialogClass", function() {
expect(4);
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added');
el.remove();
el = $('<div/>').dialog({ dialogClass: "foo" });
el = $('<div></div>').dialog({ dialogClass: "foo" });
equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added');
el.remove();
el = $('<div/>').dialog({ dialogClass: "foo bar" });
el = $('<div></div>').dialog({ dialogClass: "foo bar" });
equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added');
equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added');
el.remove();
@ -328,13 +328,13 @@ test("dialogClass", function() {
test("draggable", function() {
expect(4);
el = $('<div/>').dialog({ draggable: false });
el = $('<div></div>').dialog({ draggable: false });
shouldnotmove();
el.data('draggable.dialog', true);
shouldmove();
el.remove();
el = $('<div/>').dialog({ draggable: true });
el = $('<div></div>').dialog({ draggable: true });
shouldmove();
el.data('draggable.dialog', false);
shouldnotmove();
@ -344,15 +344,15 @@ test("draggable", function() {
test("height", function() {
expect(3);
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
equals(dlg().height(), defaults.height, "default height");
el.remove();
el = $('<div/>').dialog({ height: 437 });
el = $('<div></div>').dialog({ height: 437 });
equals(dlg().height(), 437, "explicit height");
el.remove();
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
el.data('height.dialog', 438);
equals(dlg().height(), 438, "explicit height set after init");
el.remove();
@ -361,17 +361,17 @@ test("height", function() {
test("maxHeight", function() {
expect(3);
el = $('<div/>').dialog({ maxHeight: 400 });
el = $('<div></div>').dialog({ maxHeight: 400 });
drag('.ui-resizable-s', 1000, 1000);
equals(heightAfter, 400, "maxHeight");
el.remove();
el = $('<div/>').dialog({ maxHeight: 400 });
el = $('<div></div>').dialog({ maxHeight: 400 });
drag('.ui-resizable-n', -1000, -1000);
equals(heightAfter, 400, "maxHeight");
el.remove();
el = $('<div/>').dialog({ maxHeight: 400 }).data('maxHeight.dialog', 600);
el = $('<div></div>').dialog({ maxHeight: 400 }).data('maxHeight.dialog', 600);
drag('.ui-resizable-n', -1000, -1000);
equals(heightAfter, 600, "maxHeight");
el.remove();
@ -380,17 +380,17 @@ test("maxHeight", function() {
test("maxWidth", function() {
expect(3);
el = $('<div/>').dialog({ maxWidth: 400 });
el = $('<div></div>').dialog({ maxWidth: 400 });
drag('.ui-resizable-e', 1000, 1000);
equals(widthAfter, 400, "maxWidth");
el.remove();
el = $('<div/>').dialog({ maxWidth: 400 });
el = $('<div></div>').dialog({ maxWidth: 400 });
drag('.ui-resizable-w', -1000, -1000);
equals(widthAfter, 400, "maxWidth");
el.remove();
el = $('<div/>').dialog({ maxWidth: 400 }).data('maxWidth.dialog', 600);
el = $('<div></div>').dialog({ maxWidth: 400 }).data('maxWidth.dialog', 600);
drag('.ui-resizable-w', -1000, -1000);
equals(widthAfter, 600, "maxWidth");
el.remove();
@ -399,17 +399,17 @@ test("maxWidth", function() {
test("minHeight", function() {
expect(3);
el = $('<div/>').dialog({ minHeight: 10 });
el = $('<div></div>').dialog({ minHeight: 10 });
drag('.ui-resizable-s', -1000, -1000);
equals(heightAfter, 10, "minHeight");
el.remove();
el = $('<div/>').dialog({ minHeight: 10 });
el = $('<div></div>').dialog({ minHeight: 10 });
drag('.ui-resizable-n', 1000, 1000);
equals(heightAfter, 10, "minHeight");
el.remove();
el = $('<div/>').dialog({ minHeight: 10 }).data('minHeight.dialog', 30);
el = $('<div></div>').dialog({ minHeight: 10 }).data('minHeight.dialog', 30);
drag('.ui-resizable-n', 1000, 1000);
equals(heightAfter, 30, "minHeight");
el.remove();
@ -418,17 +418,17 @@ test("minHeight", function() {
test("minWidth", function() {
expect(3);
el = $('<div/>').dialog({ minWidth: 10 });
el = $('<div></div>').dialog({ minWidth: 10 });
drag('.ui-resizable-e', -1000, -1000);
equals(widthAfter, 10, "minWidth");
el.remove();
el = $('<div/>').dialog({ minWidth: 10 });
el = $('<div></div>').dialog({ minWidth: 10 });
drag('.ui-resizable-w', 1000, 1000);
equals(widthAfter, 10, "minWidth");
el.remove();
el = $('<div/>').dialog({ minWidth: 30 }).data('minWidth.dialog', 30);
el = $('<div></div>').dialog({ minWidth: 30 }).data('minWidth.dialog', 30);
drag('.ui-resizable-w', 1000, 1000);
equals(widthAfter, 30, "minWidth");
el.remove();
@ -449,13 +449,13 @@ test("position", function() {
test("resizable", function() {
expect(4);
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
shouldresize("[default]");
el.data('resizable.dialog', false);
shouldnotresize('disabled after init');
el.remove();
el = $('<div/>').dialog({ resizable: false });
el = $('<div></div>').dialog({ resizable: false });
shouldnotresize("disabled in init options");
el.data('resizable.dialog', true);
shouldresize('enabled after init');
@ -473,7 +473,7 @@ test("title", function() {
return dlg().find(".ui-dialog-title").html();
}
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
equals(titleText(), "&nbsp;", "[default]");
el.remove();
@ -481,7 +481,7 @@ test("title", function() {
equals(titleText(), "foo", "title in element attribute");
el.remove();
el = $('<div/>').dialog({ title: 'foo' });
el = $('<div></div>').dialog({ title: 'foo' });
equals(titleText(), "foo", "title in init options");
el.remove();
@ -489,7 +489,7 @@ test("title", function() {
equals(titleText(), "bar", "title in init options should override title in element attribute");
el.remove();
el = $('<div/>').dialog().data('title.dialog', 'foo');
el = $('<div></div>').dialog().data('title.dialog', 'foo');
equals(titleText(), 'foo', 'title after init');
el.remove();
});
@ -497,11 +497,11 @@ test("title", function() {
test("width", function() {
expect(3);
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
equals(dlg().width(), defaults.width, "default width");
el.remove();
el = $('<div/>').dialog({width: 437 });
el = $('<div></div>').dialog({width: 437 });
equals(dlg().width(), 437, "explicit width");
el.data('width.dialog', 438);
equals(dlg().width(), 438, 'explicit width after init');
@ -513,13 +513,13 @@ module("dialog: Methods");
test("isOpen", function() {
expect(4);
el = $('<div/>').dialog();
el = $('<div></div>').dialog();
equals(el.dialog('isOpen'), true, "dialog is open after init");
el.dialog('close');
equals(el.dialog('isOpen'), false, "dialog is closed");
el.remove();
el = $('<div/>').dialog({autoOpen: false});
el = $('<div></div>').dialog({autoOpen: false});
equals(el.dialog('isOpen'), false, "dialog is closed after init");
el.dialog('open');
equals(el.dialog('isOpen'), true, "dialog is open");
@ -531,7 +531,7 @@ module("dialog: Callbacks");
test("open", function() {
expect(6);
el = $("<div/>");
el = $("<div></div>");
el.dialog({
open: function(ev, ui) {
ok(true, 'autoOpen: true fires open callback');
@ -540,7 +540,7 @@ test("open", function() {
});
el.remove();
el = $("<div/>");
el = $("<div></div>");
el.dialog({
autoOpen: false,
open: function(ev, ui) {
@ -551,7 +551,7 @@ test("open", function() {
el.dialog("open");
el.remove();
el = $('<div/>').dialog({
el = $('<div></div>').dialog({
autoOpen: false
});
el.bind('dialogopen', function(ev, ui) {
@ -565,7 +565,7 @@ test("open", function() {
test("dragStart", function() {
expect(2);
el = $("<div/>");
el = $("<div></div>");
el.dialog({
dragStart: function(ev, ui) {
ok(true, 'dragging fires dragStart callback');
@ -580,7 +580,7 @@ test("dragStart", function() {
test("drag", function() {
var fired = false;
el = $("<div/>");
el = $("<div></div>");
el.dialog({
drag: function(ev, ui) {
fired = true;
@ -596,7 +596,7 @@ test("drag", function() {
test("dragStop", function() {
expect(2);
el = $("<div/>");
el = $("<div></div>");
el.dialog({
dragStop: function(ev, ui) {
ok(true, 'dragging fires dragStop callback');
@ -611,7 +611,7 @@ test("dragStop", function() {
test("resizeStart", function() {
expect(2);
el = $("<div/>");
el = $("<div></div>");
el.dialog({
resizeStart: function(ev, ui) {
ok(true, 'resizing fires resizeStart callback');
@ -626,7 +626,7 @@ test("resizeStart", function() {
test("resize", function() {
var fired = false;
el = $("<div/>");
el = $("<div></div>");
el.dialog({
resize: function(ev, ui) {
fired = true;
@ -642,7 +642,7 @@ test("resize", function() {
test("resizeStop", function() {
expect(2);
el = $("<div/>");
el = $("<div></div>");
el.dialog({
resizeStop: function(ev, ui) {
ok(true, 'resizing fires resizeStop callback');
@ -657,7 +657,7 @@ test("resizeStop", function() {
test("close", function() {
expect(4);
el = $('<div/>').dialog({
el = $('<div></div>').dialog({
close: function(ev, ui) {
ok(true, '.dialog("close") fires close callback');
equals(this, el[0], "context of callback");
@ -666,7 +666,7 @@ test("close", function() {
el.dialog("close");
el.remove();
el = $('<div/>').dialog().bind('dialogclose', function(ev, ui) {
el = $('<div></div>').dialog().bind('dialogclose', function(ev, ui) {
ok(true, '.dialog("close") firse dialogclose event');
equals(this, el[0], 'context of event');
});
@ -677,7 +677,7 @@ test("close", function() {
test("beforeclose", function() {
expect(6);
el = $('<div/>').dialog({
el = $('<div></div>').dialog({
beforeclose: function(ev, ui) {
ok(true, '.dialog("close") fires beforeclose callback');
equals(this, el[0], "context of callback");
@ -688,7 +688,7 @@ test("beforeclose", function() {
isOpen('beforeclose callback should prevent dialog from closing');
el.remove();
el = $('<div/>').dialog().bind('dialogbeforeclose', function(ev, ui) {
el = $('<div></div>').dialog().bind('dialogbeforeclose', function(ev, ui) {
ok(true, '.dialog("close") triggers dialogbeforeclose event');
equals(this, el[0], "context of event");
return false;

View File

@ -5,6 +5,37 @@
//
// Draggable Test Helper Functions
//
var defaults = {
appendTo: "parent",
axis: false,
cancel: ":input",
connectToSortable: false,
containment: false,
cursor: "default",
cursorAt: null,
delay: 0,
disabled: false,
distance: 1,
grid: false,
handle: false,
helper: "original",
iframeFix: false,
opacity: 1.0,
refreshPositions: false,
revert: false,
revertDuration: 500,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 20,
scope: "default",
snap: false,
snapMode: "both",
snapTolerance: 20,
stack: false,
zIndex: null
};
var el, offsetBefore, offsetAfter, dragged;
var drag = function(handle, dx, dy) {
@ -45,44 +76,44 @@ module("draggable");
test("init", function() {
expect(6);
el = $("#draggable1").draggable();
$("<div></div>").appendTo('body').draggable().remove();
ok(true, '.draggable() called on element');
$([]).draggable();
ok(true, '.draggable() called on empty collection');
$("<div/>").draggable();
$("<div></div>").draggable();
ok(true, '.draggable() called on disconnected DOMElement');
$("<div/>").draggable().draggable("foo");
$("<div></div>").draggable().draggable("foo");
ok(true, 'arbitrary method called after init');
$("<div/>").draggable().data("foo.draggable");
$("<div></div>").draggable().data("foo.draggable");
ok(true, 'arbitrary option getter after init');
$("<div/>").draggable().data("foo.draggable", "bar");
$("<div></div>").draggable().data("foo.draggable", "bar");
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(6);
$("#draggable1").draggable().draggable("destroy");
$("<div></div>").appendTo('body').draggable().draggable("destroy").remove();
ok(true, '.draggable("destroy") called on element');
$([]).draggable().draggable("destroy");
ok(true, '.draggable("destroy") called on empty collection');
$("<div/>").draggable().draggable("destroy");
$("<div></div>").draggable().draggable("destroy");
ok(true, '.draggable("destroy") called on disconnected DOMElement');
$("<div/>").draggable().draggable("destroy").draggable("foo");
$("<div></div>").draggable().draggable("destroy").draggable("foo");
ok(true, 'arbitrary method called after destroy');
$("<div/>").draggable().draggable("destroy").data("foo.draggable");
$("<div></div>").draggable().draggable("destroy").data("foo.draggable");
ok(true, 'arbitrary option getter after destroy');
$("<div/>").draggable().draggable("destroy").data("foo.draggable", "bar");
$("<div></div>").draggable().draggable("destroy").data("foo.draggable", "bar");
ok(true, 'arbitrary option setter after destroy');
});
@ -138,42 +169,12 @@ test("element types", function() {
});
test("defaults", function() {
var expected = {
appendTo: "parent",
axis: false,
cancel: ":input",
connectToSortable: false,
containment: false,
cursor: "default",
cursorAt: null,
delay: 0,
disabled: false,
distance: 1,
grid: false,
handle: false,
helper: "original",
iframeFix: false,
opacity: 1.0,
refreshPositions: false,
revert: false,
revertDuration: 500,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 20,
scope: "default",
snap: false,
snapMode: "both",
snapTolerance: 20,
stack: false,
zIndex: null
};
el = $("#draggable1").draggable();
for (var optionName in expected)
equals(el.data(optionName + ".draggable"), expected[optionName], optionName);
el = $('<div></div>').draggable();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".draggable"), expected = val;
same(actual, expected, key);
});
el.remove();
});
test("No options, relative", function() {

View File

@ -33,44 +33,44 @@ module("droppable");
test("init", function() {
expect(6);
el = $("#droppable1").droppable();
$("<div></div>").appendTo('body').droppable().remove();
ok(true, '.droppable() called on element');
$([]).droppable();
ok(true, '.droppable() called on empty collection');
$("<div/>").droppable();
$("<div></div>").droppable();
ok(true, '.droppable() called on disconnected DOMElement');
$("<div/>").droppable().droppable("foo");
$("<div></div>").droppable().droppable("foo");
ok(true, 'arbitrary method called after init');
$("<div/>").droppable().data("foo.droppable");
$("<div></div>").droppable().data("foo.droppable");
ok(true, 'arbitrary option getter after init');
$("<div/>").droppable().data("foo.droppable", "bar");
$("<div></div>").droppable().data("foo.droppable", "bar");
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(6);
$("#droppable1").droppable().droppable("destroy");
$("<div></div>").appendTo('body').droppable().droppable("destroy").remove();
ok(true, '.droppable("destroy") called on element');
$([]).droppable().droppable("destroy");
ok(true, '.droppable("destroy") called on empty collection');
$("<div/>").droppable().droppable("destroy");
$("<div></div>").droppable().droppable("destroy");
ok(true, '.droppable("destroy") called on disconnected DOMElement');
$("<div/>").droppable().droppable("destroy").droppable("foo");
$("<div></div>").droppable().droppable("destroy").droppable("foo");
ok(true, 'arbitrary method called after destroy');
$("<div/>").droppable().droppable("destroy").data("foo.droppable");
$("<div></div>").droppable().droppable("destroy").data("foo.droppable");
ok(true, 'arbitrary option getter after destroy');
$("<div/>").droppable().droppable("destroy").data("foo.droppable", "bar");
$("<div></div>").droppable().droppable("destroy").data("foo.droppable", "bar");
ok(true, 'arbitrary option setter after destroy');
});

View File

@ -2,14 +2,28 @@
* progressbar unit tests
*/
(function($) {
//
// Progressbar Test Helper Functions
//
// Spinner Tests
var defaults = {
disabled: false,
duration: 1000,
increment: 1,
interval: 1000,
range: true,
width: 300
};
var el;
// Progressbar Tests
module("progressbar");
test("init", function() {
expect(1);
el = $("#progressbar").progressbar();
$("<div></div>").appendTo('body').progressbar().remove();
ok(true, '.progressbar() called on element');
});
@ -17,21 +31,18 @@ test("init", function() {
test("destroy", function() {
expect(1);
$("#progressbar").progressbar().progressbar("destroy");
$("<div></div>").appendTo('body').progressbar().progressbar("destroy").remove();
ok(true, '.progressbar("destroy") called on element');
});
test("defaults", function() {
expect(5);
el = $("#progressbar").progressbar();
equals(el.data("width.progressbar"), 300, "width");
equals(el.data("duration.progressbar"), 1000, "duration");
equals(el.data("interval.progressbar"), 1000, "interval");
equals(el.data("increment.progressbar"), 1, "increment");
equals(el.data("range.progressbar"), true, "range");
el = $('<div></div>').progressbar();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".progressbar"), expected = val;
same(actual, expected, key);
});
el.remove();
});
test("set defaults on init", function() {

View File

@ -6,20 +6,6 @@
// Resizable Test Helper Functions
//
var drag = function(el, dx, dy, complete) {
// speed = sync -> Drag syncrhonously.
// speed = fast|slow -> Drag asyncrhonously - animated.
//this mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used
$(el).simulate("mouseover");
return $(el).simulate("drag", {
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
});
};
var defaults = {
animate: false,
animateDuration: 'slow',
@ -48,54 +34,68 @@ var defaults = {
transparent: false
};
var drag = function(el, dx, dy, complete) {
// speed = sync -> Drag syncrhonously.
// speed = fast|slow -> Drag asyncrhonously - animated.
//this mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used
$(el).simulate("mouseover");
return $(el).simulate("drag", {
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
});
};
// Resizable Tests
module("resizable");
test("init", function() {
expect(6);
$("#resizable1").resizable().remove();
$("<div></div>").appendTo('body').resizable().remove();
ok(true, '.resizable() called on element');
$([]).resizable().remove();
ok(true, '.resizable() called on empty collection');
$('<div/>').resizable().remove();
$('<div></div>').resizable().remove();
ok(true, '.resizable() called on disconnected DOMElement');
$('<div/>').resizable().resizable("foo").remove();
$('<div></div>').resizable().resizable("foo").remove();
ok(true, 'arbitrary method called after init');
el = $('<div/>').resizable()
el = $('<div></div>').resizable()
var foo = el.data("foo.resizable");
el.remove();
ok(true, 'arbitrary option getter after init');
$('<div/>').resizable().data("foo.resizable", "bar").remove();
$('<div></div>').resizable().data("foo.resizable", "bar").remove();
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(6);
$("#dialog1").resizable().resizable("destroy").remove();
$("<div></div>").appendTo('body').resizable().resizable("destroy").remove();
ok(true, '.resizable("destroy") called on element');
$([]).resizable().resizable("destroy").remove();
ok(true, '.resizable("destroy") called on empty collection');
$('<div/>').resizable().resizable("destroy").remove();
$('<div></div>').resizable().resizable("destroy").remove();
ok(true, '.resizable("destroy") called on disconnected DOMElement');
$('<div/>').resizable().resizable("destroy").resizable("foo").remove();
$('<div></div>').resizable().resizable("destroy").resizable("foo").remove();
ok(true, 'arbitrary method called after destroy');
el = $('<div/>').resizable();
el = $('<div></div>').resizable();
var foo = el.resizable("destroy").data("foo.resizable");
el.remove();
ok(true, 'arbitrary option getter after destroy');
$('<div/>').resizable().resizable("destroy").data("foo.resizable", "bar").remove();
$('<div></div>').resizable().resizable("destroy").data("foo.resizable", "bar").remove();
ok(true, 'arbitrary option setter after destroy');
});
@ -117,7 +117,7 @@ test("element types", function() {
});
test("defaults", function() {
el = $('<div/>').resizable();
el = $('<div></div>').resizable();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".resizable"), expected = val;
same(actual, expected, key);

View File

@ -5,6 +5,13 @@
//
// Selectable Test Helper Functions
//
var defaults = {
autoRefresh: true,
disabled: false,
filter: '*'
};
var el;
var drag = function(dx, dy) {
@ -27,57 +34,53 @@ module("selectable");
test("init", function() {
expect(6);
$("#selectable1").selectable().remove();
$("<div></div>").appendTo('body').selectable().remove();
ok(true, '.selectable() called on element');
$([]).selectable().remove();
ok(true, '.selectable() called on empty collection');
$("<div/>").selectable().remove();
$("<div></div>").selectable().remove();
ok(true, '.selectable() called on disconnected DOMElement');
$("<div/>").selectable().selectable("foo").remove();
$("<div></div>").selectable().selectable("foo").remove();
ok(true, 'arbitrary method called after init');
el = $("<div/>").selectable()
el = $("<div></div>").selectable()
var foo = el.data("foo.selectable");
el.remove();
ok(true, 'arbitrary option getter after init');
$("<div/>").selectable().data("foo.selectable", "bar").remove();
$("<div></div>").selectable().data("foo.selectable", "bar").remove();
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(6);
$("#selectable1").selectable().selectable("destroy").remove();
$("<div></div>").appendTo('body').selectable().selectable("destroy").remove();
ok(true, '.selectable("destroy") called on element');
$([]).selectable().selectable("destroy").remove();
ok(true, '.selectable("destroy") called on empty collection');
$("<div/>").selectable().selectable("destroy").remove();
$("<div></div>").selectable().selectable("destroy").remove();
ok(true, '.selectable("destroy") called on disconnected DOMElement');
$("<div/>").selectable().selectable("destroy").selectable("foo").remove();
$("<div></div>").selectable().selectable("destroy").selectable("foo").remove();
ok(true, 'arbitrary method called after destroy');
el = $("<div/>").selectable();
el = $("<div></div>").selectable();
var foo = el.selectable("destroy").data("foo.selectable");
el.remove();
ok(true, 'arbitrary option getter after destroy');
$("<div/>").selectable().selectable("destroy").data("foo.selectable", "bar").remove();
$("<div></div>").selectable().selectable("destroy").data("foo.selectable", "bar").remove();
ok(true, 'arbitrary option setter after destroy');
});
test("defaults", function() {
el = $('#selectable1').selectable();
var defaults = {
autoRefresh: true,
filter: '*'
};
el = $('<div></div>').selectable();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".selectable"), expected = val;
same(actual, expected, key);

View File

@ -2,6 +2,23 @@
* slider unit tests
*/
(function($) {
//
// Selectable Test Helper Functions
//
var defaults = {
animate: false,
axis: "???",
handle: ".ui-slider-handle",
handles: "???",
disabled: false,
max: 100,
min: 0,
range: false,
startValue: "???",
stepping: "???",
steps: 0
};
var keyCodes = {
leftArrow: 37,
@ -32,7 +49,67 @@ function assertChange(stepping, start, result, action) {
}
}
module("slider: single handle")
// Slider Tests
module("slider");
test("init", function() {
expect(6);
$("<div></div>").appendTo('body').slider().remove();
ok(true, '.slider() called on element');
$([]).slider().remove();
ok(true, '.slider() called on empty collection');
$('<div></div>').slider().remove();
ok(true, '.slider() called on disconnected DOMElement');
$('<div></div>').slider().slider("foo").remove();
ok(true, 'arbitrary method called after init');
el = $('<div></div>').slider();
var foo = el.data("foo.slider");
el.remove();
ok(true, 'arbitrary option getter after init');
$('<div></div>').slider().data("foo.slider", "bar").remove();
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(6);
$("<div></div>").appendTo('body').slider().slider("destroy").remove();
ok(true, '.slider("destroy") called on element');
$([]).slider().slider("destroy").remove();
ok(true, '.slider("destroy") called on empty collection');
$('<div></div>').slider().slider("destroy").remove();
ok(true, '.slider("destroy") called on disconnected DOMElement');
$('<div></div>').slider().slider("destroy").slider("foo").remove();
ok(true, 'arbitrary method called after destroy');
el = $('<div></div>').slider();
var foo = el.slider("destroy").data("foo.slider");
el.remove();
ok(true, 'arbitrary option getter after destroy');
$('<div></div>').slider().slider("destroy").data("foo.slider", "bar").remove();
ok(true, 'arbitrary option setter after destroy');
});
test("defaults", function() {
el = $('<div></div>').slider();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".slider"), expected = val;
same(actual, expected, key);
});
el.remove();
});
module("slider: single handle");
test("change one step via keydown", assertChange(1, undefined, 1, function() {
this.find("a").rightArrow();

View File

@ -5,6 +5,23 @@
//
// 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) {
@ -31,44 +48,44 @@ module("sortable");
test("init", function() {
expect(6);
el = $("#sortable").sortable();
$("<div></div>").appendTo('body').sortable().remove();
ok(true, '.sortable() called on element');
$([]).sortable();
ok(true, '.sortable() called on empty collection');
$("<div/>").sortable();
$("<div></div>").sortable();
ok(true, '.sortable() called on disconnected DOMElement');
$("<div/>").sortable().sortable("foo");
$("<div></div>").sortable().sortable("foo");
ok(true, 'arbitrary method called after init');
$("<div/>").sortable().data("foo.sortable");
$("<div></div>").sortable().data("foo.sortable");
ok(true, 'arbitrary option getter after init');
$("<div/>").sortable().data("foo.sortable", "bar");
$("<div></div>").sortable().data("foo.sortable", "bar");
ok(true, 'arbitrary option setter after init');
});
test("destroy", function() {
expect(6);
$("#sortable").sortable().sortable("destroy");
$("<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/>").sortable().sortable("destroy");
$("<div></div>").sortable().sortable("destroy");
ok(true, '.sortable("destroy") called on disconnected DOMElement');
$("<div/>").sortable().sortable("destroy").sortable("foo");
$("<div></div>").sortable().sortable("destroy").sortable("foo");
ok(true, 'arbitrary method called after destroy');
$("<div/>").sortable().sortable("destroy").data("foo.sortable");
$("<div></div>").sortable().sortable("destroy").data("foo.sortable");
ok(true, 'arbitrary option getter after destroy');
$("<div/>").sortable().sortable("destroy").data("foo.sortable", "bar");
$("<div></div>").sortable().sortable("destroy").data("foo.sortable", "bar");
ok(true, 'arbitrary option setter after destroy');
});
@ -107,22 +124,12 @@ test("disable", function() {
});
test("defaults", function() {
el = $("#sortable").sortable();
equals(el.data("helper.sortable"), "original", "helper");
equals(el.data("tolerance.sortable"), "guess", "tolerance");
equals(el.data("distance.sortable"), 1, "distance");
equals(el.data("disabled.sortable"), false, "disabled");
equals(el.data("delay.sortable"), 0, "delay");
equals(el.data("scroll.sortable"), true, "scroll");
equals(el.data("scrollSensitivity.sortable"), 20, "scrollSensitivity");
equals(el.data("scrollSpeed.sortable"), 20, "scrollSpeed");
equals(el.data("cancel.sortable"), ":input", "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");
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() {

View File

@ -2,6 +2,26 @@
* spinner unit tests
*/
(function($) {
//
// Spinner Test Helper Functions
//
var defaults = {
currency: false,
decimals: 0,
disabled: false,
format: "%",
group: "",
incremental: true,
items: null,
max: null,
min: null,
point: ".",
start: 0,
stepping: 1
};
var el;
// Spinner Tests
module("spinner");
@ -9,7 +29,7 @@ module("spinner");
test("init", function() {
expect(2);
$("#spin").spinner();
$("<div></div>").appendTo('body').spinner().remove();
ok(true, '.spinner() called on element');
$('<input id="spinner_dis">').spinner().remove();
@ -20,7 +40,7 @@ test("init", function() {
test("destroy", function() {
expect(2);
$("#spin").spinner().spinner("destroy");
$("<div></div>").appendTo('body').spinner().spinner("destroy").remove();
ok(true, '.spinner("destroy") called on element');
$('<input id="spinner_dis">').spinner().spinner("destroy").remove();
@ -28,6 +48,15 @@ test("destroy", function() {
});
test("defaults", function() {
el = $('<div></div>').spinner();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".spinner"), expected = val;
same(actual, expected, key);
});
el.remove();
});
test("re-attach", function() {
expect(2);

View File

@ -2,6 +2,32 @@
* tabs unit tests
*/
(function($) {
//
// Tabs Test Helper Functions
//
var defaults = {
ajaxOptions: null,
cache: false,
cookie: null,
deselectable: false,
deselectableClass: 'ui-tabs-deselectable',
disabled: [],
disabledClass: 'ui-tabs-disabled',
event: 'click',
fx: null,
hideClass: 'ui-tabs-hide',
idPrefix: 'ui-tabs-',
loadingClass: 'ui-tabs-loading',
navClass: 'ui-tabs-nav',
panelClass: 'ui-tabs-panel',
panelTemplate: '<div></div>',
selectedClass: 'ui-tabs-selected',
spinner: 'Loading&#8230;',
tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>'
};
var el;
// need to wait a bit for the pseudo animation...
function defer(defered, ms) {
@ -35,35 +61,12 @@ module('tabs');
});
test("defaults", function() {
var expected = {
deselectable: false,
event: 'click',
disabled: [],
cookie: null,
spinner: 'Loading&#8230;',
cache: false,
idPrefix: 'ui-tabs-',
ajaxOptions: null,
fx: null,
tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>',
panelTemplate: '<div></div>',
navClass: 'ui-tabs-nav',
selectedClass: 'ui-tabs-selected',
deselectableClass: 'ui-tabs-deselectable',
disabledClass: 'ui-tabs-disabled',
panelClass: 'ui-tabs-panel',
hideClass: 'ui-tabs-hide',
loadingClass: 'ui-tabs-loading'
};
var el = $("#tabs1").tabs();
for (var optionName in expected) {
var actual = el.data(optionName + '.tabs'), expects = expected[optionName];
same(actual, expects, optionName);
}
el = $('#tabs1').tabs();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".tabs"), expected = val;
same(actual, expected, key);
});
el.tabs("destroy");
});
test('add', function() {