mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: support appState.exportEmbedScene to embed scene data in exportToSvg util (#3777)
* feat: add embedScene attribute to exportToSvg util * fix * return promise * add docs and remove * fix * fix tests * use * fix * fix * remove metadata and use exportEmbedScene * fix * fix * fix * fix * IIFE
This commit is contained in:
parent
62303b8a22
commit
f861a9fdd0
12 changed files with 128 additions and 79 deletions
|
@ -39,7 +39,6 @@ Object {
|
|||
"isResizing": false,
|
||||
"isRotating": false,
|
||||
"lastPointerDownWith": "mouse",
|
||||
"metadata": undefined,
|
||||
"multiElement": null,
|
||||
"name": "name",
|
||||
"openMenu": null,
|
||||
|
|
|
@ -73,11 +73,10 @@ describe("exportToSvg", () => {
|
|||
const mockedExportUtil = mockedSceneExportUtils.exportToSvg as jest.Mock;
|
||||
const passedElements = () => mockedExportUtil.mock.calls[0][0];
|
||||
const passedOptions = () => mockedExportUtil.mock.calls[0][1];
|
||||
|
||||
afterEach(jest.resetAllMocks);
|
||||
|
||||
it("with default arguments", () => {
|
||||
utils.exportToSvg({
|
||||
it("with default arguments", async () => {
|
||||
await utils.exportToSvg({
|
||||
...diagramFactory({
|
||||
overrides: { appState: void 0 },
|
||||
}),
|
||||
|
@ -88,13 +87,12 @@ describe("exportToSvg", () => {
|
|||
// To avoid varying snapshots
|
||||
name: "name",
|
||||
};
|
||||
|
||||
expect(passedElements().length).toBe(3);
|
||||
expect(passedOptionsWhenDefault).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("with deleted elements", () => {
|
||||
utils.exportToSvg({
|
||||
it("with deleted elements", async () => {
|
||||
await utils.exportToSvg({
|
||||
...diagramFactory({
|
||||
overrides: { appState: void 0 },
|
||||
elementOverrides: { isDeleted: true },
|
||||
|
@ -104,18 +102,28 @@ describe("exportToSvg", () => {
|
|||
expect(passedElements().length).toBe(0);
|
||||
});
|
||||
|
||||
it("with exportPadding and metadata", () => {
|
||||
const METADATA = "some metada";
|
||||
|
||||
utils.exportToSvg({
|
||||
it("with exportPadding", async () => {
|
||||
await utils.exportToSvg({
|
||||
...diagramFactory({ overrides: { appState: { name: "diagram name" } } }),
|
||||
exportPadding: 0,
|
||||
metadata: METADATA,
|
||||
});
|
||||
|
||||
expect(passedElements().length).toBe(3);
|
||||
expect(passedOptions()).toEqual(
|
||||
expect.objectContaining({ exportPadding: 0, metadata: METADATA }),
|
||||
expect.objectContaining({ exportPadding: 0 }),
|
||||
);
|
||||
});
|
||||
|
||||
it("with exportEmbedScene", async () => {
|
||||
await utils.exportToSvg({
|
||||
...diagramFactory({
|
||||
overrides: {
|
||||
appState: { name: "diagram name", exportEmbedScene: true },
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
expect(passedElements().length).toBe(3);
|
||||
expect(passedOptions().exportEmbedScene).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -15,16 +15,16 @@ describe("exportToSvg", () => {
|
|||
viewBackgroundColor: "#ffffff",
|
||||
};
|
||||
|
||||
it("with default arguments", () => {
|
||||
const svgElement = exportUtils.exportToSvg(ELEMENTS, DEFAULT_OPTIONS);
|
||||
it("with default arguments", async () => {
|
||||
const svgElement = await exportUtils.exportToSvg(ELEMENTS, DEFAULT_OPTIONS);
|
||||
|
||||
expect(svgElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("with background color", () => {
|
||||
it("with background color", async () => {
|
||||
const BACKGROUND_COLOR = "#abcdef";
|
||||
|
||||
const svgElement = exportUtils.exportToSvg(ELEMENTS, {
|
||||
const svgElement = await exportUtils.exportToSvg(ELEMENTS, {
|
||||
...DEFAULT_OPTIONS,
|
||||
exportBackground: true,
|
||||
viewBackgroundColor: BACKGROUND_COLOR,
|
||||
|
@ -36,8 +36,8 @@ describe("exportToSvg", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("with dark mode", () => {
|
||||
const svgElement = exportUtils.exportToSvg(ELEMENTS, {
|
||||
it("with dark mode", async () => {
|
||||
const svgElement = await exportUtils.exportToSvg(ELEMENTS, {
|
||||
...DEFAULT_OPTIONS,
|
||||
exportWithDarkMode: true,
|
||||
});
|
||||
|
@ -47,14 +47,12 @@ describe("exportToSvg", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("with exportPadding, metadata", () => {
|
||||
const svgElement = exportUtils.exportToSvg(ELEMENTS, {
|
||||
it("with exportPadding", async () => {
|
||||
const svgElement = await exportUtils.exportToSvg(ELEMENTS, {
|
||||
...DEFAULT_OPTIONS,
|
||||
exportPadding: 0,
|
||||
metadata: "some metadata",
|
||||
});
|
||||
|
||||
expect(svgElement.innerHTML).toMatch(/some metadata/);
|
||||
expect(svgElement).toHaveAttribute("height", ELEMENT_HEIGHT.toString());
|
||||
expect(svgElement).toHaveAttribute("width", ELEMENT_WIDTH.toString());
|
||||
expect(svgElement).toHaveAttribute(
|
||||
|
@ -63,10 +61,10 @@ describe("exportToSvg", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("with scale", () => {
|
||||
it("with scale", async () => {
|
||||
const SCALE = 2;
|
||||
|
||||
const svgElement = exportUtils.exportToSvg(ELEMENTS, {
|
||||
const svgElement = await exportUtils.exportToSvg(ELEMENTS, {
|
||||
...DEFAULT_OPTIONS,
|
||||
exportPadding: 0,
|
||||
exportScale: SCALE,
|
||||
|
@ -81,4 +79,12 @@ describe("exportToSvg", () => {
|
|||
(ELEMENT_WIDTH * SCALE).toString(),
|
||||
);
|
||||
});
|
||||
|
||||
it("with exportEmbedScene", async () => {
|
||||
const svgElement = await exportUtils.exportToSvg(ELEMENTS, {
|
||||
...DEFAULT_OPTIONS,
|
||||
exportEmbedScene: true,
|
||||
});
|
||||
expect(svgElement.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue