jquery-ui/tests/unit/menu/events.js

740 lines
24 KiB
JavaScript
Raw Normal View History

define( [
"jquery",
2015-04-07 14:55:52 +00:00
"./helper",
"ui/widgets/menu"
], function( $, testHelper ) {
var log = testHelper.log,
logOutput = testHelper.logOutput,
click = testHelper.click;
2012-06-18 17:26:46 +00:00
module( "menu: events", {
setup: function() {
testHelper.clearLog();
2012-06-18 17:26:46 +00:00
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
test( "handle click on menu", function() {
expect( 1 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
select: function() {
log();
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
log( "click", true );
click( element, "1" );
2012-06-18 17:26:46 +00:00
log( "afterclick" );
2012-06-27 13:49:56 +00:00
click( element, "2" );
click( element, "3" );
2012-06-27 13:49:56 +00:00
click( element, "1" );
equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
test( "handle click on custom item menu", function() {
expect( 1 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu5" ).menu( {
select: function() {
log();
},
menus: ".menu"
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
log( "click", true );
click( element, "1" );
2012-06-18 17:26:46 +00:00
log( "afterclick" );
2012-06-27 13:49:56 +00:00
click( element, "2" );
click( element, "3" );
2012-06-27 13:49:56 +00:00
click( element, "1" );
equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );
2015-08-24 12:59:13 +00:00
} );
asyncTest( "handle blur", function() {
expect( 1 );
var blurHandled = false,
2015-08-24 12:59:13 +00:00
element = $( "#menu1" ).menu( {
blur: function( event ) {
2015-08-24 12:59:13 +00:00
// Ignore duplicate blur event fired by IE
if ( !blurHandled ) {
blurHandled = true;
equal( event.type, "menublur", "blur event.type is 'menublur'" );
}
}
2015-08-24 12:59:13 +00:00
} );
2012-06-27 13:49:56 +00:00
click( element, "1" );
2015-08-24 12:59:13 +00:00
setTimeout( function() {
element.trigger( "blur" );
2015-08-24 12:59:13 +00:00
setTimeout( function() {
start();
}, 350 );
2015-08-24 12:59:13 +00:00
} );
} );
asyncTest( "handle blur via click outside", function() {
expect( 1 );
var blurHandled = false,
2015-08-24 12:59:13 +00:00
element = $( "#menu1" ).menu( {
blur: function( event ) {
2015-08-24 12:59:13 +00:00
// Ignore duplicate blur event fired by IE
if ( !blurHandled ) {
blurHandled = true;
equal( event.type, "menublur", "blur event.type is 'menublur'" );
}
}
2015-08-24 12:59:13 +00:00
} );
2012-06-27 13:49:56 +00:00
click( element, "1" );
2015-08-24 12:59:13 +00:00
setTimeout( function() {
$( "<a>", { id: "remove" } ).appendTo( "body" ).trigger( "click" );
setTimeout( function() {
start();
}, 350 );
2015-08-24 12:59:13 +00:00
} );
} );
asyncTest( "handle focus of menu with active item", function() {
expect( 1 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
focus: function( event ) {
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
log( "focus", true );
element[ 0 ].focus();
2015-08-24 12:59:13 +00:00
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element[ 0 ].blur();
2015-08-24 12:59:13 +00:00
setTimeout( function() {
element[ 0 ].focus();
2015-08-24 12:59:13 +00:00
setTimeout( function() {
equal( logOutput(), "focus,0,1,2,2", "current active item remains active" );
start();
2015-08-24 12:59:13 +00:00
} );
} );
} );
} );
test( "handle mouseenter on nested menu item", function( assert ) {
assert.expect( 8 );
$.ui.menu.prototype.delay = 1;
var activeItem,
done = assert.async(),
element = $( "#menu2" ).menu();
element
.menu( "previous" )
.menu( "expand" );
function checkSubmenus() {
equal( element.find( "ul[aria-expanded='true']" ).length, 2, "both submenus expanded" );
}
function menumouseenter1() {
element.menu( "expand" );
setTimeout( menumouseenter2, 25 );
}
function menumouseenter2() {
checkSubmenus();
activeItem = $( "#" + element.attr( "aria-activedescendant" ) );
assert.hasClasses( activeItem, "ui-state-active" );
activeItem.trigger( "mouseleave" );
setTimeout( menumouseenter3, 25 );
}
function menumouseenter3() {
checkSubmenus();
assert.lacksClasses( activeItem, "ui-state-active" );
activeItem.trigger( "mouseenter" );
setTimeout( menumouseenter4, 25 );
}
function menumouseenter4() {
checkSubmenus();
activeItem.parents( ".ui-menu-item" ).each( function( index, item ) {
assert.hasClasses( $( item ).children( ".ui-menu-item-wrapper" ), "ui-state-active" );
} );
$.ui.menu.prototype.delay = 300;
done();
}
setTimeout( menumouseenter1, 25 );
} );
asyncTest( "handle submenu auto collapse: mouseleave, default markup", function() {
expect( 4 );
$.ui.menu.prototype.delay = 1;
2012-06-27 13:49:56 +00:00
var element = $( "#menu2" ).menu(),
event = $.Event( "mouseenter" );
function menumouseleave1() {
2012-06-27 13:49:56 +00:00
equal( element.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" );
element.menu( "focus", event, element.find( "li:nth-child(7) li:first" ) );
setTimeout( menumouseleave2, 25 );
}
function menumouseleave2() {
2012-06-27 13:49:56 +00:00
equal( element.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" );
element.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" );
setTimeout( menumouseleave3, 25 );
}
function menumouseleave3() {
2012-06-27 13:49:56 +00:00
equal( element.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" );
element.trigger( "mouseleave" );
setTimeout( menumouseleave4, 25 );
}
function menumouseleave4() {
2012-06-27 13:49:56 +00:00
equal( element.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
$.ui.menu.prototype.delay = 300;
start();
}
2012-04-19 13:39:21 +00:00
2012-06-27 13:49:56 +00:00
element.find( "li:nth-child(7)" ).trigger( "mouseenter" );
setTimeout( menumouseleave1, 25 );
2015-08-24 12:59:13 +00:00
} );
asyncTest( "handle submenu auto collapse: mouseleave, custom markup", function() {
expect( 4 );
$.ui.menu.prototype.delay = 1;
2015-08-24 12:59:13 +00:00
var element = $( "#menu5" ).menu( { menus: ".menu" } ),
event = $.Event( "mouseenter" );
function menumouseleave1() {
2012-06-27 13:49:56 +00:00
equal( element.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" );
element.menu( "focus", event, element.find( ":nth-child(7)" ).find( ".menu" ).eq( 0 ).children().eq( 0 ) );
setTimeout( menumouseleave2, 25 );
}
function menumouseleave2() {
2012-06-27 13:49:56 +00:00
equal( element.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" );
element.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" );
setTimeout( menumouseleave3, 25 );
}
function menumouseleave3() {
2012-06-27 13:49:56 +00:00
equal( element.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" );
element.trigger( "mouseleave" );
setTimeout( menumouseleave4, 25 );
}
function menumouseleave4() {
2012-06-27 13:49:56 +00:00
equal( element.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
$.ui.menu.prototype.delay = 300;
start();
}
2012-04-19 13:39:21 +00:00
2012-06-27 13:49:56 +00:00
element.find( ":nth-child(7)" ).trigger( "mouseenter" );
setTimeout( menumouseleave1, 25 );
2015-08-24 12:59:13 +00:00
} );
asyncTest( "handle keyboard navigation on menu without scroll and without submenus", function() {
2012-06-18 17:26:46 +00:00
expect( 12 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
2012-06-18 17:26:46 +00:00
select: function( event, ui ) {
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element[ 0 ].focus();
2015-08-24 12:59:13 +00:00
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( logOutput(), "keydown,1", "Keydown UP" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown,4", "Keydown PAGE_DOWN" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( logOutput(), "keydown,4", "Keydown END" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( logOutput(), "keydown,0", "Keydown HOME" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
start();
2015-08-24 12:59:13 +00:00
} );
} );
2012-06-18 17:26:46 +00:00
asyncTest( "handle keyboard navigation on menu without scroll and with submenus", function() {
expect( 16 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu2" ).menu( {
2012-06-18 17:26:46 +00:00
select: function( event, ui ) {
2015-08-24 12:59:13 +00:00
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.one( "menufocus", function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,1,2", "Keydown DOWN" );
setTimeout( menukeyboard1 );
2015-08-24 12:59:13 +00:00
} );
element.trigger( "focus" );
function menukeyboard1() {
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( logOutput(), "keydown,1,0", "Keydown UP" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
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.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
2015-08-24 12:59:13 +00:00
setTimeout( function() {
equal( logOutput(), "keydown,1,2,3,4,0", "Keydown RIGHT (open submenu)" );
setTimeout( menukeyboard2 );
} );
}
function menukeyboard2() {
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( logOutput(), "keydown,4", "Keydown LEFT (close submenu)" );
// Re-open submenu
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( menukeyboard3 );
}
function menukeyboard3() {
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown,2", "Keydown PAGE_DOWN" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( logOutput(), "keydown,2", "Keydown END" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( logOutput(), "keydown,0", "Keydown HOME" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.SPACE } );
setTimeout( menukeyboard4 );
}
function menukeyboard4() {
equal( logOutput(), "keydown,0", "Keydown SPACE (open submenu)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,5,6,0,1,0,2,4,0", "Keydown skip dividers" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( menukeyboard6 );
} );
} );
}
function menukeyboard6() {
equal( logOutput(), "keydown,Ada", "Keydown ENTER (open submenu)" );
start();
}
2015-08-24 12:59:13 +00:00
} );
asyncTest( "handle keyboard navigation on menu with scroll and without submenus", function() {
2012-06-18 17:26:46 +00:00
expect( 14 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu3" ).menu( {
2012-06-18 17:26:46 +00:00
select: function( event, ui ) {
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element[ 0 ].focus();
2015-08-24 12:59:13 +00:00
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( logOutput(), "keydown,1,0", "Keydown UP" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown,34", "Keydown PAGE_DOWN" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown,17", "Keydown PAGE_UP" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( logOutput(), "keydown,37", "Keydown END" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( logOutput(), "keydown,0", "Keydown HOME" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );
start();
2015-08-24 12:59:13 +00:00
} );
} );
2012-06-18 17:26:46 +00:00
asyncTest( "handle keyboard navigation on menu with scroll and with submenus", function() {
expect( 14 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu4" ).menu( {
2012-06-18 17:26:46 +00:00
select: function( event, ui ) {
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
2015-08-24 12:59:13 +00:00
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.one( "menufocus", function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,1,2", "Keydown DOWN" );
setTimeout( menukeyboard1 );
2015-08-24 12:59:13 +00:00
} );
element.trigger( "focus" );
function menukeyboard1() {
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( logOutput(), "keydown,1,0", "Keydown UP" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( function() {
equal( logOutput(), "keydown,1,0", "Keydown RIGHT (open submenu)" );
2012-06-18 17:26:46 +00:00
}, 50 );
setTimeout( menukeyboard2, 50 );
}
function menukeyboard2() {
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( logOutput(), "keydown,1", "Keydown LEFT (close submenu)" );
// Re-open submenu
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( menukeyboard3, 50 );
}
function menukeyboard3() {
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( logOutput(), "keydown,27", "Keydown PAGE_DOWN" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown,10", "Keydown PAGE_UP" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( logOutput(), "keydown,27", "Keydown END" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( logOutput(), "keydown,0", "Keydown HOME" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( logOutput(), "keydown,1", "Keydown ESCAPE (close submenu)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( menukeyboard4, 50 );
}
function menukeyboard4() {
equal( logOutput(), "keydown,0", "Keydown ENTER (open submenu)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER (select item)" );
start();
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
asyncTest( "handle keyboard navigation and mouse click on menu with disabled items", function() {
expect( 6 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu6" ).menu( {
2012-06-18 17:26:46 +00:00
select: function( event, ui ) {
2015-08-24 12:59:13 +00:00
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
2015-08-24 12:59:13 +00:00
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.one( "menufocus", function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( logOutput(), "keydown,1", "Keydown focus but not select disabled item" );
setTimeout( menukeyboard1, 50 );
2015-08-24 12:59:13 +00:00
} );
element.trigger( "focus" );
function menukeyboard1() {
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,2,3,4", "Keydown focus disabled item with submenu" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( function() {
equal( logOutput(), "keydown", "Keydown RIGHT (no effect on disabled sub-menu)" );
2012-06-18 17:26:46 +00:00
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( function() {
equal( logOutput(), "keydown", "Keydown ENTER (no effect on disabled sub-menu)" );
2012-06-18 17:26:46 +00:00
log( "click", true );
click( element, "1" );
equal( logOutput(), "click", "Click disabled item (no effect)" );
start();
2012-06-18 17:26:46 +00:00
}, 50 );
}, 50 );
}
2015-08-24 12:59:13 +00:00
} );
asyncTest( "handle keyboard navigation and mouse click on menu with dividers and group labels", function() {
expect( 2 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu7" ).menu( {
items: "> :not('.ui-menu-group')",
select: function( event, ui ) {
2015-08-24 12:59:13 +00:00
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
log( "keydown", true );
element.one( "menufocus", function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( logOutput(), "keydown,2,Ada", "Keydown skips initial group label" );
setTimeout( menukeyboard1, 50 );
2015-08-24 12:59:13 +00:00
} );
element.trigger( "focus" );
function menukeyboard1() {
log( "keydown", true );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( logOutput(), "keydown,3,4,7", "Keydown focus skips divider and group label" );
start();
}
2015-08-24 12:59:13 +00:00
} );
asyncTest( "handle keyboard navigation with spelling of menu items", function() {
expect( 3 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu2" ).menu( {
focus: function( event ) {
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
log( "keydown", true );
element.one( "menufocus", function() {
element.simulate( "keydown", { keyCode: 65 } );
element.simulate( "keydown", { keyCode: 68 } );
element.simulate( "keydown", { keyCode: 68 } );
equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" );
element.simulate( "keydown", { keyCode: 68 } );
equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" );
element.simulate( "keydown", { keyCode: 83 } );
equal( logOutput(), "keydown,0,1,3,4,5", "Keydown focus Saarland ignoring leading space" );
start();
2015-08-24 12:59:13 +00:00
} );
element[ 0 ].focus();
2015-08-24 12:59:13 +00:00
} );
asyncTest( "Keep focus on selected item (see #10644)", function() {
expect( 1 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu2" ).menu( {
focus: function( event ) {
log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );
}
2015-08-24 12:59:13 +00:00
} );
log( "keydown", true );
element.one( "menufocus", function() {
element.simulate( "keydown", { keyCode: 65 } );
element.simulate( "keydown", { keyCode: 68 } );
element.simulate( "keydown", { keyCode: 68 } );
element.simulate( "keydown", { keyCode: 89 } );
element.simulate( "keydown", { keyCode: 83 } );
equal( logOutput(), "keydown,0,1,3,3,3",
"Focus stays on 'Addyston', even after other options are eliminated" );
start();
2015-08-24 12:59:13 +00:00
} );
element[ 0 ].focus();
2015-08-24 12:59:13 +00:00
} );
test( "#9469: Stopping propagation in a select event should not suppress subsequent select events.", function() {
expect( 1 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
select: function( event ) {
log();
event.stopPropagation();
}
2015-08-24 12:59:13 +00:00
} );
click( element, "1" );
click( element, "2" );
equal( logOutput(), "1,2", "Both select events were not triggered." );
2015-08-24 12:59:13 +00:00
} );
asyncTest( "#10571: When typing in a menu, only menu-items should be focused", function( assert ) {
expect( 3 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu8" ).menu( {
focus: function( event, ui ) {
equal( ui.item.length, 1, "There should only be one match when filtering" );
assert.hasClasses( ui.item, "ui-menu-item" );
equal( ui.item.text(), "-Saarland", "element has correct text" );
}
2015-08-24 12:59:13 +00:00
} );
2015-08-24 12:59:13 +00:00
setTimeout( function() {
element.menu( "widget" ).simulate( "keydown", { keyCode: "-".charCodeAt( 0 ) } );
start();
2015-08-24 12:59:13 +00:00
} );
} );
} );