diff options
author | Leif Johansson <leifj@sunet.se> | 2011-11-25 21:18:19 +0100 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-11-25 21:18:19 +0100 |
commit | 3909e6d89e01e4cd8777377c63037896bb95aa2f (patch) | |
tree | 59679df287c2bee55087fb5afb8d42e7f93a44fb /src/main/webapp/jquery-ui-1.9pre/tests/unit/slider | |
parent | e5f94e9be5017f627c1ccd8c6306c5cc2e200432 (diff) |
new jq layout
Diffstat (limited to 'src/main/webapp/jquery-ui-1.9pre/tests/unit/slider')
7 files changed, 758 insertions, 0 deletions
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/all.html new file mode 100644 index 0000000..cbdbd2f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Slider Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "slider" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Slider Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider.html new file mode 100644 index 0000000..60d124b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider.html @@ -0,0 +1,60 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Slider Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.slider" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.slider.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="slider_core.js"></script> + <script src="slider_defaults.js"></script> + <script src="slider_events.js"></script> + <script src="slider_methods.js"></script> + <script src="slider_options.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("slider", function() { ok(true, "disabled slider testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Slider Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="slider1"></div> +<div id="slider3" style="position: relative; margin: 40px; width: 217px; height: 28px;"> + <div class="ui-slider-handle" style="position: absolute; height: 21px; left: 0px; bottom: 0px; width: 17px;"></div> +</div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_core.js new file mode 100644 index 0000000..38d4f46 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_core.js @@ -0,0 +1,292 @@ +/* + * 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("keydown HOME on handle sets value to min", function() { + el = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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 PAGE_UP on handle increases value by 1/5 range, not greater than max", function() { + $.each(['horizontal', 'vertical'], function(i, orientation) { + el = $('<div></div>'); + options = { + max: 100, + min: 0, + orientation: orientation, + step: 1 + }; + el.slider(options); + + el.slider("value", 70); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP }); + equals(el.slider("value"), 90); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP }); + equals(el.slider("value"), 100); + + el.slider("destroy"); + }); +}); + +test("keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() { + $.each(['horizontal', 'vertical'], function(i, orientation) { + el = $('<div></div>'); + options = { + max: 100, + min: 0, + orientation: orientation, + step: 1 + }; + el.slider(options); + + el.slider("value", 30); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN }); + equals(el.slider("value"), 10); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN }); + equals(el.slider("value"), 0); + + el.slider("destroy"); + }); +}); + +test("keydown UP on handle increases value by step, not greater than max", function() { + el = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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 = $('<div></div>'); + 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/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_defaults.js new file mode 100644 index 0000000..8049fe9 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_defaults.js @@ -0,0 +1,19 @@ +commonWidgetTests( "slider", { + defaults: { + animate: false, + cancel: ':input,option', + delay: 0, + disabled: false, + distance: 0, + max: 100, + min: 0, + orientation: 'horizontal', + range: false, + step: 1, + value: 0, + values: null, + + // callbacks + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_events.js new file mode 100644 index 0000000..0b7b250 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_events.js @@ -0,0 +1,109 @@ +/* + * slider_events.js + */ +(function($) { + +module( "slider: events" ); + +//Specs from http://wiki.jqueryui.com/Slider#specs +//"change callback: triggers when the slider has stopped moving and has a new +// value (even if same as previous value), via mouse(mouseup) or keyboard(keyup) +// or value method/option" +test( "mouse based interaction", function() { + expect(4); + + var el = $( "<div></div>" ) + .appendTo( "body" ) + .slider({ + start: function(event, ui) { + equals( event.originalEvent.type, "mousedown", "start triggered by mousedown" ); + }, + slide: function(event, ui) { + equals( event.originalEvent.type, "mousemove", "slider triggered by mousemove" ); + }, + stop: function(event, ui) { + equals( event.originalEvent.type, "mouseup", "stop triggered by mouseup" ); + }, + change: function(event, ui) { + equals( event.originalEvent.type, "mouseup", "change triggered by mouseup" ); + } + }); + + el.find( ".ui-slider-handle" ).eq( 0 ) + .simulate( "drag", { dx: 10, dy: 10 } ); + +}); +test( "keyboard based interaction", function() { + expect(3); + + // Test keyup at end of handle slide (keyboard) + var el = $( "<div></div>" ) + .appendTo( "body" ) + .slider({ + start: function(event, ui) { + equals( event.originalEvent.type, "keydown", "start triggered by keydown" ); + }, + slide: function(event, ui) { + ok( false, "Slider never triggered by keys" ); + }, + stop: function(event, ui) { + equals( event.originalEvent.type, "keyup", "stop triggered by keyup" ); + }, + change: function(event, ui) { + equals( event.originalEvent.type, "keyup", "change triggered by keyup" ); + } + }); + + el.find( ".ui-slider-handle" ).eq( 0 ) + .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ) + .simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } ) + .simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } ); + +}); +test( "programmatic event triggers", function() { + expect(6); + + // Test value method + var el = $( "<div></div>" ) + .slider({ + change: function(event, ui) { + ok( true, "change triggered by value method" ); + } + }) + .slider( "value", 0 ); + + QUnit.reset(); + // Test values method + el = $( "<div></div>" ) + .slider({ + values: [ 10, 20 ], + change: function(event, ui) { + ok( true, "change triggered by values method" ); + } + }) + .slider( "values", [80, 90] ); + + QUnit.reset(); + // Test value option + el = $( "<div></div>" ) + .slider({ + change: function(event, ui) { + ok( true, "change triggered by value option" ); + } + }) + .slider( "option", "value", 0 ); + + QUnit.reset(); + // Test values option + el = $( "<div></div>" ) + .slider({ + values: [ 10, 20 ], + change: function(event, ui) { + ok( true, "change triggered by values option" ); + } + }) + .slider( "option", "values", [80, 90] ); + +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_methods.js new file mode 100644 index 0000000..66624e8 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_methods.js @@ -0,0 +1,102 @@ +/* + * slider_methods.js + */ +(function($) { + +module("slider: methods"); + +test("init", function() { + expect(5); + + $("<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'); + + var el = $('<div></div>').slider(); + var foo = el.slider("option", "foo"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('<div></div>').slider().slider("option", "foo", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<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>').appendTo('body').remove().slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on disconnected DOMElement'); + + var expected = $('<div></div>').slider(), + actual = expected.slider('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + var expected = $('<div></div>').slider(), + actual = expected.slider('enable'); + equals(actual, expected, 'enable is chainable'); + + var el = $('<div></div>').slider({ disabled: true }); + ok(el.hasClass('ui-disabled'), 'slider has ui-disabled class before enable method call'); + ok(el.hasClass('ui-slider-disabled'), 'slider has ui-slider-disabled class before enable method call'); + el.slider('enable'); + ok(!el.hasClass('ui-disabled'), 'slider does not have ui-disabled class after enable method call'); + ok(!el.hasClass('ui-slider-disabled'), 'slider does not have ui-slider-disabled class after enable method call'); +}); + +test("disable", function() { + var expected = $('<div></div>').slider(), + actual = expected.slider('disable'); + equals(actual, expected, 'disable is chainable'); + + var el = $('<div></div>').slider({ disabled: false }); + ok(!el.hasClass('ui-disabled'), 'slider does not have ui-disabled class before disabled method call'); + ok(!el.hasClass('ui-slider-disabled'), 'slider does not have ui-slider-disabled class before disable method call'); + el.slider('disable'); + ok(el.hasClass('ui-disabled'), 'slider has ui-disabled class after disable method call'); + ok(el.hasClass('ui-slider-disabled'), 'slider has ui-slider-disabled class after disable method call'); +}); + +test("value", function() { + $([false, 'min', 'max']).each(function() { + var el = $('<div></div>').slider({ + range: this, + value: 5 + }); + equals(el.slider('value'), 5, 'range: ' + this + ' slider method get'); + equals(el.slider('value', 10), el, 'value method is chainable'); + equals(el.slider('value'), 10, 'range: ' + this + ' slider method set'); + el.remove(); + }); + var el = $('<div></div>').slider({ + min: -1, value: 0, max: 1 + }); + // min with value option vs value method + el.slider('option', 'value', -2); + equals(el.slider('option', 'value'), -2, 'value option does not respect min'); + equals(el.slider('value'), -1, 'value method get respects min'); + equals(el.slider('value', -2), el, 'value method is chainable'); + equals(el.slider('option', 'value'), -1, 'value method set respects min'); + // max with value option vs value method + el.slider('option', 'value', 2); + equals(el.slider('option', 'value'), 2, 'value option does not respect max'); + equals(el.slider('value'), 1, 'value method get respects max'); + equals(el.slider('value', 2), el, 'value method is chainable'); + equals(el.slider('option', 'value'), 1, 'value method set respects max'); +}); + +//test("values", function() { +// ok(false, "missing test - untested code is broken code."); +//}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_options.js new file mode 100644 index 0000000..040589b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_options.js @@ -0,0 +1,146 @@ +/* + * slider_options.js + */ +(function($) { + +var el, options; + +function handle() { + return el.find(".ui-slider-handle"); +} + +module("slider: options"); + +test("max", function() { + el = $('<div></div>'); + + 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 = $('<div></div>'); + + 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 = $('<div></div>'); + + 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."); +//}); + +//spec: http://wiki.jqueryui.com/Slider#specs +// value option/method: the value option is not restricted by min/max/step. +// What is returned by the value method is restricted by min (>=), max (<=), and step (even multiple) +test("step", function() { + var el = $('<div></div>').slider({ + min: 0, + value: 0, + step: 10, + max: 100 + }); + equals( el.slider("value"), 0 ); + + el.slider("value", 1); + equals( el.slider("value"), 0 ); + + el.slider("value", 9); + equals( el.slider("value"), 10 ); + + el.slider("value", 11); + equals( el.slider("value"), 10 ); + + el.slider("value", 19); + equals( el.slider("value"), 20 ); + +el = $('<div></div>').slider({ + min: 0, + value: 0, + step: 20, + max: 100 + }); + el.slider("value", 0); + + el.slider("option", "value", 1); + equals( el.slider("value"), 0 ); + + el.slider("option", "value", 9); + equals( el.slider("value"), 0 ); + + el.slider("option", "value", 11); + equals( el.slider("value"), 20 ); + + el.slider("option", "value", 19); + equals( el.slider("value"), 20 ); + + el.slider('destroy'); +}); + +//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); |