Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:oliverschwendener/ueli into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Oct 22, 2018
2 parents fc872fc + 72c8094 commit 50cf9ed
Show file tree
Hide file tree
Showing 34 changed files with 581 additions and 410 deletions.
1 change: 1 addition & 0 deletions main.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h1 class="setting-section-title">App Settings</h1>
<div>Chrome: {{ process.versions.chrome }}</div>
<div>Node: {{ process.versions.node }}</div>
<div>V8: {{ process.versions.v8 }}</div>
<div>Index size: {{ indexLength }}</div>
</div>
</div>
<div class="setting-group">
Expand Down
73 changes: 45 additions & 28 deletions src/tests/integration/search-plugins/file-search-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,47 @@ describe(FileSearchPlugin.name, (): void => {
"test-file-3",
];

describe("getAllItems", (): void => {
beforeEach((): void => {
for (const parentFolder of parentFolders) {
mkdirSync(parentFolder);

for (const subFolder of subFolders) {
mkdirSync(join(parentFolder, subFolder));
beforeEach((): void => {
for (const parentFolder of parentFolders) {
mkdirSync(parentFolder);

for (const testFile of testFiles) {
const filePath = join(parentFolder, subFolder, testFile);
writeFileSync(filePath, "", "utf-8");
}
}
for (const subFolder of subFolders) {
mkdirSync(join(parentFolder, subFolder));

for (const testFile of testFiles) {
const filePath = join(parentFolder, testFile);
const filePath = join(parentFolder, subFolder, testFile);
writeFileSync(filePath, "", "utf-8");
}
}
});

afterEach((): void => {
for (const parentFolder of parentFolders) {
for (const testFile of testFiles) {
const filePath = join(parentFolder, testFile);
unlinkSync(filePath);
}
for (const testFile of testFiles) {
const filePath = join(parentFolder, testFile);
writeFileSync(filePath, "", "utf-8");
}
}
});

for (const subFolder of subFolders) {
for (const testFile of testFiles) {
const filePath = join(parentFolder, subFolder, testFile);
unlinkSync(filePath);
}
afterEach((): void => {
for (const parentFolder of parentFolders) {
for (const testFile of testFiles) {
const filePath = join(parentFolder, testFile);
unlinkSync(filePath);
}

rmdirSync(join(parentFolder, subFolder));
for (const subFolder of subFolders) {
for (const testFile of testFiles) {
const filePath = join(parentFolder, subFolder, testFile);
unlinkSync(filePath);
}

rmdirSync(parentFolder);
rmdirSync(join(parentFolder, subFolder));
}
});

rmdirSync(parentFolder);
}
});

describe("getAllItems", (): void => {
it("should return only top level files and folders if recursive search is set to false", (): void => {
const recursiveSearch = false;
const options = parentFolders.map((folder: string): FileSearchOption => {
Expand Down Expand Up @@ -143,4 +143,21 @@ describe(FileSearchPlugin.name, (): void => {
expect(acutal.length).toBe(0);
});
});

describe("getIndexLength", (): void => {
it("should return the number of files", (): void => {
const recursive = false;
const options = parentFolders.map((folder: string): FileSearchOption => {
return {
folderPath: folder,
recursive,
};
});

const plugin = new FileSearchPlugin(options, testIconSet, emptyBlackList);

const actual = plugin.getIndexLength();
expect(actual).toBe(parentFolders.length * testFiles.length + parentFolders.length * subFolders.length);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ describe(EnvironmentVariablePlugin.name, (): void => {
}
});
});

describe(plugin.getIndexLength.name, (): void => {
it("should return the length of env variables", (): void => {
const actual = plugin.getIndexLength();
expect(actual).toBe(Object.keys(fakeEnvironmentVariableCollection).length);
});
});
});
23 changes: 20 additions & 3 deletions src/tests/unit/search-plugins/mac-os-settings-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { MacOsSettingsPlugin } from "../../../ts/search-plugins/mac-os-settings-plugin";
import { testIconSet } from "../../../ts/icon-sets/test-icon-set";
import { MacOsSetting } from "../../../ts/operating-system-settings/macos/mac-os-setting";

describe(MacOsSettingsPlugin.name, () => {
const searchPlugin = new MacOsSettingsPlugin(testIconSet);
describe(MacOsSettingsPlugin.name, (): void => {
const testSettings: MacOsSetting[] = [
{ executionArgument: "exec-1", name: "name-1", tags: [] },
{ executionArgument: "exec-2", name: "name-2", tags: [] },
{ executionArgument: "exec-3", name: "name-3", tags: [] },
{ executionArgument: "exec-4", name: "name-4", tags: [] },
];

describe(searchPlugin.getAllItems.name, () => {
const searchPlugin = new MacOsSettingsPlugin(testSettings, testIconSet);

describe(searchPlugin.getAllItems.name, (): void => {
it("should return more than zero items", () => {
const actual = searchPlugin.getAllItems();
expect(actual).not.toBe(undefined);
expect(actual).not.toBe(null);
expect(actual.length).toBeGreaterThan(0);
});
});

describe(searchPlugin.getIndexLength.name, (): void => {
it("should return the number of os settings", (): void => {
const actual = searchPlugin.getIndexLength();
const expected = testSettings.length;

expect(actual).toBe(expected);
});
});
});
31 changes: 20 additions & 11 deletions src/tests/unit/search-plugins/programs-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ function getTestPrograms(programNames: string[]) {
}

describe("ProgramsPlugin", (): void => {
describe("getAllItems", (): void => {
it("should return all programs", (): void => {
const fakePrograms = getTestPrograms([
"Git Bash",
"Adobe Premiere Pro",
"FL Studio (64-bit)",
"Native Instruments Maschine 2",
"Visual Studio Code",
]);
const fakePrograms = getTestPrograms([
"Git Bash",
"Adobe Premiere Pro",
"FL Studio (64-bit)",
"Native Instruments Maschine 2",
"Visual Studio Code",
]);

const fakeProgramRepository = new FakeProgramRepository(fakePrograms);
const programsPlugin = new ProgramsPlugin(fakeProgramRepository, testIconSet);
const fakeProgramRepository = new FakeProgramRepository(fakePrograms);
const programsPlugin = new ProgramsPlugin(fakeProgramRepository, testIconSet);

describe(programsPlugin.getAllItems.name, (): void => {
it("should return all programs", (): void => {
const actual = programsPlugin.getAllItems();

expect(actual.length).toBeGreaterThan(0);
Expand All @@ -41,4 +41,13 @@ describe("ProgramsPlugin", (): void => {
}
});
});

describe(programsPlugin.getIndexLength.name, (): void => {
it("should return the number of programs", (): void => {
const actual = programsPlugin.getIndexLength();
const expected = fakePrograms.length;

expect(actual).toBe(expected);
});
});
});
18 changes: 18 additions & 0 deletions src/tests/unit/search-plugins/shortcut-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,22 @@ describe(ShortcutsPlugin.name, (): void => {
}
});
});

describe("getIndexLength", (): void => {
it("should return the number of shortcuts", (): void => {
const shortcuts: Shortcut[] = [
{ executionArgument: "execution-argument-1", name: "shortcut-1", icon: "icon" },
{ executionArgument: "execution-argument-2", name: "shortcut-2", icon: "icon" },
{ executionArgument: "execution-argument-3", name: "shortcut-3", icon: "icon" },
{ executionArgument: "execution-argument-4", name: "shortcut-4", icon: "icon" },
];

const shortcutPlugin = new ShortcutsPlugin(shortcuts, "default-shortcut-icon");

const actual = shortcutPlugin.getIndexLength();
const expected = shortcuts.length;

expect(actual).toBe(expected);
});
});
});
34 changes: 28 additions & 6 deletions src/tests/unit/search-plugins/windows-10-settings-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import { Windows10SettingsSearchPlugin } from "../../../ts/search-plugins/windows-10-settings-plugin";
import { testIconSet } from "../../../ts/icon-sets/test-icon-set";
import { WindowsSetting } from "../../../ts/operating-system-settings/windows/windows-setting";
import { Windows10App } from "../../../ts/operating-system-settings/windows/windows-10-app";

describe(Windows10SettingsSearchPlugin.name, () => {
const searchPlugin = new Windows10SettingsSearchPlugin(testIconSet);
describe(Windows10SettingsSearchPlugin.name, (): void => {
const testSettings: WindowsSetting[] = [
{ executionArgument: "exec-1", name: "setting-1", tags: [] },
{ executionArgument: "exec-2", name: "setting-2", tags: [] },
{ executionArgument: "exec-3", name: "setting-3", tags: [] },
{ executionArgument: "exec-4", name: "setting-4", tags: [] },
];

describe(searchPlugin.getAllItems.name, () => {
const testApps: Windows10App[] = [
{ executionArgument: "exec-1", name: "app-1", icon: "icon" },
{ executionArgument: "exec-2", name: "app-2", icon: "icon" },
{ executionArgument: "exec-3", name: "app-3", icon: "icon" },
{ executionArgument: "exec-4", name: "app-4", icon: "icon" },
];

const searchPlugin = new Windows10SettingsSearchPlugin(testSettings, testApps, testIconSet);

describe(searchPlugin.getAllItems.name, (): void => {
it("should return more than zero items", () => {
const actual = searchPlugin.getAllItems();
expect(actual).not.toBe(undefined);
expect(actual).not.toBe(null);
expect(actual.length).toBeGreaterThan(0);
expect(actual.length).toBe(testSettings.length + testApps.length);
});
});

describe(searchPlugin.getIndexLength.name, (): void => {
it("should return the number of settings", (): void => {
const actual = searchPlugin.getIndexLength();
const expected = testSettings.length + testApps.length;
expect(actual).toBe(expected);
});
});
});
4 changes: 2 additions & 2 deletions src/ts/available-color-themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { join } from "path";

const files = readdirSync(join(__dirname, "..", "styles"));

const colorThemes = files.filter((file: string) => {
const colorThemes = files.filter((file: string): boolean => {
return file !== "app.css";
});

export const availableColorThemes = colorThemes.map((colorTheme: string) => {
export const availableColorThemes = colorThemes.map((colorTheme: string): string => {
return colorTheme.replace(".css", "");
}).sort();
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CustomCommand } from "../custom-shortcut";
export class CustomCommandBuilder {
public static buildExecutionArgumentForCustomCommand(userInput: string, customCommand: CustomCommand): string {
const words = StringHelpers.splitIntoWords(userInput);
return `${customCommand.executionArgument} ${words.filter((word) => word !== customCommand.prefix).join(" ")}`;
return `${customCommand.executionArgument} ${words.filter((word): boolean => word !== customCommand.prefix).join(" ")}`;
}

public static buildCustomCommandName(userInput: string, customCommand: CustomCommand): string {
Expand Down
12 changes: 6 additions & 6 deletions src/ts/executors/command-line-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ export class CommandLineExecutor implements Executor {
const commandLineTool = spawn(command.name, command.args);

const commandLineToolStartedMessage = (command.args !== undefined && command.args.length > 0)
? `Started "${command.name}" with parameters: ${command.args.map((c) => `"${c}"`).join(", ")}`
? `Started "${command.name}" with parameters: ${command.args.map((c): string => `"${c}"`).join(", ")}`
: `Started "${command.name}"`;

this.sendCommandLineOutputToRenderer(commandLineToolStartedMessage);

commandLineTool.on("error", (err) => {
commandLineTool.on("error", (err): void => {
this.sendCommandLineOutputToRenderer(err.message);
});

commandLineTool.stderr.on("data", (data) => {
commandLineTool.stderr.on("data", (data): void => {
this.sendCommandLineOutputToRenderer(data.toString());
});

commandLineTool.stdout.on("data", (data) => {
commandLineTool.stdout.on("data", (data): void => {
this.sendCommandLineOutputToRenderer(data.toString());
});

commandLineTool.on("exit", (code) => {
commandLineTool.on("exit", (code): void => {
this.sendCommandLineOutputToRenderer(`Exit ${code} `);
});

ipcMain.on(IpcChannels.exitCommandLineTool, () => {
ipcMain.on(IpcChannels.exitCommandLineTool, (): void => {
commandLineTool.kill();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/ts/executors/file-path-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class FilePathExecutor implements Executor {
}

private handleExecution(command: string): void {
exec(command, (err) => {
exec(command, (err): void => {
if (err) {
throw err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ts/executors/web-search-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WebSearchExecutor implements Executor {
for (const webSearch of this.webSearches) {
if (executionArgument.startsWith(`${webSearch.prefix}${WebSearchHelpers.webSearchSeparator}`)) {
const command = Injector.getOpenUrlWithDefaultBrowserCommand(platform(), executionArgument);
exec(command, (err) => {
exec(command, (err): void => {
if (err) {
throw err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ts/executors/web-url-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class WebUrlExecutor implements Executor {
}

private handleCommandExecution(command: string): void {
exec(command, (err) => {
exec(command, (err): void => {
if (err) {
throw err;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ts/helpers/file-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export class FileHelpers {
return join(folderPath, f);
});

const accessibleFiles = filePaths.map((filePath) => {
const accessibleFiles = filePaths.map((filePath): string | undefined => {
try {
lstatSync(filePath);
return filePath;
} catch (err) {
// do nothing
}
}).filter((maybe) => maybe !== undefined) as string[];
}).filter((maybe): boolean => maybe !== undefined) as string[];

return accessibleFiles;
} catch (error) {
Expand All @@ -75,7 +75,7 @@ export class FileHelpers {
private static getFileNamesFromFolder(folderPath: string): string[] {
const allFiles = readdirSync(folderPath);

const visibleFiles = allFiles.filter((fileName) => {
const visibleFiles = allFiles.filter((fileName): boolean => {
return !fileName.startsWith(".");
});

Expand Down
2 changes: 1 addition & 1 deletion src/ts/helpers/string-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class StringHelpers {

public static stringToWords(value: string): string[] {
const words = value.split(/\s/g);
return words.filter((w) => {
return words.filter((w): boolean => {
return !StringHelpers.stringIsWhiteSpace(w);
});
}
Expand Down
Loading

0 comments on commit 50cf9ed

Please sign in to comment.