@@ -588,6 +588,78 @@ describe('typeahead tests', function() {
588
588
} ) ;
589
589
} ) ;
590
590
591
+ describe ( 'is-open indicator' , function ( ) {
592
+ var element ;
593
+
594
+ beforeEach ( function ( ) {
595
+ element = prepareInputEl ( '<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-is-open="isOpen"></div>' ) ;
596
+ } ) ;
597
+
598
+ it ( 'should bind is-open indicator as true when matches are returned' , function ( ) {
599
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
600
+ changeInputValueTo ( element , 'b' ) ;
601
+ expect ( $scope . isOpen ) . toBeTruthy ( ) ;
602
+ } ) ;
603
+
604
+ it ( 'should bind is-open indicator as false when no matches returned' , function ( ) {
605
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
606
+ changeInputValueTo ( element , 'b' ) ;
607
+ expect ( $scope . isOpen ) . toBeTruthy ( ) ;
608
+ changeInputValueTo ( element , 'not match' ) ;
609
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
610
+ } ) ;
611
+
612
+ it ( 'should bind is-open indicator as false when a match is clicked' , function ( ) {
613
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
614
+ changeInputValueTo ( element , 'b' ) ;
615
+ expect ( $scope . isOpen ) . toBeTruthy ( ) ;
616
+ var match = findMatches ( element ) . find ( 'a' ) . eq ( 0 ) ;
617
+
618
+ match . click ( ) ;
619
+ $scope . $digest ( ) ;
620
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
621
+ } ) ;
622
+ it ( 'should bind is-open indicator as false when click outside' , function ( ) {
623
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
624
+ changeInputValueTo ( element , 'b' ) ;
625
+ expect ( $scope . isOpen ) . toBeTruthy ( ) ;
626
+ $document . find ( 'body' ) . click ( ) ;
627
+ $scope . $digest ( ) ;
628
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
629
+ } ) ;
630
+
631
+ it ( 'should bind is-open indicator as false on enter' , function ( ) {
632
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
633
+ changeInputValueTo ( element , 'b' ) ;
634
+ expect ( $scope . isOpen ) . toBeTruthy ( ) ;
635
+ triggerKeyDown ( element , 13 ) ;
636
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
637
+ } ) ;
638
+
639
+ it ( 'should bind is-open indicator as false on tab' , function ( ) {
640
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
641
+ changeInputValueTo ( element , 'b' ) ;
642
+ expect ( $scope . isOpen ) . toBeTruthy ( ) ;
643
+ triggerKeyDown ( element , 9 ) ;
644
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
645
+ } ) ;
646
+
647
+ it ( 'should bind is-open indicator as false on escape key' , function ( ) {
648
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
649
+ changeInputValueTo ( element , 'b' ) ;
650
+ expect ( $scope . isOpen ) . toBeTruthy ( ) ;
651
+ triggerKeyDown ( element , 27 ) ;
652
+ expect ( $scope . isOpen ) . toBeFalsy ( ) ;
653
+ } ) ;
654
+
655
+ it ( 'should bind is-open indicator as false input value smaller than a defined threshold' , function ( ) {
656
+ var element = prepareInputEl ( '<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-is-open="isToggled" typeahead-min-length="2"></div>' ) ;
657
+ expect ( $scope . isToggled ) . toBeFalsy ( ) ;
658
+ changeInputValueTo ( element , 'b' ) ;
659
+ expect ( $scope . isToggled ) . toBeFalsy ( ) ;
660
+ } ) ;
661
+ } ) ;
662
+
591
663
describe ( 'pop-up interaction' , function ( ) {
592
664
var element ;
593
665
0 commit comments