28 lines
1.7 KiB
TypeScript
28 lines
1.7 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { canvasMediaType, prepareCanvasMediaFiles } from "@/lib/video-canvas/media-import";
|
|
|
|
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 个素材,其余文件请分批拖入"]);
|
|
});
|