aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authormeh-cfl <meh@corefiling.co.uk>2012-04-07 09:07:21 -0400
committerScott González <scott.gonzalez@gmail.com>2012-04-07 09:07:21 -0400
commit9668cb850ef97e39822cb3ef0d0ea27ff0c1fe6e (patch)
treefe5095692309c872722243298b1910f26fa71ef7 /tests
parentd040b8f42cc28932deedddebe95473a9fd13d742 (diff)
downloadjquery-ui-9668cb850ef97e39822cb3ef0d0ea27ff0c1fe6e.tar.gz
jquery-ui-9668cb850ef97e39822cb3ef0d0ea27ff0c1fe6e.zip
Autocomplete: Don't invoke a search from arrow keys when the element can have multi-line text. Fixes #7639 - Key up/key down in textarea's should optionally not toggle auto-complete.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/autocomplete/autocomplete.html1
-rw-r--r--tests/unit/autocomplete/autocomplete_core.js63
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/unit/autocomplete/autocomplete.html b/tests/unit/autocomplete/autocomplete.html
index 1e7b58e80..88b7da4d8 100644
--- a/tests/unit/autocomplete/autocomplete.html
+++ b/tests/unit/autocomplete/autocomplete.html
@@ -38,6 +38,7 @@
<div id="ac-wrap1" class="ac-wrap"></div>
<div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo" /></div>
+ <textarea id="autocomplete-textarea"></textarea>
</div>
</body>
diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js
index 84f26980f..fa7dce610 100644
--- a/tests/unit/autocomplete/autocomplete_core.js
+++ b/tests/unit/autocomplete/autocomplete_core.js
@@ -97,5 +97,68 @@ asyncTest( "handle race condition", function() {
start();
}
});
+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 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 );
+});
+
+function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
+ expect( 1 );
+
+ var didMove = false,
+ element = $( id ).autocomplete({
+ source: [ "a" ],
+ delay: 0,
+ minLength: 0
+ });
+ element.data( "autocomplete" )._move = function() {
+ didMove = true;
+ };
+ element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
+ equal( didMove, shouldMove, "respond to arrow" );
+}
+
+function arrowsMoveFocus( id, isKeyUp ) {
+ expect( 1 );
+
+ var didMove = false,
+ element = $( id ).autocomplete({
+ source: [ "a" ],
+ delay: 0,
+ minLength: 0
+ });
+ element.data( "autocomplete" )._move = function() {
+ ok( true, "repsond to arrow" );
+ };
+ element.autocomplete( "search" );
+ element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
+}
}( jQuery ) );