2011-08-07 12:10:49 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
2012-04-19 17:12:23 +00:00
|
|
|
var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp;
|
|
|
|
|
2011-08-07 12:10:49 +00:00
|
|
|
module( "spinner: events" );
|
|
|
|
|
|
|
|
test( "start", function() {
|
2011-08-07 23:11:49 +00:00
|
|
|
expect( 6 );
|
|
|
|
var element = $( "#spin" ).spinner();
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-08-07 23:11:49 +00:00
|
|
|
function shouldStart( expectation, msg ) {
|
|
|
|
element.spinner( "option", "start", function() {
|
|
|
|
ok( expectation, msg );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldStart( true, "key UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStart( true, "key DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStart( true, "key PAGE_UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStart( true, "key PAGE_DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStart( true, "button up" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
|
|
|
|
shouldStart( true, "button down" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
|
|
|
|
|
|
|
|
shouldStart( false, "stepUp" );
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
shouldStart( false, "stepDown" );
|
|
|
|
element.spinner( "stepDown" );
|
|
|
|
|
|
|
|
shouldStart( false, "pageUp" );
|
|
|
|
element.spinner( "pageUp" );
|
|
|
|
shouldStart( false, "pageDown" );
|
|
|
|
element.spinner( "pageDown" );
|
|
|
|
|
|
|
|
shouldStart( false, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "spin", function() {
|
2011-08-07 23:11:49 +00:00
|
|
|
expect( 6 );
|
|
|
|
var element = $( "#spin" ).spinner();
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-08-07 23:11:49 +00:00
|
|
|
function shouldSpin( expectation, msg ) {
|
|
|
|
element.spinner( "option", "spin", function() {
|
|
|
|
ok( expectation, msg );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldSpin( true, "key UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldSpin( true, "key DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldSpin( true, "key PAGE_UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldSpin( true, "key PAGE_DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldSpin( true, "button up" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
|
|
|
|
shouldSpin( true, "button down" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
|
|
|
|
|
|
|
|
shouldSpin( false, "stepUp" );
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
shouldSpin( false, "stepDown" );
|
|
|
|
element.spinner( "stepDown" );
|
|
|
|
|
|
|
|
shouldSpin( false, "pageUp" );
|
|
|
|
element.spinner( "pageUp" );
|
|
|
|
shouldSpin( false, "pageDown" );
|
|
|
|
element.spinner( "pageDown" );
|
|
|
|
|
|
|
|
shouldSpin( false, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "stop", function() {
|
2011-08-07 23:11:49 +00:00
|
|
|
expect( 6 );
|
|
|
|
var element = $( "#spin" ).spinner();
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-08-07 23:11:49 +00:00
|
|
|
function shouldStop( expectation, msg ) {
|
|
|
|
element.spinner( "option", "stop", function() {
|
|
|
|
ok( expectation, msg );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldStop( true, "key UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStop( true, "key DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStop( true, "key PAGE_UP" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldStop( true, "key PAGE_DOWN" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
|
|
|
|
shouldStop( true, "button up" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
|
|
|
|
shouldStop( true, "button down" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
|
|
|
|
|
|
|
|
shouldStop( false, "stepUp" );
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
shouldStop( false, "stepDown" );
|
|
|
|
element.spinner( "stepDown" );
|
|
|
|
|
|
|
|
shouldStop( false, "pageUp" );
|
|
|
|
element.spinner( "pageUp" );
|
|
|
|
shouldStop( false, "pageDown" );
|
|
|
|
element.spinner( "pageDown" );
|
|
|
|
|
|
|
|
shouldStop( false, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
2012-05-10 21:59:55 +00:00
|
|
|
asyncTest( "change", function() {
|
2011-08-07 23:11:49 +00:00
|
|
|
expect( 14 );
|
|
|
|
var element = $( "#spin" ).spinner();
|
|
|
|
|
|
|
|
function shouldChange( expectation, msg ) {
|
|
|
|
element.spinner( "option", "change", function() {
|
|
|
|
ok( expectation, msg );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-08-13 23:05:04 +00:00
|
|
|
element.focus();
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( false, "key UP, before blur" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( true, "blur after key UP" );
|
|
|
|
element.blur();
|
|
|
|
|
2011-08-13 23:05:04 +00:00
|
|
|
element.focus();
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( false, "key DOWN, before blur" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( true, "blur after key DOWN" );
|
|
|
|
element.blur();
|
2011-08-07 12:10:49 +00:00
|
|
|
|
2011-08-13 23:05:04 +00:00
|
|
|
element.focus();
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( false, "key PAGE_UP, before blur" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( true, "blur after key PAGE_UP" );
|
|
|
|
element.blur();
|
|
|
|
|
2011-08-13 23:05:04 +00:00
|
|
|
element.focus();
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( false, "key PAGE_DOWN, before blur" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
2011-08-13 23:05:04 +00:00
|
|
|
shouldChange( true, "blur after key PAGE_DOWN" );
|
2011-08-07 23:11:49 +00:00
|
|
|
element.blur();
|
|
|
|
|
|
|
|
shouldChange( false, "many keys, before blur" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( true, "blur after many keys" );
|
|
|
|
element.blur();
|
|
|
|
|
|
|
|
shouldChange( false, "many keys, same final value, before blur" );
|
2012-04-19 17:12:23 +00:00
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.UP );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
|
|
|
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
2011-08-07 23:11:49 +00:00
|
|
|
shouldChange( false, "blur after many keys, same final value" );
|
|
|
|
|
|
|
|
shouldChange( false, "button up, before blur" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
|
|
|
|
shouldChange( true, "blur after button up" );
|
2012-05-10 21:59:55 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
element.blur();
|
|
|
|
|
|
|
|
shouldChange( false, "button down, before blur" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
|
|
|
|
shouldChange( true, "blur after button down" );
|
|
|
|
setTimeout(function() {
|
|
|
|
element.blur();
|
|
|
|
|
|
|
|
shouldChange( false, "many buttons, same final value, before blur" );
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup();
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
|
|
|
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
|
|
|
|
shouldChange( false, "blur after many buttons, same final value" );
|
|
|
|
element.blur();
|
|
|
|
setTimeout(function() {
|
|
|
|
shouldChange( true, "stepUp" );
|
|
|
|
element.spinner( "stepUp" );
|
|
|
|
|
|
|
|
shouldChange( true, "stepDown" );
|
|
|
|
element.spinner( "stepDown" );
|
|
|
|
|
|
|
|
shouldChange( true, "pageUp" );
|
|
|
|
element.spinner( "pageUp" );
|
|
|
|
|
|
|
|
shouldChange( true, "pageDown" );
|
|
|
|
element.spinner( "pageDown" );
|
|
|
|
|
|
|
|
shouldChange( true, "value" );
|
|
|
|
element.spinner( "value", 999 );
|
|
|
|
|
|
|
|
shouldChange( false, "value, same value" );
|
|
|
|
element.spinner( "value", 999 );
|
|
|
|
|
|
|
|
shouldChange( true, "max, value changed" );
|
|
|
|
element.spinner( "option", "max", 900 );
|
|
|
|
|
|
|
|
shouldChange( false, "max, value not changed" );
|
|
|
|
element.spinner( "option", "max", 1000 );
|
|
|
|
|
|
|
|
shouldChange( true, "min, value changed" );
|
|
|
|
element.spinner( "option", "min", 950 );
|
|
|
|
|
|
|
|
shouldChange( false, "min, value not changed" );
|
|
|
|
element.spinner( "option", "min", 200 );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2011-08-07 12:10:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})( jQuery );
|