@@ -94,18 +94,14 @@ describe('Autocomplete', function () {
9494 expect ( autocomplete . options . lookup [ 1 ] . value ) . toBe ( 'B' ) ;
9595 } ) ;
9696
97- it ( 'Should execute onSearchStart and onSearchCompleted ' , function ( ) {
97+ it ( 'Should execute onSearchStart' , function ( ) {
9898 var input = document . createElement ( 'input' ) ,
9999 startQuery ,
100- completeQuery ,
101100 ajaxExecuted = false ,
102101 autocomplete = new $ . Autocomplete ( input , {
103102 serviceUrl : '/test' ,
104- onSearchStart : function ( query ) {
105- startQuery = query ;
106- } ,
107- onSearchComplete : function ( query ) {
108- completeQuery = query ;
103+ onSearchStart : function ( params ) {
104+ startQuery = params . query ;
109105 }
110106 } ) ;
111107
@@ -133,6 +129,44 @@ describe('Autocomplete', function () {
133129 runs ( function ( ) {
134130 expect ( ajaxExecuted ) . toBe ( true ) ;
135131 expect ( startQuery ) . toBe ( 'A' ) ;
132+ } ) ;
133+ } ) ;
134+
135+ it ( 'Should execute onSearchCompleted' , function ( ) {
136+ var input = document . createElement ( 'input' ) ,
137+ completeQuery ,
138+ ajaxExecuted = false ,
139+ url = '/test-completed' ,
140+ autocomplete = new $ . Autocomplete ( input , {
141+ serviceUrl : url ,
142+ onSearchComplete : function ( query ) {
143+ completeQuery = query ;
144+ }
145+ } ) ;
146+
147+ $ . mockjax ( {
148+ url : url ,
149+ responseTime : 50 ,
150+ response : function ( settings ) {
151+ ajaxExecuted = true ;
152+ var query = settings . data . query ,
153+ response = {
154+ query : query ,
155+ suggestions : [ ]
156+ } ;
157+ this . responseText = JSON . stringify ( response ) ;
158+ }
159+ } ) ;
160+
161+ input . value = 'A' ;
162+ autocomplete . onValueChange ( ) ;
163+
164+ waitsFor ( function ( ) {
165+ return ajaxExecuted ;
166+ } , 'Ajax call never completed.' , 100 ) ;
167+
168+ runs ( function ( ) {
169+ expect ( ajaxExecuted ) . toBe ( true ) ;
136170 expect ( completeQuery ) . toBe ( 'A' ) ;
137171 } ) ;
138172 } ) ;
0 commit comments