diff --git a/tests/dialog.js b/tests/dialog.js index 3b228ca87..8c68ae6e2 100644 --- a/tests/dialog.js +++ b/tests/dialog.js @@ -115,48 +115,48 @@ module("dialog"); test("init", function() { expect(6); - $("#dialog1").dialog().remove(); + $("
").appendTo('body').dialog().remove(); ok(true, '.dialog() called on element'); $([]).dialog().remove(); ok(true, '.dialog() called on empty collection'); - $('
').dialog().remove(); + $('
').dialog().remove(); ok(true, '.dialog() called on disconnected DOMElement'); - $('
').dialog().dialog("foo").remove(); + $('
').dialog().dialog("foo").remove(); ok(true, 'arbitrary method called after init'); - el = $('
').dialog(); + el = $('
').dialog(); var foo = el.data("foo.dialog"); el.remove(); ok(true, 'arbitrary option getter after init'); - $('
').dialog().data("foo.dialog", "bar").remove(); + $('
').dialog().data("foo.dialog", "bar").remove(); ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { expect(6); - $("#dialog1").dialog().dialog("destroy").remove(); + $("
").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'); - $('
').dialog().dialog("destroy").remove(); + $('
').dialog().dialog("destroy").remove(); ok(true, '.dialog("destroy") called on disconnected DOMElement'); - $('
').dialog().dialog("destroy").dialog("foo").remove(); + $('
').dialog().dialog("destroy").dialog("foo").remove(); ok(true, 'arbitrary method called after destroy'); - el = $('
').dialog(); + el = $('
').dialog(); var foo = el.dialog("destroy").data("foo.dialog"); el.remove(); ok(true, 'arbitrary option getter after destroy'); - $('
').dialog().dialog("destroy").data("foo.dialog", "bar").remove(); + $('
').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 = $('
').dialog(); + el = $('
').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 = $('
').dialog(); + el = $('
').dialog(); titleId = dlg().find('.ui-dialog-title').attr('id'); equals(titleId, 'ui-dialog-title-1', 'auto-numbered title id'); el.remove(); - el = $('
').dialog(); + el = $('
').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 = $('
').dialog({ autoOpen: false }); + el = $('
').dialog({ autoOpen: false }); isNotOpen('.dialog({ autoOpen: false })'); el.remove(); - el = $('
').dialog({ autoOpen: true }); + el = $('
').dialog({ autoOpen: true }); isOpen('.dialog({ autoOpen: true })'); el.remove(); }); @@ -270,7 +270,7 @@ test("buttons", function() { } }; - el = $('
').dialog({ buttons: buttons }); + el = $('
').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 = $('
').dialog(); + el = $('
').dialog(); equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added'); el.remove(); - el = $('
').dialog({ dialogClass: "foo" }); + el = $('
').dialog({ dialogClass: "foo" }); equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added'); el.remove(); - el = $('
').dialog({ dialogClass: "foo bar" }); + el = $('
').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 = $('
').dialog({ draggable: false }); + el = $('
').dialog({ draggable: false }); shouldnotmove(); el.data('draggable.dialog', true); shouldmove(); el.remove(); - el = $('
').dialog({ draggable: true }); + el = $('
').dialog({ draggable: true }); shouldmove(); el.data('draggable.dialog', false); shouldnotmove(); @@ -344,15 +344,15 @@ test("draggable", function() { test("height", function() { expect(3); - el = $('
').dialog(); + el = $('
').dialog(); equals(dlg().height(), defaults.height, "default height"); el.remove(); - el = $('
').dialog({ height: 437 }); + el = $('
').dialog({ height: 437 }); equals(dlg().height(), 437, "explicit height"); el.remove(); - el = $('
').dialog(); + el = $('
').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 = $('
').dialog({ maxHeight: 400 }); + el = $('
').dialog({ maxHeight: 400 }); drag('.ui-resizable-s', 1000, 1000); equals(heightAfter, 400, "maxHeight"); el.remove(); - el = $('
').dialog({ maxHeight: 400 }); + el = $('
').dialog({ maxHeight: 400 }); drag('.ui-resizable-n', -1000, -1000); equals(heightAfter, 400, "maxHeight"); el.remove(); - el = $('
').dialog({ maxHeight: 400 }).data('maxHeight.dialog', 600); + el = $('
').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 = $('
').dialog({ maxWidth: 400 }); + el = $('
').dialog({ maxWidth: 400 }); drag('.ui-resizable-e', 1000, 1000); equals(widthAfter, 400, "maxWidth"); el.remove(); - el = $('
').dialog({ maxWidth: 400 }); + el = $('
').dialog({ maxWidth: 400 }); drag('.ui-resizable-w', -1000, -1000); equals(widthAfter, 400, "maxWidth"); el.remove(); - el = $('
').dialog({ maxWidth: 400 }).data('maxWidth.dialog', 600); + el = $('
').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 = $('
').dialog({ minHeight: 10 }); + el = $('
').dialog({ minHeight: 10 }); drag('.ui-resizable-s', -1000, -1000); equals(heightAfter, 10, "minHeight"); el.remove(); - el = $('
').dialog({ minHeight: 10 }); + el = $('
').dialog({ minHeight: 10 }); drag('.ui-resizable-n', 1000, 1000); equals(heightAfter, 10, "minHeight"); el.remove(); - el = $('
').dialog({ minHeight: 10 }).data('minHeight.dialog', 30); + el = $('
').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 = $('
').dialog({ minWidth: 10 }); + el = $('
').dialog({ minWidth: 10 }); drag('.ui-resizable-e', -1000, -1000); equals(widthAfter, 10, "minWidth"); el.remove(); - el = $('
').dialog({ minWidth: 10 }); + el = $('
').dialog({ minWidth: 10 }); drag('.ui-resizable-w', 1000, 1000); equals(widthAfter, 10, "minWidth"); el.remove(); - el = $('
').dialog({ minWidth: 30 }).data('minWidth.dialog', 30); + el = $('
').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 = $('
').dialog(); + el = $('
').dialog(); shouldresize("[default]"); el.data('resizable.dialog', false); shouldnotresize('disabled after init'); el.remove(); - el = $('
').dialog({ resizable: false }); + el = $('
').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 = $('
').dialog(); + el = $('
').dialog(); equals(titleText(), " ", "[default]"); el.remove(); @@ -481,7 +481,7 @@ test("title", function() { equals(titleText(), "foo", "title in element attribute"); el.remove(); - el = $('
').dialog({ title: 'foo' }); + el = $('
').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 = $('
').dialog().data('title.dialog', 'foo'); + el = $('
').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 = $('
').dialog(); + el = $('
').dialog(); equals(dlg().width(), defaults.width, "default width"); el.remove(); - el = $('
').dialog({width: 437 }); + el = $('
').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 = $('
').dialog(); + el = $('
').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 = $('
').dialog({autoOpen: false}); + el = $('
').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 = $("
"); + el = $("
"); el.dialog({ open: function(ev, ui) { ok(true, 'autoOpen: true fires open callback'); @@ -540,7 +540,7 @@ test("open", function() { }); el.remove(); - el = $("
"); + el = $("
"); el.dialog({ autoOpen: false, open: function(ev, ui) { @@ -551,7 +551,7 @@ test("open", function() { el.dialog("open"); el.remove(); - el = $('
').dialog({ + el = $('
').dialog({ autoOpen: false }); el.bind('dialogopen', function(ev, ui) { @@ -565,7 +565,7 @@ test("open", function() { test("dragStart", function() { expect(2); - el = $("
"); + el = $("
"); 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 = $("
"); + el = $("
"); el.dialog({ drag: function(ev, ui) { fired = true; @@ -596,7 +596,7 @@ test("drag", function() { test("dragStop", function() { expect(2); - el = $("
"); + el = $("
"); 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 = $("
"); + el = $("
"); 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 = $("
"); + el = $("
"); el.dialog({ resize: function(ev, ui) { fired = true; @@ -642,7 +642,7 @@ test("resize", function() { test("resizeStop", function() { expect(2); - el = $("
"); + el = $("
"); 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 = $('
').dialog({ + el = $('
').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 = $('
').dialog().bind('dialogclose', function(ev, ui) { + el = $('
').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 = $('
').dialog({ + el = $('
').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 = $('
').dialog().bind('dialogbeforeclose', function(ev, ui) { + el = $('
').dialog().bind('dialogbeforeclose', function(ev, ui) { ok(true, '.dialog("close") triggers dialogbeforeclose event'); equals(this, el[0], "context of event"); return false; diff --git a/tests/draggable.js b/tests/draggable.js index c029df6b0..e0ffa660f 100644 --- a/tests/draggable.js +++ b/tests/draggable.js @@ -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(); + $("
").appendTo('body').draggable().remove(); ok(true, '.draggable() called on element'); $([]).draggable(); ok(true, '.draggable() called on empty collection'); - $("
").draggable(); + $("
").draggable(); ok(true, '.draggable() called on disconnected DOMElement'); - $("
").draggable().draggable("foo"); + $("
").draggable().draggable("foo"); ok(true, 'arbitrary method called after init'); - $("
").draggable().data("foo.draggable"); + $("
").draggable().data("foo.draggable"); ok(true, 'arbitrary option getter after init'); - $("
").draggable().data("foo.draggable", "bar"); + $("
").draggable().data("foo.draggable", "bar"); ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { expect(6); - $("#draggable1").draggable().draggable("destroy"); + $("
").appendTo('body').draggable().draggable("destroy").remove(); ok(true, '.draggable("destroy") called on element'); $([]).draggable().draggable("destroy"); ok(true, '.draggable("destroy") called on empty collection'); - $("
").draggable().draggable("destroy"); + $("
").draggable().draggable("destroy"); ok(true, '.draggable("destroy") called on disconnected DOMElement'); - $("
").draggable().draggable("destroy").draggable("foo"); + $("
").draggable().draggable("destroy").draggable("foo"); ok(true, 'arbitrary method called after destroy'); - $("
").draggable().draggable("destroy").data("foo.draggable"); + $("
").draggable().draggable("destroy").data("foo.draggable"); ok(true, 'arbitrary option getter after destroy'); - $("
").draggable().draggable("destroy").data("foo.draggable", "bar"); + $("
").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 = $('
').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() { diff --git a/tests/droppable.js b/tests/droppable.js index 345688d04..2c08d45cb 100644 --- a/tests/droppable.js +++ b/tests/droppable.js @@ -33,44 +33,44 @@ module("droppable"); test("init", function() { expect(6); - el = $("#droppable1").droppable(); + $("
").appendTo('body').droppable().remove(); ok(true, '.droppable() called on element'); $([]).droppable(); ok(true, '.droppable() called on empty collection'); - $("
").droppable(); + $("
").droppable(); ok(true, '.droppable() called on disconnected DOMElement'); - $("
").droppable().droppable("foo"); + $("
").droppable().droppable("foo"); ok(true, 'arbitrary method called after init'); - $("
").droppable().data("foo.droppable"); + $("
").droppable().data("foo.droppable"); ok(true, 'arbitrary option getter after init'); - $("
").droppable().data("foo.droppable", "bar"); + $("
").droppable().data("foo.droppable", "bar"); ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { expect(6); - $("#droppable1").droppable().droppable("destroy"); + $("
").appendTo('body').droppable().droppable("destroy").remove(); ok(true, '.droppable("destroy") called on element'); $([]).droppable().droppable("destroy"); ok(true, '.droppable("destroy") called on empty collection'); - $("
").droppable().droppable("destroy"); + $("
").droppable().droppable("destroy"); ok(true, '.droppable("destroy") called on disconnected DOMElement'); - $("
").droppable().droppable("destroy").droppable("foo"); + $("
").droppable().droppable("destroy").droppable("foo"); ok(true, 'arbitrary method called after destroy'); - $("
").droppable().droppable("destroy").data("foo.droppable"); + $("
").droppable().droppable("destroy").data("foo.droppable"); ok(true, 'arbitrary option getter after destroy'); - $("
").droppable().droppable("destroy").data("foo.droppable", "bar"); + $("
").droppable().droppable("destroy").data("foo.droppable", "bar"); ok(true, 'arbitrary option setter after destroy'); }); diff --git a/tests/progressbar.js b/tests/progressbar.js index 98f437901..d58aaacc4 100644 --- a/tests/progressbar.js +++ b/tests/progressbar.js @@ -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(); + $("
").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"); + $("
").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 = $('
').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() { diff --git a/tests/resizable.js b/tests/resizable.js index 0c924c214..7daa97c69 100644 --- a/tests/resizable.js +++ b/tests/resizable.js @@ -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(); + $("
").appendTo('body').resizable().remove(); ok(true, '.resizable() called on element'); $([]).resizable().remove(); ok(true, '.resizable() called on empty collection'); - $('
').resizable().remove(); + $('
').resizable().remove(); ok(true, '.resizable() called on disconnected DOMElement'); - $('
').resizable().resizable("foo").remove(); + $('
').resizable().resizable("foo").remove(); ok(true, 'arbitrary method called after init'); - el = $('
').resizable() + el = $('
').resizable() var foo = el.data("foo.resizable"); el.remove(); ok(true, 'arbitrary option getter after init'); - $('
').resizable().data("foo.resizable", "bar").remove(); + $('
').resizable().data("foo.resizable", "bar").remove(); ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { expect(6); - $("#dialog1").resizable().resizable("destroy").remove(); + $("
").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'); - $('
').resizable().resizable("destroy").remove(); + $('
').resizable().resizable("destroy").remove(); ok(true, '.resizable("destroy") called on disconnected DOMElement'); - $('
').resizable().resizable("destroy").resizable("foo").remove(); + $('
').resizable().resizable("destroy").resizable("foo").remove(); ok(true, 'arbitrary method called after destroy'); - el = $('
').resizable(); + el = $('
').resizable(); var foo = el.resizable("destroy").data("foo.resizable"); el.remove(); ok(true, 'arbitrary option getter after destroy'); - $('
').resizable().resizable("destroy").data("foo.resizable", "bar").remove(); + $('
').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 = $('
').resizable(); + el = $('
').resizable(); $.each(defaults, function(key, val) { var actual = el.data(key + ".resizable"), expected = val; same(actual, expected, key); diff --git a/tests/selectable.js b/tests/selectable.js index 1d0ea53d4..0bbad8d48 100644 --- a/tests/selectable.js +++ b/tests/selectable.js @@ -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(); + $("
").appendTo('body').selectable().remove(); ok(true, '.selectable() called on element'); $([]).selectable().remove(); ok(true, '.selectable() called on empty collection'); - $("
").selectable().remove(); + $("
").selectable().remove(); ok(true, '.selectable() called on disconnected DOMElement'); - $("
").selectable().selectable("foo").remove(); + $("
").selectable().selectable("foo").remove(); ok(true, 'arbitrary method called after init'); - el = $("
").selectable() + el = $("
").selectable() var foo = el.data("foo.selectable"); el.remove(); ok(true, 'arbitrary option getter after init'); - $("
").selectable().data("foo.selectable", "bar").remove(); + $("
").selectable().data("foo.selectable", "bar").remove(); ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { expect(6); - $("#selectable1").selectable().selectable("destroy").remove(); + $("
").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'); - $("
").selectable().selectable("destroy").remove(); + $("
").selectable().selectable("destroy").remove(); ok(true, '.selectable("destroy") called on disconnected DOMElement'); - $("
").selectable().selectable("destroy").selectable("foo").remove(); + $("
").selectable().selectable("destroy").selectable("foo").remove(); ok(true, 'arbitrary method called after destroy'); - el = $("
").selectable(); + el = $("
").selectable(); var foo = el.selectable("destroy").data("foo.selectable"); el.remove(); ok(true, 'arbitrary option getter after destroy'); - $("
").selectable().selectable("destroy").data("foo.selectable", "bar").remove(); + $("
").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 = $('
').selectable(); $.each(defaults, function(key, val) { var actual = el.data(key + ".selectable"), expected = val; same(actual, expected, key); diff --git a/tests/slider.js b/tests/slider.js index b13acc4a9..3fbdd8b74 100644 --- a/tests/slider.js +++ b/tests/slider.js @@ -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); + + $("
").appendTo('body').slider().remove(); + ok(true, '.slider() called on element'); + + $([]).slider().remove(); + ok(true, '.slider() called on empty collection'); + + $('
').slider().remove(); + ok(true, '.slider() called on disconnected DOMElement'); + + $('
').slider().slider("foo").remove(); + ok(true, 'arbitrary method called after init'); + + el = $('
').slider(); + var foo = el.data("foo.slider"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('
').slider().data("foo.slider", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
").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'); + + $('
').slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on disconnected DOMElement'); + + $('
').slider().slider("destroy").slider("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + el = $('
').slider(); + var foo = el.slider("destroy").data("foo.slider"); + el.remove(); + ok(true, 'arbitrary option getter after destroy'); + + $('
').slider().slider("destroy").data("foo.slider", "bar").remove(); + ok(true, 'arbitrary option setter after destroy'); +}); + +test("defaults", function() { + el = $('
').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(); diff --git a/tests/sortable.js b/tests/sortable.js index d3ab006cf..2dd720e18 100644 --- a/tests/sortable.js +++ b/tests/sortable.js @@ -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(); + $("
").appendTo('body').sortable().remove(); ok(true, '.sortable() called on element'); $([]).sortable(); ok(true, '.sortable() called on empty collection'); - $("
").sortable(); + $("
").sortable(); ok(true, '.sortable() called on disconnected DOMElement'); - $("
").sortable().sortable("foo"); + $("
").sortable().sortable("foo"); ok(true, 'arbitrary method called after init'); - $("
").sortable().data("foo.sortable"); + $("
").sortable().data("foo.sortable"); ok(true, 'arbitrary option getter after init'); - $("
").sortable().data("foo.sortable", "bar"); + $("
").sortable().data("foo.sortable", "bar"); ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { expect(6); - $("#sortable").sortable().sortable("destroy"); + $("
").appendTo('body').sortable().sortable("destroy").remove(); ok(true, '.sortable("destroy") called on element'); $([]).sortable().sortable("destroy"); ok(true, '.sortable("destroy") called on empty collection'); - $("
").sortable().sortable("destroy"); + $("
").sortable().sortable("destroy"); ok(true, '.sortable("destroy") called on disconnected DOMElement'); - $("
").sortable().sortable("destroy").sortable("foo"); + $("
").sortable().sortable("destroy").sortable("foo"); ok(true, 'arbitrary method called after destroy'); - $("
").sortable().sortable("destroy").data("foo.sortable"); + $("
").sortable().sortable("destroy").data("foo.sortable"); ok(true, 'arbitrary option getter after destroy'); - $("
").sortable().sortable("destroy").data("foo.sortable", "bar"); + $("
").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 = $('
').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() { diff --git a/tests/spinner.js b/tests/spinner.js index fdb81547e..ea7fe1809 100644 --- a/tests/spinner.js +++ b/tests/spinner.js @@ -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(); + $("
").appendTo('body').spinner().remove(); ok(true, '.spinner() called on element'); $('').spinner().remove(); @@ -20,7 +40,7 @@ test("init", function() { test("destroy", function() { expect(2); - $("#spin").spinner().spinner("destroy"); + $("
").appendTo('body').spinner().spinner("destroy").remove(); ok(true, '.spinner("destroy") called on element'); $('').spinner().spinner("destroy").remove(); @@ -28,6 +48,15 @@ test("destroy", function() { }); +test("defaults", function() { + el = $('
').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); diff --git a/tests/tabs.js b/tests/tabs.js index 1e43c5581..c00026549 100644 --- a/tests/tabs.js +++ b/tests/tabs.js @@ -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: '
', + selectedClass: 'ui-tabs-selected', + spinner: 'Loading…', + tabTemplate: '
  • #{label}
  • ' +}; + +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…', - cache: false, - idPrefix: 'ui-tabs-', - ajaxOptions: null, - fx: null, - tabTemplate: '
  • #{label}
  • ', - panelTemplate: '
    ', - 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() {