94 lines
2.6 KiB
TypeScript
94 lines
2.6 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import {
|
|
collectVideoCanvasDirectorCaptures,
|
|
mergeVideoCanvasDirectorCapture,
|
|
normalizeVideoCanvasDirectorProject,
|
|
} from "../../lib/video-canvas/director-project";
|
|
|
|
const baseProject = {
|
|
activeCameraId: "cam_1",
|
|
assets: [],
|
|
cameras: [
|
|
{
|
|
captures: [],
|
|
id: "cam_1",
|
|
lastCaptureUrl: null,
|
|
name: "机位1",
|
|
},
|
|
],
|
|
objects: [],
|
|
panoramaAssetId: null,
|
|
scene: { backgroundColor: "#060608" },
|
|
version: 1,
|
|
};
|
|
|
|
test.describe("video director project persistence", () => {
|
|
test("strips inline screenshots while preserving portable captures", () => {
|
|
const project = normalizeVideoCanvasDirectorProject({
|
|
...baseProject,
|
|
cameras: [
|
|
{
|
|
...baseProject.cameras[0],
|
|
captures: [
|
|
{ dataUrl: "data:image/png;base64,huge", id: "pending", index: 1, name: "待上传" },
|
|
{
|
|
assetId: "asset-1",
|
|
dataUrl: "/uploads/local/capture.png",
|
|
id: "stored",
|
|
index: 2,
|
|
name: "机位1-shot-02",
|
|
storagePathname: "uploads/local/capture.png",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(project?.cameras[0]?.captures).toHaveLength(1);
|
|
expect(collectVideoCanvasDirectorCaptures(project)).toEqual([
|
|
expect.objectContaining({
|
|
cameraId: "cam_1",
|
|
dataUrl: "/uploads/local/capture.png",
|
|
id: "stored",
|
|
}),
|
|
]);
|
|
});
|
|
|
|
test("merges uploaded screenshot metadata into its camera", () => {
|
|
const project = normalizeVideoCanvasDirectorProject(baseProject);
|
|
expect(project).not.toBeNull();
|
|
const merged = mergeVideoCanvasDirectorCapture(project!, {
|
|
assetId: "asset-1",
|
|
cameraId: "cam_1",
|
|
cameraName: "机位1",
|
|
dataUrl: "https://cdn.example.com/capture.png",
|
|
id: "cam_1-capture-01",
|
|
index: 1,
|
|
name: "机位1-shot-01",
|
|
storagePathname: "captures/capture.png",
|
|
});
|
|
|
|
expect(collectVideoCanvasDirectorCaptures(merged)).toEqual([
|
|
expect.objectContaining({ id: "cam_1-capture-01", index: 1 }),
|
|
]);
|
|
expect(merged.cameras[0]?.lastCaptureUrl).toBe(
|
|
"https://cdn.example.com/capture.png",
|
|
);
|
|
});
|
|
|
|
test("preserves only supported persisted viewport aspect ratios", () => {
|
|
expect(
|
|
normalizeVideoCanvasDirectorProject({
|
|
...baseProject,
|
|
viewportAspectRatio: "9:16",
|
|
})?.viewportAspectRatio,
|
|
).toBe("9:16");
|
|
expect(
|
|
normalizeVideoCanvasDirectorProject({
|
|
...baseProject,
|
|
viewportAspectRatio: "2:1",
|
|
})?.viewportAspectRatio,
|
|
).toBeUndefined();
|
|
});
|
|
});
|