Menu tests: Better handling of async focus in IE.

This commit is contained in:
Scott González 2012-12-11 09:44:39 -05:00
parent 020abcf8a9
commit 694987f2f7

View File

@ -87,7 +87,7 @@ asyncTest( "handle blur via click outside", function() {
}); });
}); });
test( "handle focus of menu with active item", function() { asyncTest( "handle focus of menu with active item", function() {
expect( 1 ); expect( 1 );
var element = $( "#menu1" ).menu({ var element = $( "#menu1" ).menu({
focus: function( event ) { focus: function( event ) {
@ -96,11 +96,19 @@ test( "handle focus of menu with active item", function() {
}); });
log( "focus", true ); log( "focus", true );
element.focus(); element[0].focus();
setTimeout(function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.focus(); element[0].blur();
setTimeout(function() {
element[0].focus();
setTimeout(function() {
equal( logOutput(), "focus,0,1,2,2", "current active item remains active" ); equal( logOutput(), "focus,0,1,2,2", "current active item remains active" );
start();
});
});
});
}); });
asyncTest( "handle submenu auto collapse: mouseleave", function() { asyncTest( "handle submenu auto collapse: mouseleave", function() {
@ -162,7 +170,7 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() {
}); });
test( "handle keyboard navigation on menu without scroll and without submenus", function() { asyncTest( "handle keyboard navigation on menu without scroll and without submenus", function() {
expect( 12 ); expect( 12 );
var element = $( "#menu1" ).menu({ var element = $( "#menu1" ).menu({
select: function( event, ui ) { select: function( event, ui ) {
@ -174,7 +182,8 @@ test( "handle keyboard navigation on menu without scroll and without submenus",
}); });
log( "keydown", true ); log( "keydown", true );
element.focus(); element[0].focus();
setTimeout(function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" ); equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
@ -222,6 +231,9 @@ test( "handle keyboard navigation on menu without scroll and without submenus",
log( "keydown", true ); log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" ); equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
start();
});
}); });
asyncTest( "handle keyboard navigation on menu without scroll and with submenus", function() { asyncTest( "handle keyboard navigation on menu without scroll and with submenus", function() {
@ -344,7 +356,7 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus"
} }
}); });
test( "handle keyboard navigation on menu with scroll and without submenus", function() { asyncTest( "handle keyboard navigation on menu with scroll and without submenus", function() {
expect( 14 ); expect( 14 );
var element = $( "#menu3" ).menu({ var element = $( "#menu3" ).menu({
select: function( event, ui ) { select: function( event, ui ) {
@ -356,7 +368,8 @@ test( "handle keyboard navigation on menu with scroll and without submenus", fun
}); });
log( "keydown", true ); log( "keydown", true );
element.focus(); element[0].focus();
setTimeout(function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" ); equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
@ -413,6 +426,9 @@ test( "handle keyboard navigation on menu with scroll and without submenus", fun
log( "keydown", true ); log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" ); equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
start();
});
}); });
asyncTest( "handle keyboard navigation on menu with scroll and with submenus", function() { asyncTest( "handle keyboard navigation on menu with scroll and with submenus", function() {
@ -561,7 +577,7 @@ asyncTest( "handle keyboard navigation and mouse click on menu with disabled ite
} }
}); });
test( "handle keyboard navigation with spelling of menu items", function() { asyncTest( "handle keyboard navigation with spelling of menu items", function() {
expect( 2 ); expect( 2 );
var element = $( "#menu2" ).menu({ var element = $( "#menu2" ).menu({
focus: function( event ) { focus: function( event ) {
@ -577,8 +593,9 @@ test( "handle keyboard navigation with spelling of menu items", function() {
equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" ); equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" );
element.simulate( "keydown", { keyCode: 68 } ); element.simulate( "keydown", { keyCode: 68 } );
equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" ); equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" );
start();
}); });
element.focus(); element[0].focus();
}); });
})( jQuery ); })( jQuery );