From 890a45a22c7b7a8ae5e7ff64cfd44008bb2cdb88 Mon Sep 17 00:00:00 2001 From: kborchers Date: Wed, 18 Apr 2012 21:29:39 -0500 Subject: [PATCH] Menu: Add unit tests for testing disabled items --- tests/unit/menu/menu.html | 16 +++++++++++ tests/unit/menu/menu_events.js | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/tests/unit/menu/menu.html b/tests/unit/menu/menu.html index 76f4a7a31..9a598ec8d 100644 --- a/tests/unit/menu/menu.html +++ b/tests/unit/menu/menu.html @@ -251,6 +251,22 @@ + +
diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js index bee6fcfa6..7d127c431 100644 --- a/tests/unit/menu/menu_events.js +++ b/tests/unit/menu/menu_events.js @@ -466,4 +466,56 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu } }); +asyncTest("handle keyboard navigation and mouse click on menu with disabled items", function() { + expect(6); + var element = $('#menu6').menu({ + select: function(event, ui) { + menu_log($(ui.item[0]).text()); + }, + focus: function( event, ui ) { + menu_log($(event.target).find(".ui-state-focus").parent().index()); + } + }); + + menu_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"); + setTimeout( menukeyboard1, 50 ); + }); + element.focus(); + + + function menukeyboard1() { + menu_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"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); + equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); + + setTimeout( function() { + equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect on disabled sub-menu)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + + setTimeout( function() { + equal( $("#log").html(), "keydown,", "Keydown ENTER (no effect on disabled sub-menu)"); + menu_log("click",true); + menu_click( element, "1" ); + equal( $("#log").html(), "click,", "Click disabled item (no effect)"); + start(); + }, 50); + }, 50); + } +}); + })(jQuery);