diff --git a/tests/unit/spinner/spinner_events.js b/tests/unit/spinner/spinner_events.js index 64f510de0..7da16c371 100644 --- a/tests/unit/spinner/spinner_events.js +++ b/tests/unit/spinner/spinner_events.js @@ -131,100 +131,129 @@ asyncTest( "change", function() { }); } - element.focus(); - shouldChange( false, "key UP, before blur" ); - simulateKeyDownUp( element, $.ui.keyCode.UP ); - shouldChange( true, "blur after key UP" ); - element.blur(); + function focusWrap( fn, next ) { + element[0].focus(); + setTimeout( function() { + fn(); + setTimeout(function() { + element[0].blur(); + setTimeout( next ); + }); + }); + } - element.focus(); - shouldChange( false, "key DOWN, before blur" ); - simulateKeyDownUp( element, $.ui.keyCode.DOWN ); - shouldChange( true, "blur after key DOWN" ); - element.blur(); + function step1() { + focusWrap(function() { + shouldChange( false, "key UP, before blur" ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + shouldChange( true, "blur after key UP" ); + }, step2 ); + } - element.focus(); - shouldChange( false, "key PAGE_UP, before blur" ); - simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); - shouldChange( true, "blur after key PAGE_UP" ); - element.blur(); + function step2() { + focusWrap(function() { + shouldChange( false, "key DOWN, before blur" ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + shouldChange( true, "blur after key DOWN" ); + }, step3 ); + } - element.focus(); - shouldChange( false, "key PAGE_DOWN, before blur" ); - simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); - shouldChange( true, "blur after key PAGE_DOWN" ); - element.blur(); + function step3() { + focusWrap(function() { + shouldChange( false, "key PAGE_UP, before blur" ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + shouldChange( true, "blur after key PAGE_UP" ); + }, step4 ); + } - shouldChange( false, "many keys, before blur" ); - 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 ); - shouldChange( true, "blur after many keys" ); - element.blur(); + function step4() { + focusWrap(function() { + shouldChange( false, "key PAGE_DOWN, before blur" ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + shouldChange( true, "blur after key PAGE_DOWN" ); + }, step5 ); + } - shouldChange( false, "many keys, same final value, before blur" ); - simulateKeyDownUp( element, $.ui.keyCode.UP ); - simulateKeyDownUp( element, $.ui.keyCode.UP ); - simulateKeyDownUp( element, $.ui.keyCode.DOWN ); - simulateKeyDownUp( element, $.ui.keyCode.DOWN ); - shouldChange( false, "blur after many keys, same final value" ); + function step5() { + focusWrap(function() { + shouldChange( false, "many keys, before blur" ); + 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 ); + shouldChange( true, "blur after many keys" ); + }, step6 ); + } - shouldChange( false, "button up, before blur" ); - element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); - shouldChange( true, "blur after button up" ); - setTimeout(function() { - element.blur(); + function step6() { + focusWrap(function() { + shouldChange( false, "many keys, same final value, before blur" ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + shouldChange( false, "blur after many keys, same final value" ); - 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, "button up, before blur" ); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); + shouldChange( true, "blur after button up" ); + }, step7 ); + } + function step7() { + focusWrap(function() { + shouldChange( false, "button down, before blur" ); + element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup(); + shouldChange( true, "blur after button down" ); + }, step8 ); + } + + function step8() { + focusWrap(function() { 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" ); + }, step9 ); + } - shouldChange( true, "stepDown" ); - element.spinner( "stepDown" ); + function step9() { + shouldChange( true, "stepUp" ); + element.spinner( "stepUp" ); - shouldChange( true, "pageUp" ); - element.spinner( "pageUp" ); + shouldChange( true, "stepDown" ); + element.spinner( "stepDown" ); - shouldChange( true, "pageDown" ); - element.spinner( "pageDown" ); + shouldChange( true, "pageUp" ); + element.spinner( "pageUp" ); - shouldChange( true, "value" ); - element.spinner( "value", 999 ); + shouldChange( true, "pageDown" ); + element.spinner( "pageDown" ); - shouldChange( false, "value, same value" ); - element.spinner( "value", 999 ); + shouldChange( true, "value" ); + element.spinner( "value", 999 ); - shouldChange( true, "max, value changed" ); - element.spinner( "option", "max", 900 ); + shouldChange( false, "value, same value" ); + element.spinner( "value", 999 ); - shouldChange( false, "max, value not changed" ); - element.spinner( "option", "max", 1000 ); + shouldChange( true, "max, value changed" ); + element.spinner( "option", "max", 900 ); - shouldChange( true, "min, value changed" ); - element.spinner( "option", "min", 950 ); + shouldChange( false, "max, value not changed" ); + element.spinner( "option", "max", 1000 ); - shouldChange( false, "min, value not changed" ); - element.spinner( "option", "min", 200 ); - shouldChange( true, "cleanup" ); - start(); - }); - }); - }); + shouldChange( true, "min, value changed" ); + element.spinner( "option", "min", 950 ); + + shouldChange( false, "min, value not changed" ); + element.spinner( "option", "min", 200 ); + start(); + } + + step1(); }); })( jQuery );