]> source.dussan.org Git - jquery-ui.git/commitdiff
Selectmenu tests: improve focus callback event test, add keydown focus test, add...
authorFelix Nagel <info@felixnagel.com>
Thu, 30 May 2013 19:02:38 +0000 (21:02 +0200)
committerFelix Nagel <info@felixnagel.com>
Thu, 30 May 2013 19:02:38 +0000 (21:02 +0200)
tests/unit/selectmenu/selectmenu_events.js

index 99d5b591cbbadf939c1bb5c1a849c383b1492ada..49f0c598cb125c7314f4c6fbcefe95615f5e01cc 100644 (file)
@@ -44,29 +44,36 @@ test( "close", function () {
 
 
 test( "focus", function () {
-       expect( 3 );
+       expect( 12 );
 
        var button, menu, links,
+               optionIndex = this.element[ 0 ].selectedIndex + 1,
                options = this.element.find( "option" );
 
        this.element.selectmenu({
                focus: function ( event, ui ) {
-                       ok( event, "focus event fired on mouseover" );
+                       ok( event, "focus event fired on element #" + optionIndex + " mouseover" );
                        equal( event.type, "selectmenufocus", "event type set to selectmenufocus" );
-                       equal( ui.item.element[ 0 ], options.eq( ui.item.index )[ 0 ], "ui.item.element contains original option element" );
+                       equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
+                       equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
                }
        });
 
        button = this.element.selectmenu( "widget" ),
        menu = this.element.selectmenu( "menuWidget" );
 
-       button.simulate( "focus" );
-       links = menu.find( "li.ui-menu-item a" );
-
+       button
+               .simulate( "focus" )
+               .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+       
        button.simulate( "click" );
+       links = menu.find( "li.ui-menu-item a" );
+       optionIndex = 0;
+       links.eq( optionIndex ).simulate( "mouseover" );        
+       optionIndex += 1;
+       links.eq( optionIndex ).simulate( "mouseover" );
 
-       menu.find( "a" ).last().simulate( "mouseover" );
-
+       // this tests for unwanted, additional focus event on close
        this.element.selectmenu( "close" );
 });