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