ai-chatbot/tests/routes/video-toolbox-workflows.test.ts

145 lines
4.7 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { normalizeVideoCanvasFunctionConfig } from "../../lib/video-canvas/config";
import {
defaultVideoCanvasToolboxConfig,
getVideoCanvasToolboxGroupOrigin,
normalizeVideoCanvasToolboxConfig,
} from "../../lib/video-canvas/toolbox-workflows";
test.describe("video canvas toolbox workflows", () => {
test("matches the two observed categories and exact template counts", () => {
expect(defaultVideoCanvasToolboxConfig.categories.map((category) => category.label)).toEqual([
"我的工具箱",
"周星驰经典名场面",
]);
expect(
defaultVideoCanvasToolboxConfig.templates.filter(
(template) => template.categoryId === "my-toolbox",
),
).toHaveLength(25);
expect(
defaultVideoCanvasToolboxConfig.templates.filter(
(template) => template.categoryId === "stephen-chow",
),
).toHaveLength(5);
});
test("keeps the observed template order including intentional duplicate names", () => {
expect(
defaultVideoCanvasToolboxConfig.templates
.filter((template) => template.categoryId === "my-toolbox")
.map((template) => template.name),
).toEqual([
"【预设】左弧滑行",
"【预设】电商手机弹出效果",
"【预设】咖啡杯出场",
"【预设】360旋转展示",
"【预设】机械臂视角",
"【预设】Live 2D",
"【预设】瞳孔拉近",
"【预设】飞鸟解体",
"【预设】破盒而出",
"【预设】商品震撼登场",
"【预设】右弧滑行",
"【预设】左弧滑行",
"【预设】颠倒空间",
"【预设】反重力漂浮",
"【预设】粒子融解",
"【预设】旅拍转场 zoom in",
"【预设】旅拍转场 zoom out",
"【预设】旅拍转场 向右旋转",
"【预设】旅拍转场 向左旋转",
"【预设】旅拍转场 生长",
"【预设】英雄视角",
"【预设】AI模特服饰动态展示",
"【预设】机械臂视角",
"【预设】大师分镜九宫格-经典暗调",
"【预设】AI室内装修效果预览",
]);
expect(
defaultVideoCanvasToolboxConfig.templates
.filter((template) => template.categoryId === "stephen-chow")
.map((template) => template.name),
).toEqual([
"喜剧之王-枪战",
"喜剧之王-神秘富豪",
"食神-食神大赛",
"食神-撒尿牛丸",
"七仔-修风扇",
]);
});
test("places a workflow group at the observed viewport-center offset without changing zoom", () => {
expect(
getVideoCanvasToolboxGroupOrigin({
layout: defaultVideoCanvasToolboxConfig.layout,
viewport: { x: 0, y: 0, zoom: 1 },
viewportHeight: 805,
viewportWidth: 1512,
}),
).toEqual({ x: 581, y: 227.5 });
expect(
getVideoCanvasToolboxGroupOrigin({
layout: defaultVideoCanvasToolboxConfig.layout,
viewport: { x: 120, y: -80, zoom: 2 },
viewportHeight: 805,
viewportWidth: 1512,
}),
).toEqual({ x: 230.5, y: 153.75 });
});
test("normalizes administrator templates, layout and category fallback", () => {
const config = normalizeVideoCanvasToolboxConfig({
categories: [{ enabled: true, id: "custom", label: "自定义" }],
layout: {
groupHeight: 1,
groupWidth: 99_999,
placementOffsetX: -99_999,
},
templates: [
{
categoryId: "missing",
coverUrl: "https://example.com/cover.png?size=small",
id: " custom-template ",
name: " 自定义模板 ",
prompt: " 自定义提示词 ",
},
],
});
expect(config.layout).toMatchObject({
groupHeight: 100,
groupWidth: 8000,
placementOffsetX: -4000,
});
expect(config.templates[0]).toMatchObject({
categoryId: "custom",
id: "custom-template",
name: "自定义模板",
prompt: "自定义提示词",
referenceUrl: "https://example.com/cover.png",
});
});
test("delivers toolbox configuration through the shared video canvas setting", () => {
const config = normalizeVideoCanvasFunctionConfig({
toolbox: {
categories: [{ id: "custom", label: "Custom" }],
templates: [
{
categoryId: "custom",
coverUrl: "https://example.com/cover.png",
id: "custom-template",
name: "Custom template",
prompt: "Prompt",
},
],
},
});
expect(config.toolbox.categories).toHaveLength(1);
expect(config.toolbox.templates).toHaveLength(1);
expect(config.toolbox.templates[0].name).toBe("Custom template");
});
});