Skip to content

Build your personal knowledge base with Trilium Notes

chore(desktop): cover the parentless macOS app picker

Elian Doranbc2bd21df031
diff --git a/apps/desktop/src/services/shell_handlers.spec.ts b/apps/desktop/src/services/shell_handlers.spec.ts
index 39d13176bb..d3696d298a 100644
--- a/apps/desktop/src/services/shell_handlers.spec.ts
+++ b/apps/desktop/src/services/shell_handlers.spec.ts
@@ -14,6 +14,7 @@ const h = vi.hoisted(() => ({
showItemInFolder: vi.fn(),
execFile: vi.fn(),
spawn: vi.fn(),
+ fromWebContents: vi.fn<() => { id: number } | null>(() => ({ id: 1 })),
showOpenDialog: vi.fn<(...args: unknown[]) => Promise<{ canceled: boolean; filePaths: string[] }>>(),
logError: vi.fn()
}));
@@ -24,7 +25,7 @@ vi.mock("electron", () => ({
on: (channel: string, fn: Handler) => h.on.set(channel, fn),
handle: (channel: string, fn: Handler) => h.handle.set(channel, fn)
},
- BrowserWindow: { fromWebContents: () => ({ id: 1 }) },
+ BrowserWindow: { fromWebContents: h.fromWebContents },
dialog: { showOpenDialog: h.showOpenDialog },
shell: {
openExternal: h.openExternal,
@@ -220,6 +221,13 @@ describe("setupShellHandlers", () => {
expect(h.openPath).not.toHaveBeenCalled();
});
+ it("shows the picker without a parent when the sender has no window", async () => {
+ h.fromWebContents.mockReturnValueOnce(null);
+ h.showOpenDialog.mockResolvedValue({ canceled: true, filePaths: [] });
+ expect(await fireHandle("open-custom", tmpFile)).toBe(true);
+ expect(h.showOpenDialog).toHaveBeenCalledWith(expect.objectContaining({ defaultPath: "/Applications" }));
+ });
+
it("opens nothing when the picker is canceled", async () => {
h.showOpenDialog.mockResolvedValue({ canceled: true, filePaths: [] });
expect(await fireHandle("open-custom", tmpFile)).toBe(true);