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