11/*jslint vars: true*/
2- /*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $*/
2+ /*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $, beforeEach */
33
4- describe ( 'Autocomplete Async' , function ( ) {
5-
6- var input = document . createElement ( 'input' ) ,
7- startQuery ,
8- ajaxExecuted = false ,
9- autocomplete = new $ . Autocomplete ( input , {
10- serviceUrl : '/test' ,
11- onSearchStart : function ( params ) {
12- startQuery = params . query ;
13- }
14- } ) ;
4+ describe ( 'Autocomplete Async' , function ( ) {
5+ 'use strict' ;
156
16- beforeEach ( function ( done ) {
17- $ . mockjax ( {
18- url : '/test' ,
19- responseTime : 50 ,
20- response : function ( settings ) {
21- ajaxExecuted = true ;
22- var query = settings . data . query ,
23- response = {
24- query : query ,
25- suggestions : [ ]
26- } ;
27- this . responseText = JSON . stringify ( response ) ;
28- done ( ) ;
29- }
30- } ) ;
7+ var input = document . createElement ( 'input' ) ,
8+ startQuery ,
9+ ajaxExecuted = false ,
10+ autocomplete = new $ . Autocomplete ( input , {
11+ serviceUrl : '/test' ,
12+ onSearchStart : function ( params ) {
13+ startQuery = params . query ;
14+ }
15+ } ) ;
3116
32- input . value = 'A' ;
33- autocomplete . onValueChange ( ) ;
17+ beforeEach ( function ( done ) {
18+ $ . mockjax ( {
19+ url : '/test' ,
20+ responseTime : 50 ,
21+ response : function ( settings ) {
22+ ajaxExecuted = true ;
23+ var query = settings . data . query ,
24+ response = {
25+ query : query ,
26+ suggestions : [ ]
27+ } ;
28+ this . responseText = JSON . stringify ( response ) ;
29+ done ( ) ;
30+ }
3431 } ) ;
3532
33+ input . value = 'A' ;
34+ autocomplete . onValueChange ( ) ;
35+ } ) ;
36+
3637 it ( 'Should execute onSearchStart' , function ( ) {
3738 expect ( ajaxExecuted ) . toBe ( true ) ;
3839 expect ( startQuery ) . toBe ( 'A' ) ;
3940 } ) ;
4041} ) ;
4142
4243describe ( 'Autocomplete Async' , function ( ) {
44+ 'use strict' ;
45+
4346 var input = document . createElement ( 'input' ) ,
4447 completeQuery ,
4548 mockupSuggestion = { value : 'A' , data : 'A' } ,
@@ -48,16 +51,16 @@ describe('Autocomplete Async', function () {
4851 url = '/test-completed' ;
4952
5053 beforeEach ( function ( done ) {
51- var autocomplete = new $ . Autocomplete ( input , {
52- serviceUrl : url ,
53- onSearchComplete : function ( query , suggestions ) {
54- completeQuery = query ;
55- resultSuggestions = suggestions ;
56- done ( ) ;
57- }
58- } ) ;
54+ var autocomplete = new $ . Autocomplete ( input , {
55+ serviceUrl : url ,
56+ onSearchComplete : function ( query , suggestions ) {
57+ completeQuery = query ;
58+ resultSuggestions = suggestions ;
59+ done ( ) ;
60+ }
61+ } ) ;
5962
60- $ . mockjax ( {
63+ $ . mockjax ( {
6164 url : url ,
6265 responseTime : 50 ,
6366 response : function ( settings ) {
@@ -83,11 +86,11 @@ describe('Autocomplete Async', function () {
8386 } ) ;
8487} ) ;
8588
86- describe ( 'Autocomplete Async' , function ( ) {
87-
89+ describe ( 'Autocomplete Async' , function ( ) {
90+ 'use strict' ;
8891 var errorMessage = false ;
8992
90- beforeEach ( function ( done ) {
93+ beforeEach ( function ( done ) {
9194 var input = document . createElement ( 'input' ) ,
9295 url = '/test-error' ,
9396 autocomplete = new $ . Autocomplete ( input , {
@@ -116,11 +119,12 @@ describe('Autocomplete Async', function() {
116119 } ) ;
117120} ) ;
118121
119- describe ( 'Asyn' , function ( ) {
122+ describe ( 'Asyn' , function ( ) {
123+ 'use strict' ;
120124
121125 var instance ;
122126
123- beforeEach ( function ( done ) {
127+ beforeEach ( function ( done ) {
124128 var input = document . createElement ( 'input' ) ,
125129 ajaxExecuted = false ,
126130 url = '/test-transform' ,
@@ -162,10 +166,12 @@ describe('Asyn', function(){
162166 } ) ;
163167} ) ;
164168
165- describe ( 'Autocomplete Async' , function ( ) {
169+ describe ( 'Autocomplete Async' , function ( ) {
170+ 'use strict' ;
171+
166172 var instance ;
167173
168- beforeEach ( function ( done ) {
174+ beforeEach ( function ( done ) {
169175 var input = document . createElement ( 'input' ) ,
170176 ajaxExecuted = false ,
171177 url = '/test-original-query' ,
@@ -200,6 +206,8 @@ describe('Autocomplete Async', function(){
200206} ) ;
201207
202208describe ( 'Autocomplete Async' , function ( ) {
209+ 'use strict' ;
210+
203211 var paramValue ;
204212
205213 beforeEach ( function ( done ) {
@@ -235,7 +243,9 @@ describe('Autocomplete Async', function () {
235243} ) ;
236244
237245describe ( 'Autocomplete Async' , function ( ) {
238- var dynamicUrl ,
246+ 'use strict' ;
247+
248+ var dynamicUrl ,
239249 data ;
240250
241251 beforeEach ( function ( done ) {
@@ -273,6 +283,8 @@ describe('Autocomplete Async', function () {
273283} ) ;
274284
275285describe ( 'Autocomplete Async' , function ( ) {
286+ 'use strict' ;
287+
276288 var instance ,
277289 cacheKey ;
278290
@@ -315,6 +327,8 @@ describe('Autocomplete Async', function () {
315327} ) ;
316328
317329describe ( 'Autocomplete Async' , function ( ) {
330+ 'use strict' ;
331+
318332 var ajaxCount = 0 ;
319333
320334 beforeEach ( function ( done ) {
@@ -330,10 +344,12 @@ describe('Autocomplete Async', function () {
330344 url : serviceUrl ,
331345 responseTime : 1 ,
332346 response : function ( settings ) {
333- ajaxCount ++ ;
347+ ajaxCount += 1 ;
334348 var response = { suggestions : [ ] } ;
335349 this . responseText = JSON . stringify ( response ) ;
336- if ( ajaxCount === 2 ) done ( ) ;
350+ if ( ajaxCount === 2 ) {
351+ done ( ) ;
352+ }
337353 }
338354 } ) ;
339355
@@ -670,65 +686,67 @@ describe('Autocomplete', function () {
670686
671687 it ( 'Should display no suggestion notice when no matching results' , function ( ) {
672688 var input = document . createElement ( 'input' ) ,
673- options = {
689+ options = {
674690 lookup : [ { value : 'Colombia' , data : 'Spain' } ] ,
675691 showNoSuggestionNotice : true ,
676692 noSuggestionNotice : 'Sorry, no matching results'
677693 } ,
678694 autocomplete = new $ . Autocomplete ( input , options ) ,
679- suggestionsContainer = $ ( autocomplete . suggestionsContainer )
695+ suggestionsContainer = $ ( autocomplete . suggestionsContainer ) ;
680696
681697 input . value = 'Jamaica' ;
682- autocomplete . onValueChange ( ) ;
698+ autocomplete . onValueChange ( ) ;
683699
684700 expect ( autocomplete . visible ) . toBe ( true ) ;
685- expect ( autocomplete . selectedIndex ) . toBe ( - 1 )
686- expect ( suggestionsContainer . find ( '.autocomplete-no-suggestion' ) . length ) . toBe ( 1 )
687- expect ( suggestionsContainer . find ( '.autocomplete-no-suggestion' ) . text ( ) ) . toBe ( 'Sorry, no matching results' )
701+ expect ( autocomplete . selectedIndex ) . toBe ( - 1 ) ;
702+ expect ( suggestionsContainer . find ( '.autocomplete-no-suggestion' ) . length ) . toBe ( 1 ) ;
703+ expect ( suggestionsContainer . find ( '.autocomplete-no-suggestion' ) . text ( ) ) . toBe ( 'Sorry, no matching results' ) ;
688704 } ) ;
689705
690706} ) ;
691707
692- describe ( 'When options.preserveInput is true' , function ( ) {
693- var input = $ ( '<input />' ) ,
694- instance ,
695- suggestionData = null ;
696-
697- beforeEach ( function ( ) {
698- input . autocomplete ( {
699- lookup : [ { value : 'Jamaica' , data : 'J' } , { value : 'Jamaica2' , data : 'J' } , { value : 'Jamaica3' , data : 'J' } ] ,
700- preserveInput : true ,
701- onSelect : function ( suggestion ) {
702- suggestionData = suggestion . data ;
703- }
704- } ) ;
705-
706- input . val ( 'J' ) ;
707- instance = input . autocomplete ( ) ;
708- } ) ;
709-
710- afterEach ( function ( ) {
711- instance . dispose ( ) ;
712- } ) ;
708+ describe ( 'When options.preserveInput is true' , function ( ) {
709+ 'use strict' ;
713710
714- it ( 'Should NOT change input value when item is selected' , function ( ) {
715- instance . onValueChange ( ) ;
716- instance . select ( 0 ) ;
711+ var input = $ ( '<input />' ) ,
712+ instance ,
713+ suggestionData = null ;
717714
718- expect ( input . val ( ) ) . toEqual ( 'J' ) ;
719- } ) ;
715+ beforeEach ( function ( ) {
716+ input . autocomplete ( {
717+ lookup : [ { value : 'Jamaica' , data : 'J' } , { value : 'Jamaica2' , data : 'J' } , { value : 'Jamaica3' , data : 'J' } ] ,
718+ preserveInput : true ,
719+ onSelect : function ( suggestion ) {
720+ suggestionData = suggestion . data ;
721+ }
722+ } ) ;
720723
721- it ( 'Should NOT change input value when move down' , function ( ) {
722- instance . onValueChange ( ) ;
723- instance . moveDown ( ) ;
724+ input . val ( 'J' ) ;
725+ instance = input . autocomplete ( ) ;
726+ } ) ;
727+
728+ afterEach ( function ( ) {
729+ instance . dispose ( ) ;
730+ } ) ;
724731
725- expect ( input . val ( ) ) . toEqual ( 'J' ) ;
726- } ) ;
732+ it ( 'Should NOT change input value when item is selected' , function ( ) {
733+ instance . onValueChange ( ) ;
734+ instance . select ( 0 ) ;
735+
736+ expect ( input . val ( ) ) . toEqual ( 'J' ) ;
737+ } ) ;
727738
728- it ( 'Should NOT change input value when move up' , function ( ) {
729- instance . onValueChange ( ) ;
730- instance . moveUp ( ) ;
739+ it ( 'Should NOT change input value when move down' , function ( ) {
740+ instance . onValueChange ( ) ;
741+ instance . moveDown ( ) ;
742+
743+ expect ( input . val ( ) ) . toEqual ( 'J' ) ;
744+ } ) ;
731745
732- expect ( input . val ( ) ) . toEqual ( 'J' ) ;
733- } ) ;
746+ it ( 'Should NOT change input value when move up' , function ( ) {
747+ instance . onValueChange ( ) ;
748+ instance . moveUp ( ) ;
749+
750+ expect ( input . val ( ) ) . toEqual ( 'J' ) ;
751+ } ) ;
734752} ) ;
0 commit comments