* fix(app): attach dropped files in composer Composer parents had to expose attachment callbacks, so New Workspace only wired image drops and JSON files never became file attachments. Centralize dropped-file ingestion in Composer so all composer surfaces share the same image and file path. * fix(app): handle desktop dropped attachment paths
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { droppedItemsToPickedFiles } from "./drop";
|
|
|
|
describe("composer dropped attachments", () => {
|
|
it("turns non-image browser files into picked files and leaves raster images for image handling", async () => {
|
|
const jsonFile = new File([JSON.stringify({ ok: true })], "config.json", {
|
|
type: "application/json",
|
|
});
|
|
const imageFile = new File([new Uint8Array([0])], "screen.png", { type: "image/png" });
|
|
|
|
const files = await droppedItemsToPickedFiles([
|
|
{ kind: "web-file", file: jsonFile },
|
|
{ kind: "web-file", file: imageFile },
|
|
]);
|
|
|
|
expect(files).toEqual([
|
|
{
|
|
fileName: "config.json",
|
|
mimeType: "application/json",
|
|
bytes: new Uint8Array(await jsonFile.arrayBuffer()),
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("turns non-image desktop paths into picked files and leaves raster images for image handling", async () => {
|
|
const windowsPath = "C:\\Users\\alice\\config.json";
|
|
const posixPath = "/Users/alice/notes/readme.txt";
|
|
const imagePath = "C:\\Users\\alice\\screen.png";
|
|
const bytesByPath = new Map([
|
|
[windowsPath, new Uint8Array([1, 2, 3])],
|
|
[posixPath, new Uint8Array([4, 5])],
|
|
]);
|
|
const readPaths: string[] = [];
|
|
|
|
const files = await droppedItemsToPickedFiles(
|
|
[
|
|
{ kind: "desktop-path", path: windowsPath },
|
|
{ kind: "desktop-path", path: imagePath },
|
|
{ kind: "desktop-path", path: posixPath },
|
|
],
|
|
{
|
|
readDesktopFileBytes: async (path) => {
|
|
readPaths.push(path);
|
|
const bytes = bytesByPath.get(path);
|
|
if (!bytes) {
|
|
throw new Error(`Unexpected desktop read: ${path}`);
|
|
}
|
|
return bytes;
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(readPaths).toEqual([windowsPath, posixPath]);
|
|
expect(files).toEqual([
|
|
{
|
|
fileName: "config.json",
|
|
mimeType: "application/octet-stream",
|
|
bytes: new Uint8Array([1, 2, 3]),
|
|
},
|
|
{
|
|
fileName: "readme.txt",
|
|
mimeType: "application/octet-stream",
|
|
bytes: new Uint8Array([4, 5]),
|
|
},
|
|
]);
|
|
});
|
|
});
|