import { createElement } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { describe, expect, it, vi } from "vitest"; import { ConversationShareImportNotice } from "@/v4/ConversationShareImportNotice.js"; import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js"; vi.mock("@/OpenSplitButton.js", async () => { const React = await import("react"); return { OpenSplitButton: (props: Record) => { const target = props.target as { path?: string } | undefined; return React.createElement("button", { type: "button", "data-open-split-button": "true", "data-target-path": target?.path ?? "", }); }, }; }); const rows = [ { rowId: 1, turnId: "turn-1", productTurnId: "product-turn-1", createdAt: 1, createdAtSeq: 1, kind: "turnHeader" as const, origin: "userInput" as const, state: "completedSuccess" as const, startedAt: 1, }, { rowId: 2, turnId: "turn-1", productTurnId: "product-turn-1", createdAt: 2, createdAtSeq: 2, kind: "userInput" as const, origin: "realUser" as const, text: "帮我看下这个报错", }, { rowId: 3, turnId: "turn-1", productTurnId: "product-turn-1", createdAt: 3, createdAtSeq: 3, kind: "assistantText" as const, text: "根因是 signer 被提前释放", state: "complete" as const, }, ]; function render(props: Parameters[0]) { return renderToStaticMarkup( createElement( ZCodeIntlProvider, { initialLocale: props.locale }, createElement(ConversationShareImportNotice, props), ), ); } describe("conversation share import notice", () => { it("可点击与静态分割线均使用导入图标,避免与 Fork 混淆", () => { for (const onOpenShareUrl of [undefined, () => {}]) { const html = render({ rows, locale: "en-US", onOpenShareUrl }); expect(html).toContain("lucide-square-arrow-right-enter"); expect(html).not.toContain("lucide-git-branch"); } }); it("渲染只读的分享对话与分割线", () => { const html = render({ rows, locale: "zh-CN", onOpenShareUrl: () => {} }); expect(html).toContain('data-conversation-share-import-notice="true"'); expect(html).toContain('data-conversation-share-import-divider="true"'); // 复用分享页渲染器:用户气泡与助手正文都应出现。 expect(html).toContain("帮我看下这个报错"); expect(html).toContain("根因是 signer 被提前释放"); expect(html).toContain("已从分享导入"); }); it("可点击时分割线是 button,不可点击时退化为静态行", () => { expect(render({ rows, locale: "zh-CN", onOpenShareUrl: () => {} })).toContain( '