import { describe, expect, it } from "vitest"; import type { EditorAssetInfo } from "../src/ipc.js"; import { audioAssets, formatAssetSize, imageAssets, mergeImported, removeById } from "../src/renderer/assets-model.js"; function image(id: string): EditorAssetInfo { return { id, kind: "image", mime: "image/png", size: 10, dataUrl: `data:image/png;base64,${id}` }; } function audio(id: string): EditorAssetInfo { return { id, kind: "audio", mime: "audio/ogg", size: 20 }; } describe("assets-model (F2)", () => { it("splits the list into images and audio", () => { const list = [image("a"), audio("b"), image("c")]; expect(imageAssets(list).map((a) => a.id)).toEqual(["a", "c"]); expect(audioAssets(list).map((a) => a.id)).toEqual(["b"]); }); it("mergeImported adds new ids, replaces existing ones, and sorts by id", () => { const current = [image("b"), image("a")]; const merged = mergeImported(current, [audio("c"), image("a")]); expect(merged.map((a) => a.id)).toEqual(["a", "b", "c"]); expect(merged[0]?.kind).toBe("image"); expect(merged[2]?.kind).toBe("audio"); }); it("removeById drops the deleted entry and formatAssetSize is human-readable", () => { const list = [image("a"), audio("b")]; expect(removeById(list, "a").map((a) => a.id)).toEqual(["b"]); expect(removeById(list, "missing").map((a) => a.id)).toEqual(["a", "b"]); expect(formatAssetSize(512)).toBe("512 B"); expect(formatAssetSize(2048)).toBe("2.0 KB"); expect(formatAssetSize(3 * 1024 * 1024)).toBe("3.0 MB"); }); });