From 4f15e66f5373170caf307237b9a8b2c505ae3dbf Mon Sep 17 00:00:00 2001 From: kborchers Date: Sun, 22 Jan 2012 11:26:41 -0600 Subject: [PATCH] Menu: Added unit tests for the enable, disable and refresh methods as well as the disabled option. Cleaned up some variable names in unit tests. --- tests/unit/menu/menu_core.js | 28 ++++++++++++++-------------- tests/unit/menu/menu_events.js | 12 ++++++------ tests/unit/menu/menu_methods.js | 30 ++++++++++++++++++++++++++++++ tests/unit/menu/menu_options.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 20 deletions(-) diff --git a/tests/unit/menu/menu_core.js b/tests/unit/menu/menu_core.js index c0feae75c..bccf4a1f2 100644 --- a/tests/unit/menu/menu_core.js +++ b/tests/unit/menu/menu_core.js @@ -9,27 +9,27 @@ module("menu: core"); test("accessibility", function () { expect(5); - var ac = $('#menu1').menu(); + var menu = $('#menu1').menu(); var item0 = $("li:eq(0) a"); - ok( ac.hasClass("ui-menu ui-widget ui-widget-content ui-corner-all"), "menu class"); - equals( ac.attr("role"), "menu", "main role"); - ok( !ac.attr("aria-activedescendant"), "aria attribute not yet active"); + ok( menu.hasClass("ui-menu ui-widget ui-widget-content ui-corner-all"), "menu class"); + equals( menu.attr("role"), "menu", "main role"); + ok( !menu.attr("aria-activedescendant"), "aria attribute not yet active"); - var item = ac.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end(); - ac.menu( "focus", $.Event(), item ); - equals( ac.attr("aria-activedescendant"), "xid", "aria attribute, id from dom"); + var item = menu.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end(); + menu.menu( "focus", $.Event(), item ); + equals( menu.attr("aria-activedescendant"), "xid", "aria attribute, id from dom"); - var item = ac.find( "li:last" ); - ac.menu( "focus", $.Event(), item ); - equals( ac.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id"); + var item = menu.find( "li:last" ); + menu.menu( "focus", $.Event(), item ); + equals( menu.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id"); }); test("items class and role", function () { - var ac = $('#menu1').menu(); - expect(1 + 5 * $("li",ac).length); - ok( ($("li",ac).length > 0 ), "number of menu items"); - $("li",ac).each(function(item) { + var menu = $('#menu1').menu(); + expect(1 + 5 * $("li",menu).length); + 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"); equals( $(this).attr("role"), "presentation", "menu item ("+ item + ") role"); equals( $("a", this).attr("role"), "menuitem", "menu item ("+ item + ") role"); diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js index 9e68e0c67..8df43fa21 100644 --- a/tests/unit/menu/menu_events.js +++ b/tests/unit/menu/menu_events.js @@ -7,7 +7,7 @@ module("menu: events"); test("handle click on menu", function() { expect(1); - var ac = $('#menu1').menu({ + var menu = $('#menu1').menu({ select: function(event, ui) { menu_log(); } @@ -15,15 +15,15 @@ test("handle click on menu", function() { menu_log("click",true); menu_click($('#menu1'),"1"); menu_log("afterclick"); - menu_click( ac,"2"); + menu_click( menu,"2"); menu_click($('#menu1'),"3"); - menu_click( ac,"1"); + menu_click( menu,"1"); equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); }); test("handle click on custom item menu", function() { expect(1); - var ac = $('#menu5').menu({ + var menu = $('#menu5').menu({ select: function(event, ui) { menu_log(); }, @@ -32,9 +32,9 @@ test("handle click on custom item menu", function() { menu_log("click",true); menu_click($('#menu5'),"1"); menu_log("afterclick"); - menu_click( ac,"2"); + menu_click( menu,"2"); menu_click($('#menu5'),"3"); - menu_click( ac,"1"); + menu_click( menu,"1"); equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); }); diff --git a/tests/unit/menu/menu_methods.js b/tests/unit/menu/menu_methods.js index 0ecaf7328..3bcab3361 100644 --- a/tests/unit/menu/menu_methods.js +++ b/tests/unit/menu/menu_methods.js @@ -5,6 +5,36 @@ module("menu: methods"); +test( "enable/disable", function() { + expect( 3 ); + var menu = $( "#menu1" ).menu({ + select: function(event, ui) { + menu_log(); + } + }); + menu.menu("disable"); + ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class"); + menu_log("click",true); + menu_click(menu,"1"); + menu_log("afterclick"); + menu.menu("enable"); + ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class"); + menu_log("click"); + menu_click(menu,"1"); + menu_log("afterclick"); + equals( $("#log").html(), "afterclick,1,click,afterclick,click,", "Click order not valid."); +}); + +test( "refresh", function() { + expect( 3 ); + var menu = $( "#menu1" ).menu(); + equals(menu.find(".ui-menu-item").length,5,"Incorrect number of menu items"); + menu.append("
  • test item
  • ").menu("refresh"); + equals(menu.find(".ui-menu-item").length,6,"Incorrect number of menu items"); + menu.find(".ui-menu-item:last").remove().end().menu("refresh"); + equals(menu.find(".ui-menu-item").length,5,"Incorrect number of menu items"); +}); + test("destroy", function() { domEqual("#menu1", function() { $("#menu1").menu().menu("destroy"); diff --git a/tests/unit/menu/menu_options.js b/tests/unit/menu/menu_options.js index 03822fd74..479aab0d1 100644 --- a/tests/unit/menu/menu_options.js +++ b/tests/unit/menu/menu_options.js @@ -5,6 +5,34 @@ module("menu: options"); +test( "{ disabled: true }", function() { + expect( 2 ); + var menu = $( "#menu1" ).menu({ + disabled: true, + select: function(event, ui) { + menu_log(); + } + }); + ok(menu.is(".ui-state-disabled"),"Missing ui-state-disabled class"); + menu_log("click",true); + menu_click(menu,"1"); + menu_log("afterclick"); + equals( $("#log").html(), "afterclick,click,", "Click order not valid."); +}); +test( "{ disabled: false }", function() { + expect( 2 ); + var menu = $( "#menu1" ).menu({ + disabled: false, + select: function(event, ui) { + menu_log(); + } + }); + ok(menu.not(".ui-state-disabled"),"Has ui-state-disabled class"); + menu_log("click",true); + menu_click(menu,"1"); + menu_log("afterclick"); + equals( $("#log").html(), "afterclick,1,click,", "Click order not valid."); +}); })(jQuery);