@@ -28,7 +28,7 @@ describe('<md-autocomplete>', function () {
28
28
}
29
29
30
30
describe ( 'basic functionality' , function ( ) {
31
- it ( 'should update selected item and search text' , inject ( function ( $timeout , $mdConstant , $rootElement ) {
31
+ it ( 'should update selected item and search text' , inject ( function ( $timeout , $mdConstant ) {
32
32
var scope = createScope ( ) ;
33
33
var template = '\
34
34
<md-autocomplete\
@@ -47,8 +47,6 @@ describe('<md-autocomplete>', function () {
47
47
expect ( scope . selectedItem ) . toBe ( null ) ;
48
48
49
49
element . scope ( ) . searchText = 'fo' ;
50
- ctrl . keydown ( { } ) ;
51
- element . scope ( ) . $apply ( ) ;
52
50
$timeout . flush ( ) ;
53
51
54
52
expect ( scope . searchText ) . toBe ( 'fo' ) ;
@@ -65,7 +63,6 @@ describe('<md-autocomplete>', function () {
65
63
preventDefault : angular . noop ,
66
64
stopPropagation : angular . noop
67
65
} ) ;
68
- scope . $apply ( ) ;
69
66
$timeout . flush ( ) ;
70
67
71
68
expect ( scope . searchText ) . toBe ( 'foo' ) ;
@@ -95,8 +92,6 @@ describe('<md-autocomplete>', function () {
95
92
expect ( scope . selectedItem ) . toBe ( null ) ;
96
93
97
94
element . scope ( ) . searchText = 'fo' ;
98
- ctrl . keydown ( { } ) ;
99
- element . scope ( ) . $apply ( ) ;
100
95
$timeout . flush ( ) ;
101
96
102
97
expect ( scope . searchText ) . toBe ( 'fo' ) ;
@@ -113,7 +108,6 @@ describe('<md-autocomplete>', function () {
113
108
preventDefault : angular . noop ,
114
109
stopPropagation : angular . noop
115
110
} ) ;
116
- scope . $apply ( ) ;
117
111
$timeout . flush ( ) ;
118
112
119
113
expect ( scope . searchText ) . toBe ( 'foo' ) ;
@@ -136,7 +130,6 @@ describe('<md-autocomplete>', function () {
136
130
<span md-highlight-text="searchText">{{item.display}}</span>\
137
131
</md-autocomplete>' ;
138
132
var element = compile ( template , scope ) ;
139
- var ctrl = element . controller ( 'mdAutocomplete' ) ;
140
133
var ul = element . find ( 'ul' ) ;
141
134
142
135
expect ( scope . searchText ) . toBe ( '' ) ;
@@ -152,7 +145,7 @@ describe('<md-autocomplete>', function () {
152
145
} ) ;
153
146
154
147
describe ( 'API access' , function ( ) {
155
- it ( 'should clear the selected item' , inject ( function ( $timeout , $mdConstant ) {
148
+ it ( 'should clear the selected item' , inject ( function ( $timeout ) {
156
149
var scope = createScope ( ) ;
157
150
var template = '\
158
151
<md-autocomplete\
@@ -167,12 +160,9 @@ describe('<md-autocomplete>', function () {
167
160
var ctrl = element . controller ( 'mdAutocomplete' ) ;
168
161
169
162
element . scope ( ) . searchText = 'fo' ;
170
- ctrl . keydown ( { } ) ;
171
- element . scope ( ) . $apply ( ) ;
172
163
$timeout . flush ( ) ;
173
164
174
165
ctrl . select ( 0 ) ;
175
- element . scope ( ) . $apply ( ) ;
176
166
$timeout . flush ( ) ;
177
167
178
168
expect ( scope . searchText ) . toBe ( 'foo' ) ;
@@ -187,10 +177,9 @@ describe('<md-autocomplete>', function () {
187
177
expect ( scope . selectedItem ) . toBe ( null ) ;
188
178
} ) ) ;
189
179
190
- it ( 'should notify selected item watchers' , inject ( function ( $timeout , $mdConstant ) {
191
- var scope = createScope ( ) ;
192
- var scopeItemChanged = 1 ;
193
- scope . itemChanged = jasmine . createSpy ( 'itemChanged' ) ;
180
+ it ( 'should notify selected item watchers' , inject ( function ( $timeout ) {
181
+ var scope = createScope ( ) ;
182
+ scope . itemChanged = jasmine . createSpy ( 'itemChanged' ) ;
194
183
195
184
var registeredWatcher = jasmine . createSpy ( 'registeredWatcher' ) ;
196
185
@@ -210,12 +199,9 @@ describe('<md-autocomplete>', function () {
210
199
ctrl . registerSelectedItemWatcher ( registeredWatcher ) ;
211
200
212
201
element . scope ( ) . searchText = 'fo' ;
213
- ctrl . keydown ( { } ) ;
214
- element . scope ( ) . $apply ( ) ;
215
202
$timeout . flush ( ) ;
216
203
217
204
ctrl . select ( 0 ) ;
218
- element . scope ( ) . $apply ( ) ;
219
205
$timeout . flush ( ) ;
220
206
221
207
expect ( scope . itemChanged ) . toHaveBeenCalled ( ) ;
@@ -237,7 +223,7 @@ describe('<md-autocomplete>', function () {
237
223
expect ( scope . itemChanged . calls . mostRecent ( ) . args [ 0 ] ) . toBeNull ( ) ;
238
224
expect ( scope . selectedItem ) . toBeNull ( ) ;
239
225
} ) ) ;
240
- it ( 'should pass value to item watcher' , inject ( function ( $timeout , $mdConstant ) {
226
+ it ( 'should pass value to item watcher' , inject ( function ( $timeout ) {
241
227
var scope = createScope ( ) ;
242
228
var itemValue = null ;
243
229
var template = '\
@@ -257,12 +243,9 @@ describe('<md-autocomplete>', function () {
257
243
var ctrl = element . controller ( 'mdAutocomplete' ) ;
258
244
259
245
element . scope ( ) . searchText = 'fo' ;
260
- ctrl . keydown ( { } ) ;
261
- element . scope ( ) . $apply ( ) ;
262
246
$timeout . flush ( ) ;
263
247
264
248
ctrl . select ( 0 ) ;
265
- element . scope ( ) . $apply ( ) ;
266
249
$timeout . flush ( ) ;
267
250
268
251
expect ( itemValue ) . not . toBeNull ( ) ;
@@ -272,4 +255,51 @@ describe('<md-autocomplete>', function () {
272
255
element . scope ( ) . $apply ( ) ;
273
256
} ) ) ;
274
257
} ) ;
258
+
259
+ describe ( 'md-select-on-match' , function ( ) {
260
+ it ( 'should select matching item on exact match when `md-select-on-match` is toggled' , inject ( function ( $timeout ) {
261
+ var scope = createScope ( ) ;
262
+ var template = '\
263
+ <md-autocomplete\
264
+ md-select-on-match\
265
+ md-selected-item="selectedItem"\
266
+ md-search-text="searchText"\
267
+ md-items="item in match(searchText)"\
268
+ md-item-text="item.display"\
269
+ placeholder="placeholder">\
270
+ <span md-highlight-text="searchText">{{item.display}}</span>\
271
+ </md-autocomplete>' ;
272
+ var element = compile ( template , scope ) ;
273
+
274
+ expect ( scope . searchText ) . toBe ( '' ) ;
275
+ expect ( scope . selectedItem ) . toBe ( null ) ;
276
+
277
+ element . scope ( ) . searchText = 'foo' ;
278
+ $timeout . flush ( ) ;
279
+
280
+ expect ( scope . selectedItem ) . not . toBe ( null ) ;
281
+ expect ( scope . selectedItem . display ) . toBe ( 'foo' ) ;
282
+ } ) ) ;
283
+ it ( 'should not select matching item on exact match when `md-select-on-match` is NOT toggled' , inject ( function ( $timeout ) {
284
+ var scope = createScope ( ) ;
285
+ var template = '\
286
+ <md-autocomplete\
287
+ md-selected-item="selectedItem"\
288
+ md-search-text="searchText"\
289
+ md-items="item in match(searchText)"\
290
+ md-item-text="item.display"\
291
+ placeholder="placeholder">\
292
+ <span md-highlight-text="searchText">{{item.display}}</span>\
293
+ </md-autocomplete>' ;
294
+ var element = compile ( template , scope ) ;
295
+
296
+ expect ( scope . searchText ) . toBe ( '' ) ;
297
+ expect ( scope . selectedItem ) . toBe ( null ) ;
298
+
299
+ element . scope ( ) . searchText = 'foo' ;
300
+ $timeout . flush ( ) ;
301
+
302
+ expect ( scope . selectedItem ) . toBe ( null ) ;
303
+ } ) ) ;
304
+ } ) ;
275
305
} ) ;
0 commit comments