From a852e5f95e77dc6ec7eac58b9c313885e0b9ff9e Mon Sep 17 00:00:00 2001 From: Warren Konkel Date: Wed, 5 Nov 2014 08:57:41 -0800 Subject: [PATCH] test(typeahead): focus-first handles preventDefault on enter/tab --- src/typeahead/test/typeahead.spec.js | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 68c751007f..8f2c7323c1 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -734,4 +734,33 @@ describe('typeahead tests', function () { }); }); + it('should not capture enter or tab until an item is focused', function () { + $scope.select_count = 0; + $scope.onSelect = function ($item, $model, $label) { + $scope.select_count = $scope.select_count + 1; + }; + var element = prepareInputEl('
'); + changeInputValueTo(element, 'b'); + + // enter key should not be captured when nothing is focused + triggerKeyDown(element, 13); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy(); + expect($scope.select_count).toEqual(0); + + // tab key should not be captured when nothing is focused + triggerKeyDown(element, 9); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy(); + expect($scope.select_count).toEqual(0); + + // down key should be captured and focus first element + triggerKeyDown(element, 40); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeTruthy(); + expect(element).toBeOpenWithActive(2, 0); + + // enter key should be captured now that something is focused + triggerKeyDown(element, 13); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeTruthy(); + expect($scope.select_count).toEqual(1); + }); + });