Skip to content

Commit c1a0f2b

Browse files
committed
Autocomplete: refactored unit tests for autoFocus option
1 parent 4881a27 commit c1a0f2b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

tests/unit/autocomplete/autocomplete_options.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,32 +97,26 @@ test( "appendTo", function() {
9797
ac.autocomplete( "destroy" );
9898
});
9999

100-
test( "autoFocus: false", function() {
100+
function autoFocusTest( afValue, focusedLength ) {
101101
var ac = $( "#autocomplete" ).autocomplete({
102-
autoFocus: false,
102+
autoFocus: afValue,
103103
delay: 0,
104104
source: data,
105105
open: function( event, ui ) {
106-
equals( 0, ac.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length, "first item is not auto focused" );
106+
equals( focusedLength, ac.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length, "first item is " + afValue ? "" : "not" + " auto focused" );
107107
start();
108108
}
109109
});
110110
ac.val( "ja" ).keydown();
111111
stop();
112+
}
113+
114+
test( "autoFocus: false", function() {
115+
autoFocusTest( false, 0 );
112116
});
113117

114118
test( "autoFocus: true", function() {
115-
var ac = $( "#autocomplete" ).autocomplete({
116-
autoFocus: true,
117-
delay: 0,
118-
source: data,
119-
open: function( event, ui ) {
120-
equals( 1, ac.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length, "first item is auto focused" );
121-
start();
122-
}
123-
});
124-
ac.val( "ja" ).keydown();
125-
stop();
119+
autoFocusTest( true, 1 );
126120
});
127121

128122
test("delay", function() {

0 commit comments

Comments
 (0)