2020-10-13 13:46:52 +02:00
|
|
|
import { render, waitFor } from "./test-utils";
|
2020-12-05 20:00:53 +05:30
|
|
|
import ExcalidrawApp from "../excalidraw-app";
|
2020-10-13 13:46:52 +02:00
|
|
|
import { API } from "./helpers/api";
|
|
|
|
import { getDefaultAppState } from "../appState";
|
2021-10-21 22:05:48 +02:00
|
|
|
import { EXPORT_DATA_TYPES, MIME_TYPES } from "../constants";
|
2020-10-13 13:46:52 +02:00
|
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
|
|
|
describe("appState", () => {
|
|
|
|
it("drag&drop file doesn't reset non-persisted appState", async () => {
|
|
|
|
const defaultAppState = getDefaultAppState();
|
|
|
|
const exportBackground = !defaultAppState.exportBackground;
|
2020-12-05 20:00:53 +05:30
|
|
|
|
|
|
|
await render(<ExcalidrawApp />, {
|
|
|
|
localStorageData: {
|
|
|
|
appState: {
|
|
|
|
exportBackground,
|
|
|
|
viewBackgroundColor: "#F00",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-10-13 13:46:52 +02:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(h.state.exportBackground).toBe(exportBackground);
|
|
|
|
expect(h.state.viewBackgroundColor).toBe("#F00");
|
|
|
|
});
|
|
|
|
|
2020-10-30 21:01:41 +01:00
|
|
|
API.drop(
|
|
|
|
new Blob(
|
|
|
|
[
|
|
|
|
JSON.stringify({
|
2021-03-20 20:20:47 +01:00
|
|
|
type: EXPORT_DATA_TYPES.excalidraw,
|
2020-10-30 21:01:41 +01:00
|
|
|
appState: {
|
|
|
|
viewBackgroundColor: "#000",
|
|
|
|
},
|
|
|
|
elements: [API.createElement({ type: "rectangle", id: "A" })],
|
|
|
|
}),
|
|
|
|
],
|
2021-10-21 22:05:48 +02:00
|
|
|
{ type: MIME_TYPES.json },
|
2020-10-30 21:01:41 +01:00
|
|
|
),
|
|
|
|
);
|
2020-10-13 13:46:52 +02:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]);
|
|
|
|
// non-imported prop → retain
|
|
|
|
expect(h.state.exportBackground).toBe(exportBackground);
|
|
|
|
// imported prop → overwrite
|
|
|
|
expect(h.state.viewBackgroundColor).toBe("#000");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|