Fix library dnd (#2314)
parent
8a50916ef2
commit
ba3f548b91
@ -0,0 +1,31 @@
|
||||
{
|
||||
"type": "excalidrawlib",
|
||||
"version": 1,
|
||||
"library": [
|
||||
[
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 38,
|
||||
"versionNonce": 1046419680,
|
||||
"isDeleted": false,
|
||||
"id": "A",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 21801,
|
||||
"y": 719.5,
|
||||
"strokeColor": "#c92a2a",
|
||||
"backgroundColor": "#e64980",
|
||||
"width": 50,
|
||||
"height": 30,
|
||||
"seed": 117297479,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": []
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
import React from "react";
|
||||
import { render, waitFor } from "./test-utils";
|
||||
import App from "../components/App";
|
||||
import { API } from "./helpers/api";
|
||||
import { MIME_TYPES } from "../constants";
|
||||
import { LibraryItem } from "../types";
|
||||
|
||||
const { h } = window;
|
||||
|
||||
describe("library", () => {
|
||||
beforeEach(() => {
|
||||
h.library.resetLibrary();
|
||||
render(<App />);
|
||||
});
|
||||
|
||||
it("import library via drag&drop", async () => {
|
||||
expect(await h.library.loadLibrary()).toEqual([]);
|
||||
await API.drop(
|
||||
await API.loadFile("./fixtures/fixture_library.excalidrawlib"),
|
||||
);
|
||||
await waitFor(async () => {
|
||||
expect(await h.library.loadLibrary()).toEqual([
|
||||
[expect.objectContaining({ id: "A" })],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
// NOTE: mocked to test logic, not actual drag&drop via UI
|
||||
it("drop library item onto canvas", async () => {
|
||||
expect(h.elements).toEqual([]);
|
||||
const libraryItems: LibraryItem = JSON.parse(
|
||||
await API.readFile("./fixtures/fixture_library.excalidrawlib", "utf8"),
|
||||
).library[0];
|
||||
await API.drop(
|
||||
new Blob([JSON.stringify(libraryItems)], {
|
||||
type: MIME_TYPES.excalidrawlib,
|
||||
}),
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(h.elements).toEqual([expect.objectContaining({ id: "A_copy" })]);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue