Permalink
Browse files

Menu tests: Cleanup.

  • Loading branch information...
1 parent 90050c7 commit 9b6c1c5cdb18d76d9febfc079a1cc439dc3789b3 @scottgonzalez scottgonzalez committed Jun 27, 2012
Showing with 71 additions and 71 deletions.
  1. +10 −10 tests/unit/menu/menu_core.js
  2. +29 −29 tests/unit/menu/menu_events.js
  3. +17 −17 tests/unit/menu/menu_methods.js
  4. +15 −15 tests/unit/menu/menu_options.js
@@ -5,20 +5,20 @@ module( "menu: core" );
test( "accessibility", function () {
expect( 5 );
var item,
- menu = $( "#menu1" ).menu(),
+ element = $( "#menu1" ).menu(),
item0 = $( "li:eq(0) a" );
- ok( menu.hasClass( "ui-menu ui-widget ui-widget-content ui-corner-all" ), "menu class");
- equal( menu.attr( "role" ), "menu", "main role" );
- ok( !menu.attr( "aria-activedescendant" ), "aria attribute not yet active" );
+ ok( element.hasClass( "ui-menu ui-widget ui-widget-content ui-corner-all" ), "menu class");
+ equal( element.attr( "role" ), "menu", "main role" );
+ ok( !element.attr( "aria-activedescendant" ), "aria attribute not yet active" );
- item = menu.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end();
- menu.menu( "focus", $.Event(), item );
- equal( menu.attr("aria-activedescendant"), "xid", "aria attribute, id from DOM" );
+ item = element.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end();
+ element.menu( "focus", $.Event(), item );
+ equal( element.attr( "aria-activedescendant" ), "xid", "aria attribute, id from DOM" );
- item = menu.find( "li:last" );
- menu.menu( "focus", $.Event(), item );
- ok( /^ui-id-\d+$/.test( menu.attr( "aria-activedescendant" ) ), "aria attribute, generated id");
+ item = element.find( "li:last" );
+ element.menu( "focus", $.Event(), item );
+ ok( /^ui-id-\d+$/.test( element.attr( "aria-activedescendant" ) ), "aria attribute, generated id");
});
})( jQuery );
@@ -12,23 +12,23 @@ module( "menu: events", {
test( "handle click on menu", function() {
expect( 1 );
- var menu = $( "#menu1" ).menu({
+ var element = $( "#menu1" ).menu({
select: function( event, ui ) {
log();
}
});
log( "click", true );
click( $( "#menu1" ), "1" );
log( "afterclick" );
- click( menu, "2" );
+ click( element, "2" );
click( $( "#menu1" ), "3" );
- click( menu, "1" );
+ click( element, "1" );
equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );
});
test( "handle click on custom item menu", function() {
expect( 1 );
- var menu = $( "#menu5" ).menu({
+ var element = $( "#menu5" ).menu({
select: function( event, ui ) {
log();
},
@@ -37,16 +37,16 @@ test( "handle click on custom item menu", function() {
log( "click", true );
click( $( "#menu5" ), "1" );
log( "afterclick" );
- click( menu, "2" );
+ click( element, "2" );
click( $( "#menu5" ), "3" );
- click( menu, "1" );
+ click( element, "1" );
equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );
});
asyncTest( "handle blur", function() {
expect( 1 );
var blurHandled = false,
- menu = $( "#menu1" ).menu({
+ element = $( "#menu1" ).menu({
blur: function( event, ui ) {
// Ignore duplicate blur event fired by IE
if ( !blurHandled ) {
@@ -56,17 +56,17 @@ asyncTest( "handle blur", function() {
}
});
- click( menu, "1" );
+ click( element, "1" );
setTimeout( function() {
- menu.blur();
+ element.blur();
start();
}, 350 );
});
asyncTest( "handle blur on click", function() {
expect( 1 );
var blurHandled = false,
- menu = $( "#menu1" ).menu({
+ element = $( "#menu1" ).menu({
blur: function( event, ui ) {
// Ignore duplicate blur event fired by IE
if ( !blurHandled ) {
@@ -76,7 +76,7 @@ asyncTest( "handle blur on click", function() {
}
});
- click( menu, "1" );
+ click( element, "1" );
setTimeout( function() {
$( "<a>", { id: "remove"} ).appendTo( "body" ).trigger( "click" );
start();
@@ -101,59 +101,59 @@ test( "handle focus of menu with active item", function() {
asyncTest( "handle submenu auto collapse: mouseleave", function() {
expect( 4 );
- var menu = $( "#menu2" ).menu(),
+ var element = $( "#menu2" ).menu(),
event = $.Event( "mouseenter" );
function menumouseleave1() {
- equal( menu.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" );
- menu.menu( "focus", event, menu.find( "li:nth-child(7) li:first" ) );
+ 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, 350 );
}
function menumouseleave2() {
- equal( menu.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" );
- menu.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" );
+ equal( element.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" );
+ element.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" );
setTimeout( menumouseleave3, 350 );
}
function menumouseleave3() {
- equal( menu.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" );
- menu.trigger( "mouseleave" );
+ equal( element.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" );
+ element.trigger( "mouseleave" );
setTimeout( menumouseleave4, 350 );
}
function menumouseleave4() {
- equal( menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
+ equal( element.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
start();
}
- menu.find( "li:nth-child(7)" ).trigger( "mouseenter" );
+ element.find( "li:nth-child(7)" ).trigger( "mouseenter" );
setTimeout( menumouseleave1, 350 );
});
asyncTest( "handle submenu auto collapse: mouseleave", function() {
expect( 4 );
- var menu = $( "#menu5" ).menu({ menus: "div" }),
+ var element = $( "#menu5" ).menu({ menus: "div" }),
event = $.Event( "mouseenter" );
function menumouseleave1() {
- equal( menu.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" );
- menu.menu( "focus", event, menu.find( ":nth-child(7)" ).find( "div" ).eq( 0 ).children().eq( 0 ) );
+ equal( element.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" );
+ element.menu( "focus", event, element.find( ":nth-child(7)" ).find( "div" ).eq( 0 ).children().eq( 0 ) );
setTimeout( menumouseleave2, 350 );
}
function menumouseleave2() {
- equal( menu.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" );
- menu.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" );
+ equal( element.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" );
+ element.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" );
setTimeout( menumouseleave3, 350 );
}
function menumouseleave3() {
- equal( menu.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" );
- menu.trigger( "mouseleave" );
+ equal( element.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" );
+ element.trigger( "mouseleave" );
setTimeout( menumouseleave4, 350 );
}
function menumouseleave4() {
- equal( menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
+ equal( element.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
start();
}
- menu.find( ":nth-child(7)" ).trigger( "mouseenter" );
+ element.find( ":nth-child(7)" ).trigger( "mouseenter" );
setTimeout( menumouseleave1, 350 );
});
@@ -12,36 +12,36 @@ module( "menu: methods", {
test( "enable/disable", function() {
expect( 3 );
- var menu = $( "#menu1" ).menu({
+ var element = $( "#menu1" ).menu({
select: function( event, ui ) {
log();
}
});
- menu.menu( "disable" );
- ok(menu.is( ".ui-state-disabled" ),"Missing ui-state-disabled class" );
+ element.menu( "disable" );
+ ok( element.is( ".ui-state-disabled" ), "Missing ui-state-disabled class" );
log( "click", true );
- click( menu, "1" );
+ click( element, "1" );
log( "afterclick" );
- menu.menu( "enable" );
- ok(menu.not( ".ui-state-disabled" ),"Has ui-state-disabled class" );
+ element.menu( "enable" );
+ ok( element.not( ".ui-state-disabled" ), "Has ui-state-disabled class" );
log( "click" );
- click( menu, "1" );
+ click( element, "1" );
log( "afterclick" );
equal( logOutput(), "click,afterclick,click,1,afterclick", "Click order not valid." );
});
test( "refresh", function() {
expect( 5 );
- var menu = $( "#menu1" ).menu();
- equal( menu.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
- menu.append( "<li><a href='#'>test item</a></li>" ).menu( "refresh" );
- equal( menu.find( ".ui-menu-item" ).length, 6, "Incorrect number of menu items" );
- menu.find( ".ui-menu-item:last" ).remove().end().menu( "refresh" );
- equal( menu.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
- menu.append( "<li>---</li>" ).menu( "refresh" );
- equal( menu.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
- menu.children( ":last" ).remove().end().menu( "refresh" );
- equal( menu.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
+ var element = $( "#menu1" ).menu();
+ equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
+ element.append( "<li><a href='#'>test item</a></li>" ).menu( "refresh" );
+ equal( element.find( ".ui-menu-item" ).length, 6, "Incorrect number of menu items" );
+ element.find( ".ui-menu-item:last" ).remove().end().menu( "refresh" );
+ equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
+ element.append( "<li>---</li>" ).menu( "refresh" );
+ equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
+ element.children( ":last" ).remove().end().menu( "refresh" );
+ equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
});
test( "destroy", function() {
@@ -12,56 +12,56 @@ module( "menu: options", {
test( "{ disabled: true }", function() {
expect( 2 );
- var menu = $( "#menu1" ).menu({
+ var element = $( "#menu1" ).menu({
disabled: true,
select: function(event, ui) {
log();
}
});
- ok( menu.is( ".ui-state-disabled" ), "Missing ui-state-disabled class" );
+ ok( element.is( ".ui-state-disabled" ), "Missing ui-state-disabled class" );
log( "click", true );
- click( menu, "1" );
+ click( element, "1" );
log( "afterclick" );
equal( logOutput(), "click,afterclick", "Click order not valid." );
});
test( "{ disabled: false }", function() {
expect( 2 );
- var menu = $( "#menu1" ).menu({
+ var element = $( "#menu1" ).menu({
disabled: false,
select: function( event, ui ) {
log();
}
});
- ok( menu.not( ".ui-state-disabled" ), "Has ui-state-disabled class" );
+ ok( element.not( ".ui-state-disabled" ), "Has ui-state-disabled class" );
log( "click", true );
- click( menu, "1" );
+ click( element, "1" );
log( "afterclick" );
equal( logOutput(), "click,1,afterclick", "Click order not valid." );
});
test( "{ role: 'menu' } ", function () {
- var menu = $( "#menu1" ).menu(),
- items = menu.find( "li" );
+ var element = $( "#menu1" ).menu(),
+ items = element.find( "li" );
expect( 2 + 5 * items.length );
- equal( menu.attr( "role" ), "menu" );
+ equal( element.attr( "role" ), "menu" );
ok( items.length > 0, "number of menu items" );
items.each(function( item ) {
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
equal( $( this ).attr( "role" ), "presentation", "menu item ("+ item + ") role" );
equal( $( "a", this ).attr( "role" ), "menuitem", "menu item ("+ item + ") role" );
- ok( $( "a", this ).hasClass( "ui-corner-all" ), "a element class for menu item ("+ item + ") " );
- equal( $( "a", this ).attr( "tabindex" ), "-1", "a element tabindex for menu item ("+ item + ") " );
+ ok( $( "a", this ).hasClass( "ui-corner-all" ), "a element class for menu item ("+ item + ")" );
+ equal( $( "a", this ).attr( "tabindex" ), "-1", "a element tabindex for menu item ("+ item + ")" );
});
});
test( "{ role: 'listbox' } ", function () {
- var menu = $( "#menu1" ).menu({
+ var element = $( "#menu1" ).menu({
role: "listbox"
}),
- items = menu.find( "li" );
- expect(2 + items.length);
- equal( menu.attr( "role" ), "listbox" );
+ items = element.find( "li" );
+ expect( 2 + items.length );
+ equal( element.attr( "role" ), "listbox" );
ok( items.length > 0, "number of menu items" );
items.each(function( item ) {
equal( $( "a", this ).attr( "role" ), "option", "menu item ("+ item + ") role" );

0 comments on commit 9b6c1c5

Please sign in to comment.