diff --git a/ui/src/ui/chat-markdown.browser.test.ts b/ui/src/ui/chat-markdown.browser.test.ts index c0e692b073..17a898bac4 100644 --- a/ui/src/ui/chat-markdown.browser.test.ts +++ b/ui/src/ui/chat-markdown.browser.test.ts @@ -1,31 +1,7 @@ -import { afterEach, beforeEach, describe, expect, it } from "vitest"; -import { OpenClawApp } from "./app.ts"; +import { describe, expect, it } from "vitest"; +import { mountApp, registerAppMountHooks } from "./test-helpers/app-mount.ts"; -// oxlint-disable-next-line typescript/unbound-method -const originalConnect = OpenClawApp.prototype.connect; - -function mountApp(pathname: string) { - window.history.replaceState({}, "", pathname); - const app = document.createElement("openclaw-app") as OpenClawApp; - document.body.append(app); - return app; -} - -beforeEach(() => { - OpenClawApp.prototype.connect = () => { - // no-op: avoid real gateway WS connections in browser tests - }; - window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined; - localStorage.clear(); - document.body.innerHTML = ""; -}); - -afterEach(() => { - OpenClawApp.prototype.connect = originalConnect; - window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined; - localStorage.clear(); - document.body.innerHTML = ""; -}); +registerAppMountHooks(); describe("chat markdown rendering", () => { it("renders markdown inside tool output sidebar", async () => { diff --git a/ui/src/ui/focus-mode.browser.test.ts b/ui/src/ui/focus-mode.browser.test.ts index 9576100d1e..c134ecb5bf 100644 --- a/ui/src/ui/focus-mode.browser.test.ts +++ b/ui/src/ui/focus-mode.browser.test.ts @@ -1,31 +1,7 @@ -import { afterEach, beforeEach, describe, expect, it } from "vitest"; -import { OpenClawApp } from "./app.ts"; +import { describe, expect, it } from "vitest"; +import { mountApp, registerAppMountHooks } from "./test-helpers/app-mount.ts"; -// oxlint-disable-next-line typescript/unbound-method -const originalConnect = OpenClawApp.prototype.connect; - -function mountApp(pathname: string) { - window.history.replaceState({}, "", pathname); - const app = document.createElement("openclaw-app") as OpenClawApp; - document.body.append(app); - return app; -} - -beforeEach(() => { - OpenClawApp.prototype.connect = () => { - // no-op: avoid real gateway WS connections in browser tests - }; - window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined; - localStorage.clear(); - document.body.innerHTML = ""; -}); - -afterEach(() => { - OpenClawApp.prototype.connect = originalConnect; - window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined; - localStorage.clear(); - document.body.innerHTML = ""; -}); +registerAppMountHooks(); describe("chat focus mode", () => { it("collapses header + sidebar on chat tab only", async () => { diff --git a/ui/src/ui/test-helpers/app-mount.ts b/ui/src/ui/test-helpers/app-mount.ts new file mode 100644 index 0000000000..f45d712a50 --- /dev/null +++ b/ui/src/ui/test-helpers/app-mount.ts @@ -0,0 +1,30 @@ +import { afterEach, beforeEach, vi } from "vitest"; +import { OpenClawApp } from "../app.ts"; + +// oxlint-disable-next-line typescript/unbound-method +const originalConnect = OpenClawApp.prototype.connect; + +export function mountApp(pathname: string) { + window.history.replaceState({}, "", pathname); + const app = document.createElement("openclaw-app") as OpenClawApp; + document.body.append(app); + return app; +} + +export function registerAppMountHooks() { + beforeEach(() => { + OpenClawApp.prototype.connect = () => { + // no-op: avoid real gateway WS connections in browser tests + }; + window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined; + localStorage.clear(); + document.body.innerHTML = ""; + }); + + afterEach(() => { + OpenClawApp.prototype.connect = originalConnect; + window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined; + localStorage.clear(); + document.body.innerHTML = ""; + }); +}