- Add Electron main-process IPC handlers and preload bridges for API proxying, window controls, update install, and platform lookup - Introduce a desktop renderer entrypoint with DesktopWrapper and a custom frameless TitleBar component - Add Electron-aware renderer utilities including API transport selection and hooks for runtime detection, auto-update events, and deep links - Update dashboard header behavior for Electron mode and expand desktop tests across preload, transport, hooks, and title bar flows - Document the desktop renderer architecture and update desktop package config/dependencies
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act, cleanup, renderHook } from "@testing-library/react";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { useAutoUpdate } from "../hooks/useAutoUpdate";
|
|
|
|
describe("useAutoUpdate", () => {
|
|
afterEach(() => {
|
|
cleanup();
|
|
window.electronAPI = undefined;
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("subscribes to update notifications and exposes update info", async () => {
|
|
let onUpdateAvailable: ((info: Record<string, unknown>) => void) | undefined;
|
|
const installUpdate = vi.fn().mockResolvedValue(undefined);
|
|
|
|
window.electronAPI = {
|
|
onUpdateAvailable: (callback) => {
|
|
onUpdateAvailable = callback;
|
|
return () => {
|
|
onUpdateAvailable = undefined;
|
|
};
|
|
},
|
|
installUpdate,
|
|
};
|
|
|
|
const { result } = renderHook(() => useAutoUpdate());
|
|
|
|
act(() => {
|
|
onUpdateAvailable?.({ version: "1.2.3" });
|
|
});
|
|
|
|
expect(result.current.updateAvailable).toBe(true);
|
|
expect(result.current.updateInfo).toEqual({ version: "1.2.3" });
|
|
|
|
await act(async () => {
|
|
await result.current.downloadAndInstall();
|
|
});
|
|
|
|
expect(installUpdate).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("returns safe defaults when not running in Electron", async () => {
|
|
window.electronAPI = undefined;
|
|
|
|
const { result } = renderHook(() => useAutoUpdate());
|
|
|
|
expect(result.current.updateAvailable).toBe(false);
|
|
expect(result.current.updateInfo).toBeNull();
|
|
|
|
await expect(result.current.downloadAndInstall()).resolves.toBeUndefined();
|
|
});
|
|
});
|