This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
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.
- Loading branch information
1 parent
670ccc8
commit 92093df
Showing
7 changed files
with
258 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Icon } from "../common/icon/icon"; | ||
import { IconType } from "../common/icon/icon-type"; | ||
|
||
export const dummyIcon: Icon = { | ||
parameter: "test", | ||
type: IconType.SVG, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { SearchPlugin } from "../main/search-plugin"; | ||
import { PluginType } from "../main/plugin-type"; | ||
import { SearchResultItem } from "../common/search-result-item"; | ||
import { UserConfigOptions } from "../common/config/user-config-options"; | ||
import { TranslationSet } from "../common/translation/translation-set"; | ||
|
||
export class FakeSearchPlugin implements SearchPlugin { | ||
public pluginType: PluginType; | ||
public openLocationSupported: boolean; | ||
private readonly items: SearchResultItem[]; | ||
private readonly enabled: boolean; | ||
|
||
constructor(pluginType: PluginType, items: SearchResultItem[], enabled: boolean) { | ||
this.pluginType = pluginType; | ||
this.items = items; | ||
this.enabled = enabled; | ||
} | ||
|
||
public getAll(): Promise<SearchResultItem[]> { | ||
return new Promise((resolve) => { | ||
resolve(this.items); | ||
}); | ||
} | ||
public refreshIndex(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
reject("Method not implemented."); | ||
}); | ||
} | ||
public clearCache(): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
reject("Method not implemented."); | ||
}); | ||
} | ||
public isEnabled(): boolean { | ||
return this.enabled; | ||
} | ||
public execute(searchResultItem: SearchResultItem, privileged: boolean): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
reject("Method not implemented."); | ||
}); | ||
} | ||
public openLocation(searchResultItem: SearchResultItem): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
reject("Method not implemented."); | ||
}); | ||
} | ||
public updateConfig(updatedConfig: UserConfigOptions, translationSet: TranslationSet): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
reject("Method not implemented."); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { SearchEngine } from "../main/search-engine"; | ||
import { SearchPlugin } from "../main/search-plugin"; | ||
import { defaultUserConfigOptions } from "../common/config/default-user-config-options"; | ||
import { UserConfigOptions } from "../common/config/user-config-options"; | ||
import { englishTranslationSet } from "../common/translation/english-translation-set"; | ||
import { FakeSearchPlugin } from "./fake-search-plugin"; | ||
import { SearchResultItem } from "../common/search-result-item"; | ||
import { PluginType } from "../main/plugin-type"; | ||
import { dummyIcon } from "./dummy-icon"; | ||
|
||
describe(SearchEngine.name, () => { | ||
it("should find search results when searching for the exact name", (done) => { | ||
const items: SearchResultItem[] = [ | ||
{ | ||
description: "Google Chrome", | ||
executionArgument: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome.lnk", | ||
hideMainWindowAfterExecution: true, | ||
icon: dummyIcon, | ||
name: "Google Chrome", | ||
originPluginType: PluginType.ApplicationSearchPlugin, | ||
searchable: ["Google Chrome"], | ||
}, | ||
]; | ||
|
||
const searchPlugins: SearchPlugin[] = [ | ||
new FakeSearchPlugin(PluginType.ApplicationSearchPlugin, items, true), | ||
]; | ||
const userConfig = { | ||
// | ||
} as UserConfigOptions; | ||
const config = Object.assign({}, defaultUserConfigOptions, userConfig); | ||
|
||
const searchEngine = new SearchEngine(searchPlugins, [], [], config, englishTranslationSet); | ||
|
||
searchEngine.getSearchResults("Google Chrome") | ||
.then((searchResults) => { | ||
expect(searchResults.length).toBe(1); | ||
expect(searchResults[0].name).toBe("Google Chrome"); | ||
done(); | ||
}) | ||
.catch((err) => done(err)); | ||
}); | ||
|
||
it("should return no search results found when searching for something non-existent", (done) => { | ||
const items: SearchResultItem[] = [ | ||
{ | ||
description: "Google Chrome", | ||
executionArgument: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome.lnk", | ||
hideMainWindowAfterExecution: true, | ||
icon: dummyIcon, | ||
name: "Google Chrome", | ||
originPluginType: PluginType.ApplicationSearchPlugin, | ||
searchable: ["Google Chrome"], | ||
}, | ||
]; | ||
const translationSet = englishTranslationSet; | ||
|
||
const searchPlugins: SearchPlugin[] = [ | ||
new FakeSearchPlugin(PluginType.ApplicationSearchPlugin, items, true), | ||
]; | ||
const userConfig = { | ||
// | ||
} as UserConfigOptions; | ||
const config = Object.assign({}, defaultUserConfigOptions, userConfig); | ||
|
||
const searchEngine = new SearchEngine(searchPlugins, [], [], config, translationSet); | ||
|
||
searchEngine.getSearchResults("blabla") | ||
.then((searchResults) => { | ||
expect(searchResults.length).toBe(1); | ||
expect(searchResults[0].name).toBe(translationSet.noSearchResultsFoundTitle); | ||
done(); | ||
}) | ||
.catch((err) => done(err)); | ||
}); | ||
|
||
it("it should be case insensitive", (done) => { | ||
const items: SearchResultItem[] = [ | ||
{ | ||
description: "Google Chrome", | ||
executionArgument: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome.lnk", | ||
hideMainWindowAfterExecution: true, | ||
icon: dummyIcon, | ||
name: "Google Chrome", | ||
originPluginType: PluginType.ApplicationSearchPlugin, | ||
searchable: ["Google Chrome"], | ||
}, | ||
]; | ||
const translationSet = englishTranslationSet; | ||
|
||
const searchPlugins: SearchPlugin[] = [ | ||
new FakeSearchPlugin(PluginType.ApplicationSearchPlugin, items, true), | ||
]; | ||
const userConfig = { | ||
// | ||
} as UserConfigOptions; | ||
const config = Object.assign({}, defaultUserConfigOptions, userConfig); | ||
|
||
const searchEngine = new SearchEngine(searchPlugins, [], [], config, translationSet); | ||
|
||
searchEngine.getSearchResults("gOoGlE ChRoMe") | ||
.then((searchResults) => { | ||
expect(searchResults.length).toBe(1); | ||
expect(searchResults[0].name).toBe("Google Chrome"); | ||
done(); | ||
}) | ||
.catch((err) => done(err)); | ||
}); | ||
|
||
it("it should allow inprecise search terms when fuzzyness threshold is higher", (done) => { | ||
const items: SearchResultItem[] = [ | ||
{ | ||
description: "Google Chrome", | ||
executionArgument: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome.lnk", | ||
hideMainWindowAfterExecution: true, | ||
icon: dummyIcon, | ||
name: "Google Chrome", | ||
originPluginType: PluginType.ApplicationSearchPlugin, | ||
searchable: ["Google Chrome"], | ||
}, | ||
]; | ||
const translationSet = englishTranslationSet; | ||
|
||
const searchPlugins: SearchPlugin[] = [ | ||
new FakeSearchPlugin(PluginType.ApplicationSearchPlugin, items, true), | ||
]; | ||
const userConfig = { | ||
searchEngineOptions: { | ||
fuzzyness: 0.8, | ||
} | ||
} as UserConfigOptions; | ||
const config = Object.assign({}, defaultUserConfigOptions, userConfig); | ||
|
||
const searchEngine = new SearchEngine(searchPlugins, [], [], config, translationSet); | ||
|
||
searchEngine.getSearchResults("gglchrm") | ||
.then((searchResults) => { | ||
expect(searchResults.length).toBe(1); | ||
expect(searchResults[0].name).toBe("Google Chrome"); | ||
done(); | ||
}) | ||
.catch((err) => done(err)); | ||
}); | ||
|
||
it("it should require more precise search terms when fuzzyness threshold is lower", (done) => { | ||
const items: SearchResultItem[] = [ | ||
{ | ||
description: "Google Chrome", | ||
executionArgument: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome.lnk", | ||
hideMainWindowAfterExecution: true, | ||
icon: dummyIcon, | ||
name: "Google Chrome", | ||
originPluginType: PluginType.ApplicationSearchPlugin, | ||
searchable: ["Google Chrome"], | ||
}, | ||
]; | ||
const translationSet = englishTranslationSet; | ||
|
||
const searchPlugins: SearchPlugin[] = [ | ||
new FakeSearchPlugin(PluginType.ApplicationSearchPlugin, items, true), | ||
]; | ||
const userConfig = { | ||
searchEngineOptions: { | ||
fuzzyness: 0.2, | ||
}, | ||
} as UserConfigOptions; | ||
const config = Object.assign({}, defaultUserConfigOptions, userConfig); | ||
|
||
const searchEngine = new SearchEngine(searchPlugins, [], [], config, translationSet); | ||
|
||
searchEngine.getSearchResults("gglchrm") | ||
.then((searchResults) => { | ||
expect(searchResults.length).toBe(1); | ||
expect(searchResults[0].name).toBe(translationSet.noSearchResultsFoundTitle); | ||
done(); | ||
}) | ||
.catch((err) => done(err)); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -49,5 +49,8 @@ | |
}, | ||
"include": [ | ||
"./src/**/*.ts", | ||
], | ||
"exclude": [ | ||
"./src/**/*.test.ts", | ||
] | ||
} |