mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(ui): share app mount hooks
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
30
ui/src/ui/test-helpers/app-mount.ts
Normal file
30
ui/src/ui/test-helpers/app-mount.ts
Normal 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 = "";
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user