11describe ( 'typeahead tests' , function ( ) {
22
3- var $scope , $compile , $document ;
3+ var $scope , $compile , $document , $timeout ;
44 var changeInputValueTo ;
55
66 beforeEach ( module ( 'ui.bootstrap.typeahead' ) ) ;
@@ -18,7 +18,7 @@ describe('typeahead tests', function () {
1818 } ;
1919 } ) ;
2020 } ) ) ;
21- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$document_ , $sniffer ) {
21+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$document_ , _$timeout_ , $sniffer ) {
2222 $scope = _$rootScope_ ;
2323 $scope . source = [ 'foo' , 'bar' , 'baz' ] ;
2424 $scope . states = [
@@ -27,6 +27,7 @@ describe('typeahead tests', function () {
2727 ] ;
2828 $compile = _$compile_ ;
2929 $document = _$document_ ;
30+ $timeout = _$timeout_ ;
3031 changeInputValueTo = function ( element , value ) {
3132 var inputEl = findInput ( element ) ;
3233 inputEl . val ( value ) ;
@@ -396,6 +397,25 @@ describe('typeahead tests', function () {
396397 expect ( inputEl . val ( ) ) . toEqual ( 'bar@host.com' ) ;
397398 } ) ;
398399
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+
399419 it ( 'does not close matches popup on click in input' , function ( ) {
400420 var element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>" ) ;
401421 var inputEl = findInput ( element ) ;
0 commit comments