12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { decodePngMetadata, decodeSvgMetadata } from "../excalidraw/data/image";
- import type { ImportedDataState } from "../excalidraw/data/types";
- import * as utils from "../utils";
- import { API } from "../excalidraw/tests/helpers/api";
- // 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({
- data: {
- elements: sourceElements,
- appState: {
- viewBackgroundColor: "#ffffff",
- gridModeEnabled: false,
- exportEmbedScene: true,
- },
- files: null,
- },
- });
- const svg = svgNode.outerHTML;
- const parsedString = decodeSvgMetadata({ 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({
- data: {
- elements: sourceElements,
- appState: {
- viewBackgroundColor: "#ffffff",
- gridModeEnabled: false,
- exportEmbedScene: true,
- },
- files: null,
- },
- config: {
- mimeType: "image/png",
- },
- });
- const parsedString = await decodePngMetadata(blob);
- const importedData: ImportedDataState = JSON.parse(parsedString);
- expect(sourceElements.map((x) => x.id)).toEqual(
- importedData.elements?.map((el) => el.id),
- );
- });
- });
- });
|