mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Spinner: More tests. Don't trigger spin when programmatically stepping or paging.
This commit is contained in:
parent
c6c957224f
commit
2a8a77a9b2
@ -176,4 +176,13 @@ test( "ARIA attributes", function() {
|
|||||||
equal( element.attr( "aria-valuemax" ), 10, "max option changed aria-valuemax changes" );
|
equal( element.attr( "aria-valuemax" ), 10, "max option changed aria-valuemax changes" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "focus text field when pressing button", function() {
|
||||||
|
expect( 2 );
|
||||||
|
var element = $( "#spin" ).spinner();
|
||||||
|
$( "body" ).focus();
|
||||||
|
ok( element[ 0 ] !== document.activeElement, "not focused before" );
|
||||||
|
element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown();
|
||||||
|
ok( element[ 0 ] === document.activeElement, "focused after" );
|
||||||
|
});
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
@ -3,48 +3,215 @@
|
|||||||
module( "spinner: events" );
|
module( "spinner: events" );
|
||||||
|
|
||||||
test( "start", function() {
|
test( "start", function() {
|
||||||
expect( 1 );
|
expect( 6 );
|
||||||
var element = $( "#spin" ).spinner({
|
var element = $( "#spin" ).spinner();
|
||||||
start: function() {
|
|
||||||
ok( true, "start" );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
function shouldStart( expectation, msg ) {
|
||||||
|
element.spinner( "option", "start", function() {
|
||||||
|
ok( expectation, msg );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldStart( true, "key UP" );
|
||||||
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
shouldStart( true, "key DOWN" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
||||||
|
|
||||||
|
shouldStart( true, "key PAGE_UP" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
||||||
|
shouldStart( true, "key PAGE_DOWN" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
||||||
|
|
||||||
|
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 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "spin", function() {
|
test( "spin", function() {
|
||||||
expect( 1 );
|
expect( 6 );
|
||||||
var element = $( "#spin" ).spinner({
|
var element = $( "#spin" ).spinner();
|
||||||
spin: function(){
|
|
||||||
ok( true, "spin" );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
function shouldSpin( expectation, msg ) {
|
||||||
|
element.spinner( "option", "spin", function() {
|
||||||
|
ok( expectation, msg );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldSpin( true, "key UP" );
|
||||||
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
shouldSpin( true, "key DOWN" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
||||||
|
|
||||||
|
shouldSpin( true, "key PAGE_UP" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
||||||
|
shouldSpin( true, "key PAGE_DOWN" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
||||||
|
|
||||||
|
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 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "stop", function() {
|
test( "stop", function() {
|
||||||
expect( 1 );
|
expect( 6 );
|
||||||
var element = $( "#spin" ).spinner({
|
var element = $( "#spin" ).spinner();
|
||||||
stop: function(){
|
|
||||||
ok( true, "stop" );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
function shouldStop( expectation, msg ) {
|
||||||
|
element.spinner( "option", "stop", function() {
|
||||||
|
ok( expectation, msg );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldStop( true, "key UP" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
shouldStop( true, "key DOWN" );
|
||||||
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
||||||
|
|
||||||
|
shouldStop( true, "key PAGE_UP" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
||||||
|
shouldStop( true, "key PAGE_DOWN" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
||||||
|
|
||||||
|
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 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "change", function() {
|
test( "change", function() {
|
||||||
expect( 1 );
|
expect( 14 );
|
||||||
var element = $( "#spin" ).spinner({
|
var element = $( "#spin" ).spinner();
|
||||||
change: function(){
|
|
||||||
ok( true, "change" );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
function shouldChange( expectation, msg ) {
|
||||||
|
element.spinner( "option", "change", function() {
|
||||||
|
ok( expectation, msg );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldChange( false, "key UP, before blur" );
|
||||||
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
shouldChange( true, "blur after key UP" );
|
||||||
element.blur();
|
element.blur();
|
||||||
|
|
||||||
|
shouldChange( false, "key DOWN, before blur" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
||||||
|
shouldChange( true, "blur after key DOWN" );
|
||||||
|
element.blur();
|
||||||
|
|
||||||
|
shouldChange( false, "key PAGE_UP, before blur" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
|
||||||
|
shouldChange( true, "blur after key PAGE_UP" );
|
||||||
|
element.blur();
|
||||||
|
|
||||||
|
shouldChange( false, "key PAGE_DOWN, before blur" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
||||||
|
shouldChange( true, "key PAGE_DOWN" );
|
||||||
|
element.blur();
|
||||||
|
|
||||||
|
shouldChange( false, "many keys, before blur" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
||||||
|
shouldChange( true, "blur after many keys" );
|
||||||
|
element.blur();
|
||||||
|
|
||||||
|
shouldChange( false, "many keys, same final value, before blur" );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.UP );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
||||||
|
spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN );
|
||||||
|
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" );
|
||||||
|
element.blur();
|
||||||
|
|
||||||
|
shouldChange( false, "button down, before blur" );
|
||||||
|
element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup();
|
||||||
|
shouldChange( true, "blur after button down" );
|
||||||
|
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();
|
||||||
|
|
||||||
|
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 );
|
||||||
});
|
});
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
2
ui/jquery.ui.spinner.js
vendored
2
ui/jquery.ui.spinner.js
vendored
@ -253,7 +253,7 @@ $.widget( "ui.spinner", {
|
|||||||
// clamp the new value
|
// clamp the new value
|
||||||
newVal = this._trimValue( newVal );
|
newVal = this._trimValue( newVal );
|
||||||
|
|
||||||
if ( this._trigger( "spin", event, { value: newVal } ) !== false) {
|
if ( !this.spinning || this._trigger( "spin", event, { value: newVal } ) !== false) {
|
||||||
this._value( newVal );
|
this._value( newVal );
|
||||||
this.counter++;
|
this.counter++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user