Files
NianAIGC/tests/video-settings.test.ts
2026-08-21 13:44:56 +08:00

47 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
VIDEO_DURATION_AUTO,
VIDEO_DURATION_DEFAULT,
VIDEO_DURATION_MAX,
VIDEO_DURATION_MIN,
SEEDANCE_25_MODEL,
clampVideoDuration,
normalizeVideoDuration,
normalizeVideoRatio,
normalizeVideoResolution,
seedanceDurationOptions
} from "@/lib/video-settings";
describe("video settings", () => {
it("clamps duration to the supported range", () => {
expect(clampVideoDuration(2)).toBe(VIDEO_DURATION_MIN);
expect(clampVideoDuration(999)).toBe(VIDEO_DURATION_MAX);
expect(clampVideoDuration(12.6)).toBe(13);
});
it("supports Seedance auto duration only when allowed", () => {
expect(normalizeVideoDuration(VIDEO_DURATION_AUTO)).toBe(VIDEO_DURATION_AUTO);
expect(clampVideoDuration(VIDEO_DURATION_AUTO, VIDEO_DURATION_DEFAULT, { allowAuto: false })).toBe(VIDEO_DURATION_MIN);
});
it("allows Seedance 2.5 durations through 30 seconds without changing 2.0", () => {
expect(clampVideoDuration(30, VIDEO_DURATION_DEFAULT, { model: SEEDANCE_25_MODEL })).toBe(30);
expect(clampVideoDuration(30)).toBe(VIDEO_DURATION_MAX);
expect(seedanceDurationOptions(SEEDANCE_25_MODEL).at(-1)).toBe(30);
});
it("keeps empty duration optional and falls back for invalid values", () => {
expect(normalizeVideoDuration(undefined)).toBeUndefined();
expect(normalizeVideoDuration("")).toBeUndefined();
expect(clampVideoDuration("not-a-number")).toBe(VIDEO_DURATION_DEFAULT);
});
it("normalizes ratio and resolution to Seedance 2.0 supported values", () => {
expect(normalizeVideoRatio("21:9")).toBe("21:9");
expect(normalizeVideoRatio("bad-ratio")).toBe("9:16");
expect(normalizeVideoResolution("1080p", "doubao-seedance-2-0-260128")).toBe("1080p");
expect(normalizeVideoResolution("4k", "doubao-seedance-2-0-260128")).toBe("720p");
expect(normalizeVideoResolution("1080p", "doubao-seedance-2-0-fast-260128")).toBe("720p");
});
});