From 9b6c1c5cdb18d76d9febfc079a1cc439dc3789b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 27 Jun 2012 09:49:56 -0400 Subject: [PATCH] Menu tests: Cleanup. --- tests/unit/menu/menu_core.js | 20 ++++++------ tests/unit/menu/menu_events.js | 58 ++++++++++++++++----------------- tests/unit/menu/menu_methods.js | 34 +++++++++---------- tests/unit/menu/menu_options.js | 30 ++++++++--------- 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/tests/unit/menu/menu_core.js b/tests/unit/menu/menu_core.js index d7082664e..ee737ceb1 100644 --- a/tests/unit/menu/menu_core.js +++ b/tests/unit/menu/menu_core.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 ); diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js index 44c792fb4..8eb8ee8c6 100644 --- a/tests/unit/menu/menu_events.js +++ b/tests/unit/menu/menu_events.js @@ -12,7 +12,7 @@ module( "menu: events", { test( "handle click on menu", function() { expect( 1 ); - var menu = $( "#menu1" ).menu({ + var element = $( "#menu1" ).menu({ select: function( event, ui ) { log(); } @@ -20,15 +20,15 @@ test( "handle click on menu", function() { 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,9 +56,9 @@ asyncTest( "handle blur", function() { } }); - click( menu, "1" ); + click( element, "1" ); setTimeout( function() { - menu.blur(); + element.blur(); start(); }, 350 ); }); @@ -66,7 +66,7 @@ asyncTest( "handle blur", function() { 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() { $( "", { 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 ); }); diff --git a/tests/unit/menu/menu_methods.js b/tests/unit/menu/menu_methods.js index cd6728266..0835f61ec 100644 --- a/tests/unit/menu/menu_methods.js +++ b/tests/unit/menu/menu_methods.js @@ -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( "
  • test item
  • " ).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( "
  • ---
  • " ).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( "
  • test item
  • " ).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( "
  • ---
  • " ).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() { diff --git a/tests/unit/menu/menu_options.js b/tests/unit/menu/menu_options.js index a25b59a2c..27c2fabb3 100644 --- a/tests/unit/menu/menu_options.js +++ b/tests/unit/menu/menu_options.js @@ -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" ); -- 2.39.5