Files
xiaoxia-saas/apps/web/src/test/api/voiceClone-utils.test.ts
T
xiaoxia 5610ef9f1a
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (push) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 1m8s
CI Build & Deploy Pipeline / Build Staging Web Image (push) Successful in 1m31s
CI/CD Pipeline / Frontend Lint (push) Successful in 2m26s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 3m46s
CI/CD Pipeline / Unit Tests (push) Successful in 3m49s
CI/CD Pipeline / Integration Tests (push) Successful in 1m52s
CI Build & Deploy Pipeline / Build Staging API Image (push) Successful in 6m29s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Successful in 8m32s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 50s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 1m21s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Successful in 3m11s
test: 前端单测覆盖率Phase1,行覆盖率0.84%→22.35% (#560)
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
2026-07-19 11:16:36 +08:00

72 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest"
import { toVoiceClone, formatDuration } from "@/api/voiceClone"
import type { VoiceCloneProfile } from "@/api/voiceClone"
describe("formatDuration", () => {
it("should format seconds correctly", () => {
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(90)).toBe("1:30")
expect(formatDuration(3600)).toBe("60:00")
})
})
describe("toVoiceClone", () => {
const baseProfile: VoiceCloneProfile = {
id: "clone-1",
name: "测试克隆",
description: "测试描述",
status: "ready",
source_audio_url: "https://example.com/audio.wav",
language: "zh",
gender: "female",
error_message: null,
created_at: "2026-01-01T00:00:00Z",
updated_at: "2026-01-02T00:00:00Z",
}
it("should map profile to VoiceClone correctly", () => {
const result = toVoiceClone(baseProfile)
expect(result.id).toBe("clone-1")
expect(result.name).toBe("测试克隆")
expect(result.description).toBe("测试描述")
expect(result.status).toBe("ready")
expect(result.sample_url).toBe("https://example.com/audio.wav")
expect(result.language).toBe("zh")
expect(result.gender).toBe("female")
expect(result.duration_seconds).toBe(0)
expect(result.progress).toBe(0)
})
it("should map pending status to processing", () => {
const pending = { ...baseProfile, status: "pending" as const }
const result = toVoiceClone(pending)
expect(result.status).toBe("processing")
})
it("should handle missing optional fields", () => {
const minimal: VoiceCloneProfile = {
id: "clone-2",
name: "最小克隆",
description: null as any,
status: "failed",
source_audio_url: null as any,
language: null as any,
gender: null as any,
error_message: "错误信息",
created_at: "2026-01-01T00:00:00Z",
updated_at: "2026-01-01T00:00:00Z",
}
const result = toVoiceClone(minimal)
expect(result.description).toBe("")
expect(result.sample_url).toBeUndefined()
expect(result.language).toBe("")
expect(result.gender).toBe("")
expect(result.error_message).toBe("错误信息")
})
})