Autocomplete: refactored unit tests for autoFocus option

(cherry picked from commit c1a0f2bf6c)
This commit is contained in:
Richard Worth 2011-03-15 09:36:36 -04:00
parent 218100e704
commit 1fe58dbf52

View File

@ -97,32 +97,26 @@ test( "appendTo", function() {
ac.autocomplete( "destroy" ); ac.autocomplete( "destroy" );
}); });
test( "autoFocus: false", function() { function autoFocusTest( afValue, focusedLength ) {
var ac = $( "#autocomplete" ).autocomplete({ var ac = $( "#autocomplete" ).autocomplete({
autoFocus: false, autoFocus: afValue,
delay: 0, delay: 0,
source: data, source: data,
open: function( event, ui ) { open: function( event, ui ) {
equals( 0, ac.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length, "first item is not auto focused" ); equals( focusedLength, ac.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length, "first item is " + afValue ? "" : "not" + " auto focused" );
start(); start();
} }
}); });
ac.val( "ja" ).keydown(); ac.val( "ja" ).keydown();
stop(); stop();
}
test( "autoFocus: false", function() {
autoFocusTest( false, 0 );
}); });
test( "autoFocus: true", function() { test( "autoFocus: true", function() {
var ac = $( "#autocomplete" ).autocomplete({ autoFocusTest( true, 1 );
autoFocus: true,
delay: 0,
source: data,
open: function( event, ui ) {
equals( 1, ac.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length, "first item is auto focused" );
start();
}
});
ac.val( "ja" ).keydown();
stop();
}); });
test("delay", function() { test("delay", function() {