aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-08-07 08:10:11 -0400
committerScott González <scott.gonzalez@gmail.com>2011-08-07 08:10:11 -0400
commit380c2e6fbdba524c56855e9c9018b6bf89225c50 (patch)
tree9bdcf068a4b0c3fe0d043c8ff6188c343be51a23 /tests
parente9cdd576f4327f947b00032b6d1aaa60c305c844 (diff)
downloadjquery-ui-380c2e6fbdba524c56855e9c9018b6bf89225c50.tar.gz
jquery-ui-380c2e6fbdba524c56855e9c9018b6bf89225c50.zip
Spinner tests: Cleanup.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/spinner/spinner_events.js65
-rw-r--r--tests/unit/spinner/spinner_methods.js252
-rw-r--r--tests/unit/spinner/spinner_options.js134
3 files changed, 204 insertions, 247 deletions
diff --git a/tests/unit/spinner/spinner_events.js b/tests/unit/spinner/spinner_events.js
index f70ac5076..66735028a 100644
--- a/tests/unit/spinner/spinner_events.js
+++ b/tests/unit/spinner/spinner_events.js
@@ -1,65 +1,50 @@
-/*
- * spinner_events.js
- */
-(function($) {
+(function( $ ) {
-module("spinner: events");
+module( "spinner: events" );
-test("start", function() {
- var start = 0;
-
- var el = $("#spin").spinner({
- start: function(){
- start++;
+test( "start", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner({
+ start: function() {
+ ok( true, "start" );
}
});
- spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
-
- equals(start, 1, "Start triggered");
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
});
-test("spin", function() {
- var spin = 0;
-
- var el = $("#spin").spinner({
+test( "spin", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner({
spin: function(){
- spin++;
+ ok( true, "spin" );
}
});
- spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
-
- equals(spin, 1, "Spin triggered");
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
});
-test("stop", function() {
- var stop = 0;
-
- var el = $("#spin").spinner({
+test( "stop", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner({
stop: function(){
- stop++;
+ ok( true, "stop" );
}
});
- spinner_simulateKeyDownUp(el, $.ui.keyCode.DOWN);
-
- equals(stop, 1, "Stop triggered");
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
});
-test("change", function() {
- var change = 0;
-
- var el = $("#spin").spinner({
+test( "change", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner({
change: function(){
- change++;
+ ok( true, "change" );
}
});
- spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
- el.blur();
-
- equals(change, 1, "Change triggered");
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ element.blur();
});
-})(jQuery);
+})( jQuery );
diff --git a/tests/unit/spinner/spinner_methods.js b/tests/unit/spinner/spinner_methods.js
index b47f68a5c..4839844c9 100644
--- a/tests/unit/spinner/spinner_methods.js
+++ b/tests/unit/spinner/spinner_methods.js
@@ -1,155 +1,159 @@
-/*
- * spinner_methods.js
- */
-(function($) {
-
-module("spinner: methods");
-
-test("disable", function() {
- var el = $("#spin").spinner({ disabled: false }),
- val = el.val(),
- wrapper = $("#spin").spinner("widget");
-
- ok(!wrapper.hasClass("ui-spinner-disabled"), "before: wrapper does not have ui-spinner-disabled class");
- ok(!el.is(':disabled'), "before: input does not have disabled attribute");
-
- el.spinner("disable");
- ok(wrapper.hasClass("ui-spinner-disabled"), "after: wrapper has ui-spinner-disabled class");
- ok(el.is(':disabled'), "after: input has disabled attribute");
-
- spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
- equals(val, el.val(), "keyboard - value does not change on key UP");
-
- spinner_simulateKeyDownUp(el, $.ui.keyCode.DOWN);
- equals(val, el.val(), "keyboard - value does not change on key DOWN");
-
- spinner_simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);
- equals(val, el.val(), "keyboard - value does not change on key PGUP");
-
- 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');
- equals(val, el.val(), "mouse - value does not change on clicking up button");
-
- wrapper.find(":ui-button").last().trigger('mousedown').trigger('mouseup');
- equals(val, el.val(), "mouse - value does not change on clicking down button");
-
- el.spinner('stepUp', 6);
- equals(6, el.val(), "script - stepUp 6 steps changes value");
-
- el.spinner('stepDown');
- equals(5, el.val(), "script - stepDown 1 step changes value");
-
- el.spinner('pageUp');
- equals(15, el.val(), "script - pageUp 1 page changes value");
-
- el.spinner('pageDown');
- equals(5, el.val(), "script - pageDown 1 page changes value");
+(function( $ ) {
+module( "spinner: methods" );
+
+test( "disable", function() {
+ expect( 14 );
+ var element = $( "#spin" ).spinner({ value: 2 }),
+ wrapper = $( "#spin" ).spinner( "widget" );
+
+ ok( !wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper does not have ui-spinner-disabled class" );
+ ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" );
+
+ element.spinner( "disable" );
+ ok( wrapper.hasClass( "ui-spinner-disabled" ), "after: wrapper has ui-spinner-disabled class" );
+ ok( element.is( ":disabled"), "after: input has disabled attribute" );
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equals( 2, element.val(), "keyboard - value does not change on key UP" );
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
+ equals( 2, element.val(), "keyboard - value does not change on key DOWN" );
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
+ equals( 2, element.val(), "keyboard - value does not change on key PGUP" );
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
+ equals( 2, element.val(), "keyboard - value does not change on key PGDN" );
+
+ wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
+ equals( 2, element.val(), "mouse - value does not change on clicking up button" );
+
+ wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
+ equals( 2, element.val(), "mouse - value does not change on clicking down button" );
+
+ element.spinner( "stepUp", 6 );
+ equals( 8, element.val(), "script - stepUp 6 steps changes value");
+
+ element.spinner( "stepDown" );
+ equals( 7, element.val(), "script - stepDown 1 step changes value" );
+
+ element.spinner( "pageUp" );
+ equals( 17, element.val(), "script - pageUp 1 page changes value" );
+
+ element.spinner( "pageDown" );
+ equals( 7, element.val(), "script - pageDown 1 page changes value" );
});
-test("enable", function() {
- var el = $("#spin").spinner({ disabled: true })
- val = el.val(),
- wrapper = el.spinner("widget");
-
- ok(wrapper.hasClass("ui-spinner-disabled"), "before: wrapper has ui-spinner-disabled class");
- ok(el.is(':disabled'), "before: input has disabled attribute");
-
- el.spinner("enable");
-
- ok(!wrapper.hasClass(".ui-spinner-disabled"), "after: wrapper does not have ui-spinner-disabled class");
- ok(!el.is(':disabled'), "after: input does not have disabled attribute");
+test( "enable", function() {
+ expect( 5 );
+ var element = $( "#spin" ).spinner({ disabled: true })
+ wrapper = element.spinner( "widget" );
+
+ ok( wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper has ui-spinner-disabled class" );
+ ok( element.is( ":disabled" ), "before: input has disabled attribute" );
+
+ element.spinner( "enable" );
+
+ ok( !wrapper.hasClass( ".ui-spinner-disabled" ), "after: wrapper does not have ui-spinner-disabled class" );
+ ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
+
+ spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
+ equals( 1, element.val(), "keyboard - value does not change on key UP" );
});
-test("pageDown", function() {
- var el = $('#spin').spinner({
- step: 2,
- value: 0,
+test( "pageDown", function() {
+ expect( 4 );
+ var element = $( "#spin" ).spinner({
+ page: 20,
+ value: -12,
min: -100
});
- el.spinner('pageDown');
- equals(el.val(), -20, "pageDown 1 page");
-
- el.spinner('pageDown', 3);
- equals(el.val(), -80, "pageDown 3 pages");
-
- el.val(-91).spinner('pageDown');
- equals(el.val(), -100, "value close to min and pageDown 1 page");
-
- el.spinner('pageDown', 10);
- equals(el.val(), -100, "value at min and pageDown 10 pages");
+ element.spinner( "pageDown" );
+ equals( element.val(), -32, "pageDown 1 page" );
+
+ element.spinner( "pageDown", 3 );
+ equals( element.val(), -92, "pageDown 3 pages" );
+
+ element.spinner( "pageDown" );
+ equals( element.val(), -100, "value close to min and pageDown 1 page" );
+
+ element.spinner( "pageDown", 10 );
+ equals( element.val(), -100, "value at min and pageDown 10 pages" );
});
-test("pageUp", function() {
- var el = $('#spin').spinner({
- step: 2,
- value: 0,
+test( "pageUp", function() {
+ expect( 4 );
+ var element = $( "#spin" ).spinner({
+ page: 20,
+ value: 12,
max: 100
});
- el.spinner('pageUp');
- equals(el.val(), 20, "pageUp 1 page");
+ element.spinner( "pageUp" );
+ equals( element.val(), 32, "pageUp 1 page" );
- el.spinner('pageUp', 3);
- equals(el.val(), 80, "pageUp 3 pages");
+ element.spinner( "pageUp", 3 );
+ equals( element.val(), 92, "pageUp 3 pages" );
- el.val(91).spinner('pageUp');
- equals(el.val(), 100, "value close to max and pageUp 1 page");
-
- el.spinner('pageUp', 10);
- equals(el.val(), 100, "value at max and pageUp 10 pages");
-
+ element.spinner( "pageUp" );
+ equals( element.val(), 100, "value close to max and pageUp 1 page" );
+
+ element.spinner( "pageUp", 10 );
+ equals( element.val(), 100, "value at max and pageUp 10 pages" );
});
-test("stepDown", function() {
- expect(4);
+test( "stepDown", function() {
+ expect( 4 );
+ var element = $( "#spin" ).spinner({
+ step: 2,
+ value: 0,
+ min: -15
+ });
- el = $('#spin').spinner({ step: 2, page: 5, value: 0, min: -15 });
+ element.spinner( "stepDown" );
+ equals( element.val(), -2, "stepDown 1 step" );
- el.spinner('stepDown')
- equals(el.val(), -2, "stepDown 1 step");
+ element.spinner( "stepDown", 5 );
+ equals( element.val(), -12, "stepDown 5 steps" );
- el.spinner('stepDown', 5)
- equals(el.val(), -12, "stepDown 5 steps");
-
- el.spinner('stepDown', 3);
- equals(el.val(), -15, "close to min and stepDown 3 steps");
+ element.spinner( "stepDown", 4 );
+ equals( element.val(), -15, "close to min and stepDown 4 steps" );
- el.spinner('stepDown');
- equals(el.val(), -15, "at min and stepDown 1 step");
+ element.spinner( "stepDown" );
+ equals( element.val(), -15, "at min and stepDown 1 step" );
});
-test("stepUp", function() {
- expect(4);
-
- el = $('#spin').spinner({ step: 2, page: 5, value: 0, max: 15 });
+test( "stepUp", function() {
+ expect( 4 );
+ var element = $( "#spin" ).spinner({
+ step: 2,
+ value: 0,
+ max: 15
+ });
- el.spinner('stepUp')
- equals(el.val(), 2, "stepUp 1 steps");
+ element.spinner( "stepUp" );
+ equals( element.val(), 2, "stepUp 1 step" );
- el.spinner('stepUp', 5)
- equals(el.val(), 12, "stepUp 5 steps");
-
- el.spinner('stepUp', 3);
- equals(el.val(), 15, "close to min and stepUp 3 steps");
+ element.spinner( "stepUp", 5 );
+ equals( element.val(), 12, "stepUp 5 steps" );
- el.spinner('stepUp');
- equals(el.val(), 15, "at min and stepUp 1 step");
+ element.spinner( "stepUp", 4 );
+ equals( element.val(), 15, "close to min and stepUp 4 steps" );
+ element.spinner( "stepUp" );
+ equals( element.val(), 15, "at max and stepUp 1 step" );
});
-test("value", function() {
- expect(2);
-
- el = $('#spin').spinner({ value: 0 });
-
- el.spinner('value', 10);
- equals(el.val(), 10, "change value via value method");
-
- equals(10, el.spinner('value'), "get value via value method");
+test( "value", function() {
+ expect( 2 );
+ var element = $( "#spin" ).spinner({ value: 0 });
+
+ element.spinner( "value", 10 );
+ equals( element.val(), 10, "change value via value method" );
+
+ equals( element.spinner( "value" ), 10, "get value via value method" );
});
-})(jQuery);
+})( jQuery );
diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js
index 2cb90ef5d..33a7c1978 100644
--- a/tests/unit/spinner/spinner_options.js
+++ b/tests/unit/spinner/spinner_options.js
@@ -1,32 +1,32 @@
-/*
- * spinner_options.js
- */
-(function($) {
+(function( $ ) {
-module("spinner: options");
+module( "spinner: options" );
-test("numberFormat, number", function() {
- var el = $("#spin").spinner({
+test( "numberFormat, number", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner({
value: "1",
numberFormat: "n"
});
- equal(el.val(), "1.00");
+ equal( element.val(), "1.00", "n" );
});
-test("numberFormat, number, simple", function() {
- var el = $("#spin").spinner({
+test( "numberFormat, number, simple", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner({
value: "1",
numberFormat: "n0"
});
- equal(el.val(), "1");
+ equal( element.val(), "1", "n0" );
});
-test("numberFormat, currency", function() {
- var el = $("#spin").spinner({
+test( "numberFormat, currency", function() {
+ expect( 1 );
+ var element = $( "#spin" ).spinner({
value: "1",
numberFormat: "C"
});
- equal(el.val(), "$1.00");
+ equal( element.val(), "$1.00", "C" );
});
/* TODO figure out how to test this properly
@@ -67,88 +67,56 @@ test("incremental - true (default)", function() {
});
*/
-test("max", function() {
- var el = $("#spin").spinner({ max: 100, value: 1000 });
- equals(el.val(), 100, "max constrained if value option is greater");
-
- el.spinner('value', 1000);
- equals(el.val(), 100, "max constrained if value method is greater");
-
- el.val(1000).blur();
- equals(el.val(), 100, "max constrained if manual entry");
-});
+test( "max", function() {
+ expect( 3 );
+ var element = $( "#spin" ).spinner({ max: 100, value: 1000 });
+ equals( element.val(), 100, "max constrained if value option is greater" );
+
+ element.spinner( "value", 1000 );
+ equals( element.val(), 100, "max constrained if value method is greater" );
-test("min", function() {
- var el = $("#spin").spinner({ min: -100, value: -1000 });
- equals(el.val(), -100, "min constrained if value option is greater");
-
- el.spinner('value', -1000);
- equals(el.val(), -100, "min constrained if value method is greater");
-
- el.val(-1000).blur();
- equals(el.val(), -100, "min constrained if manual entry");
+ element.val( 1000 ).blur();
+ equals( element.val(), 100, "max constrained if manual entry" );
});
-test("step, 2", function() {
- var el = $("#spin").spinner({ step: 2 });
- equals(el.val(), "0", "value initialized to");
-
- for ( var i = 0 ; i < 5 ; i++ ) {
- spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
- }
- equals(el.val(), "10", "UP 5 times with step: 2");
+test( "min", function() {
+ expect( 3 );
+ var element = $( "#spin" ).spinner({ min: -100, value: -1000 });
+ equals( element.val(), -100, "min constrained if value option is greater" );
- el.spinner('value', '10.5');
- equals(el.val(), "10.5", "value reset to");
+ element.spinner( "value", -1000 );
+ equals( element.val(), -100, "min constrained if value method is greater" );
- el.spinner('option', 'step', 2);
- for ( var i = 0 ; i < 5 ; i++ ) {
- spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
- }
- equals(el.val(), "20.5", "UP 5 times with step: 2");
+ element.val( -1000 ).blur();
+ equals( element.val(), -100, "min constrained if manual entry" );
});
-test("step, 0.7", function() {
- var el = $("#spin").spinner({
- step: 0.7,
- numberFormat: "n1"
- });
- equals(el.val(), "0.0", "value initialized to");
-
- spinner_simulateKeyDownUp(el, $.ui.keyCode.DOWN);
- equals(el.val(), "-0.7", "DOWN 1 time with step: 0.7");
+test( "step, 2", function() {
+ expect( 4 );
+ var element = $( "#spin" ).spinner({ step: 2 });
+ equals( element.val(), "0", "value initialized to 0" );
- for ( var i = 0 ; i < 11 ; i++ ) {
- spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
- }
- equals(el.val(), "7.0", "UP 11 times with step: 0.7");
-});
+ element.spinner( "stepUp" );
+ equals( element.val(), "2", "stepUp" );
-test("value, default, specified in markup", function() {
- var el = $('#spin2').spinner();
- equals(el.val(), 2, "starting value");
-});
+ element.spinner( "value", "10.5" );
+ equals( element.val(), "10.5", "value reset to 10.5" );
-test("value, default, nothing specified", function() {
- var el = $('#spin').spinner();
- equals(el.val(), 0, "starting value");
+ element.spinner( "stepUp" );
+ equals( element.val(), "12.5", "stepUp" );
});
-test("value, override", function() {
- var el = $('#spin').spinner({ value: 100 });
- equals(el.val(), 100, "starting value");
-});
+test( "step, 0.7", function() {
+ expect( 2 );
+ var element = $("#spin").spinner({
+ step: 0.7
+ });
+ equals( element.val(), "0", "value initialized to 0" );
-test("value, override markup", function() {
- var el = $('#spin2').spinner({ value: 100 });
- equals(el.val(), 100, "starting value");
+ element.spinner( "stepUp" );
+ equals( element.val(), "0.7", "stepUp" );
});
-test("value, override later", function() {
- var el = $('#spin').spinner();
- equals(el.val(), 0, "starting value");
- el.spinner('option', 'value', 1000);
- equals(el.val(), 1000, "value option changed and set as current value");
-});
+// TODO: test value
-})(jQuery);
+})( jQuery );