aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/autocomplete/core.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/autocomplete/core.js')
-rw-r--r--tests/unit/autocomplete/core.js164
1 files changed, 82 insertions, 82 deletions
diff --git a/tests/unit/autocomplete/core.js b/tests/unit/autocomplete/core.js
index d57f2a980..41be5ae6a 100644
--- a/tests/unit/autocomplete/core.js
+++ b/tests/unit/autocomplete/core.js
@@ -12,15 +12,15 @@ test( "markup structure", function( assert ) {
assert.hasClasses( element, "ui-autocomplete-input" );
assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" );
-});
+} );
test( "prevent form submit on enter when menu is active", function() {
expect( 2 );
var event,
element = $( "#autocomplete" )
- .autocomplete({
+ .autocomplete( {
source: [ "java", "javascript" ]
- })
+ } )
.val( "ja" )
.autocomplete( "search" ),
menu = element.autocomplete( "widget" );
@@ -35,16 +35,16 @@ test( "prevent form submit on enter when menu is active", function() {
event.keyCode = $.ui.keyCode.ENTER;
element.trigger( event );
ok( event.isDefaultPrevented(), "default action is prevented" );
-});
+} );
test( "allow form submit on enter when menu is not active", function() {
expect( 1 );
var event,
element = $( "#autocomplete" )
- .autocomplete({
+ .autocomplete( {
autoFocus: false,
source: [ "java", "javascript" ]
- })
+ } )
.val( "ja" )
.autocomplete( "search" );
@@ -52,90 +52,90 @@ test( "allow form submit on enter when menu is not active", function() {
event.keyCode = $.ui.keyCode.ENTER;
element.trigger( event );
ok( !event.isDefaultPrevented(), "default action is prevented" );
-});
+} );
-(function() {
+( function() {
test( "up arrow invokes search - input", function() {
arrowsInvokeSearch( "#autocomplete", true, true );
- });
+ } );
test( "down arrow invokes search - input", function() {
arrowsInvokeSearch( "#autocomplete", false, true );
- });
+ } );
test( "up arrow invokes search - textarea", function() {
arrowsInvokeSearch( "#autocomplete-textarea", true, false );
- });
+ } );
test( "down arrow invokes search - textarea", function() {
arrowsInvokeSearch( "#autocomplete-textarea", false, false );
- });
+ } );
test( "up arrow invokes search - contenteditable", function() {
arrowsInvokeSearch( "#autocomplete-contenteditable", true, false );
- });
+ } );
test( "down arrow invokes search - contenteditable", function() {
arrowsInvokeSearch( "#autocomplete-contenteditable", false, false );
- });
+ } );
test( "up arrow moves focus - input", function() {
arrowsMoveFocus( "#autocomplete", true );
- });
+ } );
test( "down arrow moves focus - input", function() {
arrowsMoveFocus( "#autocomplete", false );
- });
+ } );
test( "up arrow moves focus - textarea", function() {
arrowsMoveFocus( "#autocomplete-textarea", true );
- });
+ } );
test( "down arrow moves focus - textarea", function() {
arrowsMoveFocus( "#autocomplete-textarea", false );
- });
+ } );
test( "up arrow moves focus - contenteditable", function() {
arrowsMoveFocus( "#autocomplete-contenteditable", true );
- });
+ } );
test( "down arrow moves focus - contenteditable", function() {
arrowsMoveFocus( "#autocomplete-contenteditable", false );
- });
+ } );
test( "up arrow moves cursor - input", function() {
arrowsNavigateElement( "#autocomplete", true, false );
- });
+ } );
test( "down arrow moves cursor - input", function() {
arrowsNavigateElement( "#autocomplete", false, false );
- });
+ } );
test( "up arrow moves cursor - textarea", function() {
arrowsNavigateElement( "#autocomplete-textarea", true, true );
- });
+ } );
test( "down arrow moves cursor - textarea", function() {
arrowsNavigateElement( "#autocomplete-textarea", false, true );
- });
+ } );
test( "up arrow moves cursor - contenteditable", function() {
arrowsNavigateElement( "#autocomplete-contenteditable", true, true );
- });
+ } );
test( "down arrow moves cursor - contenteditable", function() {
arrowsNavigateElement( "#autocomplete-contenteditable", false, true );
- });
+ } );
function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
expect( 1 );
var didMove = false,
- element = $( id ).autocomplete({
+ element = $( id ).autocomplete( {
source: [ "a" ],
delay: 0,
minLength: 0
- });
+ } );
element.autocomplete( "instance" )._move = function() {
didMove = true;
};
@@ -146,11 +146,11 @@ test( "allow form submit on enter when menu is not active", function() {
function arrowsMoveFocus( id, isKeyUp ) {
expect( 1 );
- var element = $( id ).autocomplete({
+ var element = $( id ).autocomplete( {
source: [ "a" ],
delay: 0,
minLength: 0
- });
+ } );
element.autocomplete( "instance" )._move = function() {
ok( true, "repsond to arrow" );
};
@@ -162,25 +162,25 @@ test( "allow form submit on enter when menu is not active", function() {
expect( 1 );
var didMove = false,
- element = $( id ).autocomplete({
+ element = $( id ).autocomplete( {
source: [ "a" ],
delay: 0,
minLength: 0
- });
+ } );
element.on( "keypress", function( e ) {
didMove = !e.isDefaultPrevented();
- });
+ } );
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
element.simulate( "keypress" );
equal( didMove, shouldMove, "respond to arrow" );
}
-})();
+} )();
asyncTest( "past end of menu in multiline autocomplete", function() {
expect( 2 );
var customVal = "custom value",
- element = $( "#autocomplete-contenteditable" ).autocomplete({
+ element = $( "#autocomplete-contenteditable" ).autocomplete( {
delay: 0,
source: [ "javascript" ],
focus: function( event, ui ) {
@@ -188,25 +188,25 @@ asyncTest( "past end of menu in multiline autocomplete", function() {
$( this ).text( customVal );
event.preventDefault();
}
- });
+ } );
element
.simulate( "focus" )
.autocomplete( "search", "ja" );
- setTimeout(function() {
+ setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( element.text(), customVal );
start();
- });
-});
+ } );
+} );
asyncTest( "ESCAPE in multiline autocomplete", function() {
expect( 2 );
var customVal = "custom value",
- element = $( "#autocomplete-contenteditable" ).autocomplete({
+ element = $( "#autocomplete-contenteditable" ).autocomplete( {
delay: 0,
source: [ "javascript" ],
focus: function( event, ui ) {
@@ -214,38 +214,38 @@ asyncTest( "ESCAPE in multiline autocomplete", function() {
$( this ).text( customVal );
event.preventDefault();
}
- });
+ } );
element
.simulate( "focus" )
.autocomplete( "search", "ja" );
- setTimeout(function() {
+ setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( element.text(), customVal );
start();
- });
-});
+ } );
+} );
asyncTest( "handle race condition", function() {
expect( 3 );
var count = 0,
- element = $( "#autocomplete" ).autocomplete({
+ element = $( "#autocomplete" ).autocomplete( {
source: function( request, response ) {
count++;
if ( request.term.length === 1 ) {
equal( count, 1, "request with 1 character is first" );
- setTimeout(function() {
- response([ "one" ]);
+ setTimeout( function() {
+ response( [ "one" ] );
setTimeout( checkResults );
- });
+ } );
return;
}
equal( count, 2, "request with 2 characters is second" );
- response([ "two" ]);
+ response( [ "two" ] );
}
- });
+ } );
element.autocomplete( "search", "a" );
element.autocomplete( "search", "ab" );
@@ -255,41 +255,41 @@ asyncTest( "handle race condition", function() {
"correct results displayed" );
start();
}
-});
+} );
asyncTest( "simultaneous searches (#9334)", function() {
expect( 2 );
- var element = $( "#autocomplete" ).autocomplete({
+ var element = $( "#autocomplete" ).autocomplete( {
source: function( request, response ) {
- setTimeout(function() {
- response([ request.term ]);
- });
+ setTimeout( function() {
+ response( [ request.term ] );
+ } );
},
response: function() {
ok( true, "response from first instance" );
}
- }),
- element2 = $( "#autocomplete-textarea" ).autocomplete({
+ } ),
+ element2 = $( "#autocomplete-textarea" ).autocomplete( {
source: function( request, response ) {
- setTimeout(function() {
- response([ request.term ]);
- });
+ setTimeout( function() {
+ response( [ request.term ] );
+ } );
},
response: function() {
ok( true, "response from second instance" );
start();
}
- });
+ } );
element.autocomplete( "search", "test" );
element2.autocomplete( "search", "test" );
-});
+} );
test( "ARIA", function() {
expect( 13 );
- var element = $( "#autocomplete" ).autocomplete({
+ var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript" ]
- }),
+ } ),
liveRegion = element.autocomplete( "instance" ).liveRegion;
equal( liveRegion.children().length, 0, "Empty live region on create" );
@@ -311,7 +311,7 @@ test( "ARIA", function() {
element.one( "autocompletefocus", function( event ) {
event.preventDefault();
- });
+ } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( liveRegion.children().filter( ":visible" ).text(), "javascript",
"Live region updated when default focus is prevented" );
@@ -335,7 +335,7 @@ test( "ARIA", function() {
element.autocomplete( "destroy" );
equal( liveRegion.parent().length, 0,
"The liveRegion should be detached after destroy" );
-});
+} );
test( "ARIA, aria-label announcement", function() {
expect( 1 );
@@ -345,27 +345,27 @@ test( "ARIA, aria-label announcement", function() {
$.each( items, function( index, item ) {
that._renderItemData( ul, item )
.attr( "aria-label", item.category + " : " + item.label );
- });
+ } );
}
- });
- var element = $( "#autocomplete" ).catcomplete({
+ } );
+ var element = $( "#autocomplete" ).catcomplete( {
source: [ { label: "anders andersson", category: "People" } ]
- }),
+ } ),
liveRegion = element.catcomplete( "instance" ).liveRegion;
element.catcomplete( "search", "a" );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson",
"Live region changed on keydown to announce the highlighted value's aria-label attribute" );
-});
+} );
test( "ARIA, init on detached input", function() {
expect( 1 );
- var element = $( "<input>" ).autocomplete({
+ var element = $( "<input>" ).autocomplete( {
source: [ "java", "javascript" ]
- }),
+ } ),
liveRegion = element.autocomplete( "instance" ).liveRegion;
equal( liveRegion.parent().length, 1, "liveRegion must have a parent" );
-});
+} );
test( ".replaceWith() (#9172)", function() {
expect( 1 );
@@ -375,27 +375,27 @@ test( ".replaceWith() (#9172)", function() {
parent = element.parent();
element.replaceWith( replacement );
equal( parent.html().toLowerCase(), replacement );
-});
+} );
asyncTest( "Search if the user retypes the same value (#7434)", function() {
expect( 3 );
- var element = $( "#autocomplete" ).autocomplete({
+ var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript" ],
delay: 0
- }),
+ } ),
menu = element.autocomplete( "instance" ).menu.element;
element.val( "j" ).simulate( "keydown" );
- setTimeout(function() {
+ setTimeout( function() {
ok( menu.is( ":visible" ), "menu displays initially" );
element.trigger( "blur" );
ok( !menu.is( ":visible" ), "menu hidden after blur" );
element.val( "j" ).simulate( "keydown" );
- setTimeout(function() {
+ setTimeout( function() {
ok( menu.is( ":visible" ), "menu displays after typing the same value" );
start();
- });
- });
-});
+ } );
+ } );
+} );
} );