Skip to content
Permalink
Browse files

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.
  • Loading branch information
kborchers committed Jan 22, 2012
1 parent 8c5c6e0 commit 4f15e66f5373170caf307237b9a8b2c505ae3dbf
Showing with 78 additions and 20 deletions.
  1. +14 −14 tests/unit/menu/menu_core.js
  2. +6 −6 tests/unit/menu/menu_events.js
  3. +30 −0 tests/unit/menu/menu_methods.js
  4. +28 −0 tests/unit/menu/menu_options.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");
@@ -7,23 +7,23 @@ 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();
}
});
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.");
});

@@ -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("<li><a href='#'>test item</a></li>").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");
@@ -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);

0 comments on commit 4f15e66

Please sign in to comment.
You can’t perform that action at this time.