appState.test.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React from "react";
  2. import { render, waitFor } from "./test-utils";
  3. import App from "../components/App";
  4. import { API } from "./helpers/api";
  5. import { getDefaultAppState } from "../appState";
  6. const { h } = window;
  7. describe("appState", () => {
  8. it("drag&drop file doesn't reset non-persisted appState", async () => {
  9. const defaultAppState = getDefaultAppState();
  10. const exportBackground = !defaultAppState.exportBackground;
  11. render(
  12. <App
  13. initialData={{
  14. appState: {
  15. ...defaultAppState,
  16. exportBackground,
  17. viewBackgroundColor: "#F00",
  18. },
  19. elements: [],
  20. }}
  21. />,
  22. );
  23. await waitFor(() => {
  24. expect(h.state.exportBackground).toBe(exportBackground);
  25. expect(h.state.viewBackgroundColor).toBe("#F00");
  26. });
  27. API.drop(
  28. new Blob(
  29. [
  30. JSON.stringify({
  31. type: "excalidraw",
  32. appState: {
  33. viewBackgroundColor: "#000",
  34. },
  35. elements: [API.createElement({ type: "rectangle", id: "A" })],
  36. }),
  37. ],
  38. { type: "application/json" },
  39. ),
  40. );
  41. await waitFor(() => {
  42. expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]);
  43. // non-imported prop → retain
  44. expect(h.state.exportBackground).toBe(exportBackground);
  45. // imported prop → overwrite
  46. expect(h.state.viewBackgroundColor).toBe("#000");
  47. });
  48. });
  49. });