Files
t3code/apps/web/src/lib/desktopSnapShot.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

58 lines
1.6 KiB
TypeScript

import type { DesktopBridge } from "@t3tools/contracts";
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
import {
dispatchSnapShotComposerFocus,
getDesktopSnapShotBridge,
subscribeSnapShotComposerFocus,
} from "./desktopSnapShot";
beforeEach(() => {
Object.defineProperty(globalThis, "window", {
configurable: true,
value: new EventTarget(),
});
});
afterEach(() => {
Reflect.deleteProperty(globalThis, "window");
});
describe("getDesktopSnapShotBridge", () => {
it("rejects an older desktop bridge without window capture methods", () => {
window.desktopBridge = {} as DesktopBridge;
expect(getDesktopSnapShotBridge()).toBeUndefined();
});
it("returns a bridge with the complete window capture capability", () => {
const bridge = {
requestSnapShotPermissions: vi.fn(),
getSnapShotState: vi.fn(),
checkSnapShotShortcut: vi.fn(),
setSnapShotShortcutSuppressed: vi.fn(),
listPendingSnapShots: vi.fn(),
readSnapShot: vi.fn(),
acknowledgeSnapShot: vi.fn(),
onSnapShotEvent: vi.fn(),
} as unknown as DesktopBridge;
window.desktopBridge = bridge;
expect(getDesktopSnapShotBridge()).toBe(bridge);
});
});
describe("window capture composer focus", () => {
it("notifies active subscribers", () => {
const listener = vi.fn();
const unsubscribe = subscribeSnapShotComposerFocus(listener);
dispatchSnapShotComposerFocus();
expect(listener).toHaveBeenCalledOnce();
unsubscribe();
dispatchSnapShotComposerFocus();
expect(listener).toHaveBeenCalledOnce();
});
});