@@ -58,7 +58,7 @@ describe('<md-autocomplete>', function() {
58
58
}
59
59
60
60
describe ( 'basic functionality' , function ( ) {
61
- it ( 'should update selected item and search text' , inject ( function ( $timeout , $mdConstant , $material ) {
61
+ it ( 'updates selected item and search text' , inject ( function ( $timeout , $mdConstant , $material ) {
62
62
var scope = createScope ( ) ;
63
63
var template = '\
64
64
<md-autocomplete\
@@ -103,8 +103,7 @@ describe('<md-autocomplete>', function() {
103
103
element . remove ( ) ;
104
104
} ) ) ;
105
105
106
-
107
- it ( 'should allow you to set an input id without floating label' , inject ( function ( ) {
106
+ it ( 'allows you to set an input id without floating label' , inject ( function ( ) {
108
107
var scope = createScope ( null , { inputId : 'custom-input-id' } ) ;
109
108
var template = '\
110
109
<md-autocomplete\
@@ -124,7 +123,7 @@ describe('<md-autocomplete>', function() {
124
123
element . remove ( ) ;
125
124
} ) ) ;
126
125
127
- it ( 'should allow allow using ng-readonly' , inject ( function ( ) {
126
+ it ( 'allows using ng-readonly' , inject ( function ( ) {
128
127
var scope = createScope ( null , { inputId : 'custom-input-id' } ) ;
129
128
var template = '\
130
129
<md-autocomplete\
@@ -153,7 +152,7 @@ describe('<md-autocomplete>', function() {
153
152
element . remove ( ) ;
154
153
} ) ) ;
155
154
156
- it ( 'should allow allow using an empty readonly attribute' , inject ( function ( ) {
155
+ it ( 'allows using an empty readonly attribute' , inject ( function ( ) {
157
156
var scope = createScope ( null , { inputId : 'custom-input-id' } ) ;
158
157
var template = '\
159
158
<md-autocomplete\
@@ -174,7 +173,7 @@ describe('<md-autocomplete>', function() {
174
173
element . remove ( ) ;
175
174
} ) ) ;
176
175
177
- it ( 'should allow you to set an input id with floating label' , inject ( function ( ) {
176
+ it ( 'allows you to set an input id with floating label' , inject ( function ( ) {
178
177
var scope = createScope ( null , { inputId : 'custom-input-id' } ) ;
179
178
var template = '\
180
179
<md-autocomplete\
@@ -195,7 +194,7 @@ describe('<md-autocomplete>', function() {
195
194
element . remove ( ) ;
196
195
} ) ) ;
197
196
198
- it ( 'should forward the `md-select-on-focus` attribute to the input' , inject ( function ( ) {
197
+ it ( 'forwards the `md-select-on-focus` attribute to the input' , inject ( function ( ) {
199
198
var scope = createScope ( null , { inputId : 'custom-input-id' } ) ;
200
199
var template =
201
200
'<md-autocomplete ' +
@@ -218,7 +217,7 @@ describe('<md-autocomplete>', function() {
218
217
element . remove ( ) ;
219
218
} ) ) ;
220
219
221
- it ( 'should forward the tabindex to the input' , inject ( function ( ) {
220
+ it ( 'forwards the tabindex to the input' , inject ( function ( ) {
222
221
var scope = createScope ( null , { inputId : 'custom-input-id' } ) ;
223
222
var template =
224
223
'<md-autocomplete ' +
@@ -240,7 +239,7 @@ describe('<md-autocomplete>', function() {
240
239
element . remove ( ) ;
241
240
} ) ) ;
242
241
243
- it ( 'should always set the tabindex of the autcomplete to `-1`' , inject ( function ( ) {
242
+ it ( 'always sets the tabindex of the autcomplete to `-1`' , inject ( function ( ) {
244
243
var scope = createScope ( null , { inputId : 'custom-input-id' } ) ;
245
244
var template =
246
245
'<md-autocomplete ' +
@@ -291,7 +290,7 @@ describe('<md-autocomplete>', function() {
291
290
element . remove ( ) ;
292
291
} ) ) ;
293
292
294
- it ( 'should clear value when hitting escape' , inject ( function ( $mdConstant , $timeout ) {
293
+ it ( 'clears the value when hitting escape' , inject ( function ( $mdConstant , $timeout ) {
295
294
var scope = createScope ( ) ;
296
295
var template = '\
297
296
<md-autocomplete\
@@ -380,7 +379,7 @@ describe('<md-autocomplete>', function() {
380
379
} ) ;
381
380
382
381
describe ( 'basic functionality with template' , function ( ) {
383
- it ( 'should update selected item and search text' , inject ( function ( $timeout , $material , $mdConstant ) {
382
+ it ( 'updates selected item and search text' , inject ( function ( $timeout , $material , $mdConstant ) {
384
383
var scope = createScope ( ) ;
385
384
var template = '\
386
385
<md-autocomplete\
@@ -423,7 +422,60 @@ describe('<md-autocomplete>', function() {
423
422
element . remove ( ) ;
424
423
} ) ) ;
425
424
426
- it ( 'should compile the template against the parent scope' , inject ( function ( $timeout , $material ) {
425
+ it ( 'properly clears values when the item ends in a space character' , inject ( function ( $timeout , $material , $mdConstant ) {
426
+ var myItems = [ 'foo ' , 'bar' , 'baz' ] . map ( function ( item ) {
427
+ return { display : item } ;
428
+ } ) ;
429
+ var scope = createScope ( myItems ) ;
430
+
431
+ var template = '\
432
+ <md-autocomplete\
433
+ md-selected-item="selectedItem"\
434
+ md-search-text="searchText"\
435
+ md-items="item in match(searchText)"\
436
+ md-item-text="item.display"\
437
+ placeholder="placeholder">\
438
+ <md-item-template>\
439
+ <span md-highlight-text="searchText">{{item.display}}</span>\
440
+ </md-item-template>\
441
+ </md-autocomplete>' ;
442
+ var element = compile ( template , scope ) ;
443
+ var ctrl = element . controller ( 'mdAutocomplete' ) ;
444
+ var ul = element . find ( 'ul' ) ;
445
+
446
+ expect ( scope . searchText ) . toBe ( '' ) ;
447
+ expect ( scope . selectedItem ) . toBe ( null ) ;
448
+
449
+ $material . flushInterimElement ( ) ;
450
+
451
+ // Focus the input
452
+ ctrl . focus ( ) ;
453
+
454
+ element . scope ( ) . searchText = 'fo' ;
455
+ waitForVirtualRepeat ( element ) ;
456
+
457
+ expect ( scope . searchText ) . toBe ( 'fo' ) ;
458
+ expect ( scope . match ( scope . searchText ) . length ) . toBe ( 1 ) ;
459
+ expect ( ul . find ( 'li' ) . length ) . toBe ( 1 ) ;
460
+
461
+ ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . DOWN_ARROW ) ) ;
462
+ ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . ENTER ) ) ;
463
+
464
+ $timeout . flush ( ) ;
465
+
466
+ expect ( scope . searchText ) . toBe ( 'foo ' ) ;
467
+ expect ( scope . selectedItem ) . toBe ( scope . match ( scope . searchText ) [ 0 ] ) ;
468
+
469
+ ctrl . clear ( ) ;
470
+ $timeout . flush ( ) ;
471
+
472
+ expect ( scope . searchText ) . toBe ( '' ) ;
473
+ expect ( scope . selectedItem ) . toBe ( null ) ;
474
+
475
+ element . remove ( ) ;
476
+ } ) ) ;
477
+
478
+ it ( 'compiles the template against the parent scope' , inject ( function ( $timeout , $material ) {
427
479
var scope = createScope ( null , { bang : 'boom' } ) ;
428
480
var template =
429
481
'<md-autocomplete' +
@@ -470,7 +522,7 @@ describe('<md-autocomplete>', function() {
470
522
element . remove ( ) ;
471
523
} ) ) ;
472
524
473
- it ( 'should remove the md-scroll-mask on cleanup' , inject ( function ( $mdUtil , $timeout , $material ) {
525
+ it ( 'removes the md-scroll-mask on cleanup' , inject ( function ( $mdUtil , $timeout , $material ) {
474
526
spyOn ( $mdUtil , 'enableScrolling' ) ;
475
527
476
528
var scope = createScope ( ) ;
@@ -513,7 +565,7 @@ describe('<md-autocomplete>', function() {
513
565
expect ( $mdUtil . enableScrolling ) . toHaveBeenCalled ( ) ;
514
566
} ) ) ;
515
567
516
- it ( 'should ensure the parent scope digests along with the current scope' , inject ( function ( $timeout , $material ) {
568
+ it ( 'ensures the parent scope digests along with the current scope' , inject ( function ( $timeout , $material ) {
517
569
var scope = createScope ( null , { bang : 'boom' } ) ;
518
570
var template =
519
571
'<md-autocomplete' +
@@ -695,7 +747,7 @@ describe('<md-autocomplete>', function() {
695
747
expect ( ctrl2 . hasNotFound ) . toBe ( false ) ;
696
748
} ) ) ;
697
749
698
- it ( 'should even show the md-not-found template if we have lost focus' , inject ( function ( $timeout ) {
750
+ it ( 'shows the md-not-found template even if we have lost focus' , inject ( function ( $timeout ) {
699
751
var scope = createScope ( ) ;
700
752
var template =
701
753
'<md-autocomplete' +
@@ -807,7 +859,7 @@ describe('<md-autocomplete>', function() {
807
859
808
860
describe ( 'Async matching' , function ( ) {
809
861
810
- it ( 'should probably stop the loading indicator when clearing' , inject ( function ( $timeout , $material ) {
862
+ it ( 'properly stops the loading indicator when clearing' , inject ( function ( $timeout , $material ) {
811
863
var scope = createScope ( ) ;
812
864
var template =
813
865
'<md-autocomplete ' +
@@ -837,7 +889,7 @@ describe('<md-autocomplete>', function() {
837
889
} ) ;
838
890
839
891
describe ( 'API access' , function ( ) {
840
- it ( 'should clear the selected item' , inject ( function ( $timeout ) {
892
+ it ( 'clears the selected item' , inject ( function ( $timeout ) {
841
893
var scope = createScope ( ) ;
842
894
var template = '\
843
895
<md-autocomplete\
@@ -871,7 +923,7 @@ describe('<md-autocomplete>', function() {
871
923
element . remove ( ) ;
872
924
} ) ) ;
873
925
874
- it ( 'should notify selected item watchers' , inject ( function ( $timeout ) {
926
+ it ( 'notifies selected item watchers' , inject ( function ( $timeout ) {
875
927
var scope = createScope ( ) ;
876
928
scope . itemChanged = jasmine . createSpy ( 'itemChanged' ) ;
877
929
@@ -919,7 +971,7 @@ describe('<md-autocomplete>', function() {
919
971
920
972
element . remove ( ) ;
921
973
} ) ) ;
922
- it ( 'should pass value to item watcher' , inject ( function ( $timeout ) {
974
+ it ( 'passes the value to the item watcher' , inject ( function ( $timeout ) {
923
975
var scope = createScope ( ) ;
924
976
var itemValue = null ;
925
977
var template = '\
@@ -955,7 +1007,7 @@ describe('<md-autocomplete>', function() {
955
1007
} ) ;
956
1008
957
1009
describe ( 'md-select-on-match' , function ( ) {
958
- it ( 'should select matching item on exact match when `md-select-on-match` is toggled' , inject ( function ( $timeout ) {
1010
+ it ( 'selects matching item on exact match when `md-select-on-match` is toggled' , inject ( function ( $timeout ) {
959
1011
var scope = createScope ( ) ;
960
1012
var template = '\
961
1013
<md-autocomplete\
@@ -1004,7 +1056,7 @@ describe('<md-autocomplete>', function() {
1004
1056
element . remove ( ) ;
1005
1057
} ) ) ;
1006
1058
1007
- it ( 'should select matching item using case insensitive' , inject ( function ( $timeout ) {
1059
+ it ( 'selects matching item using case insensitive' , inject ( function ( $timeout ) {
1008
1060
var scope = createScope ( null , null , true ) ;
1009
1061
var template =
1010
1062
'<md-autocomplete ' +
@@ -1063,7 +1115,7 @@ describe('<md-autocomplete>', function() {
1063
1115
element . remove ( ) ;
1064
1116
} ) ;
1065
1117
1066
- it ( 'should validate an empty `required` as true' , function ( ) {
1118
+ it ( 'validates an empty `required` as true' , function ( ) {
1067
1119
var scope = createScope ( ) ;
1068
1120
var template = '\
1069
1121
<md-autocomplete\
@@ -1082,7 +1134,7 @@ describe('<md-autocomplete>', function() {
1082
1134
expect ( ctrl . isRequired ) . toBe ( true ) ;
1083
1135
} ) ;
1084
1136
1085
- it ( 'should correctly validate an interpolated `ng-required` value' , function ( ) {
1137
+ it ( 'correctly validates an interpolated `ng-required` value' , function ( ) {
1086
1138
var scope = createScope ( ) ;
1087
1139
var template = '\
1088
1140
<md-autocomplete\
@@ -1111,7 +1163,7 @@ describe('<md-autocomplete>', function() {
1111
1163
expect ( ctrl . isRequired ) . toBe ( true ) ;
1112
1164
} ) ;
1113
1165
1114
- it ( 'should forward the md-no-asterisk attribute' , function ( ) {
1166
+ it ( 'forwards the md-no-asterisk attribute' , function ( ) {
1115
1167
var scope = createScope ( ) ;
1116
1168
var template = '\
1117
1169
<md-autocomplete\
@@ -1133,7 +1185,7 @@ describe('<md-autocomplete>', function() {
1133
1185
} ) ;
1134
1186
1135
1187
describe ( 'md-highlight-text' , function ( ) {
1136
- it ( 'should update when content is modified' , inject ( function ( ) {
1188
+ it ( 'updates when content is modified' , inject ( function ( ) {
1137
1189
var template = '<div md-highlight-text="query">{{message}}</div>' ;
1138
1190
var scope = createScope ( null , { message : 'some text' , query : 'some' } ) ;
1139
1191
var element = compile ( template , scope ) ;
0 commit comments