diff --git a/apps/web/src/pages/voice-materials/constants.tsx b/apps/web/src/pages/voice-materials/constants.tsx index 62f3043f8..5babc19dd 100644 --- a/apps/web/src/pages/voice-materials/constants.tsx +++ b/apps/web/src/pages/voice-materials/constants.tsx @@ -1,6 +1,7 @@ /** * 配音素材库常量 */ +/* eslint-disable react-refresh/only-export-components */ import React from "react" import { ManOutlined, WomanOutlined, UserOutlined, SoundOutlined } from "@ant-design/icons" import type { VoiceGender } from "./types" diff --git a/apps/web/src/test/pages/voice-materials/format.test.ts b/apps/web/src/test/pages/voice-materials/format.test.ts new file mode 100644 index 000000000..4fcd5a5d8 --- /dev/null +++ b/apps/web/src/test/pages/voice-materials/format.test.ts @@ -0,0 +1,75 @@ +import { describe, expect, it } from "vitest" +import { + genderLabel, + genderIcon, + genderClass, + formatDuration, + formatFileSize, + formatDate, +} from "@/pages/voice-materials/utils/format" + +describe("voice-materials format utils", () => { + describe("genderLabel", () => { + it("应返回正确的性别标签", () => { + expect(genderLabel("male")).toBe("男声") + expect(genderLabel("female")).toBe("女声") + expect(genderLabel("child")).toBe("童声") + expect(genderLabel("neutral")).toBe("中性") + }) + + it("未知性别返回原值", () => { + expect(genderLabel("unknown" as any)).toBe("unknown") + }) + }) + + describe("genderIcon", () => { + it("应返回图标组件", () => { + expect(genderIcon("male")).toBeDefined() + expect(genderIcon("female")).toBeDefined() + expect(genderIcon("child")).toBeDefined() + expect(genderIcon("neutral")).toBeDefined() + }) + + it("未知性别返回 null", () => { + expect(genderIcon("unknown" as any)).toBeNull() + }) + }) + + describe("genderClass", () => { + it("应返回正确的 CSS 类名", () => { + expect(genderClass("male")).toBe("vmat-gender--male") + expect(genderClass("female")).toBe("vmat-gender--female") + }) + }) + + describe("formatDuration", () => { + it("应正确格式化秒数", () => { + expect(formatDuration(0)).toBe("0:00") + expect(formatDuration(5)).toBe("0:05") + expect(formatDuration(59)).toBe("0:59") + expect(formatDuration(60)).toBe("1:00") + expect(formatDuration(65)).toBe("1:05") + expect(formatDuration(125)).toBe("2:05") + expect(formatDuration(3600)).toBe("60:00") + }) + }) + + describe("formatFileSize", () => { + it("应正确格式化文件大小", () => { + expect(formatFileSize(0)).toBe("0 B") + expect(formatFileSize(512)).toBe("512 B") + expect(formatFileSize(1024)).toBe("1.0 KB") + expect(formatFileSize(1536)).toBe("1.5 KB") + expect(formatFileSize(1024 * 1024)).toBe("1.0 MB") + expect(formatFileSize(1024 * 1024 * 2.5)).toBe("2.5 MB") + }) + }) + + describe("formatDate", () => { + it("应格式化 ISO 日期字符串", () => { + const result = formatDate("2026-07-24T10:30:00.000Z") + // 格式应该是 YYYY/MM/DD 格式 + expect(result).toMatch(/^\d{4}\/\d{2}\/\d{2}$/) + }) + }) +})