Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

test(hud): make the click-through negative case able to fail

Etienne Lescotfa03693d00f0
diff --git a/src/components/launch/LaunchWindow.test.tsx b/src/components/launch/LaunchWindow.test.tsx
index 1b0e31101..3fdb7caae 100644
--- a/src/components/launch/LaunchWindow.test.tsx
+++ b/src/components/launch/LaunchWindow.test.tsx
@@ -434,31 +434,51 @@ describe("LaunchWindow record button", () => {
expect(hudCursorListeners).not.toHaveLength(0);
// jsdom has no layout and does not implement elementFromPoint at all, so it is
- // defined here to return what a point over the bar resolves to in a browser. The
- // assertion is that the pushed cursor drives the hit test, not that jsdom can hit-test.
+ // defined here to return what each point resolves to in a browser. The assertion
+ // is that the pushed cursor drives the hit test, not that jsdom can hit-test.
const bar = document.querySelector("[data-hud-interactive='true']");
expect(bar).not.toBeNull();
- const elementFromPoint = vi.fn(() => bar);
+ const elementFromPoint = vi.fn((_x: number, _y: number): Element | null => document.body);
Object.defineProperty(document, "elementFromPoint", {
value: elementFromPoint,
configurable: true,
});
+ const setIgnore = vi.mocked(window.electronAPI.setHudOverlayIgnoreMouseEvents);
try {
+ // The transparent reserve goes FIRST, while the window is still click-through.
+ // Do it after the bar has claimed input back and the assertion is vacuous: the
+ // renderer dedupes, so a point that wrongly enabled input would send no IPC at
+ // all and "still false" would hold either way. Here a wrong answer is an IPC.
+ setIgnore.mockClear();
+ for (const listener of hudCursorListeners) listener(10, 10);
+ expect(setIgnore).not.toHaveBeenCalled();
+
+ // And the bar hands input back.
+ elementFromPoint.mockReturnValue(bar);
for (const listener of hudCursorListeners) listener(410, 540);
expect(elementFromPoint).toHaveBeenCalledWith(410, 540);
- expect(window.electronAPI.setHudOverlayIgnoreMouseEvents).toHaveBeenLastCalledWith(false);
-
- // And a point over the transparent reserve must NOT claim the window back.
- elementFromPoint.mockReturnValue(document.body);
- for (const listener of hudCursorListeners) listener(10, 10);
- expect(window.electronAPI.setHudOverlayIgnoreMouseEvents).toHaveBeenLastCalledWith(false);
+ expect(setIgnore).toHaveBeenCalledWith(false);
} finally {
Reflect.deleteProperty(document, "elementFromPoint");
}
});
+ it("unsubscribes from the pushed cursor when the HUD unmounts", async () => {
+ platformState.value = "win32";
+
+ const { unmount } = renderLaunchWindow();
+
+ await waitFor(() => {
+ expect(hudCursorListeners).not.toHaveLength(0);
+ });
+
+ unmount();
+
+ expect(hudCursorListeners).toHaveLength(0);
+ });
+
it("keeps the HUD interactive on Linux so the drag handle can receive pointer events", async () => {
platformState.value = "linux";