176 lines
5.2 KiB
TypeScript
176 lines
5.2 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import {
|
|
defaultVideoCanvasGenerationParametersConfig,
|
|
estimateVideoCanvasGenerationParameterPoints,
|
|
mergeVideoCanvasGenerationParameterSettings,
|
|
normalizeVideoCanvasGenerationParametersConfig,
|
|
normalizeVideoCanvasGenerationRequestCount,
|
|
resolveVideoCanvasGenerationParameterSettings,
|
|
} from "../../lib/video-canvas/video-generation-parameters";
|
|
|
|
test.describe("video canvas generation parameters", () => {
|
|
test("provides the competitor-matched parameter defaults", () => {
|
|
expect(defaultVideoCanvasGenerationParametersConfig).toEqual({
|
|
countOptions: [1, 2, 4],
|
|
defaultCount: 1,
|
|
defaultDurationSeconds: 5,
|
|
defaultGenerateAudio: true,
|
|
defaultRatio: "16:9",
|
|
defaultResolution: "720P",
|
|
durationStepSeconds: 1,
|
|
maxDurationSeconds: 15,
|
|
minDurationSeconds: 4,
|
|
parameterPricingEnabled: true,
|
|
pointsPerSecondByResolution: {
|
|
"480P": 13,
|
|
"720P": 27,
|
|
"1080P": 68,
|
|
"4K": 140,
|
|
},
|
|
ratioOptions: ["Auto", "16:9", "4:3", "1:1", "3:4", "9:16", "21:9"],
|
|
resolutionOptions: ["480P", "720P", "1080P", "4K"],
|
|
});
|
|
});
|
|
|
|
test("normalizes administrator options and preserves explicit false values", () => {
|
|
const config = normalizeVideoCanvasGenerationParametersConfig({
|
|
countOptions: [1, 3, 4, 4],
|
|
defaultCount: 4,
|
|
defaultDurationSeconds: 7,
|
|
defaultGenerateAudio: false,
|
|
defaultRatio: "adaptive",
|
|
defaultResolution: "4k",
|
|
maxDurationSeconds: 20,
|
|
minDurationSeconds: 3,
|
|
parameterPricingEnabled: false,
|
|
pointsPerSecondByResolution: { "1080p": 72.345, "4k": 150 },
|
|
ratioOptions: ["adaptive", "16:9", "bad"],
|
|
resolutionOptions: ["1080p", "4k", "bad"],
|
|
});
|
|
|
|
expect(config).toMatchObject({
|
|
countOptions: [1, 4],
|
|
defaultCount: 4,
|
|
defaultDurationSeconds: 7,
|
|
defaultGenerateAudio: false,
|
|
defaultRatio: "Auto",
|
|
defaultResolution: "4K",
|
|
maxDurationSeconds: 20,
|
|
minDurationSeconds: 3,
|
|
parameterPricingEnabled: false,
|
|
pointsPerSecondByResolution: { "1080P": 72.35, "4K": 150 },
|
|
ratioOptions: ["Auto", "16:9"],
|
|
resolutionOptions: ["1080P", "4K"],
|
|
});
|
|
});
|
|
|
|
test("restores canonical top-level and saved settings values", () => {
|
|
expect(
|
|
resolveVideoCanvasGenerationParameterSettings(
|
|
{
|
|
audio: false,
|
|
count: 2,
|
|
duration: 2,
|
|
ratio: "3:4",
|
|
resolution: "1080p",
|
|
},
|
|
defaultVideoCanvasGenerationParametersConfig,
|
|
),
|
|
).toEqual({
|
|
audio: "关闭",
|
|
count: "2个",
|
|
duration: "4s",
|
|
ratio: "3:4",
|
|
resolution: "1080P",
|
|
});
|
|
|
|
expect(
|
|
resolveVideoCanvasGenerationParameterSettings(
|
|
{
|
|
settings: {
|
|
audio: "开启",
|
|
count: "4个",
|
|
duration: "15s",
|
|
ratio: "Auto",
|
|
resolution: "4K",
|
|
},
|
|
},
|
|
defaultVideoCanvasGenerationParametersConfig,
|
|
),
|
|
).toEqual({
|
|
audio: "开启",
|
|
count: "4个",
|
|
duration: "15s",
|
|
ratio: "Auto",
|
|
resolution: "4K",
|
|
});
|
|
|
|
expect(
|
|
resolveVideoCanvasGenerationParameterSettings(
|
|
{
|
|
audio: false,
|
|
count: 2,
|
|
settings: { audio: "开启", count: "4个" },
|
|
},
|
|
defaultVideoCanvasGenerationParametersConfig,
|
|
),
|
|
).toMatchObject({ audio: "关闭", count: "2个" });
|
|
});
|
|
|
|
test("persists all five settings without dropping unrelated node data", () => {
|
|
expect(
|
|
mergeVideoCanvasGenerationParameterSettings(
|
|
{
|
|
mode: "first-frame",
|
|
settings: { model: "seedance", searchEnabled: true },
|
|
},
|
|
{
|
|
audio: "关闭",
|
|
count: "2个",
|
|
duration: "7s",
|
|
ratio: "3:4",
|
|
resolution: "1080P",
|
|
},
|
|
defaultVideoCanvasGenerationParametersConfig,
|
|
),
|
|
).toEqual({
|
|
audio: false,
|
|
count: 2,
|
|
duration: 7,
|
|
mode: "first-frame",
|
|
ratio: "3:4",
|
|
resolution: "1080p",
|
|
settings: {
|
|
audio: "关闭",
|
|
count: "2个",
|
|
duration: "7s",
|
|
model: "seedance",
|
|
ratio: "3:4",
|
|
resolution: "1080P",
|
|
searchEnabled: true,
|
|
},
|
|
});
|
|
});
|
|
|
|
test("matches the observed per-second pricing formula", () => {
|
|
const estimate = (resolution: string, duration: string, count: string) =>
|
|
estimateVideoCanvasGenerationParameterPoints(
|
|
{ count, duration, resolution },
|
|
defaultVideoCanvasGenerationParametersConfig,
|
|
);
|
|
|
|
expect(estimate("480P", "6s", "1个")).toBe(78);
|
|
expect(estimate("720P", "6s", "1个")).toBe(162);
|
|
expect(estimate("1080P", "7s", "2个")).toBe(952);
|
|
expect(estimate("4K", "4s", "4个")).toBe(2240);
|
|
});
|
|
|
|
test("shares the backend batch-count validation rule", () => {
|
|
expect(normalizeVideoCanvasGenerationRequestCount(undefined)).toBe(1);
|
|
expect(normalizeVideoCanvasGenerationRequestCount(2)).toBe(2);
|
|
expect(normalizeVideoCanvasGenerationRequestCount("4")).toBe(4);
|
|
expect(normalizeVideoCanvasGenerationRequestCount(3)).toBeNull();
|
|
expect(normalizeVideoCanvasGenerationRequestCount(8)).toBeNull();
|
|
});
|
|
});
|