2015-04-06 17:04:04 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-04-06 17:04:04 +00:00
|
|
|
"ui/menu"
|
2015-04-07 14:30:07 +00:00
|
|
|
], function( $, testHelper ) {
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2012-06-18 17:26:46 +00:00
|
|
|
module( "menu: core" );
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2014-12-03 16:24:44 +00:00
|
|
|
test( "markup structure", function( assert ) {
|
|
|
|
expect( 11 );
|
|
|
|
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" );
|
|
|
|
equal( items.eq( 0 ).children().length, 2, "Item has exactly 2 children when it has a sub menu" );
|
|
|
|
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" );
|
|
|
|
equal( items.eq( 1 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" );
|
|
|
|
assert.hasClasses( items[ 2 ], "ui-menu-item" );
|
|
|
|
equal( items.eq( 2 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" );
|
2012-06-28 12:38:08 +00:00
|
|
|
});
|
|
|
|
|
2012-06-18 17:26:46 +00:00
|
|
|
test( "accessibility", function () {
|
2012-06-28 12:38:08 +00:00
|
|
|
expect( 4 );
|
|
|
|
var element = $( "#menu1" ).menu();
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2012-06-27 13:49:56 +00:00
|
|
|
equal( element.attr( "role" ), "menu", "main role" );
|
2012-06-28 12:38:08 +00:00
|
|
|
ok( !element.attr( "aria-activedescendant" ), "aria-activedescendant not set" );
|
|
|
|
|
|
|
|
element.menu( "focus", $.Event(), element.children().eq( -2 ) );
|
|
|
|
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 ) );
|
|
|
|
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
|
2010-05-06 15:10:52 +00:00
|
|
|
});
|
|
|
|
|
2013-08-26 05:06:44 +00:00
|
|
|
asyncTest( "#9044: Autofocus issue with dialog opened from menu widget", function() {
|
|
|
|
expect( 1 );
|
|
|
|
var element = $( "#menu1" ).menu();
|
|
|
|
|
|
|
|
$( "<input>", { id: "test9044" } ).appendTo( "body" );
|
|
|
|
|
2015-05-14 02:10:34 +00:00
|
|
|
$( "#testID1" ).on( "click", function() {
|
|
|
|
$( "#test9044" ).trigger( "focus" );
|
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() {
|
|
|
|
equal( document.activeElement.id, "test9044", "Focus was swallowed by menu" );
|
|
|
|
$( "#test9044" ).remove();
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
asyncTest( "#9532: Need a way in Menu to keep ui-state-active class on selected item for Selectmenu", function( assert ) {
|
2013-10-18 04:07:39 +00:00
|
|
|
expect( 1 );
|
|
|
|
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" );
|
2013-10-18 04:07:39 +00:00
|
|
|
start();
|
2015-02-17 15:11:58 +00:00
|
|
|
});
|
2013-10-18 04:07:39 +00:00
|
|
|
});
|
|
|
|
|
2015-04-06 17:04:04 +00:00
|
|
|
} );
|