@@ -469,54 +469,69 @@ describe('typeahead tests', function() {
469
469
$timeout . flush ( ) ;
470
470
expect ( $scope . isNoResults ) . toBeFalsy ( ) ;
471
471
} ) ) ;
472
+
473
+ it ( 'should not focus the input if `typeahead-focus-on-select` is false' , function ( ) {
474
+ var element = prepareInputEl ( '<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue" typeahead-focus-on-select="false"></div>' ) ;
475
+ var inputEl = findInput ( element ) ;
476
+
477
+ changeInputValueTo ( element , 'b' ) ;
478
+ var match = $ ( findMatches ( element ) [ 1 ] ) . find ( 'a' ) [ 0 ] ;
479
+
480
+ $ ( match ) . click ( ) ;
481
+ $scope . $digest ( ) ;
482
+ $timeout . flush ( ) ;
483
+
484
+ expect ( document . activeElement ) . not . toBe ( inputEl [ 0 ] ) ;
485
+ expect ( $scope . result ) . toEqual ( 'baz' ) ;
486
+ } ) ;
472
487
} ) ;
473
-
488
+
474
489
describe ( 'select on exact match' , function ( ) {
475
490
it ( 'should select on an exact match when set' , function ( ) {
476
491
$scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
477
492
var element = prepareInputEl ( '<div><input ng-model="result" typeahead-editable="false" typeahead-on-select="onSelect()" typeahead="item for item in source | filter:$viewValue" typeahead-select-on-exact="true"></div>' ) ;
478
493
var inputEl = findInput ( element ) ;
479
494
480
495
changeInputValueTo ( element , 'bar' ) ;
481
-
496
+
482
497
expect ( $scope . result ) . toEqual ( 'bar' ) ;
483
498
expect ( inputEl . val ( ) ) . toEqual ( 'bar' ) ;
484
499
expect ( element ) . toBeClosed ( ) ;
485
500
expect ( $scope . onSelect ) . toHaveBeenCalled ( ) ;
486
501
} ) ;
487
-
502
+
488
503
it ( 'should not select on an exact match by default' , function ( ) {
489
504
$scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
490
505
var element = prepareInputEl ( '<div><input ng-model="result" typeahead-editable="false" typeahead-on-select="onSelect()" typeahead="item for item in source | filter:$viewValue"></div>' ) ;
491
506
var inputEl = findInput ( element ) ;
492
-
507
+
493
508
changeInputValueTo ( element , 'bar' ) ;
494
-
509
+
495
510
expect ( $scope . result ) . toBeUndefined ( ) ;
496
511
expect ( inputEl . val ( ) ) . toEqual ( 'bar' ) ;
497
512
expect ( $scope . onSelect . calls . any ( ) ) . toBe ( false ) ;
498
513
} ) ;
499
-
514
+
500
515
it ( 'should not be case sensitive when select on an exact match' , function ( ) {
501
516
$scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
502
517
var element = prepareInputEl ( '<div><input ng-model="result" typeahead-editable="false" typeahead-on-select="onSelect()" typeahead="item for item in source | filter:$viewValue" typeahead-select-on-exact="true"></div>' ) ;
503
518
var inputEl = findInput ( element ) ;
504
519
505
520
changeInputValueTo ( element , 'BaR' ) ;
506
-
521
+
507
522
expect ( $scope . result ) . toEqual ( 'bar' ) ;
508
523
expect ( inputEl . val ( ) ) . toEqual ( 'bar' ) ;
509
524
expect ( element ) . toBeClosed ( ) ;
510
525
expect ( $scope . onSelect ) . toHaveBeenCalled ( ) ;
511
526
} ) ;
512
-
527
+
513
528
it ( 'should not auto select when not a match with one potential result left' , function ( ) {
514
529
$scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
515
530
var element = prepareInputEl ( '<div><input ng-model="result" typeahead-editable="false" typeahead-on-select="onSelect()" typeahead="item for item in source | filter:$viewValue" typeahead-select-on-exact="true"></div>' ) ;
516
531
var inputEl = findInput ( element ) ;
517
532
518
533
changeInputValueTo ( element , 'fo' ) ;
519
-
534
+
520
535
expect ( $scope . result ) . toBeUndefined ( ) ;
521
536
expect ( inputEl . val ( ) ) . toEqual ( 'fo' ) ;
522
537
expect ( $scope . onSelect . calls . any ( ) ) . toBe ( false ) ;
0 commit comments