Skip to content

Commit

Permalink
Added another test for websearch
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Sep 27, 2018
1 parent 312baca commit 9dbee12
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/tests/unit/searcher/web-search-searcher.test.ts
Expand Up @@ -35,7 +35,7 @@ describe(WebSearchSearcher.name, (): void => {
}
});

it("should throw an error if user input does not match any search engine", () => {
it("should throw an error if user input does not match any search engine", (): void => {
const invalidUserInputs = [
"",
" ",
Expand All @@ -55,6 +55,27 @@ describe(WebSearchSearcher.name, (): void => {

expect(errorCounter).toBe(invalidUserInputs.length);
});

it("should trim the user's search term", (): void => {
const userSearchTerms = [
"hallo",
" hallo ",
" hallo",
"hallo ",
];

const trimmedUserInput = "hallo";

for (const dummyWebSearch of dummyWebSearches) {
for (const userSearchTerm of userSearchTerms) {
const userInput = `${dummyWebSearch.prefix}${WebSearchHelpers.webSearchSeparator}${userSearchTerm}`;
const actual = searcher.getSearchResult(userInput);

expect(actual.length).toBe(1);
expect(actual[0].executionArgument).toBe(`${dummyWebSearch.url}${trimmedUserInput}`);
}
}
});
}
});
});
8 changes: 5 additions & 3 deletions src/ts/builders/web-search-builder.ts
Expand Up @@ -9,7 +9,7 @@ export class WebSearchBuilder {

public static buildExecutionUrl(userInput: string, webSearch: WebSearch): string {
const searchTerm = this.buildSearchTerm(userInput, webSearch);
return `${webSearch.url}${searchTerm}`;
return `${webSearch.url}${searchTerm.trim()}`;
}

public static buildSearchResultItem(userInput: string, webSearch: WebSearch): SearchResultItem {
Expand All @@ -19,9 +19,11 @@ export class WebSearchBuilder {
? `Search ${webSearch.name} for '${searchTerm.trim()}'`
: `Search ${webSearch.name}`;

const executionArgument = WebSearchBuilder.buildExecutionUrl(userInput, webSearch);

return {
description: WebSearchBuilder.buildExecutionUrl(userInput, webSearch),
executionArgument: WebSearchBuilder.buildExecutionUrl(userInput, webSearch),
description: executionArgument,
executionArgument,
icon: webSearch.icon,
name: searchResultItemName,
searchable: [],
Expand Down

0 comments on commit 9dbee12

Please sign in to comment.