Files
tutti/packages/agent/gui/shared/AgentMessageMermaid.integration.spec.tsx
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

78 lines
2.2 KiB
TypeScript

import { cleanup, render, waitFor } from "@testing-library/react";
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
import { AgentMessageMermaid } from "./AgentMessageMermaid";
describe("AgentMessageMermaid real renderer", () => {
const originalGetBBox = Object.getOwnPropertyDescriptor(
SVGElement.prototype,
"getBBox"
);
const originalGetComputedTextLength = Object.getOwnPropertyDescriptor(
SVGElement.prototype,
"getComputedTextLength"
);
beforeAll(() => {
Object.defineProperties(SVGElement.prototype, {
getBBox: {
configurable: true,
value: () => ({ height: 20, width: 120, x: 0, y: 0 })
},
getComputedTextLength: {
configurable: true,
value: () => 120
}
});
});
afterAll(() => {
restoreProperty(SVGElement.prototype, "getBBox", originalGetBBox);
restoreProperty(
SVGElement.prototype,
"getComputedTextLength",
originalGetComputedTextLength
);
});
afterEach(() => {
cleanup();
document.documentElement.removeAttribute("data-theme");
});
it("keeps flowchart labels after the defense-in-depth sanitizer", async () => {
document.documentElement.dataset.theme = "light";
const view = render(
<AgentMessageMermaid
source={`%%{init: {"htmlLabels": true}}%%
flowchart TD
A["ACP Client<br/>启动 Agent"] --> B{"初始化成功?"}
B -->|"是"| C["创建会话"]`}
streaming={false}
/>
);
await waitFor(() => {
expect(view.queryByTestId("agent-mermaid-svg")).not.toBeNull();
});
const container = view.getByTestId("agent-mermaid-svg");
expect(container.querySelector("foreignObject")).toBeNull();
expect(container.textContent).toContain("ACP Client");
expect(container.textContent).toContain("启动 Agent");
expect(container.textContent).toContain("初始化成功?");
expect(container.textContent).toContain("创建会话");
});
});
function restoreProperty(
target: object,
property: string,
descriptor: PropertyDescriptor | undefined
): void {
if (descriptor) {
Object.defineProperty(target, property, descriptor);
return;
}
Reflect.deleteProperty(target, property);
}