Skip to content
Permalink
Browse files

Spinner tests: Cleanup.

  • Loading branch information
scottgonzalez committed Aug 7, 2011
1 parent e9cdd57 commit 380c2e6fbdba524c56855e9c9018b6bf89225c50
Showing with 204 additions and 247 deletions.
  1. +25 −40 tests/unit/spinner/spinner_events.js
  2. +128 −124 tests/unit/spinner/spinner_methods.js
  3. +51 −83 tests/unit/spinner/spinner_options.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 );
@@ -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 );

0 comments on commit 380c2e6

Please sign in to comment.
You can’t perform that action at this time.