import { describe, expect, it } from "vitest"; import { escapeHtml, formatDateTime, formatSignedCredits, statusLabel, } from "../lib/format"; describe("format helpers", () => { it("转义服务端文本以阻止 HTML 注入", () => { expect(escapeHtml('')).toBe( "<img src=x onerror="alert(1)">", ); }); it("无效日期显示占位符", () => { expect(formatDateTime("not-a-date")).toBe("—"); expect(formatDateTime()).toBe("—"); }); it("积分变动保留明确正负号", () => { expect(formatSignedCredits(15)).toBe("+15"); expect(formatSignedCredits(-8)).toBe("-8"); }); it("未知状态保持原值", () => { expect(statusLabel("custom")).toBe("custom"); }); });