@@ -400,48 +400,67 @@ describe('<md-autocomplete>', function() {
400
400
placeholder="placeholder">\
401
401
<span md-highlight-text="searchText">{{item.display}}</span>\
402
402
</md-autocomplete>' ;
403
- beforeEach ( inject ( function ( $timeout ) {
403
+ beforeEach ( inject ( function ( $timeout , $material ) {
404
404
scope = createScope ( ) ;
405
405
element = compile ( template , scope ) ;
406
406
ctrl = element . controller ( 'mdAutocomplete' ) ;
407
407
408
+ $material . flushInterimElement ( ) ;
409
+
410
+ // Update the scope
411
+ element . scope ( ) . searchText = 'fo' ;
412
+ waitForVirtualRepeat ( element ) ;
413
+
408
414
// Focus the input
409
415
ctrl . focus ( ) ;
410
416
$timeout . flush ( ) ;
411
- expect ( scope . searchText ) . toBe ( '' ) ;
412
417
413
- scope . $apply ( 'searchText = "test"' ) ;
418
+ expect ( ctrl . hidden ) . toBe ( false ) ;
414
419
415
- expect ( scope . searchText ) . toBe ( 'test ' ) ;
420
+ expect ( scope . searchText ) . toBe ( 'fo ' ) ;
416
421
422
+ waitForVirtualRepeat ( element ) ;
417
423
$timeout . flush ( ) ;
424
+ expect ( ctrl . hidden ) . toBe ( false ) ;
418
425
} ) ) ;
419
426
420
427
afterEach ( function ( ) { element . remove ( ) } ) ;
421
- it ( 'does not clear the value nor blur when hitting escape' , inject ( function ( $mdConstant , $document ) {
428
+ it ( 'does not clear the value nor blur when hitting escape' , inject ( function ( $mdConstant , $document , $timeout ) {
422
429
scope . $apply ( 'escapeOptions = "none"' ) ;
423
430
scope . $apply ( function ( ) {
424
431
ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . ESCAPE ) ) ;
432
+ $timeout . flush ( ) ;
433
+ expect ( ctrl . hidden ) . toBe ( true ) ;
434
+ ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . ESCAPE ) ) ;
435
+ $timeout . flush ( ) ;
425
436
} ) ;
426
437
427
- expect ( scope . searchText ) . toBe ( 'test ' ) ;
438
+ expect ( scope . searchText ) . toBe ( 'fo ' ) ;
428
439
expect ( $document . activeElement ) . toBe ( ctrl [ 0 ] ) ;
429
440
} ) ) ;
430
441
431
- it ( 'does not clear the value but does blur when hitting escape' , inject ( function ( $mdConstant , $document ) {
442
+ it ( 'does not clear the value but does blur when hitting escape' , inject ( function ( $mdConstant , $document , $timeout ) {
432
443
scope . $apply ( 'escapeOptions = "blur"' ) ;
433
444
scope . $apply ( function ( ) {
434
445
ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . ESCAPE ) ) ;
446
+ $timeout . flush ( ) ;
447
+ expect ( ctrl . hidden ) . toBe ( true ) ;
448
+ ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . ESCAPE ) ) ;
449
+ $timeout . flush ( ) ;
435
450
} ) ;
436
451
437
- expect ( scope . searchText ) . toBe ( 'test ' ) ;
452
+ expect ( scope . searchText ) . toBe ( 'fo ' ) ;
438
453
expect ( $document . activeElement ) . toBe ( undefined ) ;
439
454
} ) ) ;
440
455
441
- it ( 'clear the value but does not blur when hitting escape' , inject ( function ( $mdConstant , $document ) {
456
+ it ( 'clear the value but does not blur when hitting escape' , inject ( function ( $mdConstant , $document , $timeout ) {
442
457
scope . $apply ( 'escapeOptions = "clear"' ) ;
443
458
scope . $apply ( function ( ) {
444
459
ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . ESCAPE ) ) ;
460
+ $timeout . flush ( ) ;
461
+ expect ( ctrl . hidden ) . toBe ( true ) ;
462
+ ctrl . keydown ( keydownEvent ( $mdConstant . KEY_CODE . ESCAPE ) ) ;
463
+ $timeout . flush ( ) ;
445
464
} ) ;
446
465
447
466
expect ( scope . searchText ) . toBe ( '' ) ;
0 commit comments