forked from oliverschwendener/ueli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added priority and isfallback properties to web search interface
- Loading branch information
1 parent
af7cd91
commit 859e492
Showing
11 changed files
with
112 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 63 additions & 2 deletions
65
src/tests/unit/searcher/fallback-web-search-searcher.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,71 @@ | ||
import { FallbackWebSearchSercher } from "../../../ts/searcher/fallback-web-search-searcher"; | ||
import { WebSearch } from "../../../ts/web-search"; | ||
import { WebSearchBuilder } from "../../../ts/builders/web-search-builder"; | ||
|
||
describe(FallbackWebSearchSercher.name, (): void => { | ||
const searcher = new FallbackWebSearchSercher([], []); | ||
|
||
it("should not block other searchers", (): void => { | ||
const searcher = new FallbackWebSearchSercher([]); | ||
const actual = searcher.blockOthers; | ||
expect(actual).toBe(false); | ||
}); | ||
|
||
it("should return a search result for earch fallback web searcher", (): void => { | ||
const webSearches: WebSearch[] = [ | ||
{ | ||
icon: "", | ||
isFallback: false, | ||
name: "non fallback", | ||
prefix: "n", | ||
priority: 1, | ||
url: "url", | ||
}, | ||
{ | ||
icon: "", | ||
isFallback: true, | ||
name: "fallback", | ||
prefix: "f", | ||
priority: 2, | ||
url: "url", | ||
}, | ||
]; | ||
|
||
const userInput = "user-input"; | ||
|
||
const searcher = new FallbackWebSearchSercher(webSearches); | ||
const actual = searcher.getSearchResult(userInput); | ||
|
||
expect(actual.length).toBe(1); | ||
}); | ||
|
||
it("should sort the result by priority", () => { | ||
const webSearches = [ | ||
{ isFallback: true, name: "asdf", priority: 4 }, | ||
{ isFallback: true, name: "asdf", priority: 0 }, | ||
{ isFallback: true, name: "asdf", priority: 3 }, | ||
{ isFallback: true, name: "asdf", priority: 2 }, | ||
{ isFallback: true, name: "asdf", priority: 1 }, | ||
{ isFallback: true, name: "asdf", priority: 4 }, | ||
{ isFallback: true, name: "asdf", priority: 0 }, | ||
{ isFallback: true, name: "asdf", priority: -1 }, | ||
] as WebSearch[]; | ||
|
||
const userInput = "asdf"; | ||
|
||
const searcher = new FallbackWebSearchSercher(webSearches); | ||
const actual = searcher.getSearchResult(userInput); | ||
expect(actual.length).toBe(webSearches.length); | ||
|
||
const sortedWebSearches = webSearches.sort((a, b) => { | ||
if (a.priority < b.priority) { | ||
return 1; | ||
} else if (a.priority > b.priority) { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
|
||
for (let i = 0; i < actual.length; i++) { | ||
expect(actual[i].name).toBe(WebSearchBuilder.buildSearchResultItem(userInput, sortedWebSearches[i]).name); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.