diff options
author | Dylan Barrell <dylan@barrell.com> | 2013-12-22 11:36:43 -0500 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2014-01-14 11:09:49 +0100 |
commit | 0b28d597fe1857590c9719c8b41f00e77967f7d7 (patch) | |
tree | 0cb11a3b5469af8222729742926726e30a25a9a5 /tests/unit/autocomplete | |
parent | 6ec452cc63313ec03f58942ce896036c7a2fcf3f (diff) | |
download | jquery-ui-0b28d597fe1857590c9719c8b41f00e77967f7d7.tar.gz jquery-ui-0b28d597fe1857590c9719c8b41f00e77967f7d7.zip |
Autocomplete: Announce autocomplete correctly in all ATs.
Fixes #9631
Closes gh-1153
Diffstat (limited to 'tests/unit/autocomplete')
-rw-r--r-- | tests/unit/autocomplete/autocomplete_core.js | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js index 58e96755a..961aca400 100644 --- a/tests/unit/autocomplete/autocomplete_core.js +++ b/tests/unit/autocomplete/autocomplete_core.js @@ -221,40 +221,76 @@ asyncTest( "simultaneous searches (#9334)", function() { }); test( "ARIA", function() { - expect( 7 ); + expect( 13 ); var element = $( "#autocomplete" ).autocomplete({ source: [ "java", "javascript" ] }), liveRegion = element.autocomplete( "instance" ).liveRegion; - equal( liveRegion.text(), "", "Empty live region on create" ); + equal( liveRegion.children().length, 0, "Empty live region on create" ); + equal( liveRegion.attr( "aria-live" ), "assertive", + "Live region's aria-live attribute must be assertive" ); + equal( liveRegion.attr( "aria-relevant" ), "additions", + "Live region's aria-relevant attribute must be additions" ); + equal( liveRegion.attr( "role" ), "status", + "Live region's role attribute must be status" ); element.autocomplete( "search", "j" ); - equal( liveRegion.text(), "2 results are available, use up and down arrow keys to navigate.", + equal( liveRegion.children().first().text(), + "2 results are available, use up and down arrow keys to navigate.", "Live region for multiple values" ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( liveRegion.text(), "2 results are available, use up and down arrow keys to navigate.", - "Live region not changed on focus" ); + equal( liveRegion.children().filter( ":visible" ).text(), "java", + "Live region changed on keydown to announce the highlighted value" ); element.one( "autocompletefocus", function( event ) { event.preventDefault(); }); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( liveRegion.text(), "javascript", + equal( liveRegion.children().filter( ":visible" ).text(), "javascript", "Live region updated when default focus is prevented" ); element.autocomplete( "search", "javas" ); - equal( liveRegion.text(), "1 result is available, use up and down arrow keys to navigate.", + equal( liveRegion.children().filter( ":visible" ).text(), + "1 result is available, use up and down arrow keys to navigate.", "Live region for one value" ); element.autocomplete( "search", "z" ); - equal( liveRegion.text(), "No search results.", + equal( liveRegion.children().filter( ":visible" ).text(), "No search results.", "Live region for no values" ); - element.autocomplete( "search", "j" ); - equal( liveRegion.text(), "2 results are available, use up and down arrow keys to navigate.", - "Live region for multiple values" ); + equal( liveRegion.children().length, 5, + "Should be five children in the live region after the above" ); + equal( liveRegion.children().filter( ":visible" ).length, 1, + "Only one should be still visible" ); + ok( liveRegion.children().filter( ":visible" )[ 0 ] === liveRegion.children().last()[ 0 ], + "The last one should be the visible one" ); + + element.autocomplete( "destroy" ); + equal( liveRegion.parent().length, 0, + "The liveRegion should be detached after destroy" ); +}); + +test( "ARIA, aria-label announcement", function() { + expect( 1 ); + $.widget( "custom.catcomplete", $.ui.autocomplete, { + _renderMenu: function( ul, items ) { + var that = this; + $.each( items, function( index, item ) { + that._renderItemData( ul, item ) + .attr( "aria-label", item.category + " : " + item.label ); + }); + } + }); + var element = $( "#autocomplete" ).catcomplete({ + source: [ { label: "anders andersson", category: "People" } ] + }), + liveRegion = element.catcomplete( "instance" ).liveRegion; + element.catcomplete( "search", "a" ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson", + "Live region changed on keydown to announce the highlighted value's aria-label attribute" ); }); test( "ARIA, init on detached input", function() { |