From: Richard Worth Date: Mon, 2 Feb 2009 05:58:49 +0000 (+0000) Subject: slider unit tests: created separate file for each module: core, common widget, events... X-Git-Tag: 1.6~113 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c3046b9d798b406803beaf83dc42e0171672fe89;p=jquery-ui.git slider unit tests: created separate file for each module: core, common widget, events, methods, options, tickets --- diff --git a/tests/unit/slider/slider.html b/tests/unit/slider/slider.html index 788f38007..dad460a03 100644 --- a/tests/unit/slider/slider.html +++ b/tests/unit/slider/slider.html @@ -12,7 +12,12 @@ - + + + + + + diff --git a/tests/unit/slider/slider.js b/tests/unit/slider/slider.js deleted file mode 100644 index 38da8624f..000000000 --- a/tests/unit/slider/slider.js +++ /dev/null @@ -1,396 +0,0 @@ -/* - * slider unit tests - */ -(function($) { -// -// Slider Test Helper Functions -// - -var defaults = { - max: 100, - min: 0, - orientation: 'auto', - step: 1, - value: 0 -}; - -var el, options; - -function handle() { - return el.find(".ui-slider-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(8); - - $("
").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'); - - $('
').appendTo('body').remove().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 (.data) after destroy'); - - el = $('
').slider(); - var foo = el.slider("destroy").slider("option", "foo"); - el.remove(); - ok(true, 'arbitrary option getter (.slider option method) after destroy'); - - $('
').slider().slider("destroy").data("foo.slider", "bar").remove(); - ok(true, 'arbitrary option setter (.data) after destroy'); - - $('
').slider().slider("destroy").slider("options", "foo", "bar").remove(); - ok(true, 'arbitrary option setter (.slider option method) 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"); - -test("keydown HOME on handle sets value to min", function() { - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); - equals(el.slider("value"), options.min); - - el.slider('destroy'); - - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); - equals(el.slider("value"), options.min); - - el.slider('destroy'); -}); - -test("keydown END on handle sets value to max", function() { - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); - equals(el.slider("value"), options.max); - - el.slider('destroy'); - - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", 0); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); - equals(el.slider("value"), options.max); - - el.slider('destroy'); -}); - -test("keydown UP on handle increases value by step, not greater than max", function() { - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); - - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); -}); - -test("keydown RIGHT on handle increases value by step, not greater than max", function() { - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); - - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.max - options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); - equals(el.slider("value"), options.max); - - el.slider("destroy"); -}); - -test("keydown DOWN on handle decreases value by step, not less than min", function() { - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); - - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); -}); - -test("keydown LEFT on handle decreases value by step, not less than min", function() { - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'horizontal', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); - - el = $('
'); - options = { - max: 5, - min: -5, - orientation: 'vertical', - step: 1 - }; - el.slider(options); - - el.slider("value", options.min + options.step); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); - equals(el.slider("value"), options.min); - - el.slider("destroy"); -}); - -module("slider: Options"); - -test("orientation", function() { - el = $('
'); - - options = { - max: 2, - min: -2, - orientation: 'vertical', - value: 1 - }; - - var percentVal = (options.value - options.min) / (options.max - options.min) * 100; - - el.slider(options).slider("option", "orientation", "horizontal"); - ok(el.is('.ui-slider-horizontal'), "horizontal slider has class .ui-slider-horizontal"); - ok(!el.is('.ui-slider-vertical'), "horizontal slider does not have class .ui-slider-vertical"); - equals(handle().css('left'), percentVal + '%', "horizontal slider handle is positioned with left: %"); - - el.slider('destroy'); - - options = { - max: 2, - min: -2, - orientation: 'horizontal', - value: -1 - }; - - var percentVal = (options.value - options.min) / (options.max - options.min) * 100; - - el.slider(options).slider("option", "orientation", "vertical"); - ok(el.is('.ui-slider-vertical'), "vertical slider has class .ui-slider-vertical"); - ok(!el.is('.ui-slider-horizontal'), "vertical slider does not have class .ui-slider-horizontal"); - equals(handle().css('bottom'), percentVal + '%', "vertical slider handle is positioned with bottom: %"); - - el.slider('destroy'); - -}); - -test("max", function() { - el = $('
'); - - options = { - max: 37, - min: 6, - orientation: 'horizontal', - step: 1, - value: 50 - }; - - el.slider(options); - ok(el.slider("option", "value") == options.value, "value option is not contained by max"); - ok(el.slider("value") == options.max, "value method is contained by max"); - el.slider('destroy'); - -}); - -test("min", function() { - el = $('
'); - - options = { - max: 37, - min: 6, - orientation: 'vertical', - step: 1, - value: 2 - }; - - el.slider(options); - ok(el.slider("option", "value") == options.value, "value option is not contained by min"); - ok(el.slider("value") == options.min, "value method is contained by min"); - el.slider('destroy'); - -}); - -})(jQuery); diff --git a/tests/unit/slider/slider_core.js b/tests/unit/slider/slider_core.js new file mode 100644 index 000000000..d2221fa01 --- /dev/null +++ b/tests/unit/slider/slider_core.js @@ -0,0 +1,302 @@ +/* + * slider unit tests + */ +(function($) { +// +// Slider Test Helper Functions +// + +var el, options; + +function handle() { + return el.find(".ui-slider-handle"); +} + +// Slider Tests +module("slider: core"); + +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(8); + + $("
").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'); + + $('
').appendTo('body').remove().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 (.data) after destroy'); + + el = $('
').slider(); + var foo = el.slider("destroy").slider("option", "foo"); + el.remove(); + ok(true, 'arbitrary option getter (.slider option method) after destroy'); + + $('
').slider().slider("destroy").data("foo.slider", "bar").remove(); + ok(true, 'arbitrary option setter (.data) after destroy'); + + $('
').slider().slider("destroy").slider("options", "foo", "bar").remove(); + ok(true, 'arbitrary option setter (.slider option method) after destroy'); +}); + +test("keydown HOME on handle sets value to min", function() { + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); + equals(el.slider("value"), options.min); + + el.slider('destroy'); + + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); + equals(el.slider("value"), options.min); + + el.slider('destroy'); +}); + +test("keydown END on handle sets value to max", function() { + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); + equals(el.slider("value"), options.max); + + el.slider('destroy'); + + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); + equals(el.slider("value"), options.max); + + el.slider('destroy'); +}); + +test("keydown UP on handle increases value by step, not greater than max", function() { + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); + + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); +}); + +test("keydown RIGHT on handle increases value by step, not greater than max", function() { + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); + + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); +}); + +test("keydown DOWN on handle decreases value by step, not less than min", function() { + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); + + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); +}); + +test("keydown LEFT on handle decreases value by step, not less than min", function() { + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); + + el = $('
'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); +}); + +})(jQuery); diff --git a/tests/unit/slider/slider_defaults.js b/tests/unit/slider/slider_defaults.js new file mode 100644 index 000000000..285e2b785 --- /dev/null +++ b/tests/unit/slider/slider_defaults.js @@ -0,0 +1,19 @@ +/* + * slider_defaults.js + */ + +var slider_defaults = { + animate: false, + delay: 0, + disabled: false, + distance: 0, + max: 100, + min: 0, + orientation: 'auto', + range: false, + step: 1, + value: 0, + values: null +}; + +commonWidgetTests('slider', { defaults: slider_defaults }); diff --git a/tests/unit/slider/slider_events.js b/tests/unit/slider/slider_events.js new file mode 100644 index 000000000..35097d708 --- /dev/null +++ b/tests/unit/slider/slider_events.js @@ -0,0 +1,24 @@ +/* + * slider_events.js + */ +(function($) { + +module("slider: events"); + +test("start", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("slide", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("change", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("stop", function() { + ok(false, "missing test - untested code is broken code."); +}); + +})(jQuery); diff --git a/tests/unit/slider/slider_methods.js b/tests/unit/slider/slider_methods.js new file mode 100644 index 000000000..6c966a248 --- /dev/null +++ b/tests/unit/slider/slider_methods.js @@ -0,0 +1,24 @@ +/* + * slider_methods.js + */ +(function($) { + +module("slider: methods"); + +test("value", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("values", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("enable", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("disable", function() { + ok(false, "missing test - untested code is broken code."); +}); + +})(jQuery); diff --git a/tests/unit/slider/slider_options.js b/tests/unit/slider/slider_options.js new file mode 100644 index 000000000..cc624a0e3 --- /dev/null +++ b/tests/unit/slider/slider_options.js @@ -0,0 +1,105 @@ +/* + * slider_options.js + */ +(function($) { + +function handle() { + return el.find(".ui-slider-handle"); +} + +module("slider: options"); + +test("animate", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("max", function() { + el = $('
'); + + options = { + max: 37, + min: 6, + orientation: 'horizontal', + step: 1, + value: 50 + }; + + el.slider(options); + ok(el.slider("option", "value") == options.value, "value option is not contained by max"); + ok(el.slider("value") == options.max, "value method is contained by max"); + el.slider('destroy'); + +}); + +test("min", function() { + el = $('
'); + + options = { + max: 37, + min: 6, + orientation: 'vertical', + step: 1, + value: 2 + }; + + el.slider(options); + ok(el.slider("option", "value") == options.value, "value option is not contained by min"); + ok(el.slider("value") == options.min, "value method is contained by min"); + el.slider('destroy'); + +}); + +test("orientation", function() { + el = $('
'); + + options = { + max: 2, + min: -2, + orientation: 'vertical', + value: 1 + }; + + var percentVal = (options.value - options.min) / (options.max - options.min) * 100; + + el.slider(options).slider("option", "orientation", "horizontal"); + ok(el.is('.ui-slider-horizontal'), "horizontal slider has class .ui-slider-horizontal"); + ok(!el.is('.ui-slider-vertical'), "horizontal slider does not have class .ui-slider-vertical"); + equals(handle().css('left'), percentVal + '%', "horizontal slider handle is positioned with left: %"); + + el.slider('destroy'); + + options = { + max: 2, + min: -2, + orientation: 'horizontal', + value: -1 + }; + + var percentVal = (options.value - options.min) / (options.max - options.min) * 100; + + el.slider(options).slider("option", "orientation", "vertical"); + ok(el.is('.ui-slider-vertical'), "vertical slider has class .ui-slider-vertical"); + ok(!el.is('.ui-slider-horizontal'), "vertical slider does not have class .ui-slider-horizontal"); + equals(handle().css('bottom'), percentVal + '%', "vertical slider handle is positioned with bottom: %"); + + el.slider('destroy'); + +}); + +test("range", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("step", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("value", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("values", function() { + ok(false, "missing test - untested code is broken code."); +}); + +})(jQuery); diff --git a/tests/unit/slider/slider_tickets.js b/tests/unit/slider/slider_tickets.js new file mode 100644 index 000000000..7397c60ba --- /dev/null +++ b/tests/unit/slider/slider_tickets.js @@ -0,0 +1,8 @@ +/* + * slider_tickets.js + */ +(function($) { + +module("slider: tickets"); + +})(jQuery);