--- /dev/null
+<!doctype html>\r
+<html lang="en">\r
+<head>\r
+ <title>jQuery UI Spinner Test Suite</title>\r
+ \r
+ <link type="text/css" href="../../../themes/base/jquery.ui.spinner.css" rel="stylesheet" />\r
+ \r
+ <script type="text/javascript" src="../../../jquery-1.4.3.js"></script>\r
+ <script type="text/javascript" src="../../../external/jquery.mousewheel-3.0.2.js"></script>\r
+ <script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>\r
+ <script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>\r
+ <script type="text/javascript" src="../../../ui/jquery.ui.spinner.js"></script>\r
+\r
+ <link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>\r
+ <script type="text/javascript" src="../../../external/qunit.js"></script>\r
+ <script type="text/javascript" src="../../jquery.simulate.js"></script>\r
+ <script type="text/javascript" src="../testsuite.js"></script>\r
+\r
+ <script type="text/javascript" src="spinner_core.js"></script>\r
+ <script type="text/javascript" src="spinner_defaults.js"></script>\r
+ <script type="text/javascript" src="spinner_events.js"></script>\r
+ <script type="text/javascript" src="spinner_methods.js"></script>\r
+ <script type="text/javascript" src="spinner_options.js"></script>\r
+</head>\r
+<body>\r
+\r
+\r
+<h1 id="qunit-header">jQuery UI Slider Test Suite</h1>\r
+<h2 id="qunit-banner"></h2>\r
+<h2 id="qunit-userAgent"></h2>\r
+<ol id="qunit-tests">\r
+</ol>\r
+\r
+<div id="qunit-fixture">\r
+ <input id="spin">\r
+</div>\r
+\r
+</body>\r
+</html>\r
--- /dev/null
+/*\r
+ * spinner_core.js\r
+ */\r
+\r
+var el,\r
+ options,\r
+ simulateKeyDownUp = function(el, kCode, shift) {\r
+ el.simulate("keydown",{keyCode:kCode, shiftKey: shift || false })\r
+ .simulate("keyup",{keyCode:kCode, shiftKey: shift || false });\r
+ },\r
+ wrapper = function() {\r
+ return el.closest('.ui-spinner');\r
+ },\r
+ upButton = function() {\r
+ return wrapper().find('.ui-spinner-up');\r
+ },\r
+ downButton = function() {\r
+ return wrapper().find('.ui-spinner-down');\r
+ },\r
+ box = function() {\r
+ return $('.ui-spinner-input', wrapper());\r
+ };\r
+\r
+(function($) {\r
+\r
+// Spinner Tests\r
+module("spinner: core");\r
+\r
+test("init", function() {\r
+ expect(3);\r
+\r
+ $("<input>").appendTo('body').spinner().remove();\r
+ ok(true, '.spinner() called on element');\r
+\r
+ $('<input id="spinner_dis">').spinner().remove();\r
+ ok(true, '.spinner() called on disconnected element');\r
+\r
+ el = $('<input>').spinner();\r
+ ok(el.hasClass('ui-spinner-input'), 'input gets ui-spinner-input class on init');\r
+\r
+});\r
+\r
+test("destroy", function() {\r
+ expect(3);\r
+\r
+ $("<input>").appendTo('body').spinner().spinner("destroy").remove();\r
+ ok(true, '.spinner("destroy") called on element');\r
+\r
+ $('<input id="spinner_dis">').spinner().spinner("destroy").remove();\r
+ ok(true, '.spinner().spinner("destroy") called on disconnected element');\r
+\r
+ el = $('<input>').spinner().spinner('destroy');\r
+ ok(!el.hasClass('ui-spinner-input'), 'ui-spinner-input class removed on destroy');\r
+});\r
+\r
+test("re-attach", function() {\r
+ expect(2);\r
+\r
+ el = $("<input>").spinner().spinner("destroy").spinner();\r
+ ok(true, '.spinner().spinner("destroy").spinner() called on element');\r
+\r
+ el = $('<input id="spinner_dis">').spinner().spinner("destroy").spinner().remove();\r
+ ok(true, '.spinner().spinner("destroy").spinner() called on disconnected element');\r
+\r
+});\r
+\r
+test("keydown UP on input, increases value not greater than max", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin");\r
+ options = {\r
+ max:100,\r
+ value:50,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ \r
+ equals(el.val(), 60);\r
+ \r
+ for (i = 0; i<11; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP); \r
+ }\r
+ \r
+ equals(el.val(), 100);\r
+ \r
+ el.val(50);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ \r
+ equals(el.val(), 60);\r
+});\r
+\r
+test("keydown DOWN on input, decreases value not less than min", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin");\r
+ options = {\r
+ min:-100,\r
+ value:50,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
+ \r
+ equals(el.val(), 40);\r
+ \r
+ for (i = 0; i<21; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN); \r
+ }\r
+ \r
+ equals(el.val(), -100);\r
+ \r
+ el.val(50);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
+ \r
+ equals(el.val(), 40);\r
+\r
+});\r
+\r
+test("keydown PGUP on input, increases value not greater than max", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin");\r
+ options = {\r
+ max:100,\r
+ value:0,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
+ \r
+ equals(el.val(), 50);\r
+ \r
+ for (i = 0; i<5; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP); \r
+ }\r
+ \r
+ equals(el.val(), 100);\r
+\r
+ el.val(0);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
+ \r
+ equals(el.val(), 50);\r
+});\r
+\r
+test("keydown PGDN on input, decreases value not less than min", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin");\r
+ options = {\r
+ min:-100,\r
+ value:0,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
+ \r
+ equals(el.val(), -50);\r
+ \r
+ for (i = 0; i<5; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN); \r
+ }\r
+ \r
+ equals(el.val(), -100);\r
+ \r
+ el.val(0);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
+ \r
+ equals(el.val(), -50);\r
+});\r
+\r
+test("hold SHIFT and keydown UP, increments value but no greater than max", function() {\r
+ expect(2);\r
+ \r
+ el = $("#spin");\r
+ options = {\r
+ max:100,\r
+ value:0,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.UP, true);\r
+ \r
+ equals(el.val(), 50);\r
+ \r
+ for (i = 0; i<5; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP, true);\r
+ }\r
+ \r
+ equals(el.val(), 100);\r
+});\r
+\r
+test("hold SHIFT and keydown DOWN, decreases value but no less than min", function() {\r
+ expect(2);\r
+ \r
+ el = $("#spin");\r
+ options = {\r
+ min:-100,\r
+ value:0,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN, true);\r
+ \r
+ equals(el.val(), -50);\r
+ \r
+ for (i = 0; i<5; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN, true); \r
+ }\r
+ \r
+ equals(el.val(), -100); \r
+});\r
+\r
+test("keydown HOME on input, sets value to minimum", function() {\r
+ el = $("#spin");\r
+ options = {\r
+ min:-100,\r
+ value:50,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.HOME); \r
+ equals(el.val(), -100);\r
+ \r
+ el.spinner('option', 'min', -200);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.HOME);\r
+ \r
+ equals(el.val(), -200);\r
+});\r
+\r
+test("keydown END on input, sets value to maximum", function() {\r
+ el = $("#spin");\r
+ options = {\r
+ max:100,\r
+ value:50,\r
+ step:10\r
+ }\r
+ el.spinner(options);\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.END); \r
+ equals(el.val(), 100);\r
+ \r
+ el.spinner('option', 'max', 200);\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.END);\r
+ \r
+ equals(el.val(), 200);\r
+});\r
+\r
+test("keydown LEFT on input has no effect", function() {\r
+ el = $("#spin");\r
+ el.spinner();\r
+ var value = el.val();\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.LEFT); \r
+ equals(el.val(), value);\r
+ \r
+ for (i = 0; i<5; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.LEFT); \r
+ }\r
+ \r
+ equals(el.val(), value);\r
+});\r
+\r
+test("keydown RIGHT on input has no effect", function() {\r
+ expect(2);\r
+ \r
+ el = $("#spin");\r
+ el.spinner();\r
+ var value = el.val();\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.RIGHT); \r
+ equals(el.val(), value);\r
+ \r
+ for (i = 0; i<5; i++) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.RIGHT); \r
+ }\r
+ \r
+ equals(el.val(), value);\r
+});\r
+\r
+test("mouse click on buttons", function() {\r
+ expect(4);\r
+ \r
+ el = $("#spin").spinner();\r
+ val = 0;\r
+ \r
+ $(".ui-spinner-up").trigger("mousedown").trigger("mouseup");\r
+\r
+ equals(el.val(), ++val, "mouse click to up");\r
+\r
+ $(".ui-spinner-down").trigger("mousedown").trigger("mouseup");\r
+\r
+ equals(el.val(), --val, "mouse click to down");\r
+ \r
+ el.val(50);\r
+ \r
+ $(".ui-spinner-up").trigger("mousedown").trigger("mouseup");\r
+ \r
+ equals(el.val(), 51);\r
+\r
+ el.val(50);\r
+ \r
+ $(".ui-spinner-down").trigger("mousedown").trigger("mouseup");\r
+ \r
+ equals(el.val(), 49);\r
+ \r
+});\r
+\r
+test("mouse wheel on input", function() {\r
+ ok(false, 'missing test - untested code is broken code');\r
+});\r
+\r
+test("reading HTML5 attributes", function() {\r
+ expect(4);\r
+ \r
+ el = $('<input id="spinner" type="number" min="-100" max="100" value="5" step="2">').spinner();\r
+\r
+ equals(el.spinner('option', 'value'), 5, 'value'); \r
+ equals(el.spinner('option', 'max'), 100, 'max');\r
+ equals(el.spinner('option', 'min'), -100, 'min');\r
+ equals(el.spinner('option', 'step'), 2, 'step');\r
+});\r
+\r
+test("ARIA attributes", function() {\r
+ expect(7);\r
+ \r
+ el = $('#spin').spinner({ min: -5, max: 5, value: 2 });\r
+ \r
+ equals(wrapper().attr('role'), 'spinbutton', 'role');\r
+ equals(wrapper().attr('aria-valuemin'), -5, 'aria-valuemin');\r
+ equals(wrapper().attr('aria-valuemax'), 5, 'aria-valuemax');\r
+ equals(wrapper().attr('aria-valuenow'), 2, 'aria-valuenow');\r
+ \r
+ el.spinner('stepUp');\r
+ \r
+ equals(wrapper().attr('aria-valuenow'), 3, 'stepUp 1 step changes aria-valuenow');\r
+ \r
+ el.spinner('option', { min: -10, max: 10 });\r
+ \r
+ equals(wrapper().attr('aria-valuemin'), -10, 'min option changed aria-valuemin changes');\r
+ equals(wrapper().attr('aria-valuemax'), 10, 'max option changed aria-valuemax changes');\r
+});\r
+\r
+})(jQuery);\r
--- /dev/null
+/*\r
+ * spinner_defaults.js\r
+ */\r
+\r
+var spinner_defaults = {\r
+ buttons: 'show',\r
+ currency: false,\r
+ dir: 'ltr',\r
+ disabled: false,\r
+ groupSeparator: '',\r
+ incremental: true,\r
+ max: null,\r
+ min: null,\r
+ mouseWheel: true,\r
+ padding: 0,\r
+ page: 5,\r
+ precision: 0,\r
+ radix: 10,\r
+ radixPoint: '.',\r
+ spinnerClass: null,\r
+ step: null,\r
+ value: 0,\r
+ width: false\r
+};\r
+\r
+commonWidgetTests('spinner', { defaults: spinner_defaults });\r
--- /dev/null
+/*\r
+ * spinner_events.js\r
+ */\r
+(function($) {\r
+\r
+module("spinner: events");\r
+\r
+test("start", function() {\r
+ expect(1);\r
+\r
+ var start = 0;\r
+ \r
+ el = $("#spin").spinner({\r
+ start: function(){\r
+ start++;\r
+ }\r
+ });\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+\r
+ equals(start, 1, "Start triggered");\r
+});\r
+\r
+test("spin", function() {\r
+ expect(1);\r
+\r
+ var spin = 0;\r
+ \r
+ el = $("#spin").spinner({\r
+ spin: function(){\r
+ spin++;\r
+ }\r
+ });\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ \r
+ equals(spin, 1, "Spin triggered");\r
+});\r
+\r
+test("stop", function() {\r
+ expect(1);\r
+\r
+ var stop = 0;\r
+ \r
+ el = $("#spin").spinner({\r
+ stop: function(){\r
+ stop++;\r
+ }\r
+ });\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
+ \r
+ equals(stop, 1, "Stop triggered");\r
+});\r
+\r
+test("change", function() {\r
+ expect(1);\r
+\r
+ var start = spin = stop = change = 0;\r
+ \r
+ el = $("#spin").spinner({\r
+ change: function(){\r
+ change++;\r
+ }\r
+ });\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ \r
+ equals(change, 1, "Change triggered");\r
+});\r
+\r
+})(jQuery);\r
--- /dev/null
+/*\r
+ * spinner_methods.js\r
+ */\r
+(function($) {\r
+\r
+module("spinner: methods");\r
+\r
+test("disable", function() {\r
+ expect(14);\r
+\r
+ el = $("#spin").spinner({ disabled: false });\r
+ var val = el.val();\r
+ \r
+ ok(!wrapper().hasClass(".ui-spinner-disabled"), "before: wrapper does not have ui-spinner-disabled class");\r
+ ok(!box().is(':disabled'), "before: input does not have disabled attribute");\r
+\r
+ el.spinner("disable");\r
+ ok(wrapper().hasClass(".ui-spinner-disabled"), "after: wrapper has ui-spinner-disabled class");\r
+ ok(box().is(':disabled'), "after: input has disabled attribute");\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.UP); \r
+ equals(val, el.val(), "keyboard - value does not change on key UP");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
+ equals(val, el.val(), "keyboard - value does not change on key DOWN");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
+ equals(val, el.val(), "keyboard - value does not change on key PGUP");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
+ equals(val, el.val(), "keyboard - value does not change on key PGDN");\r
+ \r
+ upButton().trigger('mousedown').trigger('mouseup');\r
+ equals(val, el.val(), "mouse - value does not change on clicking up button");\r
+\r
+ downButton().trigger('mousedown').trigger('mouseup');\r
+ equals(val, el.val(), "mouse - value does not change on clicking down button");\r
+ \r
+ el.spinner('stepUp', 6);\r
+ equals(6, el.val(), "script - stepUp 6 steps changes value");\r
+\r
+ el.spinner('stepDown');\r
+ equals(5, el.val(), "script - stepDown 1 step changes value");\r
+\r
+ el.spinner('pageUp');\r
+ equals(10, el.val(), "script - pageUp 1 page changes value");\r
+\r
+ el.spinner('pageDown');\r
+ equals(5, el.val(), "script - pageDown 1 page changes value");\r
+\r
+});\r
+\r
+test("enable", function() {\r
+ expect(14);\r
+\r
+ el = $("#spin").spinner({ disabled: true });\r
+ var val = el.val();\r
+ \r
+ ok(wrapper().hasClass(".ui-spinner-disabled"), "before: wrapper has ui-spinner-disabled class");\r
+ ok(box().is(':disabled'), "before: input has disabled attribute");\r
+ \r
+ el.spinner("enable");\r
+ \r
+ ok(!wrapper().hasClass(".ui-spinner-disabled"), "after: wrapper does not have ui-spinner-disabled class");\r
+ ok(!box().is(':disabled'), "after: input does not have disabled attribute");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ equals(1, el.val(), "keyboard - value changes on key UP");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
+ equals(0, el.val(), "keyboard - value changes on key DOWN");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
+ equals(5, el.val(), "keyboard - value changes on key PGUP");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
+ equals(0, el.val(), "keyboard - value changes on key PGDN");\r
+ \r
+ upButton().trigger('mousedown').trigger('mouseup');\r
+ equals(1, el.val(), "mouse - value changes on clicking up button");\r
+\r
+ downButton().trigger('mousedown').trigger('mouseup');\r
+ equals(0, el.val(), "mouse - value changes on clicking down button");\r
+ \r
+ el.spinner('stepUp', 6);\r
+ equals(6, el.val(), "script - stepUp 6 steps changes value");\r
+\r
+ el.spinner('stepDown');\r
+ equals(5, el.val(), "script - stepDown 1 step changes value");\r
+\r
+ el.spinner('pageUp');\r
+ equals(10, el.val(), "script - pageUp 1 page changes value");\r
+\r
+ el.spinner('pageDown');\r
+ equals(5, el.val(), "script - pageDown 1 page changes value"); \r
+\r
+});\r
+\r
+test("pageDown", function() {\r
+ expect(4);\r
+ \r
+ el = $('#spin').spinner({ step: 2, page: 5, value: 0, min: -100 });\r
+\r
+ el.spinner('pageDown');\r
+ equals(el.val(), -10, "pageDown 1 page");\r
+\r
+ el.spinner('pageDown', 3);\r
+ equals(el.val(), -40, "pageDown 3 pages");\r
+ \r
+ el.val(-91).spinner('pageDown');\r
+ equals(el.val(), -100, "value close to min and pageDown 1 page");\r
+ \r
+ el.spinner('pageDown', 10);\r
+ equals(el.val(), -100, "value at min and pageDown 10 pages");\r
+});\r
+\r
+test("pageUp", function() {\r
+ expect(4);\r
+\r
+ el = $('#spin').spinner({ step: 2, page: 5, value: 0, max: 100 });\r
+\r
+ el.spinner('pageUp');\r
+ equals(el.val(), 10, "pageUp 1 page");\r
+\r
+ el.spinner('pageUp', 3);\r
+ equals(el.val(), 40, "pageUp 3 pages");\r
+\r
+ el.val(91).spinner('pageUp');\r
+ equals(el.val(), 100, "value close to max and pageUp 1 page");\r
+ \r
+ el.spinner('pageUp', 10);\r
+ equals(el.val(), 100, "value at max and pageUp 10 pages");\r
+ \r
+});\r
+\r
+test("stepDown", function() {\r
+ expect(4);\r
+\r
+ el = $('#spin').spinner({ step: 2, page: 5, value: 0, min: -15 });\r
+\r
+ el.spinner('stepDown')\r
+ equals(el.val(), -2, "stepDown 1 step");\r
+\r
+ el.spinner('stepDown', 5)\r
+ equals(el.val(), -12, "stepDown 5 steps");\r
+ \r
+ el.spinner('stepDown', 3);\r
+ equals(el.val(), -15, "close to min and stepDown 3 steps");\r
+\r
+ el.spinner('stepDown');\r
+ equals(el.val(), -15, "at min and stepDown 1 step");\r
+});\r
+\r
+test("stepUp", function() {\r
+ expect(4);\r
+\r
+ el = $('#spin').spinner({ step: 2, page: 5, value: 0, max: 15 });\r
+\r
+ el.spinner('stepUp')\r
+ equals(el.val(), 2, "stepUp 1 steps");\r
+\r
+ el.spinner('stepUp', 5)\r
+ equals(el.val(), 12, "stepUp 5 steps");\r
+ \r
+ el.spinner('stepUp', 3);\r
+ equals(el.val(), 15, "close to min and stepUp 3 steps");\r
+\r
+ el.spinner('stepUp');\r
+ equals(el.val(), 15, "at min and stepUp 1 step");\r
+\r
+});\r
+\r
+test("value", function() {\r
+ expect(2);\r
+ \r
+ el = $('#spin').spinner({ value: 0 });\r
+ \r
+ el.spinner('value', 10);\r
+ equals(el.val(), 10, "change value via value method");\r
+ \r
+ equals(10, el.spinner('value'), "get value via value method");\r
+});\r
+\r
+})(jQuery);\r
--- /dev/null
+/*\r
+ * spinner_options.js\r
+ */\r
+(function($) {\r
+\r
+module("spinner: options");\r
+\r
+test("buttons - show (default)", function() {\r
+ expect(4);\r
+ \r
+ el = $('#spin'); \r
+ el.spinner({ \r
+ buttons: 'show' \r
+ });\r
+ \r
+ ok(upButton().is(':visible'), "show - before hover: up button visible");\r
+ ok(downButton().is(':visible'), "show - before hover: down button visible");\r
+ \r
+ el.trigger('mouseover');\r
+ \r
+ ok(upButton().is(':visible'), "show - after hover: up button visible");\r
+ ok(downButton().is(':visible'), "show - after hover: down button visible");\r
+ \r
+ el.trigger('mouseout'); \r
+});\r
+\r
+test("buttons - hide", function() {\r
+ expect(4);\r
+ \r
+ el = $('#spin'); \r
+ el.spinner({ \r
+ buttons: 'hide' \r
+ });\r
+ \r
+ ok(upButton().is(':hidden'), "hide - before hover: up button hidden");\r
+ ok(downButton().is(':hidden'), "hide - before hover: down button hidden");\r
+\r
+ el.trigger('mouseover');\r
+ \r
+ ok(upButton().is(':hidden'), "hide - after hover: up button hidden");\r
+ ok(downButton().is(':hidden'), "hide - after hover: down button hidden");\r
+\r
+ el.trigger('mouseout'); \r
+});\r
+\r
+test("buttons - auto (hover)", function() {\r
+ expect(4);\r
+ \r
+ el = $('#spin');\r
+ el.spinner({ \r
+ buttons: 'auto' \r
+ });\r
+ \r
+ ok(upButton().is(':hidden'), "auto - before hover: up button hidden");\r
+ ok(downButton().is(':hidden'), "auto - before hover: down button hidden");\r
+\r
+ el.trigger('mouseover');\r
+ \r
+ ok(upButton().is(':visible'), "auto - after hover: up button visible");\r
+ ok(downButton().is(':visible'), "auto - after hover: down button visible");\r
+\r
+ el.trigger('mouseout');\r
+});\r
+\r
+test("buttons - auto (focus)", function() {\r
+ expect(4);\r
+ \r
+ el = $('#spin');\r
+ el.spinner({ \r
+ buttons: 'auto' \r
+ });\r
+ \r
+ ok(upButton().is(':hidden'), "auto - before focus: up button hidden");\r
+ ok(downButton().is(':hidden'), "auto - before focus: down button hidden");\r
+\r
+ el.focus();\r
+ \r
+ ok(upButton().is(':visible'), "auto - after focus: up button visible");\r
+ ok(downButton().is(':visible'), "auto - after focus: down button visible");\r
+\r
+ el.trigger('mouseout');\r
+});\r
+\r
+test("currency - single character currency symbol", function() {\r
+ expect(5);\r
+\r
+ el = $("#spin");\r
+ \r
+ options = { \r
+ currency:"$",\r
+ max:120,\r
+ min:-50,\r
+ step:0.3\r
+ };\r
+ \r
+ el.spinner(options);\r
+\r
+ equals(el.val(), "$0.00", "start number");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+\r
+ equals(el.val(), "$0.30", "stepping 0.30");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.END);\r
+\r
+ equals(el.val(), "$120.00", "End key to max");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.HOME);\r
+\r
+ equals(el.val(), "-$50.00", "Home key to min");\r
+ \r
+ for ( var i = 1 ; i<=120 ; i++ ) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ }\r
+\r
+ equals(el.val(), "-$14.00", "keydown 120 times");\r
+});\r
+\r
+test("currency - combined character currency symbol", function() {\r
+ expect(2);\r
+ \r
+ el = $('#spin');\r
+ \r
+ options = {\r
+ currency: 'HK$',\r
+ step: 1500.50,\r
+ value: 1000\r
+ }\r
+ \r
+ el.spinner(options);\r
+\r
+ equals(el.val(), "HK$1,000.00", "Hong Kong Dollar");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ \r
+ equals(el.val(), "HK$2,500.50", "Hong Kong Dollar step-up once"); \r
+});\r
+\r
+test("currency - space as group separator", function() {\r
+ expect(2);\r
+ \r
+ el = $('#spin');\r
+ \r
+ options = {\r
+ currency: '$',\r
+ groupSeparator: ' ',\r
+ radixPoint: '.',\r
+ step: 1500.50,\r
+ value: 1000\r
+ }\r
+ \r
+ el.spinner(options);\r
+\r
+ equals(el.val(), "$1 000.00", "Australian Dollar");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+\r
+ equals(el.val(), "$2 500.50", "Australian Dollar step-up once");\r
+});\r
+\r
+test("currency - apos as group separator", function() {\r
+ expect(2);\r
+ \r
+ el = $('#spin');\r
+ options = {\r
+ currency: 'Fr ',\r
+ groupSeparator: "'",\r
+ radixPoint: '.',\r
+ step: 1500.50,\r
+ value: 1000\r
+ }\r
+ el.spinner(options);\r
+\r
+ equals(el.val(), "Fr 1'000.00", "Swiss Franc");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+\r
+ equals(el.val(), "Fr 2'500.50", "Swiss Franc step-up once");\r
+});\r
+\r
+test("currency - period as group separator and comma as radixPoint", function() {\r
+ expect(2);\r
+ \r
+ el = $('#spin');\r
+ options = {\r
+ currency: 'RUB',\r
+ groupSeparator: ".",\r
+ radixPoint: ',',\r
+ step: 1.5,\r
+ value: 1000\r
+ }\r
+ el.spinner(options);\r
+\r
+ equals(el.val(), "RUB1.000,00", "Russian Ruble");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ \r
+ equals(el.val(), "RUB1.001,50", "Russian Ruble step-up once");\r
+});\r
+\r
+test("dir - left-to-right (default)", function() { \r
+ expect(3);\r
+ \r
+ el = $("#spin"); \r
+ el.spinner();\r
+ \r
+ ok(upButton().position().left > box().position().left, 'input on left up button on right');\r
+ ok(downButton().position().left > box().position().left, 'input on left down button on right');\r
+ ok(wrapper().hasClass('ui-spinner-ltr'), 'container has correct text direction class setting');\r
+});\r
+\r
+test("dir - right-to-left", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin");\r
+ el.spinner({ dir: 'rtl' });\r
+ \r
+ ok(upButton().position().left < box().position().left, 'input on right up button on left');\r
+ ok(downButton().position().left < box().position().left, 'input on right down button on left');\r
+ ok(wrapper().hasClass('ui-spinner-rtl'), 'container has correct text direction class setting');\r
+});\r
+\r
+test("groupSeparator - comma separator (default)", function() { \r
+ expect(1);\r
+ \r
+ el = $('#spin');\r
+ options = {\r
+ groupSeparator: ',',\r
+ value: 1000000\r
+ };\r
+ el.spinner(options);\r
+ equals(el.val(), "1,000,000", "value contains 2 commas separated by 3 digits");\r
+});\r
+\r
+test("groupSeparator - space separator", function() {\r
+ expect(1);\r
+ \r
+ el = $('#spin');\r
+ options = {\r
+ groupSeparator: ' ',\r
+ value: 1000000\r
+ };\r
+ el.spinner(options);\r
+ equals(el.val(), "1 000 000", "value contains 2 spaces separated by 3 digits"); \r
+});\r
+\r
+test("groupSeparator - apos separator", function() {\r
+ expect(1);\r
+ \r
+ el = $('#spin');\r
+ options = {\r
+ groupSeparator: "'",\r
+ value: 1000000\r
+ };\r
+ el.spinner(options);\r
+ equals(el.val(), "1'000'000", "value contains apos separated by 3 digits");\r
+});\r
+\r
+test("incremental - false (default)", function() {\r
+ expect(2);\r
+ \r
+ el = $("#spin").spinner({ incremental:false });\r
+\r
+ for ( var i = 1 ; i<=120 ; i++ ) {\r
+ el.simulate("keydown",{keyCode:$.ui.keyCode.UP});\r
+ }\r
+ el.simulate("keyup",{keyCode:$.ui.keyCode.UP});\r
+\r
+ equals(el.val(), 120, "incremental false - keydown 120 times");\r
+\r
+ for ( var i = 1 ; i<=210 ; i++ ) {\r
+ el.simulate("keydown",{keyCode:$.ui.keyCode.DOWN});\r
+ }\r
+ el.simulate("keyup",{keyCode:$.ui.keyCode.DOWN});\r
+\r
+ equals(el.val(), -90, "incremental false - keydown 210 times");\r
+});\r
+\r
+test("incremental - true", function() {\r
+ expect(2);\r
+ \r
+ el.spinner('option', 'incremental', true );\r
+\r
+ for ( var i = 1 ; i<=120 ; i++ ) {\r
+ el.simulate("keydown",{keyCode:$.ui.keyCode.UP});\r
+ }\r
+ el.simulate("keyup",{keyCode:$.ui.keyCode.UP});\r
+\r
+ equals(el.val(), 300, "incremental true - keydown 120 times (100+20*10)");\r
+\r
+ for ( var i = 1 ; i<=210 ; i++ ) {\r
+ el.simulate("keydown",{keyCode:$.ui.keyCode.DOWN});\r
+ }\r
+ el.simulate("keyup",{keyCode:$.ui.keyCode.DOWN});\r
+\r
+ equals(el.val(), -1800, "incremental true - keydown 210 times (300-100-100*10-10*100)");\r
+});\r
+\r
+test("max", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin").spinner({ max: 100, value: 1000 });\r
+ equals(el.val(), 100, "max constrained if value option is greater");\r
+ \r
+ el.spinner('value', 1000);\r
+ equals(el.val(), 100, "max constrained if value method is greater");\r
+ \r
+ el.val(1000).blur();\r
+ equals(el.val(), 100, "max constrained if manual entry");\r
+});\r
+\r
+test("min", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin").spinner({ min: -100, value: -1000 });\r
+ equals(el.val(), -100, "min constrained if value option is greater");\r
+ \r
+ el.spinner('value', -1000);\r
+ equals(el.val(), -100, "min constrained if value method is greater");\r
+ \r
+ el.val(-1000).blur();\r
+ equals(el.val(), -100, "min constrained if manual entry");\r
+});\r
+\r
+test("mouseWheel", function() {\r
+ ok(false, 'missing test - untested code is broken code');\r
+});\r
+\r
+test("padding", function() {\r
+ expect(3);\r
+ \r
+ el = $('#spin').spinner({ padding: 5, value: 10 });\r
+ \r
+ equals(el.val(), '00010', 'padded output');\r
+\r
+ el.spinner('option', 'padding', 4);\r
+ equals(el.val(), '0010', 'padded output');\r
+\r
+ el.spinner('value', 15);\r
+ equals(el.val(), '0015', 'padded output');\r
+});\r
+\r
+test("page", function() {\r
+ expect(3);\r
+\r
+ el = $("#spin").spinner({ step: 2, page:2.5 });\r
+\r
+ equals(el.val(), "0", "start number");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
+\r
+ equals(el.val(), "-5", "PAGE_DOWN on spinner once");\r
+\r
+ for ( var i = 1 ; i<=11 ; i++ ) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
+ }\r
+\r
+ equals(el.val(), "50", "PAGE_UP 11 times on spinner");\r
+});\r
+\r
+test("precision", function() {\r
+ expect(3);\r
+ \r
+ el = $("#spin").spinner({ precision: 4, value: 1.23456789 });\r
+ \r
+ equals(el.val(), '1.2346', "4 decimal places");\r
+ \r
+ el.spinner('option', 'precision', 2);\r
+\r
+ equals(el.val(), '1.23', "2 decimal places"); \r
+\r
+ el.spinner('option', 'precision', 6);\r
+\r
+ equals(el.val(), '1.234568', "6 decimal places"); \r
+});\r
+\r
+test("radix", function() {\r
+ expect(2);\r
+ \r
+ el = $("#spin").spinner({\r
+ radix: 16,\r
+ value: 10\r
+ });\r
+ \r
+ equals(el.val(), 'a', 'start value');\r
+ \r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ \r
+ equals(el.val(), 'b', 'key UP on spinner')\r
+});\r
+\r
+test("radixPoint", function() {\r
+ el = $("#spin").spinner({\r
+ radixPoint: ',',\r
+ value: 20.00,\r
+ precision: 2\r
+ });\r
+ \r
+ equals(el.val(), '20,00', 'comma radix point');\r
+ \r
+ el.spinner('stepUp');\r
+ \r
+ equals(el.val(), '21,00', 'step up one');\r
+ \r
+ el.spinner('pageDown', 10);\r
+ \r
+ equals(el.val(), '-29,00', 'page down into negative space');\r
+});\r
+\r
+test("spinnerClass", function() {\r
+ expect(3);\r
+ \r
+ el = $('#spin').spinner({spinnerClass: 'my-spinner-class'});\r
+ ok(wrapper().hasClass('my-spinner-class'), 'spinner container has custom class');\r
+\r
+ el.spinner('option', 'spinnerClass', 'new-spinner-class');\r
+ ok(!wrapper().hasClass('my-spinner-class'), 'spinner no longer has old custom class');\r
+ ok(wrapper().hasClass('new-spinner-class'), 'spinner now has new custom class');\r
+});\r
+\r
+test("step", function() {\r
+ expect(7);\r
+\r
+ el = $("#spin").spinner({ step:0.7 });\r
+ equals(el.val(), "0.0", "value initialized to");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
+ equals(el.val(), "-0.7", "DOWN 1 time with step: 0.7");\r
+\r
+ for ( var i = 0 ; i < 11 ; i++ ) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ }\r
+ equals(el.val(), "7.0", "UP 11 times with step: 0.7");\r
+\r
+ el.spinner('option', 'step', 1);\r
+ for ( var i = 0 ; i < 3 ; i++ ) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ }\r
+ equals(el.val(), "10.0", "UP 3 times with step: 1");\r
+ \r
+ el.spinner('option', 'step', 2);\r
+ for ( var i = 0 ; i < 5 ; i++ ) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ }\r
+ equals(el.val(), "20.0", "UP 5 times with step: 2");\r
+\r
+ el.spinner('value', '10.5');\r
+ equals(el.val(), "10.5", "value reset to");\r
+\r
+ el.spinner('option', 'step', 2);\r
+ for ( var i = 0 ; i < 5 ; i++ ) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ }\r
+ equals(el.val(), "20.5", "UP 5 times with step: 2");\r
+\r
+\r
+});\r
+\r
+test("value", function() {\r
+ expect(2);\r
+ \r
+ el = $('#spin').spinner({ value: 100 });\r
+ \r
+ equals(el.val(), 100, "starting value");\r
+ \r
+ el.spinner('option', 'value', 1000);\r
+ \r
+ equals(el.val(), 1000, "value option changed and set as current value");\r
+});\r
+\r
+test("width", function() {\r
+ expect(2);\r
+ \r
+ el = $('#spin').spinner({ width: 1000 });\r
+ equals(el.width(), 1000, "spinner width initialized");\r
+\r
+ el.spinner('option', 'width', 500);\r
+ equals(el.width(), 500, "spinner width changed");\r
+\r
+});\r
+\r
+})(jQuery);\r