-/*\r
- * spinner_core.js\r
- */\r
+(function( $ ) {\r
\r
-var simulateKeyDownUp = function(el, kCode, shift) {\r
- el.simulate("keydown",{keyCode:kCode, shiftKey: shift || false })\r
- .simulate("keyup",{keyCode:kCode, shiftKey: shift || false });\r
-};\r
+module( "spinner: core" );\r
\r
-(function($) {\r
-\r
-// Spinner Tests\r
-module("spinner: core");\r
-\r
-test("destroy", function() {\r
+// TODO: move to spinner_methods\r
+test( "destroy", function() {\r
+ expect( 1 );\r
+ // TODO: is this cheat still needed?\r
// cheat a bit to get IE6 to pass\r
- $("#spin").val(0);\r
- var beforeHtml = $("#spin").parent().html();\r
- var afterHtml = $("#spin").spinner().spinner("destroy").parent().html();\r
- equal( afterHtml, beforeHtml, "before/after html should be the same" );\r
+ $( "#spin" ).val( 0 );\r
+ domEqual( "#spin", function() {\r
+ $( "#spin" ).spinner().spinner( "destroy" );\r
+ });\r
});\r
\r
-test("keydown UP on input, increases value not greater than max", function() {\r
- var el = $("#spin").spinner({\r
- max:100,\r
- value:50,\r
- step:10\r
+test( "keydown UP on input, increases value not greater than max", function() {\r
+ expect( 5 );\r
+ var element = $( "#spin" ).spinner({\r
+ max: 100,\r
+ value: 70,\r
+ step: 10\r
});\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.UP);\r
- equals(el.val(), 60);\r
- \r
- for (i = 0; i<11; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.UP); \r
- }\r
- equals(el.val(), 100);\r
- \r
- el.spinner("value", 50);\r
- simulateKeyDownUp(el, $.ui.keyCode.UP);\r
- equals(el.val(), 60);\r
+\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );\r
+ equals( element.val(), 80 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );\r
+ equals( element.val(), 90 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );\r
+ equals( element.val(), 100 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );\r
+ equals( element.val(), 100 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );\r
+ equals( element.val(), 100 );\r
});\r
\r
-test("keydown DOWN on input, decreases value not less than min", function() {\r
- var el = $("#spin").spinner({\r
- min:-100,\r
- value:50,\r
- step:10\r
+test( "keydown DOWN on input, decreases value not less than min", function() {\r
+ expect( 5 );\r
+ var element = $( "#spin" ).spinner({\r
+ min: 20,\r
+ value: 50,\r
+ step: 10\r
});\r
\r
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
- equals(el.val(), 40);\r
- \r
- for (i = 0; i<21; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.DOWN); \r
- }\r
- equals(el.val(), -100);\r
- \r
- el.spinner("value", 50);\r
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
- equals(el.val(), 40);\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );\r
+ equals( element.val(), 40 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );\r
+ equals( element.val(), 30 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );\r
+ equals( element.val(), 20 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );\r
+ equals( element.val(), 20 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );\r
+ equals( element.val(), 20 );\r
});\r
\r
-test("keydown PGUP on input, increases value not greater than max", function() {\r
- var el = $("#spin").spinner({\r
- max: 500,\r
- value: 0,\r
- step: 10\r
+test( "keydown PGUP on input, increases value not greater than max", function() {\r
+ expect( 5 );\r
+ var element = $( "#spin" ).spinner({\r
+ max: 100,\r
+ value: 70,\r
+ page: 10\r
});\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
- equal(el.val(), 100);\r
- \r
- for (i = 0; i<5; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP); \r
- }\r
- equal(el.val(), 500);\r
- \r
- el.spinner("value", 0);\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
- equals(el.val(), 100);\r
+\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );\r
+ equals( element.val(), 80 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );\r
+ equals( element.val(), 90 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );\r
+ equals( element.val(), 100 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );\r
+ equals( element.val(), 100 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );\r
+ equals( element.val(), 100 );\r
});\r
\r
-test("keydown PGDN on input, decreases value not less than min", function() {\r
- var el = $("#spin").spinner({\r
- min:-500,\r
- value:0,\r
- step:10\r
+test( "keydown PGDN on input, decreases value not less than min", function() {\r
+ expect( 5 );\r
+ var element = $( "#spin" ).spinner({\r
+ min: 20,\r
+ value: 50,\r
+ page: 10\r
});\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
- equals(el.val(), -100);\r
- \r
- for (i = 0; i<5; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN); \r
- }\r
- equals(el.val(), -500);\r
- \r
- el.spinner("value", 0);\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
- equals(el.val(), -100);\r
+\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );\r
+ equals( element.val(), 40 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );\r
+ equals( element.val(), 30 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );\r
+ equals( element.val(), 20 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );\r
+ equals( element.val(), 20 );\r
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );\r
+ equals( element.val(), 20 );\r
});\r
\r
-test("mouse click on buttons", function() {\r
- var el = $("#spin").spinner(),\r
+test( "mouse click on buttons", function() {\r
+ expect( 2 );\r
+ var element = $( "#spin" ).spinner(),\r
val = 0;\r
- \r
- $(".ui-spinner-up").trigger("mousedown").trigger("mouseup");\r
- equals(el.val(), ++val, "mouse click to up");\r
-\r
- $(".ui-spinner-down").trigger("mousedown").trigger("mouseup");\r
- equals(el.val(), --val, "mouse click to down");\r
- \r
- el.spinner("value", 50);\r
- $(".ui-spinner-up").trigger("mousedown").trigger("mouseup");\r
- equals(el.val(), 51);\r
-\r
- el.spinner("value", 50);\r
- $(".ui-spinner-down").trigger("mousedown").trigger("mouseup");\r
- equals(el.val(), 49);\r
+\r
+ $( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );\r
+ equals( element.val(), ++val, "mouse click on up" );\r
+\r
+ $( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );\r
+ equals( element.val(), --val, "mouse click on down");\r
});\r
\r
-test("mouse wheel on input", function() {\r
- expect(4);\r
- stop();\r
- \r
- var el = $("#spin").spinner();\r
- equal(el.val(), 0);\r
- el.trigger("mousewheel", 1);\r
- equal(el.val(), 1);\r
- \r
- // mousewheel handler uses a timeout, need to accomodate that\r
- setTimeout(function() {\r
- el.trigger("mousewheel", -1);\r
- equal(el.val(), 0);\r
- \r
- setTimeout(function() {\r
- el.trigger("mousewheel", -1);\r
- equal(el.val(), -1);\r
- start();\r
- }, 100);\r
- }, 100);\r
- \r
+test( "mouse wheel on input", function() {\r
+ expect( 4 );\r
+\r
+ var element = $( "#spin" ).spinner();\r
+ equal( element.val(), 0 );\r
+ element.trigger( "mousewheel", 1 );\r
+ equal( element.val(), 1 );\r
+\r
+ element.trigger( "mousewheel", -1 );\r
+ equal( element.val(), 0 );\r
+\r
+ element.trigger( "mousewheel", -1 );\r
+ equal(element.val(), -1 );\r
});\r
\r
-test("reading HTML5 attributes", function() {\r
- var el = $('<input id="spinner" type="number" min="-100" max="100" value="5" step="2">').spinner();\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
+test( "reading HTML5 attributes", function() {\r
+ expect( 4 );\r
+ var element = $( "<input id='spinner' type='number' min='-100' max='100' value='5' step='2'>" ).spinner();\r
+ equals( element.spinner( "option", "value" ), 5, "value" ); \r
+ equals( element.spinner( "option", "max" ), 100, "max" );\r
+ equals( element.spinner( "option", "min" ), -100, "min" );\r
+ equals( element.spinner( "option", "step" ), 2, "step" );\r
});\r
\r
-test("ARIA attributes", function() {\r
- var el = $('#spin').spinner({ min: -5, max: 5, value: 2 });;\r
- \r
- equals(el.attr('role'), 'spinbutton', 'role');\r
- equals(el.attr('aria-valuemin'), -5, 'aria-valuemin');\r
- equals(el.attr('aria-valuemax'), 5, 'aria-valuemax');\r
- equals(el.attr('aria-valuenow'), 2, 'aria-valuenow');\r
- \r
- el.spinner('stepUp');\r
- \r
- equals(el.attr('aria-valuenow'), 3, 'stepUp 1 step changes aria-valuenow');\r
- \r
- el.spinner('option', { min: -10, max: 10 });\r
- \r
- equals(el.attr('aria-valuemin'), -10, 'min option changed aria-valuemin changes');\r
- equals(el.attr('aria-valuemax'), 10, 'max option changed aria-valuemax changes');\r
+test( "ARIA attributes", function() {\r
+ expect( 7 );\r
+ var element = $( "#spin" ).spinner({ min: -5, max: 5, value: 2 });\r
+\r
+ equals( element.attr( "role" ), "spinbutton", "role" );\r
+ equals( element.attr( "aria-valuemin" ), -5, "aria-valuemin" );\r
+ equals( element.attr( "aria-valuemax" ), 5, "aria-valuemax" );\r
+ equals( element.attr( "aria-valuenow" ), 2, "aria-valuenow" );\r
+\r
+ element.spinner( "stepUp" );\r
+\r
+ equals( element.attr( "aria-valuenow" ), 3, "stepUp 1 step changes aria-valuenow" );\r
+\r
+ element.spinner( "option", { min: -10, max: 10 } );\r
+\r
+ equals( element.attr( "aria-valuemin" ), -10, "min option changed aria-valuemin changes" );\r
+ equals( element.attr( "aria-valuemax" ), 10, "max option changed aria-valuemax changes" );\r
});\r
\r
-})(jQuery);\r
+})( jQuery );\r