feat(app): store assistant image previews as assets
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { pathToFileUri } from "./utils";
|
||||
import { createImageSourceCacheKey, parseDataUrl, parseImageDataUrl, pathToFileUri } from "./utils";
|
||||
|
||||
describe("pathToFileUri", () => {
|
||||
it("converts POSIX absolute paths to file URIs", () => {
|
||||
@@ -22,3 +22,35 @@ describe("pathToFileUri", () => {
|
||||
expect(pathToFileUri("relative/path")).toBe("relative/path");
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseDataUrl", () => {
|
||||
it("accepts base64 data URLs with media-type parameters", () => {
|
||||
expect(parseDataUrl("data:image/png;charset=utf-8;name=preview;base64,AAECAw==")).toEqual({
|
||||
mimeType: "image/png",
|
||||
base64: "AAECAw==",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects non-base64 data URLs", () => {
|
||||
expect(() => parseDataUrl("data:image/png,not-base64")).toThrow(
|
||||
"Attachment data URL is not base64 encoded.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseImageDataUrl", () => {
|
||||
it("returns a compact cache key for image data URLs", () => {
|
||||
const dataUrl = `data:image/png;base64,${"a".repeat(512)}`;
|
||||
|
||||
expect(parseImageDataUrl(dataUrl)).toMatchObject({
|
||||
mimeType: "image/png",
|
||||
base64: "a".repeat(512),
|
||||
});
|
||||
expect(createImageSourceCacheKey(dataUrl)).toMatch(/^data-image:image\/png:512:/);
|
||||
expect(createImageSourceCacheKey(dataUrl)).not.toContain("a".repeat(128));
|
||||
});
|
||||
|
||||
it("ignores non-image data URLs", () => {
|
||||
expect(parseImageDataUrl("data:text/plain;base64,SGVsbG8=")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user