Merge branch 'menu' of http://github.com/dominiquevincent/jquery-ui into vincent/menu

This commit is contained in:
jzaefferer 2010-06-18 10:28:57 +02:00
commit 921e40faff
7 changed files with 178 additions and 0 deletions

74
tests/unit/menu/menu.html Normal file
View File

@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery UI Menu Test Suite</title>
<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css" type="text/css" title="ui-theme" />
<script type="text/javascript" src="../../../jquery-1.4.2.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../../../ui/jquery.ui.menu.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
<script type="text/javascript" src="../../../external/qunit.js"></script>
<script type="text/javascript" src="../../jquery.simulate.js"></script>
<script type="text/javascript" src="../testsuite.js"></script>
<script type="text/javascript">
function log(message,clear) {
if (clear && clear === true) {
$("#log").html("");
}
if ( message === undefined ) {
message = $("#log").data("lastItem");
}
$("#log").prepend( message + "," );
}
function clickMenu(menu,item) {
$("#log").data("lastItem",item);
$('li:eq(' + item + ') a',menu).trigger("click");
}
</script>
<script type="text/javascript" src="menu_core.js"></script>
<script type="text/javascript" src="menu_defaults.js"></script>
<script type="text/javascript" src="menu_events.js"></script>
<script type="text/javascript" src="menu_methods.js"></script>
<script type="text/javascript" src="menu_options.js"></script>
<script type="text/javascript" src="menu_tickets.js"></script>
<style>
#main { font-size: 10pt; font-family: 'trebuchet ms', verdana, arial; }
#list, #list1 *, #navigation, #navigation * { margin: 0; padding: 0; font-size: 12px; }
.mainOnMoon {position: absolute; top: -10000px; left: -10000px;}
</style>
</head>
<body>
<h1 id="qunit-header">jQuery UI Menu Test Suite</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>
<div id="main" class="mainOnMoon">
<ul id="menu1">
<li><a href="#">Aberdeen</a></li>
<li><a href="#">Ada</a></li>
<li><a href="#">Adamsville</a></li>
<li><a href="#">Addyston</a></li>
<li><a href="#">Adelphi</a></li>
</ul>
<div id="log"></div>
</div>
</body>
</html>

View File

@ -0,0 +1,32 @@
/*
* menu_core.js
*/
(function($) {
module("menu: core");
test("accessibility", function () {
expect(3);
var ac = $('#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"), "listbox", "main role");
equals( ac.attr("aria-activedescendant"), "ui-active-menuitem", "aria attribute");
});
test("items class and role", function () {
var ac = $('#menu1').menu();
expect(1 + 4 * $("li",ac).length);
ok( ($("li",ac).length > 0 ), "number of menu items");
$("li",ac).each(function(item) {
ok( $(this).hasClass("ui-menu-item"), "menu item ("+ item + ") class for item");
equals( $(this).attr("role"), "menuitem", "menu item ("+ item + ") role");
ok( $("a",this).hasClass("ui-corner-all"), "a element class for menu item ("+ item + ") ");
equals( $("a",this).attr("tabindex"), "-1", "a element tabindex for menu item ("+ item + ") ");
});
});
})(jQuery);

View File

@ -0,0 +1,11 @@
/*
* menu_defaults.js
*/
var menu_defaults = {
disabled: false,
navigationFilter: function() {}
};
commonWidgetTests('menu', { defaults: menu_defaults });

View File

@ -0,0 +1,24 @@
/*
* menu_events.js
*/
(function($) {
module("menu: events");
test("handle click on menu", function() {
expect(1);
var ac = $('#menu1').menu({
select: function(event, ui) {
log();
}
});
log("click",true);
clickMenu($('#menu1'),"1");
log("afterclick");
clickMenu( ac,"2");
clickMenu($('#menu1'),"3");
clickMenu( ac,"1");
equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
});
})(jQuery);

View File

@ -0,0 +1,19 @@
/*
* menu_methods.js
*/
(function($) {
module("menu: methods");
test("destroy", function() {
var beforeHtml = $("#menu1").find("div").css("font-style", "normal").end().parent().html();
var afterHtml = $("#menu1").menu().menu("destroy").parent().html();
// Opera 9 outputs role="" instead of removing the attribute like everyone else
if ($.browser.opera) {
afterHtml = afterHtml.replace(/ role=""/g, "");
}
equal( afterHtml, beforeHtml );
});
})(jQuery);

View File

@ -0,0 +1,10 @@
/*
* menu_options.js
*/
(function($) {
module("menu: options");
})(jQuery);

View File

@ -0,0 +1,8 @@
/*
* menu_tickets.js
*/
(function($) {
module("menu: tickets");
})(jQuery);