2020-10-30 21:01:41 +01:00
|
|
|
import { render, waitFor } from "./test-utils";
|
2020-12-05 20:00:53 +05:30
|
|
|
import ExcalidrawApp from "../excalidraw-app";
|
2020-10-30 21:01:41 +01:00
|
|
|
import { API } from "./helpers/api";
|
|
|
|
import { MIME_TYPES } from "../constants";
|
|
|
|
import { LibraryItem } from "../types";
|
2021-06-28 06:00:33 -04:00
|
|
|
import { UI } from "./helpers/ui";
|
2020-10-30 21:01:41 +01:00
|
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
|
|
|
describe("library", () => {
|
2020-12-05 20:00:53 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
await render(<ExcalidrawApp />);
|
2021-04-21 23:38:24 +05:30
|
|
|
h.app.library.resetLibrary();
|
2020-10-30 21:01:41 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("import library via drag&drop", async () => {
|
2021-04-21 23:38:24 +05:30
|
|
|
expect(await h.app.library.loadLibrary()).toEqual([]);
|
2020-10-30 21:01:41 +01:00
|
|
|
await API.drop(
|
|
|
|
await API.loadFile("./fixtures/fixture_library.excalidrawlib"),
|
|
|
|
);
|
|
|
|
await waitFor(async () => {
|
2021-04-21 23:38:24 +05:30
|
|
|
expect(await h.app.library.loadLibrary()).toEqual([
|
2020-10-30 21:01:41 +01:00
|
|
|
[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" })]);
|
|
|
|
});
|
|
|
|
});
|
2021-06-28 06:00:33 -04:00
|
|
|
|
|
|
|
it("inserting library item should revert to selection tool", async () => {
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
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" })]);
|
|
|
|
});
|
|
|
|
expect(h.state.elementType).toBe("selection");
|
|
|
|
});
|
2020-10-30 21:01:41 +01:00
|
|
|
});
|