Files
t3code/apps/desktop/src/electron/WindowsForegroundFocusWorker.test.ts
T
299404a754 feat(desktop): add cross-platform window capture (#8103)
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: Wout Stiens <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
2026-09-07 18:21:53 -07:00

37 lines
1.3 KiB
TypeScript

import { assert, beforeEach, it, vi } from "vite-plus/test";
const { byPid, list, on, postMessage } = vi.hoisted(() => ({
byPid: vi.fn(),
list: vi.fn(),
on: vi.fn(),
postMessage: vi.fn(),
}));
vi.mock("node:worker_threads", () => ({ parentPort: { on, postMessage } }));
vi.mock("@crowecawcaw/xa11y", () => ({ App: { byPid, list } }));
beforeEach(() => {
vi.resetModules();
vi.resetAllMocks();
});
it.each(["lookup", "children"])("falls back to enumeration after a failed %s", async (failure) => {
const error = new Error("Unavailable");
if (failure === "lookup") byPid.mockRejectedValue(error);
else byPid.mockResolvedValue({ children: () => Promise.reject(error) });
const bounds = { x: 0, y: 0, width: 800, height: 600 };
const focus = vi.fn().mockResolvedValue(undefined);
list.mockResolvedValue([{ pid: 42, asElement: () => ({ name: "T3", bounds, focus }) }]);
await import("./WindowsForegroundFocusWorker.ts");
await vi.dynamicImportSettled();
const result = Promise.withResolvers<unknown>();
postMessage.mockImplementation(result.resolve);
on.mock.calls[0]![1]({
type: "focus",
requestId: 1,
target: { windowId: 1, processId: 42, title: "T3", bounds, contentBounds: bounds },
});
assert.deepEqual(await result.promise, { type: "result", requestId: 1, focused: true });
assert.lengthOf(focus.mock.calls, 1);
});