From f262a531fa0978c3aaa0cc1c0a75cb1b8fec0155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 15 Feb 2012 11:41:30 -0500 Subject: [PATCH] Autocomplete: Added a test for exceeding minLength, then falling below, then exceeding again. --- .../unit/autocomplete/autocomplete_options.js | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js index 799a249d826..1ab40f36c72 100644 --- a/tests/unit/autocomplete/autocomplete_options.js +++ b/tests/unit/autocomplete/autocomplete_options.js @@ -127,13 +127,34 @@ asyncTest( "minLength, exceed then drop below", function() { }, 50 ); }); -// TODO: figure out how to implement this test -// When fixing #7523, I couldn't figure out a test that would fail when -// calling .close() (instead of ._close()) from ._response(). -// Use the remote demo and type "je", delete, "a", you should get results for "ja" -// but if we call .close() from ._response() the results are ignored. -//asyncTest( "minLength, exceed then drop below", function() { -//}); +test( "minLength, exceed then drop below then exceed", function() { + expect( 3 ); + var _res = [], + element = $( "#autocomplete" ).autocomplete({ + minLength: 2, + source: function( req, res ) { + _res.push( res ); + } + }), + menu = element.autocomplete( "widget" ); + + // trigger a valid search + ok( menu.is( ":hidden" ), "menu is hidden before first search" ); + element.autocomplete( "search", "12" ); + + // trigger a search below the minLength, to turn on cancelSearch flag + ok( menu.is( ":hidden" ), "menu is hidden before second search" ); + element.autocomplete( "search", "1" ); + + // trigger a valid search + element.autocomplete( "search", "13" ); + // react as if the first search was cancelled (default ajax behavior) + _res[ 0 ]([]); + // react to second search + _res[ 1 ]([ "13" ]); + + ok( menu.is( ":visible" ), "menu is visible after searches" ); +}); test( "source, local string array", function() { expect( 1 );