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 ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "menu: core", { afterEach: helper.moduleAfterEach } );
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2016-04-06 13:02:55 +00:00
|
|
|
QUnit.test( "markup structure", function( assert ) {
|
|
|
|
assert.expect( 11 );
|
2014-12-03 16:24:44 +00:00
|
|
|
var element = $( "#menu9" ).menu(),
|
|
|
|
items = element.children(),
|
|
|
|
firstItemChildren = items.eq( 0 ).children();
|
|
|
|
|
|
|
|
assert.hasClasses( element, "ui-menu ui-widget ui-widget-content" );
|
|
|
|
assert.hasClasses( items[ 0 ], "ui-menu-item" );
|
2016-04-06 13:02:55 +00:00
|
|
|
assert.equal( items.eq( 0 ).children().length, 2, "Item has exactly 2 children when it has a sub menu" );
|
2014-12-03 16:24:44 +00:00
|
|
|
assert.hasClasses( firstItemChildren[ 0 ], "ui-menu-item-wrapper" );
|
|
|
|
assert.hasClasses( firstItemChildren[ 1 ], "ui-menu ui-widget ui-widget-content" );
|
|
|
|
assert.hasClasses( firstItemChildren.eq( 1 ).children()[ 0 ], "ui-menu-item" );
|
|
|
|
assert.hasClasses( firstItemChildren.eq( 1 ).children().eq( 0 ).children(), "ui-menu-item-wrapper" );
|
|
|
|
assert.hasClasses( items[ 1 ], "ui-menu-item" );
|
2016-04-06 13:02:55 +00:00
|
|
|
assert.equal( items.eq( 1 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" );
|
2014-12-03 16:24:44 +00:00
|
|
|
assert.hasClasses( items[ 2 ], "ui-menu-item" );
|
2016-04-06 13:02:55 +00:00
|
|
|
assert.equal( items.eq( 2 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" );
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
2012-06-28 12:38:08 +00:00
|
|
|
|
2016-04-06 13:02:55 +00:00
|
|
|
QUnit.test( "accessibility", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-06-28 12:38:08 +00:00
|
|
|
var element = $( "#menu1" ).menu();
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2016-04-06 13:02:55 +00:00
|
|
|
assert.equal( element.attr( "role" ), "menu", "main role" );
|
|
|
|
assert.ok( !element.attr( "aria-activedescendant" ), "aria-activedescendant not set" );
|
2012-06-28 12:38:08 +00:00
|
|
|
|
|
|
|
element.menu( "focus", $.Event(), element.children().eq( -2 ) );
|
2016-04-06 13:02:55 +00:00
|
|
|
assert.equal( element.attr( "aria-activedescendant" ), "testID1", "aria-activedescendant from existing id" );
|
2011-05-02 18:35:58 +00:00
|
|
|
|
2012-06-28 12:38:08 +00:00
|
|
|
element.menu( "focus", $.Event(), element.children().eq( 0 ) );
|
2016-04-06 13:02:55 +00:00
|
|
|
assert.ok( /^ui-id-\d+$/.test( element.attr( "aria-activedescendant" ) ), "aria-activedescendant from generated id" );
|
2011-05-02 18:35:58 +00:00
|
|
|
|
2012-06-28 12:38:08 +00:00
|
|
|
// Item roles are tested in the role option tests
|
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( "#9044: Autofocus issue with dialog opened from menu widget", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 1 );
|
2013-08-26 05:06:44 +00:00
|
|
|
var element = $( "#menu1" ).menu();
|
|
|
|
|
|
|
|
$( "<input>", { id: "test9044" } ).appendTo( "body" );
|
|
|
|
|
2015-05-14 02:10:34 +00:00
|
|
|
$( "#testID1" ).on( "click", function() {
|
|
|
|
$( "#test9044" ).trigger( "focus" );
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
2013-08-26 05:06:44 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.click( element, "3" );
|
2013-08-26 05:06:44 +00:00
|
|
|
setTimeout( function() {
|
2016-04-06 13:02:55 +00:00
|
|
|
assert.equal( document.activeElement.id, "test9044", "Focus was swallowed by menu" );
|
2013-08-26 05:06:44 +00:00
|
|
|
$( "#test9044" ).remove();
|
2016-04-06 13:02:55 +00:00
|
|
|
ready();
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-08-26 05:06:44 +00:00
|
|
|
|
2016-04-06 13:02:55 +00:00
|
|
|
QUnit.test( "#9532: Need a way in Menu to keep ui-state-active class on selected item for Selectmenu", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 1 );
|
2013-10-18 04:07:39 +00:00
|
|
|
var element = $( "#menu1" ).menu(),
|
2014-10-25 16:18:17 +00:00
|
|
|
firstChild = element.children().eq( 0 ),
|
|
|
|
wrapper = firstChild.children( ".ui-menu-item-wrapper" );
|
2013-10-18 04:07:39 +00:00
|
|
|
|
|
|
|
element.menu( "focus", null, firstChild );
|
2014-10-25 16:18:17 +00:00
|
|
|
wrapper.addClass( "ui-state-active" );
|
2013-10-18 04:07:39 +00:00
|
|
|
setTimeout( function() {
|
2015-01-30 14:58:21 +00:00
|
|
|
assert.hasClasses( wrapper, "ui-state-active" );
|
2016-04-06 13:02:55 +00:00
|
|
|
ready();
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-10-18 04:07:39 +00:00
|
|
|
|
2016-04-06 13:02:55 +00:00
|
|
|
QUnit.test( "active menu item styling", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 5 );
|
2016-03-11 16:35:25 +00:00
|
|
|
function isActive( item ) {
|
|
|
|
assert.hasClasses( item.children( ".ui-menu-item-wrapper" ), "ui-state-active" );
|
|
|
|
}
|
|
|
|
function isInactive( item ) {
|
|
|
|
assert.lacksClasses( item.children( ".ui-menu-item-wrapper" ), "ui-state-active" );
|
|
|
|
}
|
|
|
|
$.ui.menu.prototype.delay = 0;
|
|
|
|
var element = $( "#menu4" ).menu();
|
2020-01-22 15:44:34 +00:00
|
|
|
var parentItem = element.children( "li" ).eq( 1 );
|
|
|
|
var childItem = parentItem.find( "li" ).eq( 0 );
|
2016-03-11 16:35:25 +00:00
|
|
|
element.menu( "focus", null, parentItem );
|
|
|
|
setTimeout( function() {
|
|
|
|
isActive( parentItem );
|
|
|
|
element.menu( "focus", null, childItem );
|
|
|
|
setTimeout( function() {
|
|
|
|
isActive( parentItem );
|
|
|
|
isActive( childItem );
|
2020-05-16 06:36:55 +00:00
|
|
|
element.trigger( "blur" );
|
2016-03-11 16:35:25 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
isInactive( parentItem );
|
|
|
|
isInactive( childItem );
|
|
|
|
$.ui.menu.prototype.delay = 300;
|
2016-04-06 13:02:55 +00:00
|
|
|
ready();
|
2016-03-11 16:35:25 +00:00
|
|
|
}, 50 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-04-06 17:04:04 +00:00
|
|
|
} );
|