mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
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.
This commit is contained in:
parent
8c5c6e0a32
commit
4f15e66f53
@ -9,27 +9,27 @@ module("menu: core");
|
|||||||
|
|
||||||
test("accessibility", function () {
|
test("accessibility", function () {
|
||||||
expect(5);
|
expect(5);
|
||||||
var ac = $('#menu1').menu();
|
var menu = $('#menu1').menu();
|
||||||
var item0 = $("li:eq(0) a");
|
var item0 = $("li:eq(0) a");
|
||||||
|
|
||||||
ok( ac.hasClass("ui-menu ui-widget ui-widget-content ui-corner-all"), "menu class");
|
ok( menu.hasClass("ui-menu ui-widget ui-widget-content ui-corner-all"), "menu class");
|
||||||
equals( ac.attr("role"), "menu", "main role");
|
equals( menu.attr("role"), "menu", "main role");
|
||||||
ok( !ac.attr("aria-activedescendant"), "aria attribute not yet active");
|
ok( !menu.attr("aria-activedescendant"), "aria attribute not yet active");
|
||||||
|
|
||||||
var item = ac.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end();
|
var item = menu.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end();
|
||||||
ac.menu( "focus", $.Event(), item );
|
menu.menu( "focus", $.Event(), item );
|
||||||
equals( ac.attr("aria-activedescendant"), "xid", "aria attribute, id from dom");
|
equals( menu.attr("aria-activedescendant"), "xid", "aria attribute, id from dom");
|
||||||
|
|
||||||
var item = ac.find( "li:last" );
|
var item = menu.find( "li:last" );
|
||||||
ac.menu( "focus", $.Event(), item );
|
menu.menu( "focus", $.Event(), item );
|
||||||
equals( ac.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id");
|
equals( menu.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("items class and role", function () {
|
test("items class and role", function () {
|
||||||
var ac = $('#menu1').menu();
|
var menu = $('#menu1').menu();
|
||||||
expect(1 + 5 * $("li",ac).length);
|
expect(1 + 5 * $("li",menu).length);
|
||||||
ok( ($("li",ac).length > 0 ), "number of menu items");
|
ok( ($("li",menu).length > 0 ), "number of menu items");
|
||||||
$("li",ac).each(function(item) {
|
$("li",menu).each(function(item) {
|
||||||
ok( $(this).hasClass("ui-menu-item"), "menu item ("+ item + ") class for item");
|
ok( $(this).hasClass("ui-menu-item"), "menu item ("+ item + ") class for item");
|
||||||
equals( $(this).attr("role"), "presentation", "menu item ("+ item + ") role");
|
equals( $(this).attr("role"), "presentation", "menu item ("+ item + ") role");
|
||||||
equals( $("a", this).attr("role"), "menuitem", "menu item ("+ item + ") role");
|
equals( $("a", this).attr("role"), "menuitem", "menu item ("+ item + ") role");
|
||||||
|
@ -7,7 +7,7 @@ module("menu: events");
|
|||||||
|
|
||||||
test("handle click on menu", function() {
|
test("handle click on menu", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
var ac = $('#menu1').menu({
|
var menu = $('#menu1').menu({
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
menu_log();
|
menu_log();
|
||||||
}
|
}
|
||||||
@ -15,15 +15,15 @@ test("handle click on menu", function() {
|
|||||||
menu_log("click",true);
|
menu_log("click",true);
|
||||||
menu_click($('#menu1'),"1");
|
menu_click($('#menu1'),"1");
|
||||||
menu_log("afterclick");
|
menu_log("afterclick");
|
||||||
menu_click( ac,"2");
|
menu_click( menu,"2");
|
||||||
menu_click($('#menu1'),"3");
|
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.");
|
equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("handle click on custom item menu", function() {
|
test("handle click on custom item menu", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
var ac = $('#menu5').menu({
|
var menu = $('#menu5').menu({
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
menu_log();
|
menu_log();
|
||||||
},
|
},
|
||||||
@ -32,9 +32,9 @@ test("handle click on custom item menu", function() {
|
|||||||
menu_log("click",true);
|
menu_log("click",true);
|
||||||
menu_click($('#menu5'),"1");
|
menu_click($('#menu5'),"1");
|
||||||
menu_log("afterclick");
|
menu_log("afterclick");
|
||||||
menu_click( ac,"2");
|
menu_click( menu,"2");
|
||||||
menu_click($('#menu5'),"3");
|
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.");
|
equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,6 +5,36 @@
|
|||||||
|
|
||||||
module("menu: methods");
|
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() {
|
test("destroy", function() {
|
||||||
domEqual("#menu1", function() {
|
domEqual("#menu1", function() {
|
||||||
$("#menu1").menu().menu("destroy");
|
$("#menu1").menu().menu("destroy");
|
||||||
|
@ -5,6 +5,34 @@
|
|||||||
|
|
||||||
module("menu: options");
|
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);
|
})(jQuery);
|
||||||
|
Loading…
Reference in New Issue
Block a user