Spinner tests: Cleanup.

This commit is contained in:
Scott González 2011-08-07 08:10:11 -04:00
parent e9cdd576f4
commit 380c2e6fbd
3 changed files with 195 additions and 238 deletions

View File

@ -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 );

View File

@ -1,155 +1,159 @@
/*
* spinner_methods.js
*/
(function($) {
(function( $ ) {
module("spinner: methods");
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");
test( "disable", function() {
expect( 14 );
var element = $( "#spin" ).spinner({ value: 2 }),
wrapper = $( "#spin" ).spinner( "widget" );
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");
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" );
spinner_simulateKeyDownUp(el, $.ui.keyCode.DOWN);
equals(val, el.val(), "keyboard - value does not change on key DOWN");
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(el, $.ui.keyCode.PAGE_UP);
equals(val, el.val(), "keyboard - value does not change on key PGUP");
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
equals( 2, element.val(), "keyboard - value does not change on key UP" );
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");
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
equals( 2, element.val(), "keyboard - value does not change on key DOWN" );
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");
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
equals( 2, element.val(), "keyboard - value does not change on key PGUP" );
el.spinner('stepDown');
equals(5, el.val(), "script - stepDown 1 step changes value");
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
equals( 2, element.val(), "keyboard - value does not change on key PGDN" );
el.spinner('pageUp');
equals(15, el.val(), "script - pageUp 1 page changes value");
wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
equals( 2, element.val(), "mouse - value does not change on clicking up button" );
el.spinner('pageDown');
equals(5, el.val(), "script - pageDown 1 page changes value");
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");
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(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");
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");
element.spinner( "pageDown" );
equals( element.val(), -32, "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", 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);
test( "stepUp", function() {
expect( 4 );
var element = $( "#spin" ).spinner({
step: 2,
value: 0,
max: 15
});
el = $('#spin').spinner({ step: 2, page: 5, value: 0, max: 15 });
element.spinner( "stepUp" );
equals( element.val(), 2, "stepUp 1 step" );
el.spinner('stepUp')
equals(el.val(), 2, "stepUp 1 steps");
element.spinner( "stepUp", 5 );
equals( element.val(), 12, "stepUp 5 steps" );
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");
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 );

View File

@ -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" );
element.val( 1000 ).blur();
equals( element.val(), 100, "max constrained if manual entry" );
});
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");
test( "min", function() {
expect( 3 );
var element = $( "#spin" ).spinner({ min: -100, value: -1000 });
equals( element.val(), -100, "min constrained if value option is greater" );
element.spinner( "value", -1000 );
equals( element.val(), -100, "min constrained if value method is greater" );
element.val( -1000 ).blur();
equals( element.val(), -100, "min 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( "step, 2", function() {
expect( 4 );
var element = $( "#spin" ).spinner({ step: 2 });
equals( element.val(), "0", "value initialized to 0" );
el.spinner('value', '10.5');
equals(el.val(), "10.5", "value reset to");
element.spinner( "stepUp" );
equals( element.val(), "2", "stepUp" );
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.spinner( "value", "10.5" );
equals( element.val(), "10.5", "value reset to 10.5" );
element.spinner( "stepUp" );
equals( element.val(), "12.5", "stepUp" );
});
test("step, 0.7", function() {
var el = $("#spin").spinner({
step: 0.7,
numberFormat: "n1"
test( "step, 0.7", function() {
expect( 2 );
var element = $("#spin").spinner({
step: 0.7
});
equals(el.val(), "0.0", "value initialized to");
equals( element.val(), "0", "value initialized to 0" );
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++ ) {
spinner_simulateKeyDownUp(el, $.ui.keyCode.UP);
}
equals(el.val(), "7.0", "UP 11 times with step: 0.7");
element.spinner( "stepUp" );
equals( element.val(), "0.7", "stepUp" );
});
test("value, default, specified in markup", function() {
var el = $('#spin2').spinner();
equals(el.val(), 2, "starting value");
});
// TODO: test value
test("value, default, nothing specified", function() {
var el = $('#spin').spinner();
equals(el.val(), 0, "starting value");
});
test("value, override", function() {
var el = $('#spin').spinner({ value: 100 });
equals(el.val(), 100, "starting value");
});
test("value, override markup", function() {
var el = $('#spin2').spinner({ value: 100 });
equals(el.val(), 100, "starting value");
});
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");
});
})(jQuery);
})( jQuery );