diff --git a/frontend/src/components/markdown.test.ts b/frontend/src/components/markdown.test.ts new file mode 100644 index 00000000..a2bf2c0d --- /dev/null +++ b/frontend/src/components/markdown.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it } from "bun:test"; +import React from "react"; +import { renderToStaticMarkup } from "react-dom/server"; + +import { MarkdownContent } from "./markdown"; + +function renderMarkdown(content: string): string { + return renderToStaticMarkup(React.createElement(MarkdownContent, { content })); +} + +describe("MarkdownContent images", () => { + it("renders image alt text without loading remote or local URL schemes", () => { + const rendered = renderMarkdown( + [ + "![remote](https://example.com/tracker.png)", + "![relative](/local-image.png)", + "![data](data:image/png;base64,abc)", + "![blob](blob:https://trymaple.ai/image-id)" + ].join("\n\n") + ); + + expect(rendered).not.toContain(" { + const rendered = renderMarkdown("[Maple](https://trymaple.ai)"); + + expect(rendered).toContain('href="https://trymaple.ai"'); + expect(rendered).toContain(">Maple"); + }); + + it("omits images without alt text", () => { + const rendered = renderMarkdown("![](https://example.com/hidden.png)"); + + expect(rendered).not.toContain(" (alt ? {alt} : null), pre: (props: JSX.IntrinsicElements["pre"]) => , code: (props: JSX.IntrinsicElements["code"]) => , table: (props: JSX.IntrinsicElements["table"]) => ,