1
1
describe ( 'typeahead tests' , function ( ) {
2
2
3
- var $scope , $compile , $document ;
3
+ var $scope , $compile , $document , $timeout ;
4
4
var changeInputValueTo ;
5
5
6
6
beforeEach ( module ( 'ui.bootstrap.typeahead' ) ) ;
@@ -18,7 +18,7 @@ describe('typeahead tests', function () {
18
18
} ;
19
19
} ) ;
20
20
} ) ) ;
21
- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$document_ , $sniffer ) {
21
+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$document_ , _$timeout_ , $sniffer ) {
22
22
$scope = _$rootScope_ ;
23
23
$scope . source = [ 'foo' , 'bar' , 'baz' ] ;
24
24
$scope . states = [
@@ -27,6 +27,7 @@ describe('typeahead tests', function () {
27
27
] ;
28
28
$compile = _$compile_ ;
29
29
$document = _$document_ ;
30
+ $timeout = _$timeout_ ;
30
31
changeInputValueTo = function ( element , value ) {
31
32
var inputEl = findInput ( element ) ;
32
33
inputEl . val ( value ) ;
@@ -396,6 +397,25 @@ describe('typeahead tests', function () {
396
397
expect ( inputEl . val ( ) ) . toEqual ( 'bar@host.com' ) ;
397
398
} ) ;
398
399
400
+ it ( 'issue 964 - should not show popup with matches if an element is not focused' , function ( ) {
401
+
402
+ $scope . items = function ( viewValue ) {
403
+ return $timeout ( function ( ) {
404
+ return [ viewValue ] ;
405
+ } ) ;
406
+ } ;
407
+ var element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in items($viewValue)'></div>" ) ;
408
+ var inputEl = findInput ( element ) ;
409
+
410
+ changeInputValueTo ( element , 'match' ) ;
411
+ $scope . $digest ( ) ;
412
+
413
+ inputEl . blur ( ) ;
414
+ $timeout . flush ( ) ;
415
+
416
+ expect ( element ) . toBeClosed ( ) ;
417
+ } ) ;
418
+
399
419
it ( 'does not close matches popup on click in input' , function ( ) {
400
420
var element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>" ) ;
401
421
var inputEl = findInput ( element ) ;
0 commit comments