Spinner: test case

This commit is contained in:
Chi Cheng 2008-08-18 11:38:12 +00:00
parent 41245e6a7d
commit da0ebd589e
2 changed files with 170 additions and 0 deletions

39
tests/spinner.html Normal file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery UI Spinner Test Suite</title>
<link rel="stylesheet" href="qunit/testsuite.css" type="text/css" media="screen">
<script type="text/javascript" src="../jquery-1.2.6.js"></script>
<script type="text/javascript" src="../ui/ui.core.js"></script>
<script type="text/javascript" src="../ui/ui.spinner.js"></script>
<script type="text/javascript" src="qunit/testrunner.js"></script>
<script type="text/javascript" src="simulate/jquery.simulate.js"></script>
<script type="text/javascript" src="spinner.js"></script>
<style type="text/css">
</style>
</head>
<body>
<h1 id="header">jQuery UI Spinner Test Suite</h1>
<h2 id="banner"></h2>
<h2 id="userAgent"></h2>
<ol id="tests"></ol>
<div id="main" style="position:absolute;top:-20000px">
<input type="text" id="spin" />
</div>
</body>
</html>

131
tests/spinner.js Normal file
View File

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