summaryrefslogtreecommitdiffstats
path: root/packages/utils/utils.unmocked.test.ts
diff options
context:
space:
mode:
authorkj_sh6042026-03-15 16:19:35 -0400
committerkj_sh6042026-03-15 16:19:35 -0400
commit6ec259a0e71174651bae95d4628138bf6fd68742 (patch)
tree5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/utils/utils.unmocked.test.ts
parent16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff)
refactor: packages/
Diffstat (limited to 'packages/utils/utils.unmocked.test.ts')
-rw-r--r--packages/utils/utils.unmocked.test.ts68
1 files changed, 68 insertions, 0 deletions
diff --git a/packages/utils/utils.unmocked.test.ts b/packages/utils/utils.unmocked.test.ts
new file mode 100644
index 0000000..341adef
--- /dev/null
+++ b/packages/utils/utils.unmocked.test.ts
@@ -0,0 +1,68 @@
+import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
+import * as utils from "./index";
+import { API } from "@excalidraw/excalidraw/tests/helpers/api";
+import { decodeSvgBase64Payload } from "@excalidraw/excalidraw/scene/export";
+import { decodePngMetadata } from "@excalidraw/excalidraw/data/image";
+
+// NOTE this test file is using the actual API, unmocked. Hence splitting it
+// from the other test file, because I couldn't figure out how to test
+// mocked and unmocked API in the same file.
+
+describe("embedding scene data", () => {
+ describe("exportToSvg", () => {
+ it("embedding scene data shouldn't modify them", async () => {
+ const rectangle = API.createElement({ type: "rectangle" });
+ const ellipse = API.createElement({ type: "ellipse" });
+
+ const sourceElements = [rectangle, ellipse];
+
+ const svgNode = await utils.exportToSvg({
+ elements: sourceElements,
+ appState: {
+ viewBackgroundColor: "#ffffff",
+ gridModeEnabled: false,
+ exportEmbedScene: true,
+ },
+ files: null,
+ });
+
+ const svg = svgNode.outerHTML;
+
+ const parsedString = decodeSvgBase64Payload({ svg });
+ const importedData: ImportedDataState = JSON.parse(parsedString);
+
+ expect(sourceElements.map((x) => x.id)).toEqual(
+ importedData.elements?.map((el) => el.id),
+ );
+ });
+ });
+
+ // skipped because we can't test png encoding right now
+ // (canvas.toBlob not supported in jsdom)
+ describe.skip("exportToBlob", () => {
+ it("embedding scene data shouldn't modify them", async () => {
+ const rectangle = API.createElement({ type: "rectangle" });
+ const ellipse = API.createElement({ type: "ellipse" });
+
+ const sourceElements = [rectangle, ellipse];
+
+ const blob = await utils.exportToBlob({
+ mimeType: "image/png",
+ elements: sourceElements,
+ appState: {
+ viewBackgroundColor: "#ffffff",
+ gridModeEnabled: false,
+ exportEmbedScene: true,
+ },
+ files: null,
+ });
+
+ const parsedString = await decodePngMetadata(blob);
+ const importedData: ImportedDataState = JSON.parse(parsedString);
+
+ expect(sourceElements.map((x) => x.id)).toEqual(
+ importedData.elements?.map((el) => el.id),
+ );
+ });
+ });
+});