@@ -528,6 +528,45 @@ describe('typeahead tests', function () {
528
528
expect ( $scope . isLoading ) . toBeFalsy ( ) ;
529
529
} ) ;
530
530
531
+ it ( 'should update loading callback when input loses focus' , function ( ) {
532
+ $scope . isLoading = false ;
533
+ $scope . items = function ( viewValue ) {
534
+ return $timeout ( function ( ) {
535
+ return [ viewValue ] ;
536
+ } ) ;
537
+ } ;
538
+
539
+ var element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in items($viewValue)' typeahead-loading='isLoading'></div>" ) ;
540
+ changeInputValueTo ( element , 'foo' ) ;
541
+
542
+ expect ( $scope . isLoading ) . toBeTruthy ( ) ;
543
+
544
+ findInput ( element ) . blur ( ) ;
545
+ $timeout . flush ( ) ;
546
+
547
+ expect ( $scope . isLoading ) . toBeFalsy ( ) ;
548
+ } ) ;
549
+
550
+ it ( 'should update loading callback when promise is rejected' , inject ( function ( $q ) {
551
+ var element , deferred ;
552
+
553
+ deferred = $q . defer ( ) ;
554
+ $scope . isLoading = false ;
555
+ $scope . items = function ( viewValue ) {
556
+ return deferred . promise ;
557
+ } ;
558
+
559
+ element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in items($viewValue)' typeahead-loading='isLoading'></div>" ) ;
560
+ changeInputValueTo ( element , 'foo' ) ;
561
+
562
+ expect ( $scope . isLoading ) . toBeTruthy ( ) ;
563
+
564
+ deferred . reject ( [ 'bar' ] ) ;
565
+ $timeout . flush ( ) ;
566
+
567
+ expect ( $scope . isLoading ) . toBeFalsy ( ) ;
568
+ } ) ) ;
569
+
531
570
it ( 'does not close matches popup on click in input' , function ( ) {
532
571
var element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>" ) ;
533
572
var inputEl = findInput ( element ) ;
0 commit comments