r3124 committed - some spinner option unit tests
Revision: 3124
Author: rdworth
Date: Mon Aug 24 05:06:29 2009
Log: some spinner option unit tests
http://code.google.com/p/jquery-ui/source/detail?r=3124
Modified:
/branches/dev/spinner/tests/unit/spinner/spinner_options.js
=======================================
--- /branches/dev/spinner/tests/unit/spinner/spinner_options.js Mon Aug 24
03:41:24 2009
+++ /branches/dev/spinner/tests/unit/spinner/spinner_options.js Mon Aug 24
05:06:29 2009
@@ -43,7 +43,7 @@
el.trigger('mouseout');
});
-test("buttons - auto", function() {
+test("buttons - auto (hover)", function() {
expect(4);
el = $('#spin');
@@ -62,6 +62,25 @@
el.trigger('mouseout');
});
+test("buttons - auto (focus)", function() {
+ expect(4);
+
+ el = $('#spin');
+ el.spinner({
+ buttons: 'auto'
+ });
+
+ ok(upButton().is(':hidden'), "auto - before focus: up button hidden");
+ ok(downButton().is(':hidden'), "auto - before focus: down button hidden");
+
+ el.focus();
+
+ ok(upButton().is(':visible'), "auto - after focus: up button visible");
+ ok(downButton().is(':visible'), "auto - after focus: down button
visible");
+
+ el.trigger('mouseout');
+});
+
test("currency - single character currency symbol", function() {
expect(5);
@@ -308,11 +327,17 @@
});
test("padding", function() {
- expect(1);
+ expect(3);
el = $('#spin').spinner({ padding: 5, value: 10 });
- equals(el.val(), '00010', 'padded output')
+ equals(el.val(), '00010', 'padded output');
+
+ el.spinner('option', 'padding', 4);
+ equals(el.val(), '0010', 'padded output');
+
+ el.spinner('value', 15);
+ equals(el.val(), '0015', 'padded output');
});
test("page", function() {
@@ -397,30 +422,52 @@
});
test("spinnerClass", function() {
- expect(1);
-
- el = $('#spin');
- el.spinner({spinnerClass: 'my-spinner-class'});
-
+ expect(3);
+
+ el = $('#spin').spinner({spinnerClass: 'my-spinner-class'});
ok(wrapper().hasClass('my-spinner-class'), 'spinner container has custom
class');
+
+ el.spinner('option', 'spinnerClass', 'new-spinner-class');
+ ok(!wrapper().hasClass('my-spinner-class'), 'spinner no longer has old
custom class');
+ ok(wrapper().hasClass('new-spinner-class'), 'spinner now has new custom
class');
});
test("step", function() {
- expect(3);
+ expect(7);
el = $("#spin").spinner({ step:0.7 });
-
- equals(el.val(), "0.0", "start number");
+ equals(el.val(), "0.0", "value initialized to");
simulateKeyDownUp(el, $.ui.keyCode.DOWN);
-
- equals(el.val(), "-0.7", "DOWN once on spinner");
-
- for ( var i = 1 ; i<=11 ; i++ ) {
+ equals(el.val(), "-0.7", "DOWN 1 time with step: 0.7");
+
+ for ( var i = 0 ; i < 11 ; i++ ) {
+ simulateKeyDownUp(el, $.ui.keyCode.UP);
+ }
+ equals(el.val(), "7.0", "UP 11 times with step: 0.7");
+
+ el.spinner('option', 'step', 1);
+ for ( var i = 0 ; i < 3 ; i++ ) {
simulateKeyDownUp(el, $.ui.keyCode.UP);
}
-
- equals(el.val(), "7.0", "UP 11 times on spinner");
+ equals(el.val(), "10.0", "UP 3 times with step: 1");
+
+ el.spinner('option', 'step', 2);
+ for ( var i = 0 ; i < 5 ; i++ ) {
+ simulateKeyDownUp(el, $.ui.keyCode.UP);
+ }
+ equals(el.val(), "20.0", "UP 5 times with step: 2");
+
+ el.spinner('value', '10.5');
+ equals(el.val(), "10.5", "value reset to");
+
+ el.spinner('option', 'step', 2);
+ for ( var i = 0 ; i < 5 ; i++ ) {
+ simulateKeyDownUp(el, $.ui.keyCode.UP);
+ }
+ equals(el.val(), "20.5", "UP 5 times with step: 2");
+
+
});
test("value", function() {
@@ -436,10 +483,14 @@
});
test("width", function() {
- expect(1);
+ expect(2);
el = $('#spin').spinner({ width: 1000 });
- equals(el.width(), 1000, "spinner width changed");
+ equals(el.width(), 1000, "spinner width initialized");
+
+ el.spinner('option', 'width', 500);
+ equals(el.width(), 500, "spinner width changed");
+
});
})(jQuery);