Accordion: Fix tests in IE 11 with jQuery 1.7-1.8

Closes gh-1482

(cherry picked from commit 8ea36f5e0c)
This commit is contained in:
Scott González 2015-03-10 16:10:43 -04:00
parent 82d4e60459
commit b2aa641c04

View File

@ -110,38 +110,81 @@ asyncTest( "keyboard support", function() {
keyCode = $.ui.keyCode; keyCode = $.ui.keyCode;
equal( headers.filter( ".ui-state-focus" ).length, 0, "no headers focused on init" ); equal( headers.filter( ".ui-state-focus" ).length, 0, "no headers focused on init" );
headers.eq( 0 ).simulate( "focus" ); headers.eq( 0 ).simulate( "focus" );
setTimeout(function() { setTimeout( step1 );
function step1() {
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "first header has focus" ); ok( headers.eq( 0 ).is( ".ui-state-focus" ), "first header has focus" );
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } ); headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
setTimeout( step2 );
}
// Support: IE 11 with jQuery 1.7 - 1.8 only
// All of the setTimeouts() from keydowns aren't necessary with newer jQuery.
// Only the explicit focus simulations require them.
function step2() {
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "DOWN moves focus to next header" ); ok( headers.eq( 1 ).is( ".ui-state-focus" ), "DOWN moves focus to next header" );
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } ); headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } );
setTimeout( step3 );
}
function step3() {
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "RIGHT moves focus to next header" ); ok( headers.eq( 2 ).is( ".ui-state-focus" ), "RIGHT moves focus to next header" );
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } ); headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "DOWN wraps focus to first header" ); setTimeout( step4 );
}
function step4() {
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "DOWN wraps focus to first header" );
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } ); headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } );
setTimeout( step5 );
}
function step5() {
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "UP wraps focus to last header" ); ok( headers.eq( 2 ).is( ".ui-state-focus" ), "UP wraps focus to last header" );
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } ); headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } );
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "LEFT moves focus to previous header" ); setTimeout( step6 );
}
function step6() {
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "LEFT moves focus to previous header" );
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } ); headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } );
setTimeout( step7 );
}
function step7() {
ok( headers.eq( 0 ).is( ".ui-state-focus" ), "HOME moves focus to first header" ); ok( headers.eq( 0 ).is( ".ui-state-focus" ), "HOME moves focus to first header" );
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } ); headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } );
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "END moves focus to last header" ); setTimeout( step8 );
}
function step8() {
ok( headers.eq( 2 ).is( ".ui-state-focus" ), "END moves focus to last header" );
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } ); headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
setTimeout( step9 );
}
function step9() {
equal( element.accordion( "option", "active" ) , 2, "ENTER activates panel" ); equal( element.accordion( "option", "active" ) , 2, "ENTER activates panel" );
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.SPACE } ); headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
equal( element.accordion( "option", "active" ), 1, "SPACE activates panel" ); setTimeout( step10 );
}
function step10() {
equal( element.accordion( "option", "active" ), 1, "SPACE activates panel" );
anchor.simulate( "focus" ); anchor.simulate( "focus" );
setTimeout(function() { setTimeout( step11 );
ok( !headers.eq( 1 ).is( ".ui-state-focus" ), "header loses focus when focusing inside the panel" ); }
anchor.simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } );
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "CTRL+UP moves focus to header" ); function step11() {
start(); ok( !headers.eq( 1 ).is( ".ui-state-focus" ), "header loses focus when focusing inside the panel" );
}, 1 ); anchor.simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } );
}, 1 ); setTimeout( step12 );
}
function step12() {
ok( headers.eq( 1 ).is( ".ui-state-focus" ), "CTRL+UP moves focus to header" );
start();
}
}); });
}( jQuery ) ); }( jQuery ) );