Files
t3code/apps/desktop/src/snapShot/WindowsCaptureFeedback.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

62 lines
1.9 KiB
TypeScript

import type * as Electron from "electron";
import { beforeEach, expect, it, vi } from "vite-plus/test";
const switches = vi.hoisted(() => new Set<string>());
vi.mock("electron", () => ({
app: {
commandLine: {
hasSwitch: (name: string) => switches.has(name),
appendSwitch: (name: string) => switches.add(name),
removeSwitch: (name: string) => switches.delete(name),
},
},
}));
import { showWindowsCaptureOverlay } from "./WindowsCaptureFeedback.ts";
const animationSwitch = "wm-window-animations-disabled";
function overlay(showInactive: () => void) {
return { showInactive } as Electron.BaseWindow;
}
beforeEach(() => {
switches.clear();
switches.add("unrelated-switch");
});
it("disables Chromium window animation only while showing the capture overlay", () => {
const flagsDuringShow: string[][] = [];
showWindowsCaptureOverlay(overlay(() => flagsDuringShow.push([...switches])));
expect(flagsDuringShow).toEqual([["unrelated-switch", animationSwitch]]);
expect([...switches]).toEqual(["unrelated-switch"]);
});
it("preserves an animation switch supplied before capture", () => {
switches.add(animationSwitch);
const flagsDuringShow: string[][] = [];
showWindowsCaptureOverlay(overlay(() => flagsDuringShow.push([...switches])));
expect(flagsDuringShow).toEqual([["unrelated-switch", animationSwitch]]);
expect([...switches]).toEqual(["unrelated-switch", animationSwitch]);
});
it.each([false, true])(
"restores the original switch state when showing throws (preexisting: %s)",
(preexisting) => {
if (preexisting) switches.add(animationSwitch);
const original = [...switches];
const failure = new Error("Overlay was destroyed");
const window = overlay(() => {
expect(switches.has(animationSwitch)).toBe(true);
throw failure;
});
expect(() => showWindowsCaptureOverlay(window)).toThrow(failure);
expect([...switches]).toEqual(original);
},
);