@node-projects/web-component-designer 0.1.351 → 0.1.352

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "A WYSIWYG designer webcomponent for html components",
3
3
  "name": "@node-projects/web-component-designer",
4
- "version": "0.1.351",
4
+ "version": "0.1.352",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -0,0 +1,49 @@
1
+ import { afterAll, beforeAll, expect, test } from '@jest/globals';
2
+
3
+ const svgElementGlobals = [
4
+ 'SVGPathElement',
5
+ 'SVGRectElement',
6
+ 'SVGCircleElement',
7
+ 'SVGEllipseElement',
8
+ 'SVGLineElement',
9
+ 'SVGPolylineElement',
10
+ 'SVGPolygonElement'
11
+ ] as const;
12
+
13
+ type SvgElementGlobalName = (typeof svgElementGlobals)[number];
14
+
15
+ let straightenLine: typeof import('../src/elements/helper/PathDataPolyfill').straightenLine;
16
+ const originalGlobals = new Map<SvgElementGlobalName, unknown>();
17
+
18
+ beforeAll(async () => {
19
+ for (const globalName of svgElementGlobals) {
20
+ originalGlobals.set(globalName, (<any>globalThis)[globalName]);
21
+ (<any>globalThis)[globalName] = class { };
22
+ }
23
+
24
+ ({ straightenLine } = await import('../src/elements/helper/PathDataPolyfill'));
25
+ });
26
+
27
+ afterAll(() => {
28
+ for (const globalName of svgElementGlobals) {
29
+ const originalGlobal = originalGlobals.get(globalName);
30
+ if (originalGlobal === undefined)
31
+ delete (<any>globalThis)[globalName];
32
+ else
33
+ (<any>globalThis)[globalName] = originalGlobal;
34
+ }
35
+ });
36
+
37
+ test('straightenLine keeps upward vertical snap upward', () => {
38
+ const result = straightenLine({ x: 10, y: 10 }, { x: 10, y: 0 }, 90);
39
+
40
+ expect(result.x).toBeCloseTo(10);
41
+ expect(result.y).toBeCloseTo(0);
42
+ });
43
+
44
+ test('straightenLine keeps downward vertical snap downward', () => {
45
+ const result = straightenLine({ x: 10, y: 10 }, { x: 10, y: 25 }, 90);
46
+
47
+ expect(result.x).toBeCloseTo(10);
48
+ expect(result.y).toBeCloseTo(25);
49
+ });