2011-10-19 17:47:02 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
|
|
|
module( "selectmenu: core" );
|
|
|
|
|
2013-05-07 20:13:57 +00:00
|
|
|
asyncTest( "accessibility", function() {
|
2012-05-24 16:54:47 +00:00
|
|
|
var links,
|
2013-02-13 22:58:14 +00:00
|
|
|
element = $( "#speed" ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2012-02-21 22:41:00 +00:00
|
|
|
|
2012-02-21 23:09:44 +00:00
|
|
|
button.simulate( "focus" );
|
2013-10-09 23:01:41 +00:00
|
|
|
links = menu.find( "li.ui-menu-item" );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2013-05-07 20:13:57 +00:00
|
|
|
expect( 12 + links.length * 2 );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2013-04-30 22:33:37 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
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" );
|
|
|
|
equal(
|
|
|
|
button.attr( "aria-labelledby" ),
|
|
|
|
links.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
|
|
|
"button link aria-labelledby"
|
|
|
|
);
|
|
|
|
equal( button.attr( "tabindex" ), 0, "button link tabindex" );
|
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
$.each( links, function( index ){
|
|
|
|
equal( $( this ).attr( "role" ), "option", "menu link #" + index +" role" );
|
|
|
|
equal( $( this ).attr( "tabindex" ), -1, "menu link #" + index +" tabindex" );
|
|
|
|
});
|
|
|
|
start();
|
2013-05-07 20:17:41 +00:00
|
|
|
});
|
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 ) {
|
2013-04-30 22:33:37 +00:00
|
|
|
asyncTest( "state synchronization - after keydown on button - " + settings.type, function () {
|
2013-03-09 12:30:35 +00:00
|
|
|
expect( 4 );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-05-24 16:54:47 +00:00
|
|
|
var links,
|
2013-02-13 22:58:14 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" ),
|
|
|
|
selected = element.find( "option:selected" );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-05-24 16:54:47 +00:00
|
|
|
button.simulate( "focus" );
|
2013-04-30 22:33:37 +00:00
|
|
|
setTimeout(function() {
|
2013-10-09 23:01:41 +00:00
|
|
|
links = menu.find("li.ui-menu-item");
|
2013-04-30 22:33:37 +00:00
|
|
|
|
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
|
|
equal(
|
|
|
|
menu.attr( "aria-activedescendant" ),
|
|
|
|
links.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
|
|
|
"menu aria-activedescendant"
|
|
|
|
);
|
|
|
|
equal(
|
|
|
|
button.attr( "aria-activedescendant" ),
|
|
|
|
links.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
|
|
|
"button aria-activedescendant"
|
|
|
|
);
|
|
|
|
equal(
|
|
|
|
element.find( "option:selected" ).val(),
|
|
|
|
selected.next( "option" ).val() ,
|
|
|
|
"original select state"
|
|
|
|
);
|
|
|
|
equal( button.text(), selected.next( "option" ).text(), "button text" );
|
|
|
|
start();
|
|
|
|
}, 1 );
|
2012-07-16 19:31:18 +00:00
|
|
|
});
|
|
|
|
|
2013-05-07 20:13:57 +00:00
|
|
|
asyncTest( "state synchronization - after click on item - " + settings.type, function () {
|
|
|
|
expect( 4 );
|
2012-07-16 19:31:18 +00:00
|
|
|
|
|
|
|
var links,
|
2013-02-13 22:58:14 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2012-07-16 19:31:18 +00:00
|
|
|
|
|
|
|
button.simulate( "focus" );
|
2013-04-30 22:33:37 +00:00
|
|
|
setTimeout(function() {
|
2013-10-09 23:01:41 +00:00
|
|
|
links = menu.find("li.ui-menu-item");
|
2013-04-30 22:33:37 +00:00
|
|
|
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-10-09 23:01:41 +00:00
|
|
|
menu.find( "li" ).last().simulate( "mouseover" ).trigger( "click" );
|
2013-04-30 22:33:37 +00:00
|
|
|
equal(
|
|
|
|
menu.attr( "aria-activedescendant" ),
|
|
|
|
links.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
|
|
|
"menu aria-activedescendant"
|
|
|
|
);
|
|
|
|
equal(
|
|
|
|
button.attr( "aria-activedescendant" ),
|
|
|
|
links.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
|
|
|
"button aria-activedescendant"
|
|
|
|
);
|
|
|
|
equal(
|
|
|
|
element.find( "option:selected" ).val(),
|
|
|
|
element.find( "option" ).last().val(),
|
|
|
|
"original select state"
|
|
|
|
);
|
|
|
|
equal( button.text(), element.find( "option" ).last().text(), "button text" );
|
|
|
|
start();
|
|
|
|
}, 1 );
|
2011-11-02 20:56:37 +00:00
|
|
|
});
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2013-04-30 22:33:37 +00:00
|
|
|
asyncTest( "state synchronization - after focus item and keydown on button - " + settings.type, function () {
|
2013-05-07 20:13:57 +00:00
|
|
|
expect( 4 );
|
2013-02-13 21:18:12 +00:00
|
|
|
|
|
|
|
var links,
|
2013-02-13 22:58:14 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" ),
|
|
|
|
options = element.find( "option" );
|
2013-02-13 21:18:12 +00:00
|
|
|
|
|
|
|
// init menu
|
2013-02-13 22:58:14 +00:00
|
|
|
button.simulate( "focus" );
|
|
|
|
|
2013-04-30 22:33:37 +00:00
|
|
|
setTimeout(function() {
|
2013-10-09 23:01:41 +00:00
|
|
|
links = menu.find( "li.ui-menu-item" );
|
2013-04-30 22:33:37 +00:00
|
|
|
// open menu and click first item
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-04-30 22:33:37 +00:00
|
|
|
links.first().simulate( "mouseover" ).trigger( "click" );
|
|
|
|
// open menu again and hover item
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-05-07 20:13:57 +00:00
|
|
|
links.eq( 3 ).simulate( "mouseover" );
|
2013-04-30 22:33:37 +00:00
|
|
|
// close and use keyboard control on button
|
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
button.simulate( "focus" );
|
|
|
|
setTimeout(function() {
|
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
|
|
|
|
|
|
equal( menu.attr( "aria-activedescendant" ), links.eq( 1 ).attr( "id" ), "menu aria-activedescendant" );
|
|
|
|
equal( button.attr( "aria-activedescendant" ), links.eq( 1 ).attr( "id" ), "button aria-activedescendant" );
|
|
|
|
equal( element.find( "option:selected" ).val(), options.eq( 1 ).val() , "original select state" );
|
|
|
|
equal( button.text(), options.eq( 1 ).text(), "button text" );
|
|
|
|
start();
|
|
|
|
}, 1 );
|
|
|
|
}, 1 );
|
2013-02-13 21:18:12 +00:00
|
|
|
});
|
2013-07-01 20:59:43 +00:00
|
|
|
|
|
|
|
asyncTest( "item looping - " + settings.type, function () {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var links,
|
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
2013-07-01 21:08:55 +00:00
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2013-07-01 20:59:43 +00:00
|
|
|
|
|
|
|
// init menu
|
|
|
|
button.simulate( "focus" );
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2013-10-09 23:01:41 +00:00
|
|
|
links = menu.find( "li.ui-menu-item" );
|
2013-07-01 20:59:43 +00:00
|
|
|
|
|
|
|
button.trigger( "click" );
|
|
|
|
links.first().simulate( "mouseover" ).trigger( "click" );
|
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
equal( element[ 0 ].selectedIndex, 0, "No looping beyond first item" );
|
|
|
|
|
|
|
|
button.trigger( "click" );
|
|
|
|
links.last().simulate( "mouseover" ).trigger( "click" );
|
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
|
|
equal( element[ 0 ].selectedIndex + 1, links.length, "No looping behind last item" );
|
|
|
|
start();
|
|
|
|
}, 1 );
|
|
|
|
});
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
asyncTest( "item focus and active state - " + settings.type, function () {
|
|
|
|
expect( 8 );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
|
|
|
var element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" ),
|
2013-09-04 19:34:20 +00:00
|
|
|
links, focusedItem, activeItem;
|
2013-08-02 23:16:42 +00:00
|
|
|
|
|
|
|
// init menu
|
|
|
|
button.simulate( "focus" );
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2013-10-09 23:01:41 +00:00
|
|
|
links = menu.find( "li.ui-menu-item" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
|
|
|
button.trigger( "click" );
|
2013-09-04 19:34:20 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
checkItemClasses();
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
links.eq( 3 ).simulate( "mouseover" ).trigger( "click" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
button.trigger( "click" );
|
|
|
|
links.eq( 2 ).simulate( "mouseover" );
|
|
|
|
$( document ).trigger( "click" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
button.trigger( "click" );
|
|
|
|
links.eq( 1 ).simulate( "mouseover" );
|
|
|
|
$( document ).trigger( "click" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
button.trigger( "click" );
|
|
|
|
setTimeout(function() {
|
|
|
|
checkItemClasses();
|
|
|
|
start();
|
|
|
|
}, 350 );
|
|
|
|
}, 350 );
|
2013-08-02 23:16:42 +00:00
|
|
|
}, 1 );
|
2013-09-04 19:34:20 +00:00
|
|
|
|
|
|
|
function checkItemClasses() {
|
2013-10-09 23:01:41 +00:00
|
|
|
focusedItem = menu.find( "li.ui-state-focus" );
|
2013-09-04 19:34:20 +00:00
|
|
|
equal( focusedItem.length, 1, "only one item has ui-state-focus class" );
|
|
|
|
equal( focusedItem.attr( "id" ), links.eq( element[ 0 ].selectedIndex ).attr( "id" ), "selected item has ui-state-focus class" );
|
|
|
|
|
2013-10-09 23:01:41 +00:00
|
|
|
activeItem = menu.find( "li.ui-state-active" );
|
2013-09-04 19:34:20 +00:00
|
|
|
equal( activeItem.length, 1, "only one item has ui-state-active class" );
|
|
|
|
equal( activeItem.attr( "id" ), links.eq( element[ 0 ].selectedIndex ).attr( "id" ), "selected item has ui-state-active class" );
|
|
|
|
}
|
2013-08-02 23:16:42 +00:00
|
|
|
});
|
2013-12-18 18:00:32 +00:00
|
|
|
|
|
|
|
asyncTest( "empty option - " + settings.type, function () {
|
|
|
|
expect( 7 );
|
|
|
|
|
|
|
|
var element = $( settings.selector ),
|
|
|
|
button, menu, links, link;
|
|
|
|
|
|
|
|
element.find( "option" ).first().text( "" );
|
|
|
|
element.selectmenu();
|
|
|
|
button = element.selectmenu( "widget" );
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
|
|
|
|
|
|
|
// init menu
|
|
|
|
button.simulate( "focus" );
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
links = menu.find( "li:not(.ui-selectmenu-optgroup)" );
|
|
|
|
link = links.first();
|
|
|
|
|
|
|
|
button.trigger( "click" );
|
|
|
|
|
|
|
|
equal( links.length, element.find( "option" ).length, "correct amount of list elements" );
|
|
|
|
ok( link.outerHeight() > 10, "empty item seems to have reasonable height" );
|
|
|
|
ok( link.attr( "id" ), "empty item has id attribute" );
|
|
|
|
ok( link.hasClass( "ui-menu-item" ), "empty item has ui-menu-item class" );
|
|
|
|
ok( !link.hasClass( "ui-menu-divider" ), "empty item has not ui-menu-divider class" );
|
|
|
|
equal( link.attr( "tabindex" ), -1, "empty item has tabindex" );
|
|
|
|
equal( link.attr( "role" ), "option", "empty item has role option" );
|
|
|
|
|
|
|
|
start();
|
|
|
|
}, 1 );
|
|
|
|
});
|
2011-11-02 20:56:37 +00:00
|
|
|
});
|
|
|
|
|
2011-10-19 17:47:02 +00:00
|
|
|
})( jQuery );
|