appState.test.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { render, waitFor } from "./test-utils";
  2. import ExcalidrawApp from "../excalidraw-app";
  3. import { API } from "./helpers/api";
  4. import { getDefaultAppState } from "../appState";
  5. import { EXPORT_DATA_TYPES } from "../constants";
  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. await render(<ExcalidrawApp />, {
  12. localStorageData: {
  13. appState: {
  14. exportBackground,
  15. viewBackgroundColor: "#F00",
  16. },
  17. },
  18. });
  19. await waitFor(() => {
  20. expect(h.state.exportBackground).toBe(exportBackground);
  21. expect(h.state.viewBackgroundColor).toBe("#F00");
  22. });
  23. API.drop(
  24. new Blob(
  25. [
  26. JSON.stringify({
  27. type: EXPORT_DATA_TYPES.excalidraw,
  28. appState: {
  29. viewBackgroundColor: "#000",
  30. },
  31. elements: [API.createElement({ type: "rectangle", id: "A" })],
  32. }),
  33. ],
  34. { type: "application/json" },
  35. ),
  36. );
  37. await waitFor(() => {
  38. expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]);
  39. // non-imported prop → retain
  40. expect(h.state.exportBackground).toBe(exportBackground);
  41. // imported prop → overwrite
  42. expect(h.state.viewBackgroundColor).toBe("#000");
  43. });
  44. });
  45. });