1a9c518f96
Provide TOTP-authenticated, role-controlled user and credit workflows with paginated audit data and SQL-backed statistics so operations can manage growth safely.
30 lines
780 B
TypeScript
30 lines
780 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
escapeHtml,
|
|
formatDateTime,
|
|
formatSignedCredits,
|
|
statusLabel,
|
|
} from "../lib/format";
|
|
|
|
describe("format helpers", () => {
|
|
it("转义服务端文本以阻止 HTML 注入", () => {
|
|
expect(escapeHtml('<img src=x onerror="alert(1)">')).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");
|
|
});
|
|
});
|