summaryrefslogtreecommitdiffstats
path: root/apps/it/static/js/ui/tests/unit/spinner
diff options
context:
space:
mode:
Diffstat (limited to 'apps/it/static/js/ui/tests/unit/spinner')
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/all.html30
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/spinner.html50
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/spinner_common.js23
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/spinner_core.js238
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/spinner_events.js259
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/spinner_methods.js174
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/spinner_options.js262
-rw-r--r--apps/it/static/js/ui/tests/unit/spinner/spinner_test_helpers.js8
8 files changed, 1044 insertions, 0 deletions
diff --git a/apps/it/static/js/ui/tests/unit/spinner/all.html b/apps/it/static/js/ui/tests/unit/spinner/all.html
new file mode 100644
index 0000000..bc180d4
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/all.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Spinner Test Suite</title>
+
+ <script src="../../../jquery-1.10.2.js"></script>
+
+ <link rel="stylesheet" href="../../../external/qunit.css">
+ <link rel="stylesheet" href="../qunit-composite.css">
+ <script src="../../../external/qunit.js"></script>
+ <script src="../qunit-composite.js"></script>
+ <script src="../subsuite.js"></script>
+
+ <script>
+ testAllVersions( "spinner" );
+ </script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery UI Spinner 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/apps/it/static/js/ui/tests/unit/spinner/spinner.html b/apps/it/static/js/ui/tests/unit/spinner/spinner.html
new file mode 100644
index 0000000..1d09bbc
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/spinner.html
@@ -0,0 +1,50 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Spinner Test Suite</title>
+
+ <script src="../../jquery.js"></script>
+ <script src="../../../external/jquery.mousewheel.js"></script>
+ <script src="../../../external/globalize.js"></script>
+ <script src="../../../external/globalize.culture.ja-JP.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>
+ TestHelpers.loadResources({
+ css: [ "ui.core", "ui.button", "ui.spinner" ],
+ js: [
+ "ui/jquery.ui.core.js",
+ "ui/jquery.ui.widget.js",
+ "ui/jquery.ui.button.js",
+ "ui/jquery.ui.spinner.js"
+ ]
+ });
+ </script>
+
+ <script src="spinner_test_helpers.js"></script>
+ <script src="spinner_common.js"></script>
+ <script src="spinner_core.js"></script>
+ <script src="spinner_events.js"></script>
+ <script src="spinner_methods.js"></script>
+ <script src="spinner_options.js"></script>
+
+ <script src="../swarminject.js"></script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery UI Spinner 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">
+
+<input id="spin" class="foo">
+<input id="spin2" value="2">
+
+</div>
+</body>
+</html>
diff --git a/apps/it/static/js/ui/tests/unit/spinner/spinner_common.js b/apps/it/static/js/ui/tests/unit/spinner/spinner_common.js
new file mode 100644
index 0000000..b494e3c
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/spinner_common.js
@@ -0,0 +1,23 @@
+TestHelpers.commonWidgetTests( "spinner", {
+ defaults: {
+ culture: null,
+ disabled: false,
+ icons: {
+ down: "ui-icon-triangle-1-s",
+ up: "ui-icon-triangle-1-n"
+ },
+ incremental: true,
+ max: null,
+ min: null,
+ numberFormat: null,
+ page: 10,
+ step: 1,
+
+ // callbacks
+ change: null,
+ create: null,
+ spin: null,
+ start: null,
+ stop: null
+ }
+});
diff --git a/apps/it/static/js/ui/tests/unit/spinner/spinner_core.js b/apps/it/static/js/ui/tests/unit/spinner/spinner_core.js
new file mode 100644
index 0000000..03088fe
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/spinner_core.js
@@ -0,0 +1,238 @@
+(function( $ ) {
+
+var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
+
+module( "spinner: core" );
+
+test( "keydown UP on input, increases value not greater than max", function() {
+ expect( 5 );
+ var element = $( "#spin" ).val( 70 ).spinner({
+ max: 100,
+ step: 10
+ });
+
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equal( element.val(), 80 );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equal( element.val(), 90 );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equal( element.val(), 100 );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equal( element.val(), 100 );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equal( element.val(), 100 );
+});
+
+test( "keydown DOWN on input, decreases value not less than min", function() {
+ expect( 5 );
+ var element = $( "#spin" ).val( 50 ).spinner({
+ min: 20,
+ step: 10
+ });
+
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equal( element.val(), 40 );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equal( element.val(), 30 );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equal( element.val(), 20 );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equal( element.val(), 20 );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equal( element.val(), 20 );
+});
+
+test( "keydown PAGE_UP on input, increases value not greater than max", function() {
+ expect( 5 );
+ var element = $( "#spin" ).val( 70 ).spinner({
+ max: 100,
+ page: 10
+ });
+
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equal( element.val(), 80 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equal( element.val(), 90 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equal( element.val(), 100 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equal( element.val(), 100 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equal( element.val(), 100 );
+});
+
+test( "keydown PAGE_DOWN on input, decreases value not less than min", function() {
+ expect( 5 );
+ var element = $( "#spin" ).val( 50 ).spinner({
+ min: 20,
+ page: 10
+ });
+
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equal( element.val(), 40 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equal( element.val(), 30 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equal( element.val(), 20 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equal( element.val(), 20 );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equal( element.val(), 20 );
+});
+
+asyncTest( "blur input while spinning with UP", function() {
+ expect( 3 );
+ var value,
+ element = $( "#spin" ).val( 10 ).spinner();
+
+ function step1() {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+ equal( element.val(), 11 );
+ setTimeout( step2, 750 );
+ }
+
+ function step2() {
+ value = element.val();
+ ok( value > 11, "repeating while key is down" );
+
+ element.bind( "blur", function() {
+ value = element.val();
+ setTimeout( step3, 750 );
+ })[ 0 ].blur();
+ }
+
+ function step3() {
+ equal( element.val(), value, "stopped repeating on blur" );
+ start();
+ }
+
+ element[ 0 ].focus();
+ setTimeout( step1 );
+});
+
+test( "mouse click on up button, increases value not greater than max", function() {
+ expect( 3 );
+ var element = $( "#spin" ).val( 18 ).spinner({
+ max: 20
+ }),
+ button = element.spinner( "widget" ).find( ".ui-spinner-up" );
+
+ button.trigger( "mousedown" ).trigger( "mouseup" );
+ equal( element.val(), 19 );
+ button.trigger( "mousedown" ).trigger( "mouseup" );
+ equal( element.val(), 20 );
+ button.trigger( "mousedown" ).trigger( "mouseup" );
+ equal( element.val(), 20 );
+});
+
+test( "mouse click on up button, increases value not greater than max", function() {
+ expect( 3 );
+ var element = $( "#spin" ).val( 2 ).spinner({
+ min: 0
+ }),
+ button = element.spinner( "widget" ).find( ".ui-spinner-down" );
+
+ button.trigger( "mousedown" ).trigger( "mouseup" );
+ equal( element.val(), 1 );
+ button.trigger( "mousedown" ).trigger( "mouseup" );
+ equal( element.val(), 0 );
+ button.trigger( "mousedown" ).trigger( "mouseup" );
+ equal( element.val(), 0 );
+});
+
+test( "mousewheel on input", function() {
+ expect( 4 );
+
+ var element = $( "#spin" ).val( 0 ).spinner({
+ step: 2
+ });
+
+ element.trigger( "mousewheel" );
+ equal( element.val(), 0, "mousewheel event without delta does not change value" );
+
+ element.trigger( "mousewheel", 1 );
+ equal( element.val(), 2 );
+
+ element.trigger( "mousewheel", -0.2 );
+ equal( element.val(), 0 );
+
+ element.trigger( "mousewheel", -15 );
+ equal(element.val(), -2 );
+});
+
+test( "reading HTML5 attributes", function() {
+ expect( 6 );
+ var markup = "<input type='number' min='-100' max='100' value='5' step='2'>",
+ element = $( markup ).spinner();
+ equal( element.spinner( "option", "min" ), -100, "min from markup" );
+ equal( element.spinner( "option", "max" ), 100, "max from markup" );
+ equal( element.spinner( "option", "step" ), 2, "step from markup" );
+
+ element = $( markup ).spinner({
+ min: -200,
+ max: 200,
+ step: 5
+ });
+ equal( element.spinner( "option", "min" ), -200, "min from options" );
+ equal( element.spinner( "option", "max" ), 200, "max from options" );
+ equal( element.spinner( "option", "step" ), 5, "stop from options" );
+});
+
+test( "ARIA attributes", function() {
+ expect( 9 );
+ var element = $( "#spin" ).val( 2 ).spinner({ min: -5, max: 5 });
+
+ equal( element.attr( "role" ), "spinbutton", "role" );
+ equal( element.attr( "aria-valuemin" ), "-5", "aria-valuemin" );
+ equal( element.attr( "aria-valuemax" ), "5", "aria-valuemax" );
+ equal( element.attr( "aria-valuenow" ), "2", "aria-valuenow" );
+
+ element.spinner( "stepUp" );
+
+ equal( element.attr( "aria-valuenow" ), "3", "stepUp 1 step changes aria-valuenow" );
+
+ element.spinner( "option", { min: -10, max: 10 } );
+
+ equal( element.attr( "aria-valuemin" ), "-10", "min option changed aria-valuemin changes" );
+ equal( element.attr( "aria-valuemax" ), "10", "max option changed aria-valuemax changes" );
+
+ element.spinner( "option", "min", null );
+ equal( element.attr( "aria-valuemin" ), undefined, "aria-valuemin not set when no min" );
+
+ element.spinner( "option", "max", null );
+ equal( element.attr( "aria-valuemax" ), undefined, "aria-valuemax not set when no max" );
+});
+
+test( "focus text field when pressing button", function() {
+ expect( 2 );
+ var element = $( "#spin" ).spinner();
+ $( "body" ).focus();
+ ok( element[ 0 ] !== document.activeElement, "not focused before" );
+ element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown();
+ ok( element[ 0 ] === document.activeElement, "focused after" );
+});
+
+test( "don't clear invalid value on blur", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner();
+ element.focus().val( "a" ).blur();
+ equal( element.val(), "a" );
+});
+
+test( "precision", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 0.05 ).spinner({
+ step: 0.0001
+ });
+ element.spinner( "stepUp" );
+ equal( element.val(), "0.0501", "precision from step" );
+
+ element.val( 1.05 ).spinner( "option", {
+ step: 1,
+ min: -9.95
+ });
+ element.spinner( "stepDown" );
+ equal( element.val(), "0.05", "precision from min" );
+});
+
+})( jQuery );
diff --git a/apps/it/static/js/ui/tests/unit/spinner/spinner_events.js b/apps/it/static/js/ui/tests/unit/spinner/spinner_events.js
new file mode 100644
index 0000000..610f7a2
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/spinner_events.js
@@ -0,0 +1,259 @@
+(function( $ ) {
+
+var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
+
+module( "spinner: events" );
+
+test( "start", function() {
+ expect( 10 );
+ var element = $( "#spin" ).spinner();
+
+ function shouldStart( expectation, msg ) {
+ element.spinner( "option", "start", function() {
+ ok( expectation, msg );
+ });
+ }
+
+ shouldStart( true, "key UP" );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ shouldStart( true, "key DOWN" );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+
+ shouldStart( true, "key PAGE_UP" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ shouldStart( true, "key PAGE_DOWN" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+
+ shouldStart( true, "button up" );
+ element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
+ shouldStart( true, "button down" );
+ element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
+
+ shouldStart( true, "stepUp" );
+ element.spinner( "stepUp" );
+ shouldStart( true, "stepDown" );
+ element.spinner( "stepDown" );
+
+ shouldStart( true, "pageUp" );
+ element.spinner( "pageUp" );
+ shouldStart( true, "pageDown" );
+ element.spinner( "pageDown" );
+
+ shouldStart( false, "value" );
+ element.spinner( "value", 999 );
+});
+
+test( "spin", function() {
+ expect( 10 );
+ var element = $( "#spin" ).spinner();
+
+ function shouldSpin( expectation, msg ) {
+ element.spinner( "option", "spin", function() {
+ ok( expectation, msg );
+ });
+ }
+
+ shouldSpin( true, "key UP" );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ shouldSpin( true, "key DOWN" );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+
+ shouldSpin( true, "key PAGE_UP" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ shouldSpin( true, "key PAGE_DOWN" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+
+ shouldSpin( true, "button up" );
+ element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
+ shouldSpin( true, "button down" );
+ element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
+
+ shouldSpin( true, "stepUp" );
+ element.spinner( "stepUp" );
+ shouldSpin( true, "stepDown" );
+ element.spinner( "stepDown" );
+
+ shouldSpin( true, "pageUp" );
+ element.spinner( "pageUp" );
+ shouldSpin( true, "pageDown" );
+ element.spinner( "pageDown" );
+
+ shouldSpin( false, "value" );
+ element.spinner( "value", 999 );
+});
+
+test( "stop", function() {
+ expect( 10 );
+ var element = $( "#spin" ).spinner();
+
+ function shouldStop( expectation, msg ) {
+ element.spinner( "option", "stop", function() {
+ ok( expectation, msg );
+ });
+ }
+
+ shouldStop( true, "key UP" );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ shouldStop( true, "key DOWN" );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+
+ shouldStop( true, "key PAGE_UP" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ shouldStop( true, "key PAGE_DOWN" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+
+ shouldStop( true, "button up" );
+ element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
+ shouldStop( true, "button down" );
+ element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
+
+ shouldStop( true, "stepUp" );
+ element.spinner( "stepUp" );
+ shouldStop( true, "stepDown" );
+ element.spinner( "stepDown" );
+
+ shouldStop( true, "pageUp" );
+ element.spinner( "pageUp" );
+ shouldStop( true, "pageDown" );
+ element.spinner( "pageDown" );
+
+ shouldStop( false, "value" );
+ element.spinner( "value", 999 );
+});
+
+asyncTest( "change", function() {
+ expect( 14 );
+ var element = $( "#spin" ).spinner();
+
+ function shouldChange( expectation, msg ) {
+ element.spinner( "option", "change", function() {
+ ok( expectation, msg );
+ });
+ }
+
+ function focusWrap( fn, next ) {
+ element[0].focus();
+ setTimeout( function() {
+ fn();
+ setTimeout(function() {
+ element[0].blur();
+ setTimeout( next );
+ });
+ });
+ }
+
+ function step1() {
+ focusWrap(function() {
+ shouldChange( false, "key UP, before blur" );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ shouldChange( true, "blur after key UP" );
+ }, step2 );
+ }
+
+ function step2() {
+ focusWrap(function() {
+ shouldChange( false, "key DOWN, before blur" );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ shouldChange( true, "blur after key DOWN" );
+ }, step3 );
+ }
+
+ function step3() {
+ focusWrap(function() {
+ shouldChange( false, "key PAGE_UP, before blur" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ shouldChange( true, "blur after key PAGE_UP" );
+ }, step4 );
+ }
+
+ function step4() {
+ focusWrap(function() {
+ shouldChange( false, "key PAGE_DOWN, before blur" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ shouldChange( true, "blur after key PAGE_DOWN" );
+ }, step5 );
+ }
+
+ function step5() {
+ focusWrap(function() {
+ shouldChange( false, "many keys, before blur" );
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ shouldChange( true, "blur after many keys" );
+ }, step6 );
+ }
+
+ function step6() {
+ focusWrap(function() {
+ shouldChange( false, "many keys, same final value, before blur" );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ shouldChange( false, "blur after many keys, same final value" );
+
+ shouldChange( false, "button up, before blur" );
+ element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
+ shouldChange( true, "blur after button up" );
+ }, step7 );
+ }
+
+ function step7() {
+ focusWrap(function() {
+ shouldChange( false, "button down, before blur" );
+ element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
+ shouldChange( true, "blur after button down" );
+ }, step8 );
+ }
+
+ function step8() {
+ focusWrap(function() {
+ shouldChange( false, "many buttons, same final value, before blur" );
+ element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
+ element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
+ element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
+ element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
+ shouldChange( false, "blur after many buttons, same final value" );
+ }, step9 );
+ }
+
+ function step9() {
+ shouldChange( true, "stepUp" );
+ element.spinner( "stepUp" );
+
+ shouldChange( true, "stepDown" );
+ element.spinner( "stepDown" );
+
+ shouldChange( true, "pageUp" );
+ element.spinner( "pageUp" );
+
+ shouldChange( true, "pageDown" );
+ element.spinner( "pageDown" );
+
+ shouldChange( true, "value" );
+ element.spinner( "value", 999 );
+
+ shouldChange( false, "value, same value" );
+ element.spinner( "value", 999 );
+
+ shouldChange( true, "max, value changed" );
+ element.spinner( "option", "max", 900 );
+
+ shouldChange( false, "max, value not changed" );
+ element.spinner( "option", "max", 1000 );
+
+ shouldChange( true, "min, value changed" );
+ element.spinner( "option", "min", 950 );
+
+ shouldChange( false, "min, value not changed" );
+ element.spinner( "option", "min", 200 );
+ start();
+ }
+
+ setTimeout( step1 );
+});
+
+})( jQuery );
diff --git a/apps/it/static/js/ui/tests/unit/spinner/spinner_methods.js b/apps/it/static/js/ui/tests/unit/spinner/spinner_methods.js
new file mode 100644
index 0000000..af872f2
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/spinner_methods.js
@@ -0,0 +1,174 @@
+(function( $ ) {
+
+var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
+
+module( "spinner: methods" );
+
+test( "destroy", function() {
+ expect( 1 );
+ domEqual( "#spin", function() {
+ $( "#spin" ).spinner().spinner( "destroy" );
+ });
+});
+
+test( "disable", function() {
+ expect( 14 );
+ var element = $( "#spin" ).val( 2 ).spinner(),
+ wrapper = $( "#spin" ).spinner( "widget" );
+
+ ok( !wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper does not have ui-spinner-disabled class" );
+ ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" );
+
+ element.spinner( "disable" );
+ ok( wrapper.hasClass( "ui-spinner-disabled" ), "after: wrapper has ui-spinner-disabled class" );
+ ok( element.is( ":disabled"), "after: input has disabled attribute" );
+
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equal( 2, element.val(), "keyboard - value does not change on key UP" );
+
+ simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equal( 2, element.val(), "keyboard - value does not change on key DOWN" );
+
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equal( 2, element.val(), "keyboard - value does not change on key PGUP" );
+
+ simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equal( 2, element.val(), "keyboard - value does not change on key PGDN" );
+
+ wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
+ equal( 2, element.val(), "mouse - value does not change on clicking up button" );
+
+ wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
+ equal( 2, element.val(), "mouse - value does not change on clicking down button" );
+
+ element.spinner( "stepUp", 6 );
+ equal( 8, element.val(), "script - stepUp 6 steps changes value");
+
+ element.spinner( "stepDown" );
+ equal( 7, element.val(), "script - stepDown 1 step changes value" );
+
+ element.spinner( "pageUp" );
+ equal( 17, element.val(), "script - pageUp 1 page changes value" );
+
+ element.spinner( "pageDown" );
+ equal( 7, element.val(), "script - pageDown 1 page changes value" );
+});
+
+test( "enable", function() {
+ expect( 5 );
+ var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }),
+ wrapper = element.spinner( "widget" );
+
+ ok( wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper has ui-spinner-disabled class" );
+ ok( element.is( ":disabled" ), "before: input has disabled attribute" );
+
+ element.spinner( "enable" );
+
+ ok( !wrapper.hasClass( ".ui-spinner-disabled" ), "after: wrapper does not have ui-spinner-disabled class" );
+ ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
+
+ simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equal( 2, element.val(), "keyboard - value changes on key UP" );
+});
+
+test( "pageDown", function() {
+ expect( 4 );
+ var element = $( "#spin" ).val( -12 ).spinner({
+ page: 20,
+ min: -100
+ });
+
+ element.spinner( "pageDown" );
+ equal( element.val(), -32, "pageDown 1 page" );
+
+ element.spinner( "pageDown", 3 );
+ equal( element.val(), -92, "pageDown 3 pages" );
+
+ element.spinner( "pageDown" );
+ equal( element.val(), -100, "value close to min and pageDown 1 page" );
+
+ element.spinner( "pageDown", 10 );
+ equal( element.val(), -100, "value at min and pageDown 10 pages" );
+});
+
+test( "pageUp", function() {
+ expect( 4 );
+ var element = $( "#spin" ).val( 12 ).spinner({
+ page: 20,
+ max: 100
+ });
+
+ element.spinner( "pageUp" );
+ equal( element.val(), 32, "pageUp 1 page" );
+
+ element.spinner( "pageUp", 3 );
+ equal( element.val(), 92, "pageUp 3 pages" );
+
+ element.spinner( "pageUp" );
+ equal( element.val(), 100, "value close to max and pageUp 1 page" );
+
+ element.spinner( "pageUp", 10 );
+ equal( element.val(), 100, "value at max and pageUp 10 pages" );
+});
+
+test( "stepDown", function() {
+ expect( 4 );
+ var element = $( "#spin" ).val( 0 ).spinner({
+ step: 2,
+ min: -15
+ });
+
+ element.spinner( "stepDown" );
+ equal( element.val(), "-1", "stepDown 1 step" );
+
+ element.spinner( "stepDown", 5 );
+ equal( element.val(), "-11", "stepDown 5 steps" );
+
+ element.spinner( "stepDown", 4 );
+ equal( element.val(), "-15", "close to min and stepDown 4 steps" );
+
+ element.spinner( "stepDown" );
+ equal( element.val(), "-15", "at min and stepDown 1 step" );
+});
+
+test( "stepUp", function() {
+ expect( 4 );
+ var element = $( "#spin" ).val( 0 ).spinner({
+ step: 2,
+ max: 16
+ });
+
+ element.spinner( "stepUp" );
+ equal( element.val(), 2, "stepUp 1 step" );
+
+ element.spinner( "stepUp", 5 );
+ equal( element.val(), 12, "stepUp 5 steps" );
+
+ element.spinner( "stepUp", 4 );
+ equal( element.val(), 16, "close to min and stepUp 4 steps" );
+
+ element.spinner( "stepUp" );
+ equal( element.val(), 16, "at max and stepUp 1 step" );
+});
+
+test( "value", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 0 ).spinner({
+ step: 3
+ });
+
+ element.spinner( "value", 10 );
+ equal( element.val(), 9, "change value via value method" );
+
+ equal( element.spinner( "value" ), 9, "get value via value method" );
+});
+
+test( "widget", function() {
+ expect( 2 );
+ var element = $( "#spin" ).spinner(),
+ widgetElement = element.spinner( "widget" );
+ equal( widgetElement.length, 1, "one element" );
+ strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" );
+});
+
+})( jQuery );
diff --git a/apps/it/static/js/ui/tests/unit/spinner/spinner_options.js b/apps/it/static/js/ui/tests/unit/spinner/spinner_options.js
new file mode 100644
index 0000000..6f3650f
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/spinner_options.js
@@ -0,0 +1,262 @@
+(function( $ ) {
+
+module( "spinner: options" );
+
+// culture is tested after numberFormat, since it depends on numberFormat
+
+test( "icons: default ", function() {
+ expect( 4 );
+ var element = $( "#spin" ).val( 0 ).spinner();
+ equal( element.spinner( "widget" ).find( ".ui-icon:first" ).attr( "class" ), "ui-icon ui-icon-triangle-1-n" );
+ equal( element.spinner( "widget" ).find( ".ui-icon:last" ).attr( "class" ), "ui-icon ui-icon-triangle-1-s" );
+
+ element.spinner( "option", "icons", {
+ up: "ui-icon-carat-1-n",
+ down: "ui-icon-carat-1-s"
+ });
+ equal( element.spinner( "widget" ).find( ".ui-icon:first" ).attr( "class" ), "ui-icon ui-icon-carat-1-n" );
+ equal( element.spinner( "widget" ).find( ".ui-icon:last" ).attr( "class" ), "ui-icon ui-icon-carat-1-s" );
+});
+
+test( "icons: custom ", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 0 ).spinner({
+ icons: {
+ down: "custom-down",
+ up: "custom-up"
+ }
+ }).spinner( "widget" );
+ equal( element.find( ".ui-icon:first" ).attr( "class" ), "ui-icon custom-up" );
+ equal( element.find( ".ui-icon:last" ).attr( "class" ), "ui-icon custom-down" );
+});
+
+test( "incremental, false", function() {
+ expect( 100 );
+
+ var i,
+ prev = 0,
+ element = $( "#spin" ).val( prev ).spinner({
+ incremental: false,
+ spin: function( event, ui ) {
+ equal( ui.value - prev, 1 );
+ prev = ui.value;
+ }
+ });
+
+ for ( i = 0; i < 100; i++ ) {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+ }
+ element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
+});
+
+test( "incremental, true", function() {
+ expect( 100 );
+
+ function fill( num, val ) {
+ return $.map( new Array( num ), function() {
+ return val;
+ });
+ }
+
+ var i,
+ prev = 0,
+ expected = [].concat( fill( 18, 1 ), fill( 37, 2 ), fill( 14, 3 ),
+ fill( 9, 4 ), fill( 6, 5 ), fill( 5, 6 ), fill ( 5, 7 ),
+ fill( 4, 8 ), fill( 2, 9 ) ),
+ element = $( "#spin" ).val( prev ).spinner({
+ incremental: true,
+ spin: function( event, ui ) {
+ equal( ui.value - prev, expected[ i ] );
+ prev = ui.value;
+ }
+ });
+
+ for ( i = 0; i < 100; i++ ) {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+ }
+ element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
+});
+
+test( "incremental, function", function() {
+ expect( 100 );
+
+ var i,
+ prev = 0,
+ element = $( "#spin" ).val( prev ).spinner({
+ incremental: function( i ) {
+ return i;
+ },
+ spin: function( event, ui ) {
+ equal( ui.value - prev, i + 1 );
+ prev = ui.value;
+ }
+ });
+
+ for ( i = 0; i < 100; i++ ) {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
+ }
+ element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
+});
+
+test( "numberFormat, number", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n" });
+ equal( element.val(), "0.00", "formatted on init" );
+ element.spinner( "stepUp" );
+ equal( element.val(), "1.00", "formatted after step" );
+});
+
+test( "numberFormat, number, simple", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n0" });
+ equal( element.val(), "0", "formatted on init" );
+ element.spinner( "stepUp" );
+ equal( element.val(), "1", "formatted after step" );
+});
+
+test( "numberFormat, currency", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" });
+ equal( element.val(), "$0.00", "formatted on init" );
+ element.spinner( "stepUp" );
+ equal( element.val(), "$1.00", "formatted after step" );
+});
+
+test( "numberFormat, change", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 5 ).spinner({ numberFormat: "n1" });
+ equal( element.val(), "5.0", "formatted on init" );
+ element.spinner( "option", "numberFormat", "c" );
+ equal( element.val(), "$5.00", "formatted after change" );
+});
+
+test( "culture, null", function() {
+ expect( 2 );
+ Globalize.culture( "ja-JP" );
+ var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" });
+ equal( element.val(), "¥0", "formatted on init" );
+ element.spinner( "stepUp" );
+ equal( element.val(), "¥1", "formatted after step" );
+
+ // reset culture
+ Globalize.culture( "default" );
+});
+
+test( "currency, ja-JP", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 0 ).spinner({
+ numberFormat: "C",
+ culture: "ja-JP"
+ });
+ equal( element.val(), "¥0", "formatted on init" );
+ element.spinner( "stepUp" );
+ equal( element.val(), "¥1", "formatted after step" );
+});
+
+test( "currency, change", function() {
+ expect( 2 );
+ var element = $( "#spin" ).val( 5 ).spinner({
+ numberFormat: "C",
+ culture: "ja-JP"
+ });
+ equal( element.val(), "¥5", "formatted on init" );
+ element.spinner( "option", "culture", "en" );
+ equal( element.val(), "$5.00", "formatted after change" );
+});
+
+test( "max", function() {
+ expect( 3 );
+ var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 });
+ equal( element.val(), 1000, "value not constrained on init" );
+
+ element.spinner( "value", 1000 );
+ equal( element.val(), 100, "max constrained in value method" );
+
+ element.val( 1000 ).blur();
+ equal( element.val(), 1000, "max not constrained if manual entry" );
+});
+
+test( "max, string", function() {
+ expect( 3 );
+ var element = $( "#spin" )
+ .val( 1000 )
+ .spinner({
+ max: "$100.00",
+ numberFormat: "C",
+ culture: "en"
+ });
+ equal( element.val(), "$1,000.00", "value not constrained on init" );
+ equal( element.spinner( "option", "max" ), 100, "option converted to number" );
+
+ element.spinner( "value", 1000 );
+ equal( element.val(), "$100.00", "max constrained in value method" );
+});
+
+test( "min", function() {
+ expect( 3 );
+ var element = $( "#spin" ).val( -1000 ).spinner({ min: -100 });
+ equal( element.val(), -1000, "value not constrained on init" );
+
+ element.spinner( "value", -1000 );
+ equal( element.val(), -100, "min constrained in value method" );
+
+ element.val( -1000 ).blur();
+ equal( element.val(), -1000, "min not constrained if manual entry" );
+});
+
+test( "min, string", function() {
+ expect( 3 );
+ var element = $( "#spin" )
+ .val( -1000 )
+ .spinner({
+ min: "-$100.00",
+ numberFormat: "C",
+ culture: "en"
+ });
+ equal( element.val(), "($1,000.00)", "value not constrained on init" );
+ equal( element.spinner( "option", "min" ), -100, "option converted to number" );
+
+ element.spinner( "value", -1000 );
+ equal( element.val(), "($100.00)", "min constrained in value method" );
+});
+
+test( "step, 2", function() {
+ expect( 3 );
+ var element = $( "#spin" ).val( 0 ).spinner({ step: 2 });
+
+ element.spinner( "stepUp" );
+ equal( element.val(), "2", "stepUp" );
+
+ element.spinner( "value", "10.5" );
+ equal( element.val(), "10", "value reset to 10" );
+
+ element.val( "4.5" );
+ element.spinner( "stepUp" );
+ equal( element.val(), "6", "stepUp" );
+});
+
+test( "step, 0.7", function() {
+ expect( 1 );
+ var element = $("#spin").val( 0 ).spinner({
+ step: 0.7
+ });
+
+ element.spinner( "stepUp" );
+ equal( element.val(), "0.7", "stepUp" );
+});
+
+test( "step, string", function() {
+ expect( 2 );
+ var element = $("#spin").val( 0 ).spinner({
+ step: "$0.70",
+ numberFormat: "C",
+ culture: "en"
+ });
+
+ equal( element.spinner( "option", "step" ), 0.7, "option converted to number" );
+
+ element.spinner( "stepUp" );
+ equal( element.val(), "$0.70", "stepUp" );
+});
+
+})( jQuery );
diff --git a/apps/it/static/js/ui/tests/unit/spinner/spinner_test_helpers.js b/apps/it/static/js/ui/tests/unit/spinner/spinner_test_helpers.js
new file mode 100644
index 0000000..2021e8f
--- /dev/null
+++ b/apps/it/static/js/ui/tests/unit/spinner/spinner_test_helpers.js
@@ -0,0 +1,8 @@
+TestHelpers.spinner = {
+ simulateKeyDownUp: function( element, keyCode, shift ) {
+ element
+ .simulate( "keydown", { keyCode: keyCode, shiftKey: shift || false } )
+ .simulate( "keyup", { keyCode: keyCode, shiftKey: shift || false } );
+ }
+};
+