From 908bb938fb6119474d037db32f6fa64a3c5cf82a Mon Sep 17 00:00:00 2001 From: webadderall <131426131+webadderall@users.noreply.github.com> Date: Thu, 12 Nov 2026 06:43:33 +1100 Subject: [PATCH] Test auto-zoom click filtering for recording overlays --- electron/ipc/cursor/interaction.test.ts | 62 ++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/electron/ipc/cursor/interaction.test.ts b/electron/ipc/cursor/interaction.test.ts index d64f0d06..d239bb2a 100644 --- a/electron/ipc/cursor/interaction.test.ts +++ b/electron/ipc/cursor/interaction.test.ts @@ -12,14 +12,72 @@ vi.mock("electron", () => ({ })); vi.mock("../../windows", () => ({ - getHudOverlayInteractiveBounds: vi.fn(() => null), - getHudOverlayWindow: vi.fn(() => null), + getHudOverlayInteractiveBounds: vi.fn(), + getHudOverlayWindow: vi.fn(() => ({ + isVisible: () => true, + isMinimized: () => false, + })), })); +vi.mock("../utils", () => ({ + getScreen: vi.fn(), +})); + +vi.mock("./telemetry", () => ({ + getCursorCaptureElapsedMs: () => 42, + getNormalizedCursorPoint: () => ({ cx: 0.2, cy: 0.3 }), + isCursorCapturePaused: () => false, + pushCursorSample: vi.fn(), +})); + +import { getHudOverlayInteractiveBounds } from "../../windows"; +import { setIsCursorCaptureActive, setLastLeftClick } from "../state"; +import { getScreen } from "../utils"; import { + recordCursorMouseDown, repairBundledUiohookBinaryForCurrentArch, shouldStartGlobalInteractionHook, } from "./interaction"; +import { pushCursorSample } from "./telemetry"; + +describe("recordCursorMouseDown with recording overlays", () => { + afterEach(() => { + setIsCursorCaptureActive(false); + setLastLeftClick(null); + vi.clearAllMocks(); + }); + + it("skips clicks on the HUD and webcam preview and records clicks outside both", () => { + setIsCursorCaptureActive(true); + setLastLeftClick(null); + vi.mocked(getHudOverlayInteractiveBounds).mockReturnValue([ + { left: 100, top: 100, right: 400, bottom: 150 }, + { left: 450, top: 200, right: 550, bottom: 300 }, + ]); + const getCursorScreenPoint = vi + .fn() + .mockReturnValueOnce({ x: 200, y: 125 }) + .mockReturnValueOnce({ x: 500, y: 250 }) + .mockReturnValueOnce({ x: 425, y: 180 }); + vi.mocked(getScreen).mockReturnValue({ getCursorScreenPoint } as ReturnType< + typeof getScreen + >); + + recordCursorMouseDown(1); + recordCursorMouseDown(1); + expect(pushCursorSample).not.toHaveBeenCalled(); + + recordCursorMouseDown(1); + expect(pushCursorSample).toHaveBeenCalledExactlyOnceWith( + 0.2, + 0.3, + 42, + "click", + undefined, + 1, + ); + }); +}); describe("shouldStartGlobalInteractionHook", () => { it("does not start the synchronous uiohook event tap on macOS", () => {