1import type * as Electron from "electron";
2import { beforeEach, expect, it, vi } from "vite-plus/test";
3
4const switches = vi.hoisted(() => new Set<string>());
5vi.mock("electron", () => ({
6 app: {
7 commandLine: {
8 hasSwitch: (name: string) => switches.has(name),
9 appendSwitch: (name: string) => switches.add(name),
10 removeSwitch: (name: string) => switches.delete(name),
11 },
12 },
13}));
14
15import { showWindowsCaptureOverlay } from "./WindowsCaptureFeedback.ts";
16
17const animationSwitch = "wm-window-animations-disabled";
18
19function overlay(showInactive: () => void) {
20 return { showInactive } as Electron.BaseWindow;
21}
22
23beforeEach(() => {
24 switches.clear();
25 switches.add("unrelated-switch");
26});
27
28it("disables Chromium window animation only while showing the capture overlay", () => {
29 const flagsDuringShow: string[][] = [];
30
31 showWindowsCaptureOverlay(overlay(() => flagsDuringShow.push([...switches])));
32
33 expect(flagsDuringShow).toEqual([["unrelated-switch", animationSwitch]]);
34 expect([...switches]).toEqual(["unrelated-switch"]);
35});
36
37it("preserves an animation switch supplied before capture", () => {
38 switches.add(animationSwitch);
39 const flagsDuringShow: string[][] = [];
40
41 showWindowsCaptureOverlay(overlay(() => flagsDuringShow.push([...switches])));
42
43 expect(flagsDuringShow).toEqual([["unrelated-switch", animationSwitch]]);
44 expect([...switches]).toEqual(["unrelated-switch", animationSwitch]);
45});
46
47it.each([false, true])(
48 "restores the original switch state when showing throws (preexisting: %s)",
49 (preexisting) => {
50 if (preexisting) switches.add(animationSwitch);
51 const original = [...switches];
52 const failure = new Error("Overlay was destroyed");
53 const window = overlay(() => {
54 expect(switches.has(animationSwitch)).toBe(true);
55 throw failure;
56 });
57
58 expect(() => showWindowsCaptureOverlay(window)).toThrow(failure);
59 expect([...switches]).toEqual(original);
60 },
61);