Skip to content

Commit

Permalink
Autocomplete: refactored unit tests for autoFocus option
Browse files Browse the repository at this point in the history
(cherry picked from commit c1a0f2b)
  • Loading branch information
rdworth committed Mar 15, 2011
1 parent 218100e commit 1fe58db
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tests/unit/autocomplete/autocomplete_options.js
Expand Up @@ -97,32 +97,26 @@ test( "appendTo", function() {
ac.autocomplete( "destroy" );
});

test( "autoFocus: false", function() {
function autoFocusTest( afValue, focusedLength ) {
var ac = $( "#autocomplete" ).autocomplete({
autoFocus: false,
autoFocus: afValue,
delay: 0,
source: data,
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();
}
});
ac.val( "ja" ).keydown();
stop();
}

test( "autoFocus: false", function() {
autoFocusTest( false, 0 );
});

test( "autoFocus: true", function() {
var ac = $( "#autocomplete" ).autocomplete({
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();
autoFocusTest( true, 1 );
});

test("delay", function() {
Expand Down

0 comments on commit 1fe58db

Please sign in to comment.