Skip to content

Commit

Permalink
JSUI-2404 Don't send the "tab" parameter to querySuggest if it's an e…
Browse files Browse the repository at this point in the history
…mpty string (#1042)

* Don't send the "tab" parameter to querySuggest if it's an empty string

https://coveord.atlassian.net/browse/JSUI-2404
  • Loading branch information
ThibodeauJF committed Mar 14, 2019
1 parent 5a7e37a commit 31115fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ui/Omnibox/QuerySuggestAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { map, every, last, indexOf, find } from 'underscore';
import { QUERY_STATE_ATTRIBUTES } from '../../models/QueryStateModel';
import { history } from 'coveo.analytics';
import { Cookie } from '../../utils/CookieUtils';
import { Utils } from '../../utils/Utils';

export interface IQuerySuggestAddon {
getSuggestion(): Promise<IOmniboxSuggestion[]>;
Expand Down Expand Up @@ -112,7 +113,13 @@ export class QuerySuggestAddon implements IQuerySuggestAddon {
}

private get tab() {
return this.omnibox.getBindings().queryStateModel.get(QUERY_STATE_ATTRIBUTES.T) as string;
const tab = this.omnibox.getBindings().queryStateModel.get(QUERY_STATE_ATTRIBUTES.T) as string;

if (Utils.isNonEmptyString(tab)) {
return tab;
}

return undefined;
}

private get locale() {
Expand Down
10 changes: 10 additions & 0 deletions unitTests/ui/QuerySuggestAddonTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ export function QuerySuggestAddonTest() {
done();
});

it("without the tab if it's empty", async done => {
(omnibox.env.queryStateModel.get as jasmine.Spy).and.callFake(
(param: string) => (param == QUERY_STATE_ATTRIBUTES.T ? '' : 'something else')
);
querySuggest = new QuerySuggestAddon(omnibox.cmp);
await querySuggest.getSuggestion();
spyShouldHaveBeenCalledWith('tab', undefined);
done();
});

it('with enableWordCompletion', async done => {
omnibox.cmp.options.enableSearchAsYouType = true;
querySuggest = new QuerySuggestAddon(omnibox.cmp);
Expand Down

0 comments on commit 31115fe

Please sign in to comment.