Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 161a996

Browse files
chrisirhcpkozlowski-opensource
authored andcommitted
test(typeahead): increase coverage of tests
1 parent 7515df4 commit 161a996

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

Diff for: src/typeahead/test/typeahead.spec.js

+85
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ describe('typeahead tests', function () {
276276

277277
expect(findMatches(element).eq(0).find('p').text()).toEqual('0 Alaska');
278278
}));
279+
280+
it('should throw error on invalid expression', function () {
281+
var prepareInvalidDir = function () {
282+
prepareInputEl("<div><input ng-model='result' typeahead='an invalid expression'></div>");
283+
};
284+
expect(prepareInvalidDir).toThrow();
285+
});
279286
});
280287

281288
describe('selecting a match', function () {
@@ -354,6 +361,84 @@ describe('typeahead tests', function () {
354361
});
355362
});
356363

364+
describe('pop-up interaction', function () {
365+
var element;
366+
367+
beforeEach(function () {
368+
element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>");
369+
});
370+
371+
it('should activate prev/next matches on up/down keys', function () {
372+
changeInputValueTo(element, 'b');
373+
expect(element).toBeOpenWithActive(2, 0);
374+
375+
// Down arrow key
376+
triggerKeyDown(element, 40);
377+
expect(element).toBeOpenWithActive(2, 1);
378+
379+
// Down arrow key goes back to first element
380+
triggerKeyDown(element, 40);
381+
expect(element).toBeOpenWithActive(2, 0);
382+
383+
// Up arrow key goes back to last element
384+
triggerKeyDown(element, 38);
385+
expect(element).toBeOpenWithActive(2, 1);
386+
387+
// Up arrow key goes back to last element
388+
triggerKeyDown(element, 38);
389+
expect(element).toBeOpenWithActive(2, 0);
390+
});
391+
392+
it('should close popup on escape key', function () {
393+
changeInputValueTo(element, 'b');
394+
expect(element).toBeOpenWithActive(2, 0);
395+
396+
// Escape key
397+
triggerKeyDown(element, 27);
398+
expect(element).toBeClosed();
399+
});
400+
401+
it('should highlight match on mouseenter', function () {
402+
changeInputValueTo(element, 'b');
403+
expect(element).toBeOpenWithActive(2, 0);
404+
405+
findMatches(element).eq(1).trigger('mouseenter');
406+
expect(element).toBeOpenWithActive(2, 1);
407+
});
408+
409+
});
410+
411+
describe('promises', function () {
412+
var element, deferred;
413+
414+
beforeEach(inject(function ($q) {
415+
deferred = $q.defer();
416+
$scope.source = function () {
417+
return deferred.promise;
418+
};
419+
element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in source()'></div>");
420+
}));
421+
422+
it('should display matches from promise', function () {
423+
changeInputValueTo(element, 'c');
424+
expect(element).toBeClosed();
425+
426+
deferred.resolve(['good', 'stuff']);
427+
$scope.$digest();
428+
expect(element).toBeOpenWithActive(2, 0);
429+
});
430+
431+
it('should not display anything when promise is rejected', function () {
432+
changeInputValueTo(element, 'c');
433+
expect(element).toBeClosed();
434+
435+
deferred.reject('fail');
436+
$scope.$digest();
437+
expect(element).toBeClosed();
438+
});
439+
440+
});
441+
357442
describe('non-regressions tests', function () {
358443

359444
it('issue 231 - closes matches popup on click outside typeahead', function () {

0 commit comments

Comments
 (0)