fix: 修正 markdown-to-jsx 导入方式 + 新增 formatDateLabel 日期工具函数

- TextPart: default import → named import
- MaterialCard: 使用 formatDateLabel 显示今天/昨天/日期
- 清理旧测试文件,新增 ResourceTable 测试
This commit is contained in:
2026-06-03 21:08:00 +08:00
parent 83cc28fe1b
commit eb93de52d8
17 changed files with 252 additions and 1177 deletions

View File

@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
import {
formatCountdown,
formatDateLabel,
formatDurationUnit,
formatRelativeTime,
isOlderThan,
@@ -77,3 +78,32 @@ describe("isOlderThan", () => {
expect(isOlderThan("2025-01-01T00:01:30.000Z", 60000, now)).toBe(false);
});
});
describe("formatDateLabel", () => {
const now = new Date("2026-06-03T12:00:00.000Z");
test("今天", () => {
expect(formatDateLabel("2026-06-03", now)).toBe("今天");
expect(formatDateLabel("2026-06-03T08:00:00.000Z", now)).toBe("今天");
});
test("昨天", () => {
expect(formatDateLabel("2026-06-02", now)).toBe("昨天");
expect(formatDateLabel("2026-06-02T23:59:59.000Z", now)).toBe("昨天");
});
test("其他日期返回 YYYY-MM-DD", () => {
expect(formatDateLabel("2026-05-30", now)).toBe("2026-05-30");
expect(formatDateLabel("2025-01-15", now)).toBe("2025-01-15");
});
test("无效输入返回占位符", () => {
expect(formatDateLabel("", now)).toBe("—");
expect(formatDateLabel("not-a-date", now)).toBe("—");
});
test("不传 now 参数使用当前日期", () => {
const result = formatDateLabel(new Date().toISOString().slice(0, 10));
expect(result).toBe("今天");
});
});