@@ -456,6 +456,63 @@ describe('typeahead tests', function () {
456
456
expect ( inputEl . val ( ) ) . toEqual ( 'AL' ) ;
457
457
} ) ;
458
458
} ) ;
459
+
460
+ describe ( 'select on exact match' , function ( ) {
461
+
462
+ it ( 'should select on an exact match when set' , function ( ) {
463
+
464
+ $scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
465
+ 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>' ) ;
466
+ var inputEl = findInput ( element ) ;
467
+
468
+ changeInputValueTo ( element , 'bar' ) ;
469
+
470
+ expect ( $scope . result ) . toEqual ( 'bar' ) ;
471
+ expect ( inputEl . val ( ) ) . toEqual ( 'bar' ) ;
472
+ expect ( element ) . toBeClosed ( ) ;
473
+ expect ( $scope . onSelect ) . toHaveBeenCalled ( ) ;
474
+ } ) ;
475
+
476
+ it ( 'should not select on an exact match by default' , function ( ) {
477
+
478
+ $scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
479
+ var element = prepareInputEl ( '<div><input ng-model="result" typeahead-editable="false" typeahead-on-select="onSelect()" typeahead="item for item in source | filter:$viewValue"></div>' ) ;
480
+ var inputEl = findInput ( element ) ;
481
+
482
+ changeInputValueTo ( element , 'bar' ) ;
483
+
484
+ expect ( $scope . result ) . toBeUndefined ( ) ;
485
+ expect ( inputEl . val ( ) ) . toEqual ( 'bar' ) ;
486
+ expect ( $scope . onSelect . calls . any ( ) ) . toBe ( false ) ;
487
+ } ) ;
488
+
489
+ it ( 'should not be case sensitive when select on an exact match' , function ( ) {
490
+
491
+ $scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
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>' ) ;
493
+ var inputEl = findInput ( element ) ;
494
+
495
+ changeInputValueTo ( element , 'BaR' ) ;
496
+
497
+ expect ( $scope . result ) . toEqual ( 'bar' ) ;
498
+ expect ( inputEl . val ( ) ) . toEqual ( 'bar' ) ;
499
+ expect ( element ) . toBeClosed ( ) ;
500
+ expect ( $scope . onSelect ) . toHaveBeenCalled ( ) ;
501
+ } ) ;
502
+
503
+ it ( 'should not auto select when not a match with one potential result left' , function ( ) {
504
+
505
+ $scope . onSelect = jasmine . createSpy ( 'onSelect' ) ;
506
+ 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>' ) ;
507
+ var inputEl = findInput ( element ) ;
508
+
509
+ changeInputValueTo ( element , 'fo' ) ;
510
+
511
+ expect ( $scope . result ) . toBeUndefined ( ) ;
512
+ expect ( inputEl . val ( ) ) . toEqual ( 'fo' ) ;
513
+ expect ( $scope . onSelect . calls . any ( ) ) . toBe ( false ) ;
514
+ } ) ;
515
+ } ) ;
459
516
460
517
describe ( 'pop-up interaction' , function ( ) {
461
518
var element ;
0 commit comments