mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 20:44:47 +00:00
test: guard ui sidebar mock calls
This commit is contained in:
@@ -29,6 +29,21 @@ vi.mock("../icons.ts", () => ({
|
||||
icons: {},
|
||||
}));
|
||||
|
||||
function requireFirstMockArg(
|
||||
mock: ReturnType<typeof vi.fn>,
|
||||
label: string,
|
||||
): Record<string, unknown> {
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
const [arg] = call;
|
||||
if (!arg || typeof arg !== "object" || Array.isArray(arg)) {
|
||||
throw new Error(`expected ${label} payload`);
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
vi.mock("../views/agents-utils.ts", () => {
|
||||
const isRenderableControlUiAvatarUrl = (value: string) =>
|
||||
/^data:image\//i.test(value) || (value.startsWith("/") && !value.startsWith("//"));
|
||||
@@ -1768,7 +1783,6 @@ describe("grouped chat rendering", () => {
|
||||
|
||||
expect(container.querySelector(".chat-tool-card__preview-frame")).toBeNull();
|
||||
expect(onOpenSidebar).toHaveBeenCalledTimes(1);
|
||||
const sidebarPayload = onOpenSidebar.mock.calls[0]?.[0] as { kind?: string } | undefined;
|
||||
expect(sidebarPayload?.kind).toBe("markdown");
|
||||
expect(requireFirstMockArg(onOpenSidebar, "sidebar open").kind).toBe("markdown");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,6 +20,21 @@ vi.mock("../tool-display.ts", () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
function requireFirstMockArg(
|
||||
mock: ReturnType<typeof vi.fn>,
|
||||
label: string,
|
||||
): Record<string, unknown> {
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
const [arg] = call;
|
||||
if (!arg || typeof arg !== "object" || Array.isArray(arg)) {
|
||||
throw new Error(`expected ${label} payload`);
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
describe("tool-cards", () => {
|
||||
it("renders expanded cards with inline input and output sections", () => {
|
||||
const container = document.createElement("div");
|
||||
@@ -178,11 +193,9 @@ describe("tool-cards", () => {
|
||||
expect(sidebarButton?.classList.contains("chat-tool-card__action-btn")).toBe(true);
|
||||
sidebarButton!.click();
|
||||
|
||||
const sidebar = onOpenSidebar.mock.calls[0]?.[0] as
|
||||
| { kind?: string; docId?: string; entryUrl?: string }
|
||||
| undefined;
|
||||
expect(sidebar?.kind).toBe("canvas");
|
||||
expect(sidebar?.docId).toBe("cv_sidebar");
|
||||
expect(sidebar?.entryUrl).toBe("/__openclaw__/canvas/documents/cv_sidebar/index.html");
|
||||
const sidebar = requireFirstMockArg(onOpenSidebar, "sidebar open");
|
||||
expect(sidebar.kind).toBe("canvas");
|
||||
expect(sidebar.docId).toBe("cv_sidebar");
|
||||
expect(sidebar.entryUrl).toBe("/__openclaw__/canvas/documents/cv_sidebar/index.html");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user