diff options
author | Felix Nagel <info@felixnagel.com> | 2013-05-01 00:33:37 +0200 |
---|---|---|
committer | Felix Nagel <info@felixnagel.com> | 2013-05-01 00:33:37 +0200 |
commit | adcfa63ac4f4541729316dcbc89359486db4486a (patch) | |
tree | 846e8bddbe03216ccfbea1eee77ccd562cd650ee /tests/unit/selectmenu | |
parent | 5e06985fb42a9ef1c15db0f0377b9add6b9ded22 (diff) | |
download | jquery-ui-adcfa63ac4f4541729316dcbc89359486db4486a.tar.gz jquery-ui-adcfa63ac4f4541729316dcbc89359486db4486a.zip |
Selectmenu Tests: use asyncTest when working with focus events
Diffstat (limited to 'tests/unit/selectmenu')
-rw-r--r-- | tests/unit/selectmenu/selectmenu_core.js | 181 |
1 files changed, 98 insertions, 83 deletions
diff --git a/tests/unit/selectmenu/selectmenu_core.js b/tests/unit/selectmenu/selectmenu_core.js index 6c9ce5221..9e1ec6e1d 100644 --- a/tests/unit/selectmenu/selectmenu_core.js +++ b/tests/unit/selectmenu/selectmenu_core.js @@ -2,7 +2,7 @@ module( "selectmenu: core" ); -test("accessibility", function () { +asyncTest("accessibility", function () { var links, element = $( "#speed" ).selectmenu(), button = element.selectmenu( "widget" ), @@ -13,31 +13,34 @@ test("accessibility", function () { expect(12 + links.length * 2); - 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" ); - }); + 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(); + }, 1 ); }); @@ -51,7 +54,7 @@ $.each([ selector: "#files" } ], function( i, settings ) { - test( "state synchronization - after keydown on button - " + settings.type, function () { + asyncTest( "state synchronization - after keydown on button - " + settings.type, function () { expect( 4 ); var links, @@ -61,28 +64,31 @@ $.each([ selected = element.find( "option:selected" ); button.simulate( "focus" ); - links = menu.find("li.ui-menu-item a"); - - 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" ); + setTimeout(function() { + links = menu.find("li.ui-menu-item a"); + + 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 ); }); - test("state synchronization - after click on item - " + settings.type, function () { + asyncTest("state synchronization - after click on item - " + settings.type, function () { expect(4); var links, @@ -91,29 +97,32 @@ $.each([ menu = element.selectmenu( "menuWidget" ); button.simulate( "focus" ); - links = menu.find("li.ui-menu-item a"); - - button.simulate( "click" ); - menu.find( "a" ).last().simulate( "mouseover" ).trigger( "click" ); - 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" ); + setTimeout(function() { + links = menu.find("li.ui-menu-item a"); + + button.simulate( "click" ); + menu.find( "a" ).last().simulate( "mouseover" ).trigger( "click" ); + 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 ); }); - test( "state synchronization - after focus item and keydown on button - " + settings.type, function () { + asyncTest( "state synchronization - after focus item and keydown on button - " + settings.type, function () { expect(4); var links, @@ -124,22 +133,28 @@ $.each([ // init menu button.simulate( "focus" ); - links = menu.find( "li.ui-menu-item a" ); - // open menu and click first item - button.simulate( "click" ); - links.first().simulate( "mouseover" ).trigger( "click" ); - // open menu again and hover item - button.simulate( "click" ); - links.eq(3).simulate( "mouseover" ); - // close and use keyboard control on button - button.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - button.simulate( "focus" ); - 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" ); + setTimeout(function() { + links = menu.find( "li.ui-menu-item a" ); + // open menu and click first item + button.simulate( "click" ); + links.first().simulate( "mouseover" ).trigger( "click" ); + // open menu again and hover item + button.simulate( "click" ); + links.eq(3).simulate( "mouseover" ); + // 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 ); }); }); |