mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-01 06:02:56 +00:00
* fix(app): preserve image attachment MIME types Image intake discarded clipboard and desktop path metadata, then guessed JPEG when a later file object had no type. Resolve MIME once at the platform boundary and require it downstream. * fix(app): honor native picker MIME metadata
104 lines
2.7 KiB
TypeScript
104 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
normalizePickedImageAssetsWith,
|
|
type ExportPickedImageAsPng,
|
|
} from "./picked-image-normalizer";
|
|
|
|
function fakeExportAsPng(): {
|
|
exportAsPng: ExportPickedImageAsPng;
|
|
recordedUris: string[];
|
|
} {
|
|
const recordedUris: string[] = [];
|
|
return {
|
|
exportAsPng: async (uri: string) => {
|
|
recordedUris.push(uri);
|
|
return "file:///cache/ImageManipulator/safe-picked.png";
|
|
},
|
|
recordedUris,
|
|
};
|
|
}
|
|
|
|
describe("native image attachment picker", () => {
|
|
it("preserves native picked JPEG and PNG attachment inputs", async () => {
|
|
const { exportAsPng, recordedUris } = fakeExportAsPng();
|
|
|
|
const result = await normalizePickedImageAssetsWith(
|
|
[
|
|
{
|
|
uri: "file:///photos/IMG_0001.JPG",
|
|
mimeType: "image/jpeg",
|
|
fileName: "picked.jpeg",
|
|
},
|
|
{
|
|
uri: "file:///photos/screenshot.png",
|
|
mimeType: "image/png",
|
|
fileName: "screenshot.png",
|
|
},
|
|
],
|
|
exportAsPng,
|
|
);
|
|
|
|
expect(result).toEqual([
|
|
{
|
|
source: { kind: "file_uri", uri: "file:///photos/IMG_0001.JPG" },
|
|
mimeType: "image/jpeg",
|
|
fileName: "picked.jpg",
|
|
},
|
|
{
|
|
source: { kind: "file_uri", uri: "file:///photos/screenshot.png" },
|
|
mimeType: "image/png",
|
|
fileName: "screenshot.png",
|
|
},
|
|
]);
|
|
expect(recordedUris).toEqual([]);
|
|
});
|
|
|
|
it("uses explicit native MIME metadata before the URI extension", async () => {
|
|
const { exportAsPng, recordedUris } = fakeExportAsPng();
|
|
|
|
const result = await normalizePickedImageAssetsWith(
|
|
[
|
|
{
|
|
uri: "file:///photos/screenshot.jpg",
|
|
mimeType: "image/png",
|
|
fileName: "screenshot.png",
|
|
},
|
|
],
|
|
exportAsPng,
|
|
);
|
|
|
|
expect(result).toEqual([
|
|
{
|
|
source: { kind: "file_uri", uri: "file:///photos/screenshot.jpg" },
|
|
mimeType: "image/png",
|
|
fileName: "screenshot.png",
|
|
},
|
|
]);
|
|
expect(recordedUris).toEqual([]);
|
|
});
|
|
|
|
it("turns a native picked HEIC-like asset into a PNG attachment input", async () => {
|
|
const { exportAsPng, recordedUris } = fakeExportAsPng();
|
|
|
|
const result = await normalizePickedImageAssetsWith(
|
|
[
|
|
{
|
|
uri: "file:///photos/IMG_0001.HEIC",
|
|
mimeType: "image/png",
|
|
fileName: "picked.png",
|
|
},
|
|
],
|
|
exportAsPng,
|
|
);
|
|
|
|
expect(result).toEqual([
|
|
{
|
|
source: { kind: "file_uri", uri: "file:///cache/ImageManipulator/safe-picked.png" },
|
|
mimeType: "image/png",
|
|
fileName: "picked.png",
|
|
},
|
|
]);
|
|
expect(recordedUris).toEqual(["file:///photos/IMG_0001.HEIC"]);
|
|
});
|
|
});
|