From 05ec0f1552c673b39a25f44f1c6de3e512c3cf77 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 27 Apr 2026 19:01:40 +0200 Subject: [PATCH] Test: Ensure Escape key does not consume event when pointer lock is active --- tests/unit/runtime-host.test.ts | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/unit/runtime-host.test.ts b/tests/unit/runtime-host.test.ts index 51a46291..68383662 100644 --- a/tests/unit/runtime-host.test.ts +++ b/tests/unit/runtime-host.test.ts @@ -3889,6 +3889,73 @@ describe("RuntimeHost", () => { host.dispose(); }); + it("does not consume Escape for clear-target while pointer lock is active", () => { + const host = new RuntimeHost({ + enableRendering: false + }); + const hostInternals = host as unknown as { + domElement: HTMLCanvasElement; + runtimeScene: unknown; + sceneReady: boolean; + activeRuntimeTargetReference: { + kind: "npc" | "interactable"; + entityId: string; + } | null; + handleRuntimeKeyDown(event: KeyboardEvent): void; + }; + const escapeEvent = { + code: "Escape", + defaultPrevented: false, + repeat: false, + altKey: false, + ctrlKey: false, + metaKey: false, + target: null, + preventDefault: vi.fn(), + stopImmediatePropagation: vi.fn() + } as unknown as KeyboardEvent; + + Object.defineProperty(document, "pointerLockElement", { + configurable: true, + get: () => hostInternals.domElement + }); + + hostInternals.runtimeScene = { + playerInputBindings: { + keyboard: { + clearTarget: "Escape", + pauseTime: "KeyP" + } + }, + entities: { + cameraRigs: [], + interactables: [], + npcs: [] + }, + interactionLinks: [] + } as never; + hostInternals.sceneReady = true; + hostInternals.activeRuntimeTargetReference = { + kind: "npc", + entityId: "npc-active" + }; + + hostInternals.handleRuntimeKeyDown(escapeEvent); + + expect(hostInternals.activeRuntimeTargetReference).toEqual({ + kind: "npc", + entityId: "npc-active" + }); + expect(escapeEvent.preventDefault).not.toHaveBeenCalled(); + expect(escapeEvent.stopImmediatePropagation).not.toHaveBeenCalled(); + + Object.defineProperty(document, "pointerLockElement", { + configurable: true, + get: () => null + }); + host.dispose(); + }); + it("switches an active target once from directional screen-space look input", () => { const host = new RuntimeHost({ enableRendering: false