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");
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();
},
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.");
});
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");
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);