--- /dev/null
+/*\r
+ * spinner unit tests\r
+ */\r
+(function($) {\r
+\r
+// Spinner Tests\r
+module("spinner");\r
+\r
+test("init", function() {\r
+ expect(1);\r
+\r
+ el = $("#spin").spinner();\r
+ ok(true, '.spinner() called on element');\r
+\r
+});\r
+\r
+test("destroy", function() {\r
+ expect(1);\r
+\r
+ $("#spin").spinner().spinner("destroy"); \r
+ ok(true, '.spinner("destroy") called on element');\r
+\r
+});\r
+\r
+test("defaults", function() {\r
+ expect(5);\r
+ el = $("#spin").spinner();\r
+\r
+ equals(el.data("incremental.spinner"), true, "incremental");\r
+ equals(el.data("max.spinner"), undefined, "max");\r
+ equals(el.data("min.spinner"), undefined, "min");\r
+ equals(el.data("start.spinner"), 0, "start");\r
+ equals(el.data("stepping.spinner"), 1, "stepping");\r
+\r
+});\r
+\r
+test("set defaults on init", function() {\r
+ expect(5);\r
+ el = $("#spin").spinner({ incremental:false, max:200, min:-100, start:50, stepping:2 });\r
+\r
+ equals(el.data("incremental.spinner"), false, "incremental");\r
+ equals(el.data("max.spinner"), 200, "max");\r
+ equals(el.data("min.spinner"), -100, "min");\r
+ equals(el.data("start.spinner"), 50, "start");\r
+ equals(el.data("stepping.spinner"), 2, "stepping");\r
+\r
+});\r
+\r
+test("keydown on input", function() {\r
+ expect(5);\r
+ el = $("#spin").spinner();\r
+\r
+ equals(el.val(), 0, "start number");\r
+\r
+ el.simulate("keydown",{keyCode:$.simulate.VK_UP})\r
+ .simulate("keyup",{keyCode:$.simulate.VK_UP});\r
+\r
+ equals(el.val(), 1, "Up key");\r
+\r
+ el.simulate("keydown",{keyCode:$.simulate.VK_RIGHT})\r
+ .simulate("keyup",{keyCode:$.simulate.VK_RIGHT});\r
+\r
+ equals(el.val(), 2, "Right key");\r
+\r
+ el.simulate("keydown",{keyCode:$.simulate.VK_DOWN})\r
+ .simulate("keyup",{keyCode:$.simulate.VK_DOWN});\r
+\r
+ equals(el.val(), 1, "Down Key");\r
+\r
+ el.simulate("keydown",{keyCode:$.simulate.VK_LEFT})\r
+ .simulate("keyup",{keyCode:$.simulate.VK_LEFT});\r
+\r
+ equals(el.val(), 0, "Left Key");\r
+\r
+});\r
+\r
+test("keydown on input with options", function() {\r
+ expect(4);\r
+\r
+ el = $("#spin").spinner({ incremental:false, max:200, min:-100, start:50, stepping:10 });\r
+\r
+ equals(el.val(), 50, "start number");\r
+\r
+ el.simulate("keydown",{keyCode:$.simulate.VK_UP})\r
+ .simulate("keyup",{keyCode:$.simulate.VK_UP});\r
+\r
+ equals(el.val(), 60, "Stepping 10 on 50");\r
+\r
+ el.simulate("keydown",{keyCode:$.simulate.VK_END})\r
+ .simulate("keyup",{keyCode:$.simulate.VK_END});\r
+\r
+ equals(el.val(), 200, "End key to max");\r
+\r
+ el.simulate("keydown",{keyCode:$.simulate.VK_HOME})\r
+ .simulate("keyup",{keyCode:$.simulate.VK_HOME});\r
+\r
+ equals(el.val(), -100, "Home key to min");\r
+\r
+\r
+});\r
+\r
+test("mouse click on buttons", function() {\r
+ expect(4);\r
+ el = $("#spin").spinner();\r
+\r
+ $("div.ui-spinner-up").trigger("mousedown").trigger("mouseup");\r
+\r
+ equals(el.val(), 1, "Mouse click to up");\r
+\r
+ $("div.ui-spinner-up").trigger("dblclick");\r
+\r
+ equals(el.val(), 2, "Mouse double click to up");\r
+\r
+ $("div.ui-spinner-down").trigger("mousedown").trigger("mouseup");\r
+\r
+ equals(el.val(), 1, "Mouse click to down");\r
+\r
+ $("div.ui-spinner-down").trigger("dblclick");\r
+\r
+ equals(el.val(), 0, "Mouse double click to down");\r
+\r
+\r
+});\r
+\r
+test("mouse wheel on input", function() {\r
+ expect(0);\r
+\r
+\r
+});\r
+\r
+})(jQuery);\r