diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-06-18 13:26:46 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-06-18 13:26:46 -0400 |
commit | f92f8bb56bf9e01ccc5d0c84e0f089c3660283d8 (patch) | |
tree | abc95c092557972edb1d3bddf4c6d3b946164a9e /tests/unit | |
parent | 35f7a67c09fc0862b5a639ec867b061d248927a7 (diff) | |
download | jquery-ui-f92f8bb56bf9e01ccc5d0c84e0f089c3660283d8.tar.gz jquery-ui-f92f8bb56bf9e01ccc5d0c84e0f089c3660283d8.zip |
Menu tests: Cleanup.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/menu/menu_core.js | 27 | ||||
-rw-r--r-- | tests/unit/menu/menu_events.js | 453 | ||||
-rw-r--r-- | tests/unit/menu/menu_methods.js | 76 | ||||
-rw-r--r-- | tests/unit/menu/menu_options.js | 74 | ||||
-rw-r--r-- | tests/unit/menu/menu_test_helpers.js | 25 |
5 files changed, 334 insertions, 321 deletions
diff --git a/tests/unit/menu/menu_core.js b/tests/unit/menu/menu_core.js index 7732fd7b7..d7082664e 100644 --- a/tests/unit/menu/menu_core.js +++ b/tests/unit/menu/menu_core.js @@ -1,29 +1,24 @@ -/* - * menu_core.js - */ +(function( $ ) { +module( "menu: core" ); -(function($) { - -module("menu: core"); - -test("accessibility", function () { - expect(5); +test( "accessibility", function () { + expect( 5 ); var item, - menu = $('#menu1').menu(), - item0 = $("li:eq(0) a"); + menu = $( "#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( 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" ); 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"); + equal( menu.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"); }); -})(jQuery); +})( jQuery ); diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js index 2132ff764..944e76b57 100644 --- a/tests/unit/menu/menu_events.js +++ b/tests/unit/menu/menu_events.js @@ -1,50 +1,52 @@ -/* - * menu_events.js - */ -(function($) { +(function( $ ) { var log = TestHelpers.menu.log, + logOutput = TestHelpers.menu.logOutput, click = TestHelpers.menu.click; -module("menu: events"); +module( "menu: events", { + setup: function() { + TestHelpers.menu.clearLog(); + } +}); -test("handle click on menu", function() { - expect(1); - var menu = $('#menu1').menu({ - select: function(event, ui) { +test( "handle click on menu", function() { + expect( 1 ); + var menu = $( "#menu1" ).menu({ + select: function( event, ui ) { log(); } }); - log("click",true); - click($('#menu1'),"1"); - log("afterclick"); - click( menu,"2"); - click($('#menu1'),"3"); - click( menu,"1"); - equal( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); + log( "click", true ); + click( $( "#menu1" ), "1" ); + log( "afterclick" ); + click( menu, "2" ); + click( $( "#menu1" ), "3" ); + click( menu, "1" ); + equal( logOutput(), "1,3,2,afterclick,1,click,", "Click order not valid." ); }); -test("handle click on custom item menu", function() { - expect(1); - var menu = $('#menu5').menu({ - select: function(event, ui) { +test( "handle click on custom item menu", function() { + expect( 1 ); + var menu = $( "#menu5" ).menu({ + select: function( event, ui ) { log(); }, menus: "div" }); - log("click",true); - click($('#menu5'),"1"); - log("afterclick"); - click( menu,"2"); - click($('#menu5'),"3"); - click( menu,"1"); - equal( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); + log( "click", true ); + click( $( "#menu5" ), "1" ); + log( "afterclick" ); + click( menu, "2" ); + click( $( "#menu5" ), "3" ); + click( menu, "1" ); + equal( logOutput(), "1,3,2,afterclick,1,click,", "Click order not valid." ); }); asyncTest( "handle blur", function() { expect( 1 ); var blurHandled = false, - $menu = $( "#menu1" ).menu({ + menu = $( "#menu1" ).menu({ blur: function( event, ui ) { // Ignore duplicate blur event fired by IE if ( !blurHandled ) { @@ -54,17 +56,17 @@ asyncTest( "handle blur", function() { } }); - click( $menu, "1" ); + click( menu, "1" ); setTimeout( function() { - $menu.blur(); + menu.blur(); start(); - }, 350); + }, 350 ); }); asyncTest( "handle blur on click", function() { expect( 1 ); var blurHandled = false, - $menu = $( "#menu1" ).menu({ + menu = $( "#menu1" ).menu({ blur: function( event, ui ) { // Ignore duplicate blur event fired by IE if ( !blurHandled ) { @@ -74,12 +76,11 @@ asyncTest( "handle blur on click", function() { } }); - click( $menu, "1" ); + click( menu, "1" ); setTimeout( function() { - $( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" ); - $("#remove").remove(); + $( "<a>", { id: "remove"} ).appendTo( "body" ).trigger( "click" ); start(); - }, 350); + }, 350 ); }); test( "handle focus of menu with active item", function() { @@ -95,226 +96,225 @@ test( "handle focus of menu with active item", function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.focus(); - equal( $("#log").html(), "2,2,1,0,focus,", "current active item remains active"); + equal( logOutput(), "2,2,1,0,focus,", "current active item remains active" ); }); asyncTest( "handle submenu auto collapse: mouseleave", function() { expect( 4 ); - var $menu = $( "#menu2" ).menu(), + var menu = $( "#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( menu.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" ); + menu.menu( "focus", event, menu.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( menu.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" ); + menu.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( menu.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + menu.trigger( "mouseleave" ); setTimeout( menumouseleave4, 350 ); } function menumouseleave4() { - equal( $menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + equal( menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); start(); } - $menu.find( "li:nth-child(7)" ).trigger( "mouseenter" ); + menu.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 menu = $( "#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( 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 ) ); 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( menu.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" ); + menu.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( menu.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + menu.trigger( "mouseleave" ); setTimeout( menumouseleave4, 350 ); } function menumouseleave4() { - equal( $menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + equal( menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); start(); } - $menu.find( ":nth-child(7)" ).trigger( "mouseenter" ); + menu.find( ":nth-child(7)" ).trigger( "mouseenter" ); setTimeout( menumouseleave1, 350 ); - }); -test("handle keyboard navigation on menu without scroll and without submenus", function() { - expect(12); - var element = $('#menu1').menu({ - select: function(event, ui) { - log($(ui.item[0]).text()); +test( "handle keyboard navigation on menu without scroll and without submenus", function() { + expect( 12 ); + var element = $( "#menu1" ).menu({ + select: function( event, ui ) { + log( $( ui.item[0] ).text() ); }, focus: function( event, ui ) { - log($(event.target).find(".ui-state-focus").parent().index()); + log( $( event.target ).find( ".ui-state-focus" ).parent().index() ); } }); - log("keydown",true); + log( "keydown", true ); element.focus(); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( $("#log").html(), "2,1,0,keydown,", "Keydown DOWN"); + equal( logOutput(), "2,1,0,keydown,", "Keydown DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( $("#log").html(), "1,keydown,", "Keydown UP"); + equal( logOutput(), "1,keydown,", "Keydown UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + equal( logOutput(), "keydown,", "Keydown LEFT (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); - equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)"); + equal( logOutput(), "keydown,", "Keydown RIGHT (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "4,keydown,", "Keydown PAGE_DOWN"); + equal( logOutput(), "4,keydown,", "Keydown PAGE_DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); + equal( logOutput(), "keydown,", "Keydown PAGE_DOWN (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + equal( logOutput(), "0,keydown,", "Keydown PAGE_UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); + equal( logOutput(), "keydown,", "Keydown PAGE_UP (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( $("#log").html(), "4,keydown,", "Keydown END"); + equal( logOutput(), "4,keydown,", "Keydown END" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( $("#log").html(), "0,keydown,", "Keydown HOME"); + equal( logOutput(), "0,keydown,", "Keydown HOME" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)"); + equal( logOutput(), "keydown,", "Keydown ESCAPE (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER"); + equal( logOutput(), "Aberdeen,keydown,", "Keydown ENTER" ); }); -asyncTest("handle keyboard navigation on menu without scroll and with submenus", function() { - expect(16); - var element = $('#menu2').menu({ - select: function(event, ui) { - log($(ui.item[0]).text()); +asyncTest( "handle keyboard navigation on menu without scroll and with submenus", function() { + expect( 16 ); + var element = $( "#menu2" ).menu({ + select: function( event, ui ) { + log( $( ui.item[0] ).text() ); }, focus: function( event, ui ) { - log($(event.target).find(".ui-state-focus").parent().index()); + log( $( event.target ).find( ".ui-state-focus" ).parent().index() ); } }); - log("keydown",true); + log( "keydown", true ); element.one( "menufocus", function( event, ui ) { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( $("#log").html(), "2,1,keydown,", "Keydown DOWN"); + equal( logOutput(), "2,1,keydown,", "Keydown DOWN" ); setTimeout( menukeyboard1, 50 ); }); element.focus(); function menukeyboard1() { - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( $("#log").html(), "0,1,keydown,", "Keydown UP"); + equal( logOutput(), "0,1,keydown,", "Keydown UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + equal( logOutput(), "keydown,", "Keydown LEFT (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); - setTimeout( function() { - equal( $("#log").html(), "0,4,3,2,1,keydown,", "Keydown RIGHT (open submenu)"); - }, 50); - setTimeout( menukeyboard2, 50 ); + setTimeout(function() { + equal( logOutput(), "0,4,3,2,1,keydown,", "Keydown RIGHT (open submenu)" ); + setTimeout( menukeyboard2, 50 ); + }, 50 ); } function menukeyboard2() { - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( $("#log").html(), "4,keydown,", "Keydown LEFT (close submenu)"); + equal( logOutput(), "4,keydown,", "Keydown LEFT (close submenu)" ); - //re-open submenu + // re-open submenu element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); setTimeout( menukeyboard3, 50 ); } function menukeyboard3() { - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "2,keydown,", "Keydown PAGE_DOWN"); + equal( logOutput(), "2,keydown,", "Keydown PAGE_DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); + equal( logOutput(), "keydown,", "Keydown PAGE_DOWN (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + equal( logOutput(), "0,keydown,", "Keydown PAGE_UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); + equal( logOutput(), "keydown,", "Keydown PAGE_UP (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( $("#log").html(), "2,keydown,", "Keydown END"); + equal( logOutput(), "2,keydown,", "Keydown END" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( $("#log").html(), "0,keydown,", "Keydown HOME"); + equal( logOutput(), "0,keydown,", "Keydown HOME" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)"); + equal( logOutput(), "4,keydown,", "Keydown ESCAPE (close submenu)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.SPACE } ); setTimeout( menukeyboard4, 50 ); } function menukeyboard4() { - equal( $("#log").html(), "0,keydown,", "Keydown SPACE (open submenu)"); + equal( logOutput(), "0,keydown,", "Keydown SPACE (open submenu)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)"); + equal( logOutput(), "4,keydown,", "Keydown ESCAPE (close submenu)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); @@ -325,9 +325,9 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus", element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( $("#log").html(), "0,4,2,0,1,0,6,5,keydown,", "Keydown skip dividers and items without anchors"); + equal( logOutput(), "0,4,2,0,1,0,6,5,keydown,", "Keydown skip dividers and items without anchors" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); setTimeout( menukeyboard6, 50 ); }, 50 ); @@ -335,232 +335,229 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus", } function menukeyboard6() { - equal( $("#log").html(), "Ada,keydown,", "Keydown ENTER (open submenu)"); - + equal( logOutput(), "Ada,keydown,", "Keydown ENTER (open submenu)" ); start(); } }); -test("handle keyboard navigation on menu with scroll and without submenus", function() { - expect(14); - var element = $('#menu3').menu({ - select: function(event, ui) { - log($(ui.item[0]).text()); +test( "handle keyboard navigation on menu with scroll and without submenus", function() { + expect( 14 ); + var element = $( "#menu3" ).menu({ + select: function( event, ui ) { + log( $( ui.item[0] ).text() ); }, focus: function( event, ui ) { - log($(event.target).find(".ui-state-focus").parent().index()); + log( $( event.target ).find( ".ui-state-focus" ).parent().index()); } }); - log("keydown",true); + log( "keydown", true ); element.focus(); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( $("#log").html(), "2,1,0,keydown,", "Keydown DOWN"); + equal( logOutput(), "2,1,0,keydown,", "Keydown DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( $("#log").html(), "0,1,keydown,", "Keydown UP"); + equal( logOutput(), "0,1,keydown,", "Keydown UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + equal( logOutput(), "keydown,", "Keydown LEFT (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); - equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)"); + equal( logOutput(), "keydown,", "Keydown RIGHT (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN"); + equal( logOutput(), "10,keydown,", "Keydown PAGE_DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN"); + equal( logOutput(), "20,keydown,", "Keydown PAGE_DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "10,keydown,", "Keydown PAGE_UP"); + equal( logOutput(), "10,keydown,", "Keydown PAGE_UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + equal( logOutput(), "0,keydown,", "Keydown PAGE_UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); + equal( logOutput(), "keydown,", "Keydown PAGE_UP (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( $("#log").html(), "37,keydown,", "Keydown END"); + equal( logOutput(), "37,keydown,", "Keydown END" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); + equal( logOutput(), "keydown,", "Keydown PAGE_DOWN (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( $("#log").html(), "0,keydown,", "Keydown HOME"); + equal( logOutput(), "0,keydown,", "Keydown HOME" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)"); + equal( logOutput(), "keydown,", "Keydown ESCAPE (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER"); + equal( logOutput(), "Aberdeen,keydown,", "Keydown ENTER" ); }); -asyncTest("handle keyboard navigation on menu with scroll and with submenus", function() { - expect(14); - var element = $('#menu4').menu({ - select: function(event, ui) { - log($(ui.item[0]).text()); +asyncTest( "handle keyboard navigation on menu with scroll and with submenus", function() { + expect( 14 ); + var element = $( "#menu4" ).menu({ + select: function( event, ui ) { + log( $( ui.item[0] ).text() ); }, focus: function( event, ui ) { - log($(event.target).find(".ui-state-focus").parent().index()); + log( $( event.target ).find( ".ui-state-focus" ).parent().index()); } }); - log("keydown",true); + log( "keydown", true ); element.one( "menufocus", function( event, ui ) { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( $("#log").html(), "2,1,keydown,", "Keydown DOWN"); + equal( logOutput(), "2,1,keydown,", "Keydown DOWN" ); setTimeout( menukeyboard1, 50 ); }); element.focus(); - function menukeyboard1() { - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( $("#log").html(), "0,1,keydown,", "Keydown UP"); + equal( logOutput(), "0,1,keydown,", "Keydown UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + equal( logOutput(), "keydown,", "Keydown LEFT (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); setTimeout( function() { - equal( $("#log").html(), "0,1,keydown,", "Keydown RIGHT (open submenu)"); - }, 50); + equal( logOutput(), "0,1,keydown,", "Keydown RIGHT (open submenu)" ); + }, 50 ); setTimeout( menukeyboard2, 50 ); } function menukeyboard2() { - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( $("#log").html(), "1,keydown,", "Keydown LEFT (close submenu)"); + equal( logOutput(), "1,keydown,", "Keydown LEFT (close submenu)" ); - //re-open submenu + // re-open submenu element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); setTimeout( menukeyboard3, 50 ); } function menukeyboard3() { - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN"); + equal( logOutput(), "10,keydown,", "Keydown PAGE_DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN"); + equal( logOutput(), "20,keydown,", "Keydown PAGE_DOWN" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "10,keydown,", "Keydown PAGE_UP"); + equal( logOutput(), "10,keydown,", "Keydown PAGE_UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + equal( logOutput(), "0,keydown,", "Keydown PAGE_UP" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( $("#log").html(), "27,keydown,", "Keydown END"); + equal( logOutput(), "27,keydown,", "Keydown END" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( $("#log").html(), "0,keydown,", "Keydown HOME"); + equal( logOutput(), "0,keydown,", "Keydown HOME" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( $("#log").html(), "1,keydown,", "Keydown ESCAPE (close submenu)"); + equal( logOutput(), "1,keydown,", "Keydown ESCAPE (close submenu)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); setTimeout( menukeyboard4, 50 ); } function menukeyboard4() { - equal( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)"); + equal( logOutput(), "0,keydown,", "Keydown ENTER (open submenu)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER (select item)"); + equal( logOutput(), "Aberdeen,keydown,", "Keydown ENTER (select item)" ); start(); } }); -asyncTest("handle keyboard navigation and mouse click on menu with disabled items", function() { - expect(6); - var element = $('#menu6').menu({ - select: function(event, ui) { - log($(ui.item[0]).text()); +asyncTest( "handle keyboard navigation and mouse click on menu with disabled items", function() { + expect( 6 ); + var element = $( "#menu6" ).menu({ + select: function( event, ui ) { + log( $( ui.item[0] ).text() ); }, focus: function( event, ui ) { - log($(event.target).find(".ui-state-focus").parent().index()); + log( $( event.target ).find( ".ui-state-focus" ).parent().index()); } }); - log("keydown",true); + log( "keydown", true ); element.one( "menufocus", function( event, ui ) { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( $("#log").html(), "1,keydown,", "Keydown focus but not select disabled item"); + equal( logOutput(), "1,keydown,", "Keydown focus but not select disabled item" ); setTimeout( menukeyboard1, 50 ); }); element.focus(); - function menukeyboard1() { - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( $("#log").html(), "4,3,2,keydown,", "Keydown focus disabled item with submenu"); + equal( logOutput(), "4,3,2,keydown,", "Keydown focus disabled item with submenu" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + equal( logOutput(), "keydown,", "Keydown LEFT (no effect)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); setTimeout( function() { - equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect on disabled sub-menu)"); + equal( logOutput(), "keydown,", "Keydown RIGHT (no effect on disabled sub-menu)" ); - log("keydown",true); + log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); setTimeout( function() { - equal( $("#log").html(), "keydown,", "Keydown ENTER (no effect on disabled sub-menu)"); - log("click",true); + equal( logOutput(), "keydown,", "Keydown ENTER (no effect on disabled sub-menu)" ); + log( "click", true ); click( element, "1" ); - equal( $("#log").html(), "click,", "Click disabled item (no effect)"); + equal( logOutput(), "click,", "Click disabled item (no effect)" ); start(); - }, 50); - }, 50); + }, 50 ); + }, 50 ); } }); -test("handle keyboard navigation with spelling of menu items", function() { +test( "handle keyboard navigation with spelling of menu items", function() { expect( 2 ); var element = $( "#menu2" ).menu({ focus: function( event, ui ) { @@ -573,14 +570,14 @@ test("handle keyboard navigation with spelling of menu items", function() { element.simulate( "keydown", { keyCode: 65 } ); element.simulate( "keydown", { keyCode: 68 } ); element.simulate( "keydown", { keyCode: 68 } ); - equal( $("#log").html(), "3,1,0,keydown,", "Keydown focus Addyston by spelling the first 3 letters"); + equal( logOutput(), "3,1,0,keydown,", "Keydown focus Addyston by spelling the first 3 letters" ); element.simulate( "keydown", { keyCode: 68 } ); - equal( $("#log").html(), "4,3,1,0,keydown,", "Keydown focus Delphi by repeating the 'd' again"); + equal( logOutput(), "4,3,1,0,keydown,", "Keydown focus Delphi by repeating the 'd' again" ); }); element.focus(); }); -asyncTest("handle page up and page down before the menu has focus", function() { +asyncTest( "handle page up and page down before the menu has focus", function() { expect( 1 ); var element = $( "#menu1" ).menu({ focus: function( event, ui ) { @@ -593,9 +590,9 @@ asyncTest("handle page up and page down before the menu has focus", function() { element.blur(); setTimeout( function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( $("#log").html(), "0,0,keydown,", "Page Up and Page Down bring initial focus to first item"); + equal( logOutput(), "0,0,keydown,", "Page Up and Page Down bring initial focus to first item" ); start(); - }, 500); + }, 500 ); }); -})(jQuery); +})( jQuery ); diff --git a/tests/unit/menu/menu_methods.js b/tests/unit/menu/menu_methods.js index 3a7b2d8fe..faaa7609f 100644 --- a/tests/unit/menu/menu_methods.js +++ b/tests/unit/menu/menu_methods.js @@ -1,61 +1,63 @@ -/* - * menu_methods.js - */ -(function($) { +(function( $ ) { var log = TestHelpers.menu.log, + logOutput = TestHelpers.menu.logOutput, click = TestHelpers.menu.click; -module("menu: methods"); +module( "menu: methods", { + setup: function() { + TestHelpers.menu.clearLog(); + } +}); test( "enable/disable", function() { expect( 3 ); var menu = $( "#menu1" ).menu({ - select: function(event, ui) { + select: function( event, ui ) { log(); } }); - menu.menu("disable"); - ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class"); - log("click",true); - click(menu,"1"); - log("afterclick"); - menu.menu("enable"); - ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class"); - log("click"); - click(menu,"1"); - log("afterclick"); - equal( $("#log").html(), "afterclick,1,click,afterclick,click,", "Click order not valid."); + menu.menu( "disable" ); + ok(menu.is( ".ui-state-disabled" ),"Missing ui-state-disabled class" ); + log( "click", true ); + click( menu, "1" ); + log( "afterclick" ); + menu.menu( "enable" ); + ok(menu.not( ".ui-state-disabled" ),"Has ui-state-disabled class" ); + log( "click" ); + click( menu, "1" ); + log( "afterclick" ); + equal( logOutput(), "afterclick,1,click,afterclick,click,", "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"); + 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" ); }); -test("destroy", function() { - domEqual("#menu1", function() { - $("#menu1").menu().menu("destroy"); +test( "destroy", function() { + expect( 4 ); + domEqual( "#menu1", function() { + $( "#menu1" ).menu().menu( "destroy" ); }); - domEqual("#menu2", function() { - $("#menu2").menu().menu("destroy"); + domEqual( "#menu2", function() { + $( "#menu2" ).menu().menu( "destroy" ); }); - domEqual("#menu5", function() { - $("#menu5").menu().menu("destroy"); + domEqual( "#menu5", function() { + $( "#menu5").menu().menu( "destroy" ); }); - domEqual("#menu6", function() { - $("#menu6").menu().menu("destroy"); + domEqual( "#menu6", function() { + $( "#menu6" ).menu().menu( "destroy" ); }); }); - -})(jQuery); +})( jQuery ); diff --git a/tests/unit/menu/menu_options.js b/tests/unit/menu/menu_options.js index 306f575ea..df2ae4380 100644 --- a/tests/unit/menu/menu_options.js +++ b/tests/unit/menu/menu_options.js @@ -1,12 +1,14 @@ -/* - * menu_options.js - */ -(function($) { +(function( $ ) { var log = TestHelpers.menu.log, + logOutput = TestHelpers.menu.logOutput, click = TestHelpers.menu.click; -module("menu: options"); +module( "menu: options", { + setup: function() { + TestHelpers.menu.clearLog(); + } +}); test( "{ disabled: true }", function() { expect( 2 ); @@ -16,52 +18,54 @@ test( "{ disabled: true }", function() { log(); } }); - ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class"); - log("click",true); - click(menu,"1"); - log("afterclick"); - equal( $("#log").html(), "afterclick,click,", "Click order not valid."); + ok( menu.is( ".ui-state-disabled" ), "Missing ui-state-disabled class" ); + log( "click", true ); + click( menu, "1" ); + log( "afterclick" ); + equal( logOutput(), "afterclick,click,", "Click order not valid." ); }); test( "{ disabled: false }", function() { expect( 2 ); var menu = $( "#menu1" ).menu({ disabled: false, - select: function(event, ui) { + select: function( event, ui ) { log(); } }); - ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class"); - log("click",true); - click(menu,"1"); - log("afterclick"); - equal( $("#log").html(), "afterclick,1,click,", "Click order not valid."); + ok( menu.not( ".ui-state-disabled" ), "Has ui-state-disabled class" ); + log( "click", true ); + click( menu, "1" ); + log( "afterclick" ); + equal( logOutput(), "afterclick,1,click,", "Click order not valid." ); }); -test("{ role: 'menu' } ", function () { - var menu = $('#menu1').menu(); - expect(2 + 5 * $("li", menu).length); +test( "{ role: 'menu' } ", function () { + var menu = $( "#menu1" ).menu(), + items = menu.find( "li" ); + expect( 2 + 5 * items.length ); equal( menu.attr( "role" ), "menu" ); - ok( $("li", menu).length > 0, "number of menu items"); - $("li", menu).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( 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 + ") " ); }); }); -test("{ role: 'listbox' } ", function () { - var menu = $('#menu1').menu({ - role: "listbox" - }); - expect(2 + $("li", menu).length); +test( "{ role: 'listbox' } ", function () { + var menu = $( "#menu1" ).menu({ + role: "listbox" + }), + items = menu.find( "li" ); + expect(2 + items.length); equal( menu.attr( "role" ), "listbox" ); - ok( ($("li", menu).length > 0 ), "number of menu items"); - $("li", menu).each(function(item) { - equal( $("a", this).attr("role"), "option", "menu item ("+ item + ") role"); + ok( items.length > 0, "number of menu items" ); + items.each(function( item ) { + equal( $( "a", this ).attr( "role" ), "option", "menu item ("+ item + ") role" ); }); }); -})(jQuery); +})( jQuery ); diff --git a/tests/unit/menu/menu_test_helpers.js b/tests/unit/menu/menu_test_helpers.js index a576af19a..820cbcdce 100644 --- a/tests/unit/menu/menu_test_helpers.js +++ b/tests/unit/menu/menu_test_helpers.js @@ -1,16 +1,31 @@ +(function() { + +var lastItem, + log = []; + TestHelpers.menu = { log: function( message, clear ) { if ( clear ) { - $( "#log" ).empty(); + log.length = 0; } if ( message === undefined ) { - message = $( "#log" ).data( "lastItem" ); + message = lastItem; } - $( "#log" ).prepend( $.trim( message ) + "," ); + log.unshift( $.trim( message ) ); + }, + + logOutput: function() { + return log.join( "," ) + ","; + }, + + clearLog: function() { + log.length = 0; }, click: function( menu, item ) { - $( "#log" ).data( "lastItem", item ); + lastItem = item; menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( "click" ); } -};
\ No newline at end of file +}; + +})(); |