mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
test: Add unit tests for package/utils (#3357)
* Update return type to reflect actual signature * add tests * Set getDimensions as optional * add newlines between specs * remove redundant assertion * move fixtures to separate files * Add spacing * Move tests, add cases * Add unit tests for package/utils exportToSvg * extract default object in test * Move test suite to new file
This commit is contained in:
parent
bdf6e53289
commit
4ac1841d92
7 changed files with 437 additions and 2 deletions
31
src/tests/fixtures/diagramFixture.ts
vendored
Normal file
31
src/tests/fixtures/diagramFixture.ts
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
import {
|
||||
diamondFixture,
|
||||
ellipseFixture,
|
||||
rectangleFixture,
|
||||
} from "./elementFixture";
|
||||
|
||||
export const diagramFixture = {
|
||||
type: "excalidraw",
|
||||
version: 2,
|
||||
source: "https://excalidraw.com",
|
||||
elements: [diamondFixture, ellipseFixture, rectangleFixture],
|
||||
appState: {
|
||||
viewBackgroundColor: "#ffffff",
|
||||
gridSize: null,
|
||||
},
|
||||
};
|
||||
|
||||
export const diagramFactory = ({
|
||||
overrides = {},
|
||||
elementOverrides = {},
|
||||
} = {}) => ({
|
||||
...diagramFixture,
|
||||
elements: [
|
||||
{ ...diamondFixture, ...elementOverrides },
|
||||
{ ...ellipseFixture, ...elementOverrides },
|
||||
{ ...rectangleFixture, ...elementOverrides },
|
||||
],
|
||||
...overrides,
|
||||
});
|
||||
|
||||
export default diagramFixture;
|
37
src/tests/fixtures/elementFixture.ts
vendored
Normal file
37
src/tests/fixtures/elementFixture.ts
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { ExcalidrawElement } from "../../element/types";
|
||||
|
||||
const elementBase: Omit<ExcalidrawElement, "type"> = {
|
||||
id: "vWrqOAfkind2qcm7LDAGZ",
|
||||
x: 414,
|
||||
y: 237,
|
||||
width: 214,
|
||||
height: 214,
|
||||
angle: 0,
|
||||
strokeColor: "#000000",
|
||||
backgroundColor: "#15aabf",
|
||||
fillStyle: "hachure",
|
||||
strokeWidth: 1,
|
||||
strokeStyle: "solid",
|
||||
roughness: 1,
|
||||
opacity: 100,
|
||||
groupIds: [],
|
||||
strokeSharpness: "sharp",
|
||||
seed: 1041657908,
|
||||
version: 120,
|
||||
versionNonce: 1188004276,
|
||||
isDeleted: false,
|
||||
boundElementIds: null,
|
||||
};
|
||||
|
||||
export const rectangleFixture: ExcalidrawElement = {
|
||||
...elementBase,
|
||||
type: "rectangle",
|
||||
};
|
||||
export const ellipseFixture: ExcalidrawElement = {
|
||||
...elementBase,
|
||||
type: "ellipse",
|
||||
};
|
||||
export const diamondFixture: ExcalidrawElement = {
|
||||
...elementBase,
|
||||
type: "diamond",
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue