]> source.dussan.org Git - jquery-ui.git/commitdiff
Selectmenu tests: check item focus
authorFelix Nagel <info@felixnagel.com>
Fri, 2 Aug 2013 23:16:42 +0000 (01:16 +0200)
committerFelix Nagel <info@felixnagel.com>
Fri, 2 Aug 2013 23:16:42 +0000 (01:16 +0200)
tests/unit/selectmenu/selectmenu_core.js

index 21b4adb4df91ccdb755a472797a3ca6c48a96ef7..1f97d8f179cc92ecfc496cec82eed4542d1bc3c2 100644 (file)
@@ -183,6 +183,43 @@ $.each([
                        start();
                }, 1 );
        });
+
+       asyncTest( "item focus - " + settings.type, function () {
+               expect( 4 );
+
+               var element = $( settings.selector ).selectmenu(),
+                       button = element.selectmenu( "widget" ),
+                       menu = element.selectmenu( "menuWidget" ),
+                       links, activeItem, focusedItem;
+
+               // init menu
+               button.simulate( "focus" );
+
+               setTimeout(function() {
+                       links = menu.find( "li.ui-menu-item a" );
+
+                       button.trigger( "click" );
+                       focusedItem = menu.find( "li.ui-menu-item a.ui-state-focus" );
+                       equal( focusedItem.length, 1, "only one item has focus after first opening" );
+                       equal( focusedItem.attr( "id" ), links.eq( element[ 0 ].selectedIndex ).attr( "id" ), "active item has focus after first opening" );
+
+                       links.eq( 3 ).simulate( "mouseover" ).trigger( "click" );
+
+                       button.trigger( "click" );
+                       links.eq( 2 ).simulate( "mouseover" );
+                       $( document ).trigger( "click" );
+
+                       button.trigger( "click" );
+                       links.eq( 1 ).simulate( "mouseover" );
+                       $( document ).trigger( "click" );
+
+                       button.trigger( "click" );
+                       focusedItem = menu.find( "li.ui-menu-item a.ui-state-focus" );
+                       equal( focusedItem.length, 1, "only one item has focus" );
+                       equal( focusedItem.attr( "id" ), links.eq( element[ 0 ].selectedIndex ).attr( "id" ), "active item has focus" );
+                       start();
+               }, 1 );
+       });
 });
 
 })( jQuery );