Files
plainleaf/client/components/plainleaf_markdown_preview.test.ts
wushenghuaandCodex becc6694c2 feat: 完善云叶冒险皮肤与笔记体验
统一登录、工作区、待办、设置和管理页面的视觉语言,补充 Markdown 预览、皮肤切换及移动端体验。

Co-Authored-By: Codex <noreply@anthropic.com>
2026-08-13 09:44:30 +08:00

63 lines
1.6 KiB
TypeScript

import { expect, test, vi } from "vitest";
import {
renderPlainleafMarkdownPreview,
resolvePlainleafPreviewUrl,
} from "./plainleaf_markdown_preview.ts";
test("renders Markdown for reading and sends the result through the sanitizer", () => {
const sanitize = vi.fn((html: string) =>
html.replace(/<script.*?<\/script>/g, ""),
);
const html = renderPlainleafMarkdownPreview(
"# 标题\n\n- 列表\n\n<script>alert(1)</script>",
[],
(url) => url,
sanitize,
);
expect(sanitize).toHaveBeenCalledOnce();
expect(html).toContain("<h1>标题</h1>");
expect(html).toContain("<ul>");
expect(html).not.toContain("<script");
});
test("translates local link URLs during rendering", () => {
const html = renderPlainleafMarkdownPreview(
"[文档](guide.md)",
[],
(url, type) => `/${type}/${url}`,
(value) => value,
);
expect(html).toContain('href="/link/guide.md"');
});
test("resolves preview media through the current space file endpoint", () => {
expect(
resolvePlainleafPreviewUrl(
"项目/计划",
"https://notes.example.com/",
".fs/图片/photo 1.png",
"image",
),
).toBe(
"https://notes.example.com/.fs/%E9%A1%B9%E7%9B%AE/%E5%9B%BE%E7%89%87/photo%201.png",
);
expect(
resolvePlainleafPreviewUrl(
"项目/计划",
"https://notes.example.com/",
"guide.md",
"link",
),
).toBe("项目/guide.md");
expect(
resolvePlainleafPreviewUrl(
"项目/计划",
"https://notes.example.com/",
"https://cdn.example.com/photo.png",
"image",
),
).toBe("https://cdn.example.com/photo.png");
});