File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,41 @@ describe('Autocomplete', function () {
210210 } ) ;
211211 } ) ;
212212
213+ it ( 'Should not require orginal query value from the server' , function ( ) {
214+ var input = document . createElement ( 'input' ) ,
215+ ajaxExecuted = false ,
216+ url = '/test-original-query' ,
217+ autocomplete = new $ . Autocomplete ( input , {
218+ serviceUrl : url
219+ } ) ;
220+
221+ $ . mockjax ( {
222+ url : url ,
223+ responseTime : 50 ,
224+ response : function ( ) {
225+ ajaxExecuted = true ;
226+ var response = {
227+ query : null ,
228+ suggestions : [ 'A' , 'B' , 'C' ]
229+ } ;
230+ this . responseText = JSON . stringify ( response ) ;
231+ }
232+ } ) ;
233+
234+ input . value = 'A' ;
235+ autocomplete . onValueChange ( ) ;
236+
237+ waitsFor ( function ( ) {
238+ return ajaxExecuted ;
239+ } , 'Ajax call never completed.' , 100 ) ;
240+
241+ runs ( function ( ) {
242+ expect ( ajaxExecuted ) . toBe ( true ) ;
243+ expect ( autocomplete . suggestions . length ) . toBe ( 3 ) ;
244+ expect ( autocomplete . suggestions [ 0 ] . value ) . toBe ( 'A' ) ;
245+ } ) ;
246+ } ) ;
247+
213248 it ( 'Should should not preventDefault when tabDisabled is set to false' , function ( ) {
214249 var input = document . createElement ( 'input' ) ,
215250 autocomplete = new $ . Autocomplete ( input , {
Original file line number Diff line number Diff line change 9595 } ,
9696 paramName : 'query' ,
9797 transformResult : function ( response , originalQuery ) {
98- return typeof response === 'string' ? $ . parseJSON ( response ) : response ;
98+ var result = typeof response === 'string' ? $ . parseJSON ( response ) : response ;
99+ result . query = originalQuery ;
100+ return result ;
99101 }
100102 } ;
101103
491493 }
492494
493495 // Display suggestions only if returned query matches current value:
494- if ( result [ options . paramName ] === that . getQuery ( that . currentValue ) ) {
496+ if ( result . query === that . getQuery ( that . currentValue ) ) {
495497 that . suggestions = result . suggestions ;
496498 that . suggest ( ) ;
497499 }
You can’t perform that action at this time.
0 commit comments