aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/spinner
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-08-06 17:07:12 -0400
committerScott González <scott.gonzalez@gmail.com>2011-08-06 17:07:12 -0400
commit160a301d96c09403b87ef8365b201617344e425d (patch)
treea76335aa39fbd7dd4bcdbcf5c1f387581353f3a0 /tests/unit/spinner
parent2b22bbdd6a5ed5206f90c29ab4bfc9d9a84b6835 (diff)
downloadjquery-ui-160a301d96c09403b87ef8365b201617344e425d.tar.gz
jquery-ui-160a301d96c09403b87ef8365b201617344e425d.zip
Spinner tests: Cleanup.
Diffstat (limited to 'tests/unit/spinner')
-rw-r--r--tests/unit/spinner/spinner.html1
-rw-r--r--tests/unit/spinner/spinner_core.js268
-rw-r--r--tests/unit/spinner/spinner_events.js8
-rw-r--r--tests/unit/spinner/spinner_methods.js8
-rw-r--r--tests/unit/spinner/spinner_options.js8
-rw-r--r--tests/unit/spinner/spinner_test_helpers.js5
6 files changed, 142 insertions, 156 deletions
diff --git a/tests/unit/spinner/spinner.html b/tests/unit/spinner/spinner.html
index b59275e5f..59185a441 100644
--- a/tests/unit/spinner/spinner.html
+++ b/tests/unit/spinner/spinner.html
@@ -19,6 +19,7 @@
<script src="../../jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
+ <script src="spinner_test_helpers.js"></script>
<script src="spinner_core.js"></script>
<script src="spinner_defaults.js"></script>
<script src="spinner_events.js"></script>
diff --git a/tests/unit/spinner/spinner_core.js b/tests/unit/spinner/spinner_core.js
index 19bdb3495..b05a6630f 100644
--- a/tests/unit/spinner/spinner_core.js
+++ b/tests/unit/spinner/spinner_core.js
@@ -1,171 +1,151 @@
-/*
- * spinner_core.js
- */
+(function( $ ) {
-var simulateKeyDownUp = function(el, kCode, shift) {
- el.simulate("keydown",{keyCode:kCode, shiftKey: shift || false })
- .simulate("keyup",{keyCode:kCode, shiftKey: shift || false });
-};
+module( "spinner: core" );
-(function($) {
-
-// Spinner Tests
-module("spinner: core");
-
-test("destroy", function() {
+// TODO: move to spinner_methods
+test( "destroy", function() {
+ expect( 1 );
+ // TODO: is this cheat still needed?
// cheat a bit to get IE6 to pass
- $("#spin").val(0);
- var beforeHtml = $("#spin").parent().html();
- var afterHtml = $("#spin").spinner().spinner("destroy").parent().html();
- equal( afterHtml, beforeHtml, "before/after html should be the same" );
+ $( "#spin" ).val( 0 );
+ domEqual( "#spin", function() {
+ $( "#spin" ).spinner().spinner( "destroy" );
+ });
});
-test("keydown UP on input, increases value not greater than max", function() {
- var el = $("#spin").spinner({
- max:100,
- value:50,
- step:10
+test( "keydown UP on input, increases value not greater than max", function() {
+ expect( 5 );
+ var element = $( "#spin" ).spinner({
+ max: 100,
+ value: 70,
+ step: 10
});
-
- simulateKeyDownUp(el, $.ui.keyCode.UP);
- equals(el.val(), 60);
-
- for (i = 0; i<11; i++) {
- simulateKeyDownUp(el, $.ui.keyCode.UP);
- }
- equals(el.val(), 100);
-
- el.spinner("value", 50);
- simulateKeyDownUp(el, $.ui.keyCode.UP);
- equals(el.val(), 60);
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equals( element.val(), 80 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equals( element.val(), 90 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equals( element.val(), 100 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equals( element.val(), 100 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equals( element.val(), 100 );
});
-test("keydown DOWN on input, decreases value not less than min", function() {
- var el = $("#spin").spinner({
- min:-100,
- value:50,
- step:10
+test( "keydown DOWN on input, decreases value not less than min", function() {
+ expect( 5 );
+ var element = $( "#spin" ).spinner({
+ min: 20,
+ value: 50,
+ step: 10
});
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);
- equals(el.val(), 40);
-
- for (i = 0; i<21; i++) {
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);
- }
- equals(el.val(), -100);
-
- el.spinner("value", 50);
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);
- equals(el.val(), 40);
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equals( element.val(), 40 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equals( element.val(), 30 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equals( element.val(), 20 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equals( element.val(), 20 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equals( element.val(), 20 );
});
-test("keydown PGUP on input, increases value not greater than max", function() {
- var el = $("#spin").spinner({
- max: 500,
- value: 0,
- step: 10
+test( "keydown PGUP on input, increases value not greater than max", function() {
+ expect( 5 );
+ var element = $( "#spin" ).spinner({
+ max: 100,
+ value: 70,
+ page: 10
});
-
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
- equal(el.val(), 100);
-
- for (i = 0; i<5; i++) {
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
- }
- equal(el.val(), 500);
-
- el.spinner("value", 0);
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
- equals(el.val(), 100);
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equals( element.val(), 80 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equals( element.val(), 90 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equals( element.val(), 100 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equals( element.val(), 100 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equals( element.val(), 100 );
});
-test("keydown PGDN on input, decreases value not less than min", function() {
- var el = $("#spin").spinner({
- min:-500,
- value:0,
- step:10
+test( "keydown PGDN on input, decreases value not less than min", function() {
+ expect( 5 );
+ var element = $( "#spin" ).spinner({
+ min: 20,
+ value: 50,
+ page: 10
});
-
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
- equals(el.val(), -100);
-
- for (i = 0; i<5; i++) {
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
- }
- equals(el.val(), -500);
-
- el.spinner("value", 0);
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
- equals(el.val(), -100);
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equals( element.val(), 40 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equals( element.val(), 30 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equals( element.val(), 20 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equals( element.val(), 20 );
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equals( element.val(), 20 );
});
-test("mouse click on buttons", function() {
- var el = $("#spin").spinner(),
+test( "mouse click on buttons", function() {
+ expect( 2 );
+ var element = $( "#spin" ).spinner(),
val = 0;
-
- $(".ui-spinner-up").trigger("mousedown").trigger("mouseup");
- equals(el.val(), ++val, "mouse click to up");
-
- $(".ui-spinner-down").trigger("mousedown").trigger("mouseup");
- equals(el.val(), --val, "mouse click to down");
-
- el.spinner("value", 50);
- $(".ui-spinner-up").trigger("mousedown").trigger("mouseup");
- equals(el.val(), 51);
-
- el.spinner("value", 50);
- $(".ui-spinner-down").trigger("mousedown").trigger("mouseup");
- equals(el.val(), 49);
+
+ $( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
+ equals( element.val(), ++val, "mouse click on up" );
+
+ $( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
+ equals( element.val(), --val, "mouse click on down");
});
-test("mouse wheel on input", function() {
- expect(4);
- stop();
-
- var el = $("#spin").spinner();
- equal(el.val(), 0);
- el.trigger("mousewheel", 1);
- equal(el.val(), 1);
-
- // mousewheel handler uses a timeout, need to accomodate that
- setTimeout(function() {
- el.trigger("mousewheel", -1);
- equal(el.val(), 0);
-
- setTimeout(function() {
- el.trigger("mousewheel", -1);
- equal(el.val(), -1);
- start();
- }, 100);
- }, 100);
-
+test( "mouse wheel on input", function() {
+ expect( 4 );
+
+ var element = $( "#spin" ).spinner();
+ equal( element.val(), 0 );
+ element.trigger( "mousewheel", 1 );
+ equal( element.val(), 1 );
+
+ element.trigger( "mousewheel", -1 );
+ equal( element.val(), 0 );
+
+ element.trigger( "mousewheel", -1 );
+ equal(element.val(), -1 );
});
-test("reading HTML5 attributes", function() {
- var el = $('<input id="spinner" type="number" min="-100" max="100" value="5" step="2">').spinner();
- equals(el.spinner('option', 'value'), 5, 'value');
- equals(el.spinner('option', 'max'), 100, 'max');
- equals(el.spinner('option', 'min'), -100, 'min');
- equals(el.spinner('option', 'step'), 2, 'step');
+test( "reading HTML5 attributes", function() {
+ expect( 4 );
+ var element = $( "<input id='spinner' type='number' min='-100' max='100' value='5' step='2'>" ).spinner();
+ equals( element.spinner( "option", "value" ), 5, "value" );
+ equals( element.spinner( "option", "max" ), 100, "max" );
+ equals( element.spinner( "option", "min" ), -100, "min" );
+ equals( element.spinner( "option", "step" ), 2, "step" );
});
-test("ARIA attributes", function() {
- var el = $('#spin').spinner({ min: -5, max: 5, value: 2 });;
-
- equals(el.attr('role'), 'spinbutton', 'role');
- equals(el.attr('aria-valuemin'), -5, 'aria-valuemin');
- equals(el.attr('aria-valuemax'), 5, 'aria-valuemax');
- equals(el.attr('aria-valuenow'), 2, 'aria-valuenow');
-
- el.spinner('stepUp');
-
- equals(el.attr('aria-valuenow'), 3, 'stepUp 1 step changes aria-valuenow');
-
- el.spinner('option', { min: -10, max: 10 });
-
- equals(el.attr('aria-valuemin'), -10, 'min option changed aria-valuemin changes');
- equals(el.attr('aria-valuemax'), 10, 'max option changed aria-valuemax changes');
+test( "ARIA attributes", function() {
+ expect( 7 );
+ var element = $( "#spin" ).spinner({ min: -5, max: 5, value: 2 });
+
+ equals( element.attr( "role" ), "spinbutton", "role" );
+ equals( element.attr( "aria-valuemin" ), -5, "aria-valuemin" );
+ equals( element.attr( "aria-valuemax" ), 5, "aria-valuemax" );
+ equals( element.attr( "aria-valuenow" ), 2, "aria-valuenow" );
+
+ element.spinner( "stepUp" );
+
+ equals( element.attr( "aria-valuenow" ), 3, "stepUp 1 step changes aria-valuenow" );
+
+ element.spinner( "option", { min: -10, max: 10 } );
+
+ equals( element.attr( "aria-valuemin" ), -10, "min option changed aria-valuemin changes" );
+ equals( element.attr( "aria-valuemax" ), 10, "max option changed aria-valuemax changes" );
});
-})(jQuery);
+})( jQuery );
diff --git a/tests/unit/spinner/spinner_events.js b/tests/unit/spinner/spinner_events.js
index 0f64067d7..f70ac5076 100644
--- a/tests/unit/spinner/spinner_events.js
+++ b/tests/unit/spinner/spinner_events.js
@@ -14,7 +14,7 @@ test("start", function() {
}
});
- simulateKeyDownUp(el, $.ui.keyCode.UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(start, 1, "Start triggered");
});
@@ -28,7 +28,7 @@ test("spin", function() {
}
});
- simulateKeyDownUp(el, $.ui.keyCode.UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(spin, 1, "Spin triggered");
});
@@ -42,7 +42,7 @@ test("stop", function() {
}
});
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(stop, 1, "Stop triggered");
});
@@ -56,7 +56,7 @@ test("change", function() {
}
});
- simulateKeyDownUp(el, $.ui.keyCode.UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
el.blur();
equals(change, 1, "Change triggered");
diff --git a/tests/unit/spinner/spinner_methods.js b/tests/unit/spinner/spinner_methods.js
index fb58edbdf..b47f68a5c 100644
--- a/tests/unit/spinner/spinner_methods.js
+++ b/tests/unit/spinner/spinner_methods.js
@@ -17,16 +17,16 @@ test("disable", function() {
ok(wrapper.hasClass("ui-spinner-disabled"), "after: wrapper has ui-spinner-disabled class");
ok(el.is(':disabled'), "after: input has disabled attribute");
- simulateKeyDownUp(el, $.ui.keyCode.UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
equals(val, el.val(), "keyboard - value does not change on key UP");
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(val, el.val(), "keyboard - value does not change on key DOWN");
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
equals(val, el.val(), "keyboard - value does not change on key PGUP");
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);
equals(val, el.val(), "keyboard - value does not change on key PGDN");
wrapper.find(":ui-button").first().trigger('mousedown').trigger('mouseup');
diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js
index 398780ad2..2cb90ef5d 100644
--- a/tests/unit/spinner/spinner_options.js
+++ b/tests/unit/spinner/spinner_options.js
@@ -94,7 +94,7 @@ test("step, 2", function() {
equals(el.val(), "0", "value initialized to");
for ( var i = 0 ; i < 5 ; i++ ) {
- simulateKeyDownUp(el, $.ui.keyCode.UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "10", "UP 5 times with step: 2");
@@ -103,7 +103,7 @@ test("step, 2", function() {
el.spinner('option', 'step', 2);
for ( var i = 0 ; i < 5 ; i++ ) {
- simulateKeyDownUp(el, $.ui.keyCode.UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "20.5", "UP 5 times with step: 2");
});
@@ -115,11 +115,11 @@ test("step, 0.7", function() {
});
equals(el.val(), "0.0", "value initialized to");
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(el.val(), "-0.7", "DOWN 1 time with step: 0.7");
for ( var i = 0 ; i < 11 ; i++ ) {
- simulateKeyDownUp(el, $.ui.keyCode.UP);
+ spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "7.0", "UP 11 times with step: 0.7");
});
diff --git a/tests/unit/spinner/spinner_test_helpers.js b/tests/unit/spinner/spinner_test_helpers.js
new file mode 100644
index 000000000..af555dbf2
--- /dev/null
+++ b/tests/unit/spinner/spinner_test_helpers.js
@@ -0,0 +1,5 @@
+var spinner_simulateKeyDownUp = function( element, keyCode, shift ) {
+ element
+ .simulate( "keydown", { keyCode: keyCode, shiftKey: shift || false } )
+ .simulate( "keyup", { keyCode: keyCode, shiftKey: shift || false } );
+};