1
1
/*jslint vars: true*/
2
- /*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $*/
2
+ /*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $, beforeEach */
3
3
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' ;
15
6
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
+ } ) ;
31
16
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
+ }
34
31
} ) ;
35
32
33
+ input . value = 'A' ;
34
+ autocomplete . onValueChange ( ) ;
35
+ } ) ;
36
+
36
37
it ( 'Should execute onSearchStart' , function ( ) {
37
38
expect ( ajaxExecuted ) . toBe ( true ) ;
38
39
expect ( startQuery ) . toBe ( 'A' ) ;
39
40
} ) ;
40
41
} ) ;
41
42
42
43
describe ( 'Autocomplete Async' , function ( ) {
44
+ 'use strict' ;
45
+
43
46
var input = document . createElement ( 'input' ) ,
44
47
completeQuery ,
45
48
mockupSuggestion = { value : 'A' , data : 'A' } ,
@@ -48,16 +51,16 @@ describe('Autocomplete Async', function () {
48
51
url = '/test-completed' ;
49
52
50
53
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
+ } ) ;
59
62
60
- $ . mockjax ( {
63
+ $ . mockjax ( {
61
64
url : url ,
62
65
responseTime : 50 ,
63
66
response : function ( settings ) {
@@ -83,11 +86,11 @@ describe('Autocomplete Async', function () {
83
86
} ) ;
84
87
} ) ;
85
88
86
- describe ( 'Autocomplete Async' , function ( ) {
87
-
89
+ describe ( 'Autocomplete Async' , function ( ) {
90
+ 'use strict' ;
88
91
var errorMessage = false ;
89
92
90
- beforeEach ( function ( done ) {
93
+ beforeEach ( function ( done ) {
91
94
var input = document . createElement ( 'input' ) ,
92
95
url = '/test-error' ,
93
96
autocomplete = new $ . Autocomplete ( input , {
@@ -116,11 +119,12 @@ describe('Autocomplete Async', function() {
116
119
} ) ;
117
120
} ) ;
118
121
119
- describe ( 'Asyn' , function ( ) {
122
+ describe ( 'Asyn' , function ( ) {
123
+ 'use strict' ;
120
124
121
125
var instance ;
122
126
123
- beforeEach ( function ( done ) {
127
+ beforeEach ( function ( done ) {
124
128
var input = document . createElement ( 'input' ) ,
125
129
ajaxExecuted = false ,
126
130
url = '/test-transform' ,
@@ -162,10 +166,12 @@ describe('Asyn', function(){
162
166
} ) ;
163
167
} ) ;
164
168
165
- describe ( 'Autocomplete Async' , function ( ) {
169
+ describe ( 'Autocomplete Async' , function ( ) {
170
+ 'use strict' ;
171
+
166
172
var instance ;
167
173
168
- beforeEach ( function ( done ) {
174
+ beforeEach ( function ( done ) {
169
175
var input = document . createElement ( 'input' ) ,
170
176
ajaxExecuted = false ,
171
177
url = '/test-original-query' ,
@@ -200,6 +206,8 @@ describe('Autocomplete Async', function(){
200
206
} ) ;
201
207
202
208
describe ( 'Autocomplete Async' , function ( ) {
209
+ 'use strict' ;
210
+
203
211
var paramValue ;
204
212
205
213
beforeEach ( function ( done ) {
@@ -235,7 +243,9 @@ describe('Autocomplete Async', function () {
235
243
} ) ;
236
244
237
245
describe ( 'Autocomplete Async' , function ( ) {
238
- var dynamicUrl ,
246
+ 'use strict' ;
247
+
248
+ var dynamicUrl ,
239
249
data ;
240
250
241
251
beforeEach ( function ( done ) {
@@ -273,6 +283,8 @@ describe('Autocomplete Async', function () {
273
283
} ) ;
274
284
275
285
describe ( 'Autocomplete Async' , function ( ) {
286
+ 'use strict' ;
287
+
276
288
var instance ,
277
289
cacheKey ;
278
290
@@ -315,6 +327,8 @@ describe('Autocomplete Async', function () {
315
327
} ) ;
316
328
317
329
describe ( 'Autocomplete Async' , function ( ) {
330
+ 'use strict' ;
331
+
318
332
var ajaxCount = 0 ;
319
333
320
334
beforeEach ( function ( done ) {
@@ -330,10 +344,12 @@ describe('Autocomplete Async', function () {
330
344
url : serviceUrl ,
331
345
responseTime : 1 ,
332
346
response : function ( settings ) {
333
- ajaxCount ++ ;
347
+ ajaxCount += 1 ;
334
348
var response = { suggestions : [ ] } ;
335
349
this . responseText = JSON . stringify ( response ) ;
336
- if ( ajaxCount === 2 ) done ( ) ;
350
+ if ( ajaxCount === 2 ) {
351
+ done ( ) ;
352
+ }
337
353
}
338
354
} ) ;
339
355
@@ -670,65 +686,67 @@ describe('Autocomplete', function () {
670
686
671
687
it ( 'Should display no suggestion notice when no matching results' , function ( ) {
672
688
var input = document . createElement ( 'input' ) ,
673
- options = {
689
+ options = {
674
690
lookup : [ { value : 'Colombia' , data : 'Spain' } ] ,
675
691
showNoSuggestionNotice : true ,
676
692
noSuggestionNotice : 'Sorry, no matching results'
677
693
} ,
678
694
autocomplete = new $ . Autocomplete ( input , options ) ,
679
- suggestionsContainer = $ ( autocomplete . suggestionsContainer )
695
+ suggestionsContainer = $ ( autocomplete . suggestionsContainer ) ;
680
696
681
697
input . value = 'Jamaica' ;
682
- autocomplete . onValueChange ( ) ;
698
+ autocomplete . onValueChange ( ) ;
683
699
684
700
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' ) ;
688
704
} ) ;
689
705
690
706
} ) ;
691
707
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' ;
713
710
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 ;
717
714
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
+ } ) ;
720
723
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
+ } ) ;
724
731
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
+ } ) ;
727
738
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
+ } ) ;
731
745
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
+ } ) ;
734
752
} ) ;
0 commit comments