Skip to content

Build your personal knowledge base with Trilium Notes

chore(desktop): cover the open-with paths left untested

Elian Doran0acf7c10f90b
diff --git a/apps/client/src/components/root_command_executor.spec.ts b/apps/client/src/components/root_command_executor.spec.ts
new file mode 100644
index 0000000000..25c836deda
--- /dev/null
+++ b/apps/client/src/components/root_command_executor.spec.ts
@@ -0,0 +1,31 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+import openService from "../services/open.js";
+import { buildNote } from "../test/easy-froca.js";
+import appContext from "./app_context.js";
+import type NoteContext from "./note_context.js";
+import RootCommandExecutor from "./root_command_executor.js";
+import type TabManager from "./tab_manager.js";
+
+describe("openNoteCustomCommand", () => {
+ const executor = new RootCommandExecutor();
+
+ beforeEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it("opens the command context's note with the application chooser", () => {
+ const note = buildNote({ title: "Report", type: "file", mime: "application/pdf" });
+ const contexts: Record<string, NoteContext> = { ntx1: { note } as NoteContext };
+ appContext.tabManager = {
+ getCommandContext: (ntxId?: string | null) => (ntxId ? contexts[ntxId] : undefined)
+ } as unknown as TabManager;
+ const openNoteCustom = vi.spyOn(openService, "openNoteCustom").mockResolvedValue(undefined);
+
+ executor.openNoteCustomCommand({ ntxId: "ntx1" });
+ expect(openNoteCustom).toHaveBeenCalledExactlyOnceWith(note.noteId);
+
+ executor.openNoteCustomCommand({ ntxId: "missing" });
+ expect(openNoteCustom).toHaveBeenCalledOnce();
+ });
+});
diff --git a/apps/client/src/services/file_watcher.spec.ts b/apps/client/src/services/file_watcher.spec.ts
index 6167c58768..53f9b4a469 100644
--- a/apps/client/src/services/file_watcher.spec.ts
+++ b/apps/client/src/services/file_watcher.spec.ts
@@ -91,6 +91,16 @@ describe("file_watcher", () => {
expect(shown.notes).toEqual([ { noteId: "owner1", description: "photo.png" } ]);
});
+ it("shows an attachment's toast without a note link when the attachment is gone", async () => {
+ vi.spyOn(froca, "getAttachment").mockResolvedValue(null);
+ watchOpenedFile("/tmp/attGone");
+ await receive(makeUpdate("attachments", "attGone"));
+
+ const shown = lastToast();
+ expect(shown.id).toBe("opened-file-updated-attachments-attGone");
+ expect(shown.notes).toBeUndefined();
+ });
+
it("leaves a file opened from another window to that window", async () => {
await receive(makeUpdate("notes", "otherWindowNote"));
expect(toast.showPersistent).not.toHaveBeenCalled();
diff --git a/apps/desktop/src/services/shell_handlers.spec.ts b/apps/desktop/src/services/shell_handlers.spec.ts
index ae6b4effd9..5fda0603e9 100644
--- a/apps/desktop/src/services/shell_handlers.spec.ts
+++ b/apps/desktop/src/services/shell_handlers.spec.ts
@@ -13,7 +13,8 @@ const h = vi.hoisted(() => ({
openPath: vi.fn(() => Promise.resolve("")),
showItemInFolder: vi.fn(),
execFile: vi.fn(),
- spawn: vi.fn()
+ spawn: vi.fn(),
+ logError: vi.fn()
}));
vi.mock("electron", () => ({
@@ -34,7 +35,7 @@ vi.mock("child_process", () => ({ execFile: h.execFile, spawn: h.spawn }));
vi.mock("@triliumnext/core", async (importOriginal) => {
const actual = await importOriginal<typeof import("@triliumnext/core")>();
- return { ...actual, getLog: () => ({ info: vi.fn(), error: vi.fn() }) };
+ return { ...actual, getLog: () => ({ info: vi.fn(), error: h.logError }) };
});
const { setupShellHandlers } = await import("./shell.js");
@@ -240,6 +241,23 @@ describe("setupShellHandlers", () => {
expect(await fireHandle("open-custom", tmpFile)).toBe(false);
expect(h.openPath).not.toHaveBeenCalled();
});
+
+ it("settles once and logs the portal's stderr when a failed spawn emits both error and close", async () => {
+ const closeSync = vi.spyOn(fs, "closeSync");
+ h.spawn.mockImplementationOnce(() => {
+ const child = Object.assign(new EventEmitter(), { stderr: new EventEmitter() });
+ setImmediate(() => {
+ child.stderr.emit("data", "No such interface\n");
+ child.emit("close", 1);
+ child.emit("error", new Error("late"));
+ });
+ return child;
+ });
+
+ expect(await fireHandle("open-custom", tmpFile)).toBe(false);
+ expect(closeSync).toHaveBeenCalledOnce();
+ expect(h.logError).toHaveBeenCalledWith(expect.stringContaining("No such interface"));
+ });
});
describe("win32", () => {