2011-10-19 17:47:02 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
|
|
|
module( "selectmenu: core" );
|
|
|
|
|
2011-11-02 20:56:37 +00:00
|
|
|
test("accessibility", function () {
|
2012-05-24 16:54:47 +00:00
|
|
|
var links,
|
2013-01-02 19:28:22 +00:00
|
|
|
element = $("#speed").selectmenu(),
|
2012-02-21 23:09:44 +00:00
|
|
|
button = element.selectmenu("widget"),
|
2012-11-13 20:58:23 +00:00
|
|
|
menu = element.selectmenu("menuWidget");
|
2012-02-21 22:41:00 +00:00
|
|
|
|
2012-02-21 23:09:44 +00:00
|
|
|
button.simulate( "focus" );
|
2012-05-24 16:54:47 +00:00
|
|
|
links = menu.find("li.ui-menu-item a");
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-10-25 18:53:57 +00:00
|
|
|
expect(13 + links.length * 2);
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-03-01 03:11:20 +00:00
|
|
|
equal( button.attr("role"), "combobox", "button link role" );
|
|
|
|
equal( button.attr("aria-haspopup"), "true", "button link aria-haspopup" );
|
|
|
|
equal( button.attr("aria-expanded"), "false", "button link aria-expanded" );
|
|
|
|
equal( button.attr("aria-autocomplete"), "list", "button link aria-autocomplete" );
|
|
|
|
equal( button.attr("aria-owns"), menu.attr("id"), "button link aria-owns" );
|
2012-11-10 00:37:54 +00:00
|
|
|
equal( button.attr("aria-labelledby"), links.eq( element[0].selectedIndex ).attr( "id" ), "button link aria-labelledby" );
|
2012-03-01 03:11:20 +00:00
|
|
|
equal( button.attr("tabindex"), 0, "button link tabindex" );
|
2012-02-21 23:09:44 +00:00
|
|
|
|
2012-03-01 03:11:20 +00:00
|
|
|
equal( menu.attr("role"), "listbox", "menu role" );
|
|
|
|
equal( menu.attr("aria-labelledby"), button.attr("id"), "menu aria-labelledby" );
|
|
|
|
equal( menu.attr("aria-hidden"), "true", "menu aria-hidden" );
|
|
|
|
equal( menu.attr("tabindex"), 0, "menu tabindex" );
|
|
|
|
equal( menu.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "menu aria-activedescendant" );
|
2011-11-02 20:56:37 +00:00
|
|
|
$.each( links, function(index){
|
2012-03-01 03:11:20 +00:00
|
|
|
equal( $(this).attr("role"), "option", "menu link #" + index +" role" );
|
|
|
|
equal( $(this).attr("tabindex"), -1, "menu link #" + index +" tabindex" );
|
2011-11-21 20:54:04 +00:00
|
|
|
});
|
2012-03-01 03:11:20 +00:00
|
|
|
equal( links.eq(element[0].selectedIndex).attr("aria-selected"), "true", "selected menu link aria-selected" );
|
2011-11-21 20:54:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$.each([
|
|
|
|
{
|
|
|
|
type: "default",
|
2011-11-21 23:35:27 +00:00
|
|
|
selector: "#speed"
|
2011-11-21 20:54:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "optgroups",
|
2011-11-21 23:35:27 +00:00
|
|
|
selector: "#files"
|
2011-11-21 20:54:04 +00:00
|
|
|
}
|
|
|
|
], function( i, settings ) {
|
2012-07-16 19:31:18 +00:00
|
|
|
test("state synchronization - after keydown - " + settings.type, function () {
|
2012-10-25 20:24:50 +00:00
|
|
|
expect(5);
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-05-24 16:54:47 +00:00
|
|
|
var links,
|
|
|
|
element = $(settings.selector).selectmenu(),
|
2012-02-21 23:09:44 +00:00
|
|
|
button = element.selectmenu("widget"),
|
|
|
|
menu = element.selectmenu("menuWidget"),
|
2012-01-13 18:49:42 +00:00
|
|
|
selected = element.find("option:selected");
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-05-24 16:54:47 +00:00
|
|
|
button.simulate( "focus" );
|
|
|
|
links = menu.find("li.ui-menu-item a");
|
2012-02-21 22:41:00 +00:00
|
|
|
|
2012-02-21 23:09:44 +00:00
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2012-07-16 19:38:47 +00:00
|
|
|
equal( menu.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "menu aria-activedescendant" );
|
|
|
|
equal( links.eq(element[0].selectedIndex).attr("aria-selected"), "true", "selected menu link aria-selected" );
|
2012-10-25 20:24:50 +00:00
|
|
|
equal( button.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "button aria-activedescendant" );
|
2012-07-16 19:38:47 +00:00
|
|
|
equal( element.find("option:selected").val(), selected.next("option").val() , "original select state" );
|
|
|
|
equal( button.text(), selected.next("option").text(), "button text" );
|
2012-07-16 19:31:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("state synchronization - after click - " + settings.type, function () {
|
2012-10-25 20:24:50 +00:00
|
|
|
expect(5);
|
2012-07-16 19:31:18 +00:00
|
|
|
|
|
|
|
var links,
|
|
|
|
element = $(settings.selector).selectmenu(),
|
|
|
|
button = element.selectmenu("widget"),
|
2012-11-13 20:58:23 +00:00
|
|
|
menu = element.selectmenu("menuWidget");
|
2012-07-16 19:31:18 +00:00
|
|
|
|
|
|
|
button.simulate( "focus" );
|
|
|
|
links = menu.find("li.ui-menu-item a");
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-03-01 03:09:13 +00:00
|
|
|
button.simulate( "click" );
|
|
|
|
menu.find("a").last().simulate( "mouseover" ).trigger( "click" );
|
2012-07-16 19:38:47 +00:00
|
|
|
equal( menu.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "menu aria-activedescendant" );
|
|
|
|
equal( links.eq(element[0].selectedIndex).attr("aria-selected"), "true", "selected menu link aria-selected" );
|
2012-10-25 20:24:50 +00:00
|
|
|
equal( button.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "button aria-activedescendant" );
|
2012-07-16 19:38:47 +00:00
|
|
|
equal( element.find("option:selected").val(), element.find("option").last().val(), "original select state" );
|
|
|
|
equal( button.text(), element.find("option").last().text(), "button text" );
|
2011-11-02 20:56:37 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-10-19 17:47:02 +00:00
|
|
|
})( jQuery );
|