deer-flow/frontend/tests/unit/core/streamdown-plugins.test.ts
March7 bb0088127b
fix(frontend): prevent streamed word animation replay (#4266)
* fix(frontend): stop replaying streamed word animations

* fix(frontend): restore Streamdown rendering plugins

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-07-22 09:03:46 +08:00

50 lines
1.4 KiB
TypeScript

import { expect, test } from "@rstest/core";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { artifactMarkdownPlugins } from "@/components/workspace/artifacts/markdown-preview-plugins";
import { ArtifactLink } from "@/components/workspace/citations/artifact-link";
import {
SafeStreamdown,
streamdownPlugins,
toStreamdownComponents,
} from "@/core/streamdown";
function renderArtifactMarkdown(content: string) {
return renderToStaticMarkup(
createElement(
SafeStreamdown,
{
...artifactMarkdownPlugins,
components: toStreamdownComponents({ a: ArtifactLink }),
},
content,
),
);
}
function renderSharedMarkdown(content: string) {
return renderToStaticMarkup(
createElement(SafeStreamdown, streamdownPlugins, content),
);
}
test("adds GitHub-style heading anchors to artifact markdown previews", () => {
const html = renderArtifactMarkdown(
["[概述](#概述)", "", "## 概述"].join("\n"),
);
expect(html).toContain('href="#%E6%A6%82%E8%BF%B0"');
expect(html).toContain('id="概述"');
expect(html).not.toContain("target=");
});
test("does not add heading anchors to the shared streamdown plugin config", () => {
const html = [
renderSharedMarkdown("## Summary"),
renderSharedMarkdown("## Summary"),
].join("");
expect(html).not.toContain('id="summary"');
});