Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit ae6f7c9

Browse files
committed
Added test coverage for debounce logic
Test coverage. Verify that the custom debounce always overrides the default.
1 parent 7511454 commit ae6f7c9

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

source/components/inputs/typeahead/typeahead.tests.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import __search = services.search;
1010

1111
import { ComponentValidator } from '../../../services/componentValidator/componentValidator.service';
1212

13-
import { TypeaheadComponent, DEFAULT_SERVER_SEARCH_DEBOUNCE } from './typeahead';
13+
import { TypeaheadComponent, DEFAULT_SERVER_SEARCH_DEBOUNCE, DEFAULT_CLIENT_SEARCH_DEBOUNCE } from './typeahead';
1414

1515
interface ITransformMock {
1616
getValue: Sinon.SinonSpy;
@@ -69,6 +69,38 @@ describe('TypeaheadComponent', () => {
6969
expect(typeahead.collapsed).to.be.true;
7070
});
7171

72+
describe('debounce', () => {
73+
it('should use the default server search debounce by default', () => {
74+
typeahead.ngOnInit();
75+
expect(typeahead.loadDelay).to.equal(DEFAULT_SERVER_SEARCH_DEBOUNCE);
76+
});
77+
78+
it('should use the default client search debounce if client searching is on', () => {
79+
typeahead.clientSearch = true;
80+
typeahead.ngOnInit();
81+
expect(typeahead.loadDelay).to.equal(DEFAULT_CLIENT_SEARCH_DEBOUNCE);
82+
});
83+
84+
it('should use the custom debounce when client searching is off', () => {
85+
const debounce = 10000;
86+
typeahead.debounce = debounce;
87+
88+
typeahead.ngOnInit();
89+
90+
expect(typeahead.loadDelay).to.equal(debounce);
91+
});
92+
93+
it('should use the custom debounce when client searching is on', () => {
94+
const debounce = 10000;
95+
typeahead.debounce = debounce;
96+
97+
typeahead.clientSearch = true;
98+
typeahead.ngOnInit();
99+
100+
expect(typeahead.loadDelay).to.equal(debounce);
101+
});
102+
});
103+
72104
describe('loadItems', (): void => {
73105
let items: string[];
74106

0 commit comments

Comments
 (0)