import { test, expect } from "@playwright/test"; import { canvasMediaType, prepareCanvasMediaFiles } from "@/lib/video-canvas/media-import"; import { getUploadedMediaNodeSize } from "@/lib/video-canvas/media-node-size"; test("Finder files without MIME retain bytes and get the correct image/video upload route", async () => { const input = [new File(["image bytes"], "照片.PNG"), new File(["video bytes"], "镜头.MOV", { type: "application/octet-stream" })]; const { files, errors } = prepareCanvasMediaFiles(input); expect(errors).toEqual([]); expect(files.map(f => f.type)).toEqual(["image/png", "video/quicktime"]); expect(await Promise.all(files.map(f => f.text()))).toEqual(["image bytes", "video bytes"]); expect(files.map(canvasMediaType)).toEqual(["image", "video"]); }); test("invalid mixed drops cannot create empty or unsupported media nodes", () => { const valid = new File(["video"], "clip.mp4", { type: "video/mp4" }); const result = prepareCanvasMediaFiles([new File([], "folder"), new File([], "empty.png", { type: "image/png" }), new File(["text"], "wrong.png", { type: "text/plain" }), valid]); expect(result.files).toEqual([valid]); expect(result.errors).toHaveLength(3); const oversized = new File(["video"], "large.mp4", { type: "video/mp4" }); Object.defineProperty(oversized, "size", { value: 126 * 1024 * 1024 }); expect(prepareCanvasMediaFiles([oversized]).errors[0]).toContain("125 MiB"); }); test("a drop beyond the batch limit explicitly reports skipped files", () => { const result = prepareCanvasMediaFiles(Array.from({ length: 12 }, (_, i) => new File(["png"], `${i}.png`, { type: "image/png" }))); expect(result.files).toHaveLength(10); expect(result.errors).toEqual(["每次最多导入 10 个素材,其余文件请分批拖入"]); }); test("portrait and landscape uploads preserve their visible aspect ratio below the node title", () => { for (const [width, height, mediaType] of [ [1080, 1440, "video"], [1440, 1080, "video"], [768, 1024, "image"], [1920, 1080, "image"], ] as const) { const node = getUploadedMediaNodeSize(width, height, mediaType); expect(node).not.toBeNull(); expect(node!.width).toBeLessThanOrEqual(mediaType === "video" ? 560 : 420); expect(node!.height - 32).toBeLessThanOrEqual(560); expect(node!.width / (node!.height - 32)).toBeCloseTo(width / height, 2); } });