diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html index c6a6a61b9c9..242ddb7f669 100644 --- a/tests/unit/sortable/sortable.html +++ b/tests/unit/sortable/sortable.html @@ -12,7 +12,12 @@ - + + + + + + diff --git a/tests/unit/sortable/sortable.js b/tests/unit/sortable/sortable.js deleted file mode 100644 index e269542c63e..00000000000 --- a/tests/unit/sortable/sortable.js +++ /dev/null @@ -1,151 +0,0 @@ -/* - * sortable unit tests - */ -(function($) { -// -// Sortable Test Helper Functions -// - -var defaults = { - appendTo: "parent", - cancel: ":input,option", - cursor: 'default', - cursorAt: false, - delay: 0, - disabled: false, - distance: 1, - dropOnEmpty: true, - helper: "original", - items: "> *", - opacity: false, - scroll: true, - scrollSensitivity: 20, - scrollSpeed: 20, - tolerance: "intersect", - 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); - - $("
").appendTo('body').sortable().remove(); - ok(true, '.sortable() called on element'); - - $([]).sortable(); - ok(true, '.sortable() called on empty collection'); - - $("
").sortable(); - ok(true, '.sortable() called on disconnected DOMElement'); - - $("
").sortable().sortable("foo"); - ok(true, 'arbitrary method called after init'); - - $("
").sortable().data("foo.sortable"); - ok(true, 'arbitrary option getter after init'); - - $("
").sortable().data("foo.sortable", "bar"); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - expect(6); - - $("
").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"); - ok(true, '.sortable("destroy") called on disconnected DOMElement'); - - $("
").sortable().sortable("destroy").sortable("foo"); - ok(true, 'arbitrary method called after destroy'); - - $("
").sortable().sortable("destroy").data("foo.sortable"); - ok(true, 'arbitrary option getter after destroy'); - - $("
").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 = $('
').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); diff --git a/tests/unit/sortable/sortable_core.js b/tests/unit/sortable/sortable_core.js index 0a050e800fd..850678928ce 100644 --- a/tests/unit/sortable/sortable_core.js +++ b/tests/unit/sortable/sortable_core.js @@ -1,6 +1,27 @@ /* * sortable_core.js */ + +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)); } + (function($) { module("sortable: core"); diff --git a/tests/unit/sortable/sortable_defaults.js b/tests/unit/sortable/sortable_defaults.js index 392f1c858a4..ed0097fdd4e 100644 --- a/tests/unit/sortable/sortable_defaults.js +++ b/tests/unit/sortable/sortable_defaults.js @@ -3,7 +3,30 @@ */ var sortable_defaults = { - disabled: false + appendTo: "parent", + cancel: ":input,option", + connectWith: false, + cssNamespace: "ui", + cursor: 'default', + cursorAt: false, + delay: 0, + disabled: false, + distance: 1, + dropOnEmpty: true, + forcePlaceholderSize: false, + forceHelperSize: false, + handle: false, + helper: "original", + items: "> *", + opacity: false, + placeholder: false, + scope: "default", + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + sortIndicator: "???", + tolerance: "intersect", + zIndex: 1000 }; commonWidgetTests('sortable', { defaults: sortable_defaults }); diff --git a/tests/unit/sortable/sortable_events.js b/tests/unit/sortable/sortable_events.js index 9cdc2e5dcfa..d55bf816e68 100644 --- a/tests/unit/sortable/sortable_events.js +++ b/tests/unit/sortable/sortable_events.js @@ -5,7 +5,51 @@ module("sortable: events"); -test("testname", function() { +test("start", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("sort", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("change", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("beforeStop", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("stop", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("update", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("receive", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("remove", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("over", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("out", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("activate", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("deactivate", function() { ok(false, "missing test - untested code is broken code."); }); diff --git a/tests/unit/sortable/sortable_methods.js b/tests/unit/sortable/sortable_methods.js index cc505ebc0e4..7e1fd2c90da 100644 --- a/tests/unit/sortable/sortable_methods.js +++ b/tests/unit/sortable/sortable_methods.js @@ -5,8 +5,82 @@ module("sortable: methods"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); +test("init", function() { + expect(6); + + $("
").appendTo('body').sortable().remove(); + ok(true, '.sortable() called on element'); + + $([]).sortable(); + ok(true, '.sortable() called on empty collection'); + + $("
").sortable(); + ok(true, '.sortable() called on disconnected DOMElement'); + + $("
").sortable().sortable("foo"); + ok(true, 'arbitrary method called after init'); + + $("
").sortable().data("foo.sortable"); + ok(true, 'arbitrary option getter after init'); + + $("
").sortable().data("foo.sortable", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("
").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"); + ok(true, '.sortable("destroy") called on disconnected DOMElement'); + + $("
").sortable().sortable("destroy").sortable("foo"); + ok(true, 'arbitrary method called after destroy'); + + $("
").sortable().sortable("destroy").data("foo.sortable"); + ok(true, 'arbitrary option getter after destroy'); + + $("
").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)'); }); })(jQuery); diff --git a/tests/unit/sortable/sortable_options.js b/tests/unit/sortable/sortable_options.js index 49f291bb6bb..b20cffbc852 100644 --- a/tests/unit/sortable/sortable_options.js +++ b/tests/unit/sortable/sortable_options.js @@ -5,7 +5,35 @@ module("sortable: options"); -test("testname", function() { +test("{ appendTo: 'parent' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ appendTo: Selector }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: 'x' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: 'y' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: ? }, unexpected", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cancel: ':input,button' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cancel: Selector }", function() { ok(false, "missing test - untested code is broken code."); }); diff --git a/tests/unit/sortable/sortable_tickets.js b/tests/unit/sortable/sortable_tickets.js index a5cd9a8deab..53ef62ae95c 100644 --- a/tests/unit/sortable/sortable_tickets.js +++ b/tests/unit/sortable/sortable_tickets.js @@ -5,8 +5,18 @@ module("sortable: tickets"); -test("testname", function() { - ok(false, "missing test - untested code is broken code."); +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);