Menu tests: Don't pollute the global namespace with helpers.

This commit is contained in:
kborchers 2012-04-19 11:19:52 -05:00
parent 163555d7bf
commit c16bd7c510
5 changed files with 125 additions and 116 deletions

View File

@ -368,8 +368,6 @@ grunt.initConfig({
init: true, init: true,
isNotOpen: true, isNotOpen: true,
isOpen: true, isOpen: true,
menu_click: true,
menu_log: true,
modal: true, modal: true,
module: true, module: true,
moved: true, moved: true,

View File

@ -3,21 +3,24 @@
*/ */
(function($) { (function($) {
var log = TestHelpers.menu.log,
click = TestHelpers.menu.click;
module("menu: events"); module("menu: events");
test("handle click on menu", function() { test("handle click on menu", function() {
expect(1); expect(1);
var menu = $('#menu1').menu({ var menu = $('#menu1').menu({
select: function(event, ui) { select: function(event, ui) {
menu_log(); log();
} }
}); });
menu_log("click",true); log("click",true);
menu_click($('#menu1'),"1"); click($('#menu1'),"1");
menu_log("afterclick"); log("afterclick");
menu_click( menu,"2"); click( menu,"2");
menu_click($('#menu1'),"3"); click($('#menu1'),"3");
menu_click( menu,"1"); click( menu,"1");
equal( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); equal( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
}); });
@ -25,16 +28,16 @@ test("handle click on custom item menu", function() {
expect(1); expect(1);
var menu = $('#menu5').menu({ var menu = $('#menu5').menu({
select: function(event, ui) { select: function(event, ui) {
menu_log(); log();
}, },
menus: "div" menus: "div"
}); });
menu_log("click",true); log("click",true);
menu_click($('#menu5'),"1"); click($('#menu5'),"1");
menu_log("afterclick"); log("afterclick");
menu_click( menu,"2"); click( menu,"2");
menu_click($('#menu5'),"3"); click($('#menu5'),"3");
menu_click( menu,"1"); click( menu,"1");
equal( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); equal( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
}); });
@ -75,7 +78,7 @@ test( "handle blur on custom item menu: click", function() {
items: "div" items: "div"
}); });
menu_click($('#menu5'),"1"); click($('#menu5'),"1");
$( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" ); $( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" );
$("#remove").remove(); $("#remove").remove();
@ -144,60 +147,60 @@ test("handle keyboard navigation on menu without scroll and without submenus", f
expect(12); expect(12);
var element = $('#menu1').menu({ var element = $('#menu1').menu({
select: function(event, ui) { select: function(event, ui) {
menu_log($(ui.item[0]).text()); log($(ui.item[0]).text());
}, },
focus: function( event, ui ) { focus: function( event, ui ) {
menu_log($(event.target).find(".ui-state-focus").parent().index()); log($(event.target).find(".ui-state-focus").parent().index());
} }
}); });
menu_log("keydown",true); log("keydown",true);
element.focus(); element.focus();
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 } );
equal( $("#log").html(), "2,1,0,keydown,", "Keydown DOWN"); equal( $("#log").html(), "2,1,0,keydown,", "Keydown DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( $("#log").html(), "1,keydown,", "Keydown UP"); equal( $("#log").html(), "1,keydown,", "Keydown UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)"); equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "4,keydown,", "Keydown PAGE_DOWN"); equal( $("#log").html(), "4,keydown,", "Keydown PAGE_DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( $("#log").html(), "4,keydown,", "Keydown END"); equal( $("#log").html(), "4,keydown,", "Keydown END");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( $("#log").html(), "0,keydown,", "Keydown HOME"); equal( $("#log").html(), "0,keydown,", "Keydown HOME");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)"); equal( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER"); equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER");
}); });
@ -206,14 +209,14 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
expect(14); expect(14);
var element = $('#menu2').menu({ var element = $('#menu2').menu({
select: function(event, ui) { select: function(event, ui) {
menu_log($(ui.item[0]).text()); log($(ui.item[0]).text());
}, },
focus: function( event, ui ) { focus: function( event, ui ) {
menu_log($(event.target).find(".ui-state-focus").parent().index()); log($(event.target).find(".ui-state-focus").parent().index());
} }
}); });
menu_log("keydown",true); log("keydown",true);
element.one( "menufocus", function( event, ui ) { element.one( "menufocus", function( event, ui ) {
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 } );
@ -223,16 +226,16 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
element.focus(); element.focus();
function menukeyboard1() { function menukeyboard1() {
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( $("#log").html(), "0,1,keydown,", "Keydown UP"); equal( $("#log").html(), "0,1,keydown,", "Keydown UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
menu_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.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
@ -246,7 +249,7 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
} }
function menukeyboard2() { function menukeyboard2() {
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( $("#log").html(), "4,keydown,", "Keydown LEFT (close submenu)"); equal( $("#log").html(), "4,keydown,", "Keydown LEFT (close submenu)");
@ -256,35 +259,35 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
} }
function menukeyboard3() { function menukeyboard3() {
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "2,keydown,", "Keydown PAGE_DOWN"); equal( $("#log").html(), "2,keydown,", "Keydown PAGE_DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( $("#log").html(), "2,keydown,", "Keydown END"); equal( $("#log").html(), "2,keydown,", "Keydown END");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( $("#log").html(), "0,keydown,", "Keydown HOME"); equal( $("#log").html(), "0,keydown,", "Keydown HOME");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)"); equal( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( menukeyboard4, 50 ); setTimeout( menukeyboard4, 50 );
} }
@ -292,7 +295,7 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
function menukeyboard4() { function menukeyboard4() {
equal( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)"); equal( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( $("#log").html(), "Ada,keydown,", "Keydown ENTER (select item)"); equal( $("#log").html(), "Ada,keydown,", "Keydown ENTER (select item)");
@ -304,69 +307,69 @@ test("handle keyboard navigation on menu with scroll and without submenus", func
expect(14); expect(14);
var element = $('#menu3').menu({ var element = $('#menu3').menu({
select: function(event, ui) { select: function(event, ui) {
menu_log($(ui.item[0]).text()); log($(ui.item[0]).text());
}, },
focus: function( event, ui ) { focus: function( event, ui ) {
menu_log($(event.target).find(".ui-state-focus").parent().index()); log($(event.target).find(".ui-state-focus").parent().index());
} }
}); });
menu_log("keydown",true); log("keydown",true);
element.focus(); element.focus();
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 } );
equal( $("#log").html(), "2,1,0,keydown,", "Keydown DOWN"); equal( $("#log").html(), "2,1,0,keydown,", "Keydown DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( $("#log").html(), "0,1,keydown,", "Keydown UP"); equal( $("#log").html(), "0,1,keydown,", "Keydown UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)"); equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN"); equal( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN"); equal( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "10,keydown,", "Keydown PAGE_UP"); equal( $("#log").html(), "10,keydown,", "Keydown PAGE_UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); equal( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( $("#log").html(), "37,keydown,", "Keydown END"); equal( $("#log").html(), "37,keydown,", "Keydown END");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); equal( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( $("#log").html(), "0,keydown,", "Keydown HOME"); equal( $("#log").html(), "0,keydown,", "Keydown HOME");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)"); equal( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER"); equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER");
}); });
@ -375,14 +378,14 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
expect(14); expect(14);
var element = $('#menu4').menu({ var element = $('#menu4').menu({
select: function(event, ui) { select: function(event, ui) {
menu_log($(ui.item[0]).text()); log($(ui.item[0]).text());
}, },
focus: function( event, ui ) { focus: function( event, ui ) {
menu_log($(event.target).find(".ui-state-focus").parent().index()); log($(event.target).find(".ui-state-focus").parent().index());
} }
}); });
menu_log("keydown",true); log("keydown",true);
element.one( "menufocus", function( event, ui ) { element.one( "menufocus", function( event, ui ) {
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 } );
@ -393,16 +396,16 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
function menukeyboard1() { function menukeyboard1() {
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal( $("#log").html(), "0,1,keydown,", "Keydown UP"); equal( $("#log").html(), "0,1,keydown,", "Keydown UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
menu_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 } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
@ -413,7 +416,7 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
} }
function menukeyboard2() { function menukeyboard2() {
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( $("#log").html(), "1,keydown,", "Keydown LEFT (close submenu)"); equal( $("#log").html(), "1,keydown,", "Keydown LEFT (close submenu)");
@ -423,35 +426,35 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
} }
function menukeyboard3() { function menukeyboard3() {
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN"); equal( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN"); equal( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "10,keydown,", "Keydown PAGE_UP"); equal( $("#log").html(), "10,keydown,", "Keydown PAGE_UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); equal( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal( $("#log").html(), "27,keydown,", "Keydown END"); equal( $("#log").html(), "27,keydown,", "Keydown END");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal( $("#log").html(), "0,keydown,", "Keydown HOME"); equal( $("#log").html(), "0,keydown,", "Keydown HOME");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( $("#log").html(), "1,keydown,", "Keydown ESCAPE (close submenu)"); equal( $("#log").html(), "1,keydown,", "Keydown ESCAPE (close submenu)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( menukeyboard4, 50 ); setTimeout( menukeyboard4, 50 );
} }
@ -459,7 +462,7 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
function menukeyboard4() { function menukeyboard4() {
equal( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)"); equal( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER (select item)"); equal( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER (select item)");
@ -471,14 +474,14 @@ asyncTest("handle keyboard navigation and mouse click on menu with disabled item
expect(6); expect(6);
var element = $('#menu6').menu({ var element = $('#menu6').menu({
select: function(event, ui) { select: function(event, ui) {
menu_log($(ui.item[0]).text()); log($(ui.item[0]).text());
}, },
focus: function( event, ui ) { focus: function( event, ui ) {
menu_log($(event.target).find(".ui-state-focus").parent().index()); log($(event.target).find(".ui-state-focus").parent().index());
} }
}); });
menu_log("keydown",true); log("keydown",true);
element.one( "menufocus", function( event, ui ) { element.one( "menufocus", function( event, ui ) {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
@ -489,29 +492,29 @@ asyncTest("handle keyboard navigation and mouse click on menu with disabled item
function menukeyboard1() { function menukeyboard1() {
menu_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.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( $("#log").html(), "4,3,2,keydown,", "Keydown focus disabled item with submenu"); equal( $("#log").html(), "4,3,2,keydown,", "Keydown focus disabled item with submenu");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( function() { setTimeout( function() {
equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect on disabled sub-menu)"); equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect on disabled sub-menu)");
menu_log("keydown",true); log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( function() { setTimeout( function() {
equal( $("#log").html(), "keydown,", "Keydown ENTER (no effect on disabled sub-menu)"); equal( $("#log").html(), "keydown,", "Keydown ENTER (no effect on disabled sub-menu)");
menu_log("click",true); log("click",true);
menu_click( element, "1" ); click( element, "1" );
equal( $("#log").html(), "click,", "Click disabled item (no effect)"); equal( $("#log").html(), "click,", "Click disabled item (no effect)");
start(); start();
}, 50); }, 50);

View File

@ -3,25 +3,28 @@
*/ */
(function($) { (function($) {
var log = TestHelpers.menu.log,
click = TestHelpers.menu.click;
module("menu: methods"); module("menu: methods");
test( "enable/disable", function() { test( "enable/disable", function() {
expect( 3 ); expect( 3 );
var menu = $( "#menu1" ).menu({ var menu = $( "#menu1" ).menu({
select: function(event, ui) { select: function(event, ui) {
menu_log(); log();
} }
}); });
menu.menu("disable"); menu.menu("disable");
ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class"); ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class");
menu_log("click",true); log("click",true);
menu_click(menu,"1"); click(menu,"1");
menu_log("afterclick"); log("afterclick");
menu.menu("enable"); menu.menu("enable");
ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class"); ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class");
menu_log("click"); log("click");
menu_click(menu,"1"); click(menu,"1");
menu_log("afterclick"); log("afterclick");
equal( $("#log").html(), "afterclick,1,click,afterclick,click,", "Click order not valid."); equal( $("#log").html(), "afterclick,1,click,afterclick,click,", "Click order not valid.");
}); });

View File

@ -3,6 +3,9 @@
*/ */
(function($) { (function($) {
var log = TestHelpers.menu.log,
click = TestHelpers.menu.click;
module("menu: options"); module("menu: options");
test( "{ disabled: true }", function() { test( "{ disabled: true }", function() {
@ -10,13 +13,13 @@ test( "{ disabled: true }", function() {
var menu = $( "#menu1" ).menu({ var menu = $( "#menu1" ).menu({
disabled: true, disabled: true,
select: function(event, ui) { select: function(event, ui) {
menu_log(); log();
} }
}); });
ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class"); ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class");
menu_log("click",true); log("click",true);
menu_click(menu,"1"); click(menu,"1");
menu_log("afterclick"); log("afterclick");
equal( $("#log").html(), "afterclick,click,", "Click order not valid."); equal( $("#log").html(), "afterclick,click,", "Click order not valid.");
}); });
@ -25,13 +28,13 @@ test( "{ disabled: false }", function() {
var menu = $( "#menu1" ).menu({ var menu = $( "#menu1" ).menu({
disabled: false, disabled: false,
select: function(event, ui) { select: function(event, ui) {
menu_log(); log();
} }
}); });
ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class"); ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class");
menu_log("click",true); log("click",true);
menu_click(menu,"1"); click(menu,"1");
menu_log("afterclick"); log("afterclick");
equal( $("#log").html(), "afterclick,1,click,", "Click order not valid."); equal( $("#log").html(), "afterclick,1,click,", "Click order not valid.");
}); });

View File

@ -1,4 +1,5 @@
function menu_log( message, clear ) { TestHelpers.menu = {
log: function( message, clear ) {
if ( clear ) { if ( clear ) {
$( "#log" ).empty(); $( "#log" ).empty();
} }
@ -6,9 +7,10 @@ function menu_log( message, clear ) {
message = $( "#log" ).data( "lastItem" ); message = $( "#log" ).data( "lastItem" );
} }
$( "#log" ).prepend( $.trim( message ) + "," ); $( "#log" ).prepend( $.trim( message ) + "," );
} },
function menu_click( menu, item ) { click: function( menu, item ) {
$( "#log" ).data( "lastItem", item ); $( "#log" ).data( "lastItem", item );
menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( "click" ); menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( "click" );
} }
};