-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'excalidraw:master' into fix/45/flowchart_rendering_issues
- Loading branch information
Showing
6 changed files
with
901 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../tsconfig.common.json", | ||
"compilerOptions": { | ||
"types": ["vitest/globals"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { | ||
getTransformAttr, | ||
entityCodesToText, | ||
computeEdgePositions, | ||
} from "../src/utils.js"; | ||
|
||
describe("Test Utils", () => { | ||
describe("Test entityCodesToText", () => { | ||
it("should convert entity codes to text", () => { | ||
expect(entityCodesToText("#9829;")).toBe("♥"); | ||
expect(entityCodesToText("#6672;")).toBe("ᨐ"); | ||
}); | ||
}); | ||
|
||
describe("Test getTransformAttr", () => { | ||
let el: HTMLDivElement; | ||
|
||
beforeEach(() => { | ||
el = document.createElement("div"); | ||
}); | ||
|
||
it("should return the correct transformX and transformY when transform attrubute is present", () => { | ||
el.setAttribute("transform", "translate(100, 200)"); | ||
const { transformX, transformY } = getTransformAttr(el); | ||
expect(transformX).toBe(100); | ||
expect(transformY).toBe(200); | ||
}); | ||
|
||
it("should return 0 for transformX and transformY if no transform attribute is set", () => { | ||
const { transformX, transformY } = getTransformAttr(el); | ||
expect(transformX).toBe(0); | ||
expect(transformY).toBe(0); | ||
}); | ||
}); | ||
|
||
describe("Test computeEdgePositions", () => { | ||
let pathElement: SVGPathElement; | ||
|
||
beforeEach(() => { | ||
pathElement = document.createElementNS( | ||
"http://www.w3.org/2000/svg", | ||
"path" | ||
); | ||
}); | ||
|
||
it("should throw an error if the element is not a path", () => { | ||
const divElement = document.createElement("div"); | ||
//@ts-expect-error | ||
expect(() => computeEdgePositions(divElement)).toThrowError( | ||
'Invalid input: Expected an HTMLElement of tag "path", got DIV' | ||
); | ||
}); | ||
|
||
it("should throw an error if the path element does not contain a 'd' attribute", () => { | ||
expect(() => computeEdgePositions(pathElement)).toThrowError( | ||
'Path element does not contain a "d" attribute' | ||
); | ||
}); | ||
|
||
it("should return the correct startX, startY, endX, endY, and reflectionPoints", () => { | ||
pathElement.setAttribute("d", "M29.383,38.5L29.383,63.5L29.383,83.2"); | ||
const { startX, startY, endX, endY, reflectionPoints } = | ||
computeEdgePositions(pathElement); | ||
expect(startX).toBe(29.383); | ||
expect(startY).toBe(38.5); | ||
expect(endX).toBe(29.383); | ||
expect(endY).toBe(83.2); | ||
expect(reflectionPoints).toEqual([ | ||
{ x: 29.383, y: 38.5 }, | ||
{ x: 29.383, y: 83.2 }, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{ | ||
"files": [], | ||
"references": [{ "path": "./src" }, { "path": "./playground" }] | ||
"references": [ | ||
{ "path": "./src" }, | ||
{ "path": "./playground" }, | ||
{ "path": "./tests" } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: "jsdom", | ||
coverage: { | ||
reporter: ["text", "json-summary", "json", "html", "lcovonly"], | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.