library.test.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from "react";
  2. import { render, waitFor } from "./test-utils";
  3. import ExcalidrawApp from "../excalidraw-app";
  4. import { API } from "./helpers/api";
  5. import { MIME_TYPES } from "../constants";
  6. import { LibraryItem } from "../types";
  7. const { h } = window;
  8. describe("library", () => {
  9. beforeEach(async () => {
  10. await render(<ExcalidrawApp />);
  11. h.app.library.resetLibrary();
  12. });
  13. it("import library via drag&drop", async () => {
  14. expect(await h.app.library.loadLibrary()).toEqual([]);
  15. await API.drop(
  16. await API.loadFile("./fixtures/fixture_library.excalidrawlib"),
  17. );
  18. await waitFor(async () => {
  19. expect(await h.app.library.loadLibrary()).toEqual([
  20. [expect.objectContaining({ id: "A" })],
  21. ]);
  22. });
  23. });
  24. // NOTE: mocked to test logic, not actual drag&drop via UI
  25. it("drop library item onto canvas", async () => {
  26. expect(h.elements).toEqual([]);
  27. const libraryItems: LibraryItem = JSON.parse(
  28. await API.readFile("./fixtures/fixture_library.excalidrawlib", "utf8"),
  29. ).library[0];
  30. await API.drop(
  31. new Blob([JSON.stringify(libraryItems)], {
  32. type: MIME_TYPES.excalidrawlib,
  33. }),
  34. );
  35. await waitFor(() => {
  36. expect(h.elements).toEqual([expect.objectContaining({ id: "A_copy" })]);
  37. });
  38. });
  39. });