Debian Codegraph @

tests/unit/menu/core.js

raw symbols SCIP
1 define( [
2 "qunit",
3 "jquery",
4 "lib/helper",
5 "./helper",
6 "ui/widgets/menu"
7 ], function( QUnit, $, helper, testHelper ) {
8 "use strict";
9
10 QUnit.module( "menu: core", { afterEach: helper.moduleAfterEach } );
11
12 QUnit.test( "markup structure", function( assert ) {
13 assert.expect( 11 );
14 var element = $( "#menu9" ).menu(),
15 items = element.children(),
16 firstItemChildren = items.eq( 0 ).children();
17
18 assert.hasClasses( element, "ui-menu ui-widget ui-widget-content" );
19 assert.hasClasses( items[ 0 ], "ui-menu-item" );
20 assert.equal( items.eq( 0 ).children().length, 2, "Item has exactly 2 children when it has a sub menu" );
21 assert.hasClasses( firstItemChildren[ 0 ], "ui-menu-item-wrapper" );
22 assert.hasClasses( firstItemChildren[ 1 ], "ui-menu ui-widget ui-widget-content" );
23 assert.hasClasses( firstItemChildren.eq( 1 ).children()[ 0 ], "ui-menu-item" );
24 assert.hasClasses( firstItemChildren.eq( 1 ).children().eq( 0 ).children(), "ui-menu-item-wrapper" );
25 assert.hasClasses( items[ 1 ], "ui-menu-item" );
26 assert.equal( items.eq( 1 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" );
27 assert.hasClasses( items[ 2 ], "ui-menu-item" );
28 assert.equal( items.eq( 2 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" );
29 } );
30
31 QUnit.test( "accessibility", function( assert ) {
32 assert.expect( 4 );
33 var element = $( "#menu1" ).menu();
34
35 assert.equal( element.attr( "role" ), "menu", "main role" );
36 assert.ok( !element.attr( "aria-activedescendant" ), "aria-activedescendant not set" );
37
38 element.menu( "focus", $.Event(), element.children().eq( -2 ) );
39 assert.equal( element.attr( "aria-activedescendant" ), "testID1", "aria-activedescendant from existing id" );
40
41 element.menu( "focus", $.Event(), element.children().eq( 0 ) );
42 assert.ok( /^ui-id-\d+$/.test( element.attr( "aria-activedescendant" ) ), "aria-activedescendant from generated id" );
43
44 // Item roles are tested in the role option tests
45 } );
46
47 QUnit.test( "#9044: Autofocus issue with dialog opened from menu widget", function( assert ) {
48 var ready = assert.async();
49 assert.expect( 1 );
50 var element = $( "#menu1" ).menu();
51
52 $( "<input>", { id: "test9044" } ).appendTo( "body" );
53
54 $( "#testID1" ).on( "click", function() {
55 $( "#test9044" ).trigger( "focus" );
56 } );
57
58 testHelper.click( element, "3" );
59 setTimeout( function() {
60 assert.equal( document.activeElement.id, "test9044", "Focus was swallowed by menu" );
61 $( "#test9044" ).remove();
62 ready();
63 } );
64 } );
65
66 QUnit.test( "#9532: Need a way in Menu to keep ui-state-active class on selected item for Selectmenu", function( assert ) {
67 var ready = assert.async();
68 assert.expect( 1 );
69 var element = $( "#menu1" ).menu(),
70 firstChild = element.children().eq( 0 ),
71 wrapper = firstChild.children( ".ui-menu-item-wrapper" );
72
73 element.menu( "focus", null, firstChild );
74 wrapper.addClass( "ui-state-active" );
75 setTimeout( function() {
76 assert.hasClasses( wrapper, "ui-state-active" );
77 ready();
78 } );
79 } );
80
81 QUnit.test( "active menu item styling", function( assert ) {
82 var ready = assert.async();
83 assert.expect( 5 );
84 function isActive( item ) {
85 assert.hasClasses( item.children( ".ui-menu-item-wrapper" ), "ui-state-active" );
86 }
87 function isInactive( item ) {
88 assert.lacksClasses( item.children( ".ui-menu-item-wrapper" ), "ui-state-active" );
89 }
90 $.ui.menu.prototype.delay = 0;
91 var element = $( "#menu4" ).menu();
92 var parentItem = element.children( "li" ).eq( 1 );
93 var childItem = parentItem.find( "li" ).eq( 0 );
94 element.menu( "focus", null, parentItem );
95 setTimeout( function() {
96 isActive( parentItem );
97 element.menu( "focus", null, childItem );
98 setTimeout( function() {
99 isActive( parentItem );
100 isActive( childItem );
101 element.trigger( "blur" );
102 setTimeout( function() {
103 isInactive( parentItem );
104 isInactive( childItem );
105 $.ui.menu.prototype.delay = 300;
106 ready();
107 }, 50 );
108 } );
109 } );
110 } );
111
112 } );