Skip to content

Commit

Permalink
test: application classes (oliverschwendener#1239)
Browse files Browse the repository at this point in the history
* test: added tests for MacOsApplication and WindowsApplication

* Added test for LinuxApplication
  • Loading branch information
oliverschwendener authored Oct 26, 2024
1 parent b9fa5cd commit 37057e1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Image } from "@common/Core/Image";
import { describe, expect, it } from "vitest";
import { LinuxApplication } from "./LinuxApplication";

describe(LinuxApplication, () => {
describe(LinuxApplication.prototype.toSearchResultItem, () => {
it("should have the OpenDesktopFile action as default", () => {
const application = new LinuxApplication("MyApp", "/Path/To/MyApp.desktop", <Image>{});
const defaultAction = application.toSearchResultItem().defaultAction;
expect(defaultAction.handlerId).toBe("LaunchDesktopFile");
});

it("should have ShowItemInFileExplorer and CopyToClipboard as additional actions", () => {
const application = new LinuxApplication("MyApp", "/Path/To/MyApp.desktop", <Image>{});
const additionalActions = application.toSearchResultItem().additionalActions;
expect(additionalActions?.map((a) => a.handlerId)).toEqual(["ShowItemInFileExplorer", "copyToClipboard"]);
});
});

describe(LinuxApplication.prototype.getId, () => {
it("should return a base64 encoded string containing the file path", () => {
const application = new LinuxApplication("MyApp", "/Path/To/MyApp.desktop", <Image>{});
const base64DecodedId = Buffer.from(application.getId(), "base64").toString();
expect(base64DecodedId).toBe("[LinuxApplication][/Path/To/MyApp.desktop]");
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Image } from "@common/Core/Image";
import { describe, expect, it } from "vitest";
import { WindowsApplication } from "./WindowsApplication";

describe(WindowsApplication, () => {
describe(WindowsApplication.prototype.toSearchResultItem, () => {
it("should have OpenFilePath as the default action", () => {
const application = new WindowsApplication("name", "filePath", <Image>{});
const defaultAction = application.toSearchResultItem().defaultAction;
expect(defaultAction.handlerId).toBe("OpenFilePath");
});

it("should have OpenFilePathAsAdministrator as an additional action", () => {
const application = new WindowsApplication("name", "filePath", <Image>{});
const additionalActions = application.toSearchResultItem().additionalActions;
expect(additionalActions?.map((a) => a.handlerId)).toEqual([
"WindowsOpenAsAdministrator",
"ShowItemInFileExplorer",
"copyToClipboard",
]);
});
});

describe(WindowsApplication.prototype.getId, () => {
it("should return a base64 encoded string containing the file path", () => {
const application = new WindowsApplication("name", "filePath", <Image>{});
const base64DecodedId = Buffer.from(application.getId(), "base64").toString();
expect(base64DecodedId).toBe("[WindowsApplication][filePath]");
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Image } from "@common/Core/Image";
import { describe, expect, it } from "vitest";
import { MacOsApplication } from "./MacOsApplication";

describe(MacOsApplication, () => {
describe(MacOsApplication.prototype.toSearchResultItem, () => {
it("should have the OpenFilePath action as default", () => {
const application = new MacOsApplication("MyApp", "/Path/To/MyApp.app", <Image>{});
const defaultAction = application.toSearchResultItem().defaultAction;
expect(defaultAction.handlerId).toBe("OpenFilePath");
});

it("should OpenFileLocation and CopyToclipboard as additional actions", () => {
const application = new MacOsApplication("MyApp", "/Path/To/MyApp.app", <Image>{});
const additionalActions = application.toSearchResultItem().additionalActions;
expect(additionalActions?.map((a) => a.handlerId)).toEqual(["ShowItemInFileExplorer", "copyToClipboard"]);
});
});

describe(MacOsApplication.prototype.getId, () => {
it("should be a base64 encoded string including the file path", () => {
const application = new MacOsApplication("MyApp", "/Path/To/MyApp.app", <Image>{});
const base64DecodedId = Buffer.from(application.getId(), "base64").toString();
expect(base64DecodedId).toBe("[MacOsApplication][/Path/To/MyApp.app]");
});
});
});

0 comments on commit 37057e1

Please sign in to comment.