import { describe, expect, it } from "vitest"; import { GLTF_APPEARANCE_PNG } from "../test-fixtures/gltf-appearance-fixtures"; import { decodeToolcraftModelAppearanceDataUri } from "./model-appearance-data-uri"; function dataUri(bytes: Uint8Array): string { let binary = ""; for (const byte of bytes) binary += String.fromCharCode(byte); return `data:image/png;base64,${btoa(binary)}`; } describe("model appearance data URI", () => { it("decodes canonical base64 without browser image APIs", () => { expect( decodeToolcraftModelAppearanceDataUri( dataUri(GLTF_APPEARANCE_PNG), GLTF_APPEARANCE_PNG.byteLength, ), ).toEqual({ bytes: GLTF_APPEARANCE_PNG, kind: "decoded", mimeType: "image/png", }); }); it("distinguishes invalid, oversized, and non-data sources", () => { expect(decodeToolcraftModelAppearanceDataUri("mesh.png", 1)).toEqual({ kind: "not-data", }); expect( decodeToolcraftModelAppearanceDataUri("data:image/png;base64,AA=A", 10), ).toEqual({ kind: "invalid" }); expect( decodeToolcraftModelAppearanceDataUri("data:image/png;base64,AB==", 10), ).toEqual({ kind: "invalid" }); expect( decodeToolcraftModelAppearanceDataUri(dataUri(GLTF_APPEARANCE_PNG), 1), ).toEqual({ byteLength: GLTF_APPEARANCE_PNG.byteLength, kind: "too-large", }); }); });