r3190 committed - spinner: add tests to cover scenarios where user manually enters a val...

r3190 committed - spinner: add tests to cover scenarios where user manually enters a val...


Revision: 3190
Author: pazu2k@gmail.com
Date: Thu Sep 3 22:18:27 2009
Log: spinner: add tests to cover scenarios where user manually enters a
value then clicks on up/down arrows or uses UP/DOWN/PGUP/PGDN keys.
http://code.google.com/p/jquery-ui/source/detail?r=3190
Modified:
/branches/dev/spinner/tests/unit/spinner/spinner_core.js
=======================================
--- /branches/dev/spinner/tests/unit/spinner/spinner_core.js    Thu Aug 27
19:08:52 2009
+++ /branches/dev/spinner/tests/unit/spinner/spinner_core.js    Thu Sep 3
22:18:27 2009
@@ -65,7 +65,7 @@
});
test("keydown UP on input, increases value not greater than max",
function() {
-    expect(2);
+    expect(3);
    el = $("#spin");
    options = {
@@ -84,10 +84,16 @@
    }
    equals(el.val(), 100);
+
+    el.val(50);
+
+    simulateKeyDownUp(el, $.ui.keyCode.UP);
+
+    equals(el.val(), 60);
});
test("keydown DOWN on input, decreases value not less than min",
function() {
-    expect(2);
+    expect(3);
    el = $("#spin");
    options = {
@@ -106,11 +112,17 @@
    }
    equals(el.val(), -100);
+
+    el.val(50);
+
+    simulateKeyDownUp(el, $.ui.keyCode.DOWN);
+
+    equals(el.val(), 40);
});
test("keydown PGUP on input, increases value not greater than max",
function() {
-    expect(2);
+    expect(3);
    el = $("#spin");
    options = {
@@ -128,11 +140,17 @@
        simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
    }
-    equals(el.val(), 100);
+    equals(el.val(), 100);
+
+    el.val(0);
+
+    simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
+
+    equals(el.val(), 50);
});
test("keydown PGDN on input, decreases value not less than min",
function() {
-    expect(2);
+    expect(3);
    el = $("#spin");
    options = {
@@ -150,7 +168,13 @@
        simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
    }
-    equals(el.val(), -100);
+    equals(el.val(), -100);
+
+    el.val(0);
+
+    simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
+
+    equals(el.val(), -50);
});
test("hold SHIFT and keydown UP, increments value but no greater than
max", function() {
@@ -268,7 +292,7 @@
});
test("mouse click on buttons", function() {
-    expect(2);
+    expect(4);
    el = $("#spin").spinner();
    val = 0;
@@ -281,6 +305,18 @@
    equals(el.val(), --val, "mouse click to down");
+    el.val(50);
+
+    $(".ui-spinner-up").trigger("mousedown").trigger("mouseup");
+
+    equals(el.val(), 51);
+
+    el.val(50);
+
+    $(".ui-spinner-down").trigger("mousedown").trigger("mouseup");
+
+    equals(el.val(), 49);
+
});
test("mouse wheel on input", function() {