]> source.dussan.org Git - jquery-ui.git/commitdiff
Spinner: test case
authorChi Cheng <cloudream@gmail.com>
Mon, 18 Aug 2008 11:38:12 +0000 (11:38 +0000)
committerChi Cheng <cloudream@gmail.com>
Mon, 18 Aug 2008 11:38:12 +0000 (11:38 +0000)
tests/spinner.html [new file with mode: 0644]
tests/spinner.js [new file with mode: 0644]

diff --git a/tests/spinner.html b/tests/spinner.html
new file mode 100644 (file)
index 0000000..05d730f
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>\r
+<html lang="en">\r
+<head>\r
+       <title>jQuery UI Spinner Test Suite</title>\r
+\r
+       <link rel="stylesheet" href="qunit/testsuite.css" type="text/css" media="screen">\r
+       \r
+       <script type="text/javascript" src="../jquery-1.2.6.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.core.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.spinner.js"></script>\r
+       \r
+       <script type="text/javascript" src="qunit/testrunner.js"></script>\r
+       <script type="text/javascript" src="simulate/jquery.simulate.js"></script>\r
+       \r
+       <script type="text/javascript" src="spinner.js"></script>\r
+\r
+       <style type="text/css">\r
+\r
+\r
+\r
+       </style>\r
+\r
+\r
+\r
+</head>\r
+<body>\r
+\r
+<h1 id="header">jQuery UI Spinner Test Suite</h1>\r
+<h2 id="banner"></h2>\r
+<h2 id="userAgent"></h2>\r
+\r
+<ol id="tests"></ol>\r
+\r
+<div id="main" style="position:absolute;top:-20000px">\r
+       <input type="text" id="spin" />\r
+</div>\r
+       \r
+</body>\r
+</html>\r
diff --git a/tests/spinner.js b/tests/spinner.js
new file mode 100644 (file)
index 0000000..a27c5bd
--- /dev/null
@@ -0,0 +1,131 @@
+/*\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