refactor(ui): share app mount hooks

This commit is contained in:
Peter Steinberger
2026-02-15 21:09:32 +00:00
parent 2ac3e780e3
commit c623c51cf4
3 changed files with 36 additions and 54 deletions

View File

@@ -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 () => {

View File

@@ -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 () => {

View File

@@ -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 = "";
});
}