@yh-ui/flow 0.1.56 → 1.0.4
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/dist/__tests__/bpmn-engine.test.cjs +357 -0
- package/dist/__tests__/bpmn-engine.test.d.ts +1 -0
- package/dist/__tests__/bpmn-engine.test.mjs +406 -0
- package/dist/__tests__/bpmn-utils.test.cjs +268 -0
- package/dist/__tests__/bpmn-utils.test.d.ts +1 -0
- package/dist/__tests__/bpmn-utils.test.mjs +227 -0
- package/dist/__tests__/bpmn-xml.test.cjs +150 -0
- package/dist/__tests__/bpmn-xml.test.d.ts +1 -0
- package/dist/__tests__/bpmn-xml.test.mjs +112 -0
- package/dist/__tests__/collaboration.test.cjs +487 -0
- package/dist/__tests__/collaboration.test.d.ts +1 -0
- package/dist/__tests__/collaboration.test.mjs +424 -0
- package/dist/__tests__/edge-types.test.cjs +275 -0
- package/dist/__tests__/edge-types.test.d.ts +1 -0
- package/dist/__tests__/edge-types.test.mjs +234 -0
- package/dist/__tests__/edge-utils.test.cjs +375 -0
- package/dist/__tests__/edge-utils.test.d.ts +1 -0
- package/dist/__tests__/edge-utils.test.mjs +376 -0
- package/dist/__tests__/events-types.test.cjs +184 -0
- package/dist/__tests__/events-types.test.d.ts +1 -0
- package/dist/__tests__/events-types.test.mjs +184 -0
- package/dist/__tests__/export-image-plugin.test.cjs +142 -0
- package/dist/__tests__/export-image-plugin.test.d.ts +1 -0
- package/dist/__tests__/export-image-plugin.test.mjs +118 -0
- package/dist/__tests__/export.test.cjs +237 -0
- package/dist/__tests__/export.test.d.ts +1 -0
- package/dist/__tests__/export.test.mjs +171 -0
- package/dist/__tests__/flow-context.test.cjs +16 -0
- package/dist/__tests__/flow-context.test.d.ts +1 -0
- package/dist/__tests__/flow-context.test.mjs +16 -0
- package/dist/__tests__/flow-props.test.cjs +94 -0
- package/dist/__tests__/flow-props.test.d.ts +1 -0
- package/dist/__tests__/flow-props.test.mjs +92 -0
- package/dist/__tests__/layout-plugin.test.cjs +233 -0
- package/dist/__tests__/layout-plugin.test.d.ts +1 -0
- package/dist/__tests__/layout-plugin.test.mjs +215 -0
- package/dist/__tests__/node-types.test.cjs +368 -0
- package/dist/__tests__/node-types.test.d.ts +1 -0
- package/dist/__tests__/node-types.test.mjs +292 -0
- package/dist/__tests__/performance.test.cjs +313 -0
- package/dist/__tests__/performance.test.d.ts +1 -0
- package/dist/__tests__/performance.test.mjs +218 -0
- package/dist/__tests__/plugin-advanced.test.cjs +301 -0
- package/dist/__tests__/plugin-advanced.test.d.ts +1 -0
- package/dist/__tests__/plugin-advanced.test.mjs +225 -0
- package/dist/__tests__/plugins.test.cjs +412 -0
- package/dist/__tests__/plugins.test.d.ts +1 -0
- package/dist/__tests__/plugins.test.mjs +402 -0
- package/dist/__tests__/screenshot-capture.test.cjs +183 -0
- package/dist/__tests__/screenshot-capture.test.d.ts +1 -0
- package/dist/__tests__/screenshot-capture.test.mjs +124 -0
- package/dist/__tests__/screenshot.test.cjs +74 -0
- package/dist/__tests__/screenshot.test.d.ts +1 -0
- package/dist/__tests__/screenshot.test.mjs +69 -0
- package/dist/__tests__/theme.test.cjs +185 -0
- package/dist/__tests__/theme.test.d.ts +1 -0
- package/dist/__tests__/theme.test.mjs +191 -0
- package/dist/__tests__/transform.test.cjs +376 -50
- package/dist/__tests__/transform.test.mjs +229 -28
- package/dist/__tests__/useAlignment.test.cjs +37 -0
- package/dist/__tests__/useAlignment.test.mjs +20 -0
- package/dist/__tests__/useNodeDistribution.test.cjs +643 -0
- package/dist/__tests__/useNodeDistribution.test.d.ts +1 -0
- package/dist/__tests__/useNodeDistribution.test.mjs +297 -0
- package/dist/__tests__/viewport-types.test.cjs +324 -0
- package/dist/__tests__/viewport-types.test.d.ts +1 -0
- package/dist/__tests__/viewport-types.test.mjs +207 -0
- package/dist/utils/bpmn.cjs +27 -16
- package/dist/utils/bpmn.mjs +27 -19
- package/package.json +3 -3
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
isEdge,
|
|
4
|
+
isEdgeType
|
|
5
|
+
} from "../types/edge.mjs";
|
|
6
|
+
describe("flow/types/edge", () => {
|
|
7
|
+
describe("EdgeType", () => {
|
|
8
|
+
it("should accept valid edge types", () => {
|
|
9
|
+
const types = ["smoothstep", "step", "bezier", "straight", "default"];
|
|
10
|
+
types.forEach((type) => {
|
|
11
|
+
expect(isEdgeType(type)).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("should reject invalid edge types", () => {
|
|
15
|
+
expect(isEdgeType("invalid")).toBe(false);
|
|
16
|
+
expect(isEdgeType("")).toBe(false);
|
|
17
|
+
expect(isEdgeType("smooth")).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe("Connection", () => {
|
|
21
|
+
it("should define connection with source and target", () => {
|
|
22
|
+
const conn = {
|
|
23
|
+
source: "node-1",
|
|
24
|
+
target: "node-2"
|
|
25
|
+
};
|
|
26
|
+
expect(conn.source).toBe("node-1");
|
|
27
|
+
expect(conn.target).toBe("node-2");
|
|
28
|
+
});
|
|
29
|
+
it("should support optional handles", () => {
|
|
30
|
+
const conn = {
|
|
31
|
+
source: "node-1",
|
|
32
|
+
target: "node-2",
|
|
33
|
+
sourceHandle: "handle-top",
|
|
34
|
+
targetHandle: null
|
|
35
|
+
};
|
|
36
|
+
expect(conn.sourceHandle).toBe("handle-top");
|
|
37
|
+
expect(conn.targetHandle).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("EdgeStyle", () => {
|
|
41
|
+
it("should allow style properties", () => {
|
|
42
|
+
const style = {
|
|
43
|
+
stroke: "#409eff",
|
|
44
|
+
strokeWidth: 2,
|
|
45
|
+
strokeDasharray: "5,5"
|
|
46
|
+
};
|
|
47
|
+
expect(style.stroke).toBe("#409eff");
|
|
48
|
+
expect(style.strokeWidth).toBe(2);
|
|
49
|
+
expect(style.strokeDasharray).toBe("5,5");
|
|
50
|
+
});
|
|
51
|
+
it("should support custom properties", () => {
|
|
52
|
+
const style = {
|
|
53
|
+
stroke: "#fff",
|
|
54
|
+
customProp: "value"
|
|
55
|
+
};
|
|
56
|
+
expect(style.customProp).toBe("value");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("EdgeData", () => {
|
|
60
|
+
it("should define edge data with label and style", () => {
|
|
61
|
+
const data = {
|
|
62
|
+
label: "Edge Label",
|
|
63
|
+
type: "bezier",
|
|
64
|
+
animated: true,
|
|
65
|
+
style: { stroke: "#000" }
|
|
66
|
+
};
|
|
67
|
+
expect(data.label).toBe("Edge Label");
|
|
68
|
+
expect(data.type).toBe("bezier");
|
|
69
|
+
expect(data.animated).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
it("should support label styling options", () => {
|
|
72
|
+
const data = {
|
|
73
|
+
label: "Test",
|
|
74
|
+
labelStyle: { color: "#fff" },
|
|
75
|
+
labelShowBg: true,
|
|
76
|
+
labelBgColor: "#000",
|
|
77
|
+
labelBgPadding: [4, 4],
|
|
78
|
+
labelBgBorderRadius: 4
|
|
79
|
+
};
|
|
80
|
+
expect(data.labelShowBg).toBe(true);
|
|
81
|
+
expect(data.labelBgColor).toBe("#000");
|
|
82
|
+
expect(data.labelBgPadding).toEqual([4, 4]);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("Edge", () => {
|
|
86
|
+
it("should create basic edge", () => {
|
|
87
|
+
const edge = {
|
|
88
|
+
id: "edge-1",
|
|
89
|
+
source: "node-1",
|
|
90
|
+
target: "node-2"
|
|
91
|
+
};
|
|
92
|
+
expect(edge.id).toBe("edge-1");
|
|
93
|
+
expect(edge.source).toBe("node-1");
|
|
94
|
+
expect(edge.target).toBe("node-2");
|
|
95
|
+
});
|
|
96
|
+
it("should support optional edge properties", () => {
|
|
97
|
+
const edge = {
|
|
98
|
+
id: "edge-1",
|
|
99
|
+
source: "node-1",
|
|
100
|
+
target: "node-2",
|
|
101
|
+
type: "smoothstep",
|
|
102
|
+
animated: true,
|
|
103
|
+
label: "Flow",
|
|
104
|
+
selectable: true,
|
|
105
|
+
deletable: true,
|
|
106
|
+
hidden: false,
|
|
107
|
+
selected: false,
|
|
108
|
+
zIndex: 1
|
|
109
|
+
};
|
|
110
|
+
expect(edge.type).toBe("smoothstep");
|
|
111
|
+
expect(edge.animated).toBe(true);
|
|
112
|
+
expect(edge.label).toBe("Flow");
|
|
113
|
+
});
|
|
114
|
+
it("should support marker definitions", () => {
|
|
115
|
+
const edge = {
|
|
116
|
+
id: "edge-1",
|
|
117
|
+
source: "node-1",
|
|
118
|
+
target: "node-2",
|
|
119
|
+
markerEnd: "arrow",
|
|
120
|
+
markerStart: { type: "arrow", color: "#000", width: 12, height: 12 }
|
|
121
|
+
};
|
|
122
|
+
expect(edge.markerEnd).toBe("arrow");
|
|
123
|
+
expect(edge.markerStart).toEqual({ type: "arrow", color: "#000", width: 12, height: 12 });
|
|
124
|
+
});
|
|
125
|
+
it("should support updatable configuration", () => {
|
|
126
|
+
const edgeSource = {
|
|
127
|
+
id: "edge-1",
|
|
128
|
+
source: "node-1",
|
|
129
|
+
target: "node-2",
|
|
130
|
+
updatable: "source"
|
|
131
|
+
};
|
|
132
|
+
const edgeTarget = {
|
|
133
|
+
id: "edge-2",
|
|
134
|
+
source: "node-2",
|
|
135
|
+
target: "node-3",
|
|
136
|
+
updatable: "target"
|
|
137
|
+
};
|
|
138
|
+
const edgeBoth = {
|
|
139
|
+
id: "edge-3",
|
|
140
|
+
source: "node-3",
|
|
141
|
+
target: "node-4",
|
|
142
|
+
updatable: true
|
|
143
|
+
};
|
|
144
|
+
const edgeFixed = {
|
|
145
|
+
id: "edge-4",
|
|
146
|
+
source: "node-4",
|
|
147
|
+
target: "node-5",
|
|
148
|
+
updatable: false
|
|
149
|
+
};
|
|
150
|
+
expect(edgeSource.updatable).toBe("source");
|
|
151
|
+
expect(edgeTarget.updatable).toBe("target");
|
|
152
|
+
expect(edgeBoth.updatable).toBe(true);
|
|
153
|
+
expect(edgeFixed.updatable).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe("EdgeChangeType", () => {
|
|
157
|
+
it("should define all change types", () => {
|
|
158
|
+
const types = ["select", "remove", "style", "data", "selectMulti", "unselect"];
|
|
159
|
+
expect(types).toContain("select");
|
|
160
|
+
expect(types).toContain("remove");
|
|
161
|
+
expect(types).toContain("style");
|
|
162
|
+
expect(types).toContain("data");
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe("EdgeChange", () => {
|
|
166
|
+
it("should create edge change object", () => {
|
|
167
|
+
const edge = { id: "edge-1", source: "n1", target: "n2" };
|
|
168
|
+
const change = {
|
|
169
|
+
type: "select",
|
|
170
|
+
id: "edge-1",
|
|
171
|
+
item: edge,
|
|
172
|
+
selected: true
|
|
173
|
+
};
|
|
174
|
+
expect(change.type).toBe("select");
|
|
175
|
+
expect(change.selected).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
it("should support style change", () => {
|
|
178
|
+
const edge = { id: "edge-1", source: "n1", target: "n2" };
|
|
179
|
+
const change = {
|
|
180
|
+
type: "style",
|
|
181
|
+
id: "edge-1",
|
|
182
|
+
item: edge,
|
|
183
|
+
style: { stroke: "#f00", strokeWidth: 3 }
|
|
184
|
+
};
|
|
185
|
+
expect(change.style?.stroke).toBe("#f00");
|
|
186
|
+
});
|
|
187
|
+
it("should support data change", () => {
|
|
188
|
+
const edge = { id: "edge-1", source: "n1", target: "n2" };
|
|
189
|
+
const change = {
|
|
190
|
+
type: "data",
|
|
191
|
+
id: "edge-1",
|
|
192
|
+
item: edge,
|
|
193
|
+
data: { label: "Updated", animated: true }
|
|
194
|
+
};
|
|
195
|
+
expect(change.data?.label).toBe("Updated");
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe("isEdge", () => {
|
|
199
|
+
it("should return true for valid edge objects", () => {
|
|
200
|
+
const edge = { id: "e1", source: "n1", target: "n2" };
|
|
201
|
+
expect(isEdge(edge)).toBe(true);
|
|
202
|
+
});
|
|
203
|
+
it("should return true for edge with optional properties", () => {
|
|
204
|
+
const edge = {
|
|
205
|
+
id: "e1",
|
|
206
|
+
source: "n1",
|
|
207
|
+
target: "n2",
|
|
208
|
+
type: "bezier",
|
|
209
|
+
label: "Test"
|
|
210
|
+
};
|
|
211
|
+
expect(isEdge(edge)).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
it("should return false for null", () => {
|
|
214
|
+
expect(isEdge(null)).toBe(false);
|
|
215
|
+
});
|
|
216
|
+
it("should return false for undefined", () => {
|
|
217
|
+
expect(isEdge(void 0)).toBe(false);
|
|
218
|
+
});
|
|
219
|
+
it("should return false for object missing source", () => {
|
|
220
|
+
expect(isEdge({ id: "e1", target: "n2" })).toBe(false);
|
|
221
|
+
});
|
|
222
|
+
it("should return false for object missing target", () => {
|
|
223
|
+
expect(isEdge({ id: "e1", source: "n1" })).toBe(false);
|
|
224
|
+
});
|
|
225
|
+
it("should return false for primitive values", () => {
|
|
226
|
+
expect(isEdge("edge")).toBe(false);
|
|
227
|
+
expect(isEdge(123)).toBe(false);
|
|
228
|
+
expect(isEdge(true)).toBe(false);
|
|
229
|
+
});
|
|
230
|
+
it("should return false for arrays", () => {
|
|
231
|
+
expect(isEdge([])).toBe(false);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
});
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _edge = require("../utils/edge.cjs");
|
|
5
|
+
function createMockNode(x, y, width = 150, height = 80, style) {
|
|
6
|
+
return {
|
|
7
|
+
id: "test",
|
|
8
|
+
type: "default",
|
|
9
|
+
position: {
|
|
10
|
+
x,
|
|
11
|
+
y
|
|
12
|
+
},
|
|
13
|
+
width,
|
|
14
|
+
height,
|
|
15
|
+
style,
|
|
16
|
+
data: {},
|
|
17
|
+
selected: false,
|
|
18
|
+
dragging: false
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
(0, _vitest.describe)("flow/utils/edge", () => {
|
|
22
|
+
(0, _vitest.describe)("getHandlePosition", () => {
|
|
23
|
+
(0, _vitest.it)("should return center for unknown position", () => {
|
|
24
|
+
const node = createMockNode(0, 0, 100, 50);
|
|
25
|
+
const result = (0, _edge.getHandlePosition)(node, "unknown");
|
|
26
|
+
(0, _vitest.expect)(result.x).toBe(50);
|
|
27
|
+
(0, _vitest.expect)(result.y).toBe(25);
|
|
28
|
+
});
|
|
29
|
+
(0, _vitest.it)("should return top handle position", () => {
|
|
30
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
31
|
+
const result = (0, _edge.getHandlePosition)(node, "top");
|
|
32
|
+
(0, _vitest.expect)(result.x).toBe(60);
|
|
33
|
+
(0, _vitest.expect)(result.y).toBe(20);
|
|
34
|
+
});
|
|
35
|
+
(0, _vitest.it)("should return bottom handle position", () => {
|
|
36
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
37
|
+
const result = (0, _edge.getHandlePosition)(node, "bottom");
|
|
38
|
+
(0, _vitest.expect)(result.x).toBe(60);
|
|
39
|
+
(0, _vitest.expect)(result.y).toBe(70);
|
|
40
|
+
});
|
|
41
|
+
(0, _vitest.it)("should return left handle position", () => {
|
|
42
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
43
|
+
const result = (0, _edge.getHandlePosition)(node, "left");
|
|
44
|
+
(0, _vitest.expect)(result.x).toBe(10);
|
|
45
|
+
(0, _vitest.expect)(result.y).toBe(45);
|
|
46
|
+
});
|
|
47
|
+
(0, _vitest.it)("should return right handle position", () => {
|
|
48
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
49
|
+
const result = (0, _edge.getHandlePosition)(node, "right");
|
|
50
|
+
(0, _vitest.expect)(result.x).toBe(110);
|
|
51
|
+
(0, _vitest.expect)(result.y).toBe(45);
|
|
52
|
+
});
|
|
53
|
+
(0, _vitest.it)("should fallback to default dimensions when width/height are undefined", () => {
|
|
54
|
+
const node = {
|
|
55
|
+
position: {
|
|
56
|
+
x: 0,
|
|
57
|
+
y: 0
|
|
58
|
+
},
|
|
59
|
+
data: {},
|
|
60
|
+
selected: false,
|
|
61
|
+
dragging: false
|
|
62
|
+
};
|
|
63
|
+
const result = (0, _edge.getHandlePosition)(node, "right");
|
|
64
|
+
(0, _vitest.expect)(result.x).toBe(150);
|
|
65
|
+
(0, _vitest.expect)(result.y).toBe(20);
|
|
66
|
+
});
|
|
67
|
+
(0, _vitest.it)("should use right as default position", () => {
|
|
68
|
+
const node = createMockNode(0, 0, 100, 50);
|
|
69
|
+
const result = (0, _edge.getHandlePosition)(node);
|
|
70
|
+
(0, _vitest.expect)(result.x).toBe(100);
|
|
71
|
+
(0, _vitest.expect)(result.y).toBe(25);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
(0, _vitest.describe)("getBezierPath", () => {
|
|
75
|
+
(0, _vitest.it)("should generate bezier path", () => {
|
|
76
|
+
const result = (0, _edge.getBezierPath)({
|
|
77
|
+
sourceX: 0,
|
|
78
|
+
sourceY: 0,
|
|
79
|
+
targetX: 100,
|
|
80
|
+
targetY: 50,
|
|
81
|
+
sourcePosition: "right",
|
|
82
|
+
targetPosition: "left"
|
|
83
|
+
});
|
|
84
|
+
(0, _vitest.expect)(result).toContain("M0,0");
|
|
85
|
+
(0, _vitest.expect)(result).toContain("100,50");
|
|
86
|
+
(0, _vitest.expect)(result).toContain("C");
|
|
87
|
+
});
|
|
88
|
+
(0, _vitest.it)("should use custom curvature", () => {
|
|
89
|
+
const result = (0, _edge.getBezierPath)({
|
|
90
|
+
sourceX: 0,
|
|
91
|
+
sourceY: 0,
|
|
92
|
+
targetX: 100,
|
|
93
|
+
targetY: 50,
|
|
94
|
+
sourcePosition: "right",
|
|
95
|
+
targetPosition: "left",
|
|
96
|
+
curvature: 0.5
|
|
97
|
+
});
|
|
98
|
+
(0, _vitest.expect)(result).toContain("M0,0");
|
|
99
|
+
(0, _vitest.expect)(result).toContain("100,50");
|
|
100
|
+
});
|
|
101
|
+
(0, _vitest.it)("should handle vertical movement", () => {
|
|
102
|
+
const result = (0, _edge.getBezierPath)({
|
|
103
|
+
sourceX: 50,
|
|
104
|
+
sourceY: 0,
|
|
105
|
+
targetX: 50,
|
|
106
|
+
targetY: 100,
|
|
107
|
+
sourcePosition: "bottom",
|
|
108
|
+
targetPosition: "top"
|
|
109
|
+
});
|
|
110
|
+
(0, _vitest.expect)(result).toContain("M50,0");
|
|
111
|
+
(0, _vitest.expect)(result).toContain("50,100");
|
|
112
|
+
});
|
|
113
|
+
(0, _vitest.it)("should handle top to bottom direction", () => {
|
|
114
|
+
const result = (0, _edge.getBezierPath)({
|
|
115
|
+
sourceX: 50,
|
|
116
|
+
sourceY: 0,
|
|
117
|
+
targetX: 50,
|
|
118
|
+
targetY: 100,
|
|
119
|
+
sourcePosition: "top",
|
|
120
|
+
targetPosition: "bottom"
|
|
121
|
+
});
|
|
122
|
+
(0, _vitest.expect)(result).toContain("M50,0");
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
(0, _vitest.describe)("getStraightPath", () => {
|
|
126
|
+
(0, _vitest.it)("should generate straight line path", () => {
|
|
127
|
+
const result = (0, _edge.getStraightPath)({
|
|
128
|
+
sourceX: 0,
|
|
129
|
+
sourceY: 0,
|
|
130
|
+
targetX: 100,
|
|
131
|
+
targetY: 50,
|
|
132
|
+
sourcePosition: "right",
|
|
133
|
+
targetPosition: "left"
|
|
134
|
+
});
|
|
135
|
+
(0, _vitest.expect)(result).toBe("M0,0 L100,50");
|
|
136
|
+
});
|
|
137
|
+
(0, _vitest.it)("should handle diagonal line", () => {
|
|
138
|
+
const result = (0, _edge.getStraightPath)({
|
|
139
|
+
sourceX: 10,
|
|
140
|
+
sourceY: 20,
|
|
141
|
+
targetX: 300,
|
|
142
|
+
targetY: 400,
|
|
143
|
+
sourcePosition: "right",
|
|
144
|
+
targetPosition: "left"
|
|
145
|
+
});
|
|
146
|
+
(0, _vitest.expect)(result).toBe("M10,20 L300,400");
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
(0, _vitest.describe)("getStepPath", () => {
|
|
150
|
+
(0, _vitest.it)("should generate step path when source is horizontal and target is vertical", () => {
|
|
151
|
+
const result = (0, _edge.getStepPath)({
|
|
152
|
+
sourceX: 0,
|
|
153
|
+
sourceY: 0,
|
|
154
|
+
targetX: 100,
|
|
155
|
+
targetY: 50,
|
|
156
|
+
sourcePosition: "right",
|
|
157
|
+
targetPosition: "top"
|
|
158
|
+
});
|
|
159
|
+
(0, _vitest.expect)(result).toContain("M0,0");
|
|
160
|
+
(0, _vitest.expect)(result).toContain("L");
|
|
161
|
+
(0, _vitest.expect)(result).toContain("100,50");
|
|
162
|
+
});
|
|
163
|
+
(0, _vitest.it)("should generate step path when source is vertical and target is horizontal", () => {
|
|
164
|
+
const result = (0, _edge.getStepPath)({
|
|
165
|
+
sourceX: 0,
|
|
166
|
+
sourceY: 0,
|
|
167
|
+
targetX: 100,
|
|
168
|
+
targetY: 50,
|
|
169
|
+
sourcePosition: "top",
|
|
170
|
+
targetPosition: "right"
|
|
171
|
+
});
|
|
172
|
+
(0, _vitest.expect)(result).toContain("M0,0");
|
|
173
|
+
(0, _vitest.expect)(result).toContain("L");
|
|
174
|
+
});
|
|
175
|
+
(0, _vitest.it)("should handle both horizontal", () => {
|
|
176
|
+
const result = (0, _edge.getStepPath)({
|
|
177
|
+
sourceX: 0,
|
|
178
|
+
sourceY: 50,
|
|
179
|
+
targetX: 100,
|
|
180
|
+
targetY: 50,
|
|
181
|
+
sourcePosition: "right",
|
|
182
|
+
targetPosition: "left"
|
|
183
|
+
});
|
|
184
|
+
(0, _vitest.expect)(result).toContain("M0,50");
|
|
185
|
+
(0, _vitest.expect)(result).toContain("L");
|
|
186
|
+
});
|
|
187
|
+
(0, _vitest.it)("should handle both vertical", () => {
|
|
188
|
+
const result = (0, _edge.getStepPath)({
|
|
189
|
+
sourceX: 50,
|
|
190
|
+
sourceY: 0,
|
|
191
|
+
targetX: 50,
|
|
192
|
+
targetY: 100,
|
|
193
|
+
sourcePosition: "bottom",
|
|
194
|
+
targetPosition: "top"
|
|
195
|
+
});
|
|
196
|
+
(0, _vitest.expect)(result).toContain("M50,0");
|
|
197
|
+
(0, _vitest.expect)(result).toContain("L");
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
(0, _vitest.describe)("getSmoothStepPath", () => {
|
|
201
|
+
(0, _vitest.it)("should generate smooth step path for horizontal source", () => {
|
|
202
|
+
const result = (0, _edge.getSmoothStepPath)({
|
|
203
|
+
sourceX: 0,
|
|
204
|
+
sourceY: 0,
|
|
205
|
+
targetX: 100,
|
|
206
|
+
targetY: 50,
|
|
207
|
+
sourcePosition: "right",
|
|
208
|
+
targetPosition: "top"
|
|
209
|
+
});
|
|
210
|
+
(0, _vitest.expect)(result).toContain("M0,0");
|
|
211
|
+
(0, _vitest.expect)(result).toContain("Q");
|
|
212
|
+
(0, _vitest.expect)(result).toContain("100,50");
|
|
213
|
+
});
|
|
214
|
+
(0, _vitest.it)("should generate smooth step path for vertical source", () => {
|
|
215
|
+
const result = (0, _edge.getSmoothStepPath)({
|
|
216
|
+
sourceX: 0,
|
|
217
|
+
sourceY: 0,
|
|
218
|
+
targetX: 100,
|
|
219
|
+
targetY: 50,
|
|
220
|
+
sourcePosition: "bottom",
|
|
221
|
+
targetPosition: "right"
|
|
222
|
+
});
|
|
223
|
+
(0, _vitest.expect)(result).toContain("M0,0");
|
|
224
|
+
(0, _vitest.expect)(result).toContain("Q");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
(0, _vitest.describe)("getEdgePath", () => {
|
|
228
|
+
(0, _vitest.it)("should return bezier path for bezier type", () => {
|
|
229
|
+
const result = (0, _edge.getEdgePath)("bezier", {
|
|
230
|
+
sourceX: 0,
|
|
231
|
+
sourceY: 0,
|
|
232
|
+
targetX: 100,
|
|
233
|
+
targetY: 50,
|
|
234
|
+
sourcePosition: "right",
|
|
235
|
+
targetPosition: "left"
|
|
236
|
+
});
|
|
237
|
+
(0, _vitest.expect)(result).toContain("C");
|
|
238
|
+
});
|
|
239
|
+
(0, _vitest.it)("should return straight path for straight type", () => {
|
|
240
|
+
const result = (0, _edge.getEdgePath)("straight", {
|
|
241
|
+
sourceX: 0,
|
|
242
|
+
sourceY: 0,
|
|
243
|
+
targetX: 100,
|
|
244
|
+
targetY: 50,
|
|
245
|
+
sourcePosition: "right",
|
|
246
|
+
targetPosition: "left"
|
|
247
|
+
});
|
|
248
|
+
(0, _vitest.expect)(result).toBe("M0,0 L100,50");
|
|
249
|
+
});
|
|
250
|
+
(0, _vitest.it)("should return step path for step type", () => {
|
|
251
|
+
const result = (0, _edge.getEdgePath)("step", {
|
|
252
|
+
sourceX: 0,
|
|
253
|
+
sourceY: 0,
|
|
254
|
+
targetX: 100,
|
|
255
|
+
targetY: 50,
|
|
256
|
+
sourcePosition: "right",
|
|
257
|
+
targetPosition: "top"
|
|
258
|
+
});
|
|
259
|
+
(0, _vitest.expect)(result).toContain("L");
|
|
260
|
+
});
|
|
261
|
+
(0, _vitest.it)("should return smooth step path for smoothstep type", () => {
|
|
262
|
+
const result = (0, _edge.getEdgePath)("smoothstep", {
|
|
263
|
+
sourceX: 0,
|
|
264
|
+
sourceY: 0,
|
|
265
|
+
targetX: 100,
|
|
266
|
+
targetY: 50,
|
|
267
|
+
sourcePosition: "right",
|
|
268
|
+
targetPosition: "top"
|
|
269
|
+
});
|
|
270
|
+
(0, _vitest.expect)(result).toContain("Q");
|
|
271
|
+
});
|
|
272
|
+
(0, _vitest.it)("should default to bezier for unknown type", () => {
|
|
273
|
+
const result = (0, _edge.getEdgePath)("unknown", {
|
|
274
|
+
sourceX: 0,
|
|
275
|
+
sourceY: 0,
|
|
276
|
+
targetX: 100,
|
|
277
|
+
targetY: 50,
|
|
278
|
+
sourcePosition: "right",
|
|
279
|
+
targetPosition: "left"
|
|
280
|
+
});
|
|
281
|
+
(0, _vitest.expect)(result).toContain("C");
|
|
282
|
+
});
|
|
283
|
+
(0, _vitest.it)("should default to bezier for default type", () => {
|
|
284
|
+
const result = (0, _edge.getEdgePath)("default", {
|
|
285
|
+
sourceX: 0,
|
|
286
|
+
sourceY: 0,
|
|
287
|
+
targetX: 100,
|
|
288
|
+
targetY: 50,
|
|
289
|
+
sourcePosition: "right",
|
|
290
|
+
targetPosition: "left"
|
|
291
|
+
});
|
|
292
|
+
(0, _vitest.expect)(result).toContain("C");
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
(0, _vitest.describe)("getEdgeCenter", () => {
|
|
296
|
+
(0, _vitest.it)("should return center for bezier type", () => {
|
|
297
|
+
const result = (0, _edge.getEdgeCenter)({
|
|
298
|
+
sourceX: 0,
|
|
299
|
+
sourceY: 0,
|
|
300
|
+
targetX: 100,
|
|
301
|
+
targetY: 50,
|
|
302
|
+
sourcePosition: "right",
|
|
303
|
+
targetPosition: "left",
|
|
304
|
+
type: "bezier"
|
|
305
|
+
});
|
|
306
|
+
(0, _vitest.expect)(result).toHaveProperty("x");
|
|
307
|
+
(0, _vitest.expect)(result).toHaveProperty("y");
|
|
308
|
+
(0, _vitest.expect)(result).toHaveProperty("ox");
|
|
309
|
+
(0, _vitest.expect)(result).toHaveProperty("oy");
|
|
310
|
+
});
|
|
311
|
+
(0, _vitest.it)("should return center for straight type", () => {
|
|
312
|
+
const result = (0, _edge.getEdgeCenter)({
|
|
313
|
+
sourceX: 0,
|
|
314
|
+
sourceY: 0,
|
|
315
|
+
targetX: 100,
|
|
316
|
+
targetY: 50,
|
|
317
|
+
sourcePosition: "right",
|
|
318
|
+
targetPosition: "left",
|
|
319
|
+
type: "straight"
|
|
320
|
+
});
|
|
321
|
+
(0, _vitest.expect)(result.x).toBe(50);
|
|
322
|
+
(0, _vitest.expect)(result.y).toBe(25);
|
|
323
|
+
});
|
|
324
|
+
(0, _vitest.it)("should return center for step type", () => {
|
|
325
|
+
const result = (0, _edge.getEdgeCenter)({
|
|
326
|
+
sourceX: 0,
|
|
327
|
+
sourceY: 0,
|
|
328
|
+
targetX: 100,
|
|
329
|
+
targetY: 50,
|
|
330
|
+
sourcePosition: "right",
|
|
331
|
+
targetPosition: "left",
|
|
332
|
+
type: "step"
|
|
333
|
+
});
|
|
334
|
+
(0, _vitest.expect)(result.x).toBe(50);
|
|
335
|
+
(0, _vitest.expect)(result.y).toBe(25);
|
|
336
|
+
});
|
|
337
|
+
(0, _vitest.it)("should default to bezier when type is undefined", () => {
|
|
338
|
+
const result = (0, _edge.getEdgeCenter)({
|
|
339
|
+
sourceX: 0,
|
|
340
|
+
sourceY: 0,
|
|
341
|
+
targetX: 100,
|
|
342
|
+
targetY: 50,
|
|
343
|
+
sourcePosition: "right",
|
|
344
|
+
targetPosition: "left"
|
|
345
|
+
});
|
|
346
|
+
(0, _vitest.expect)(result).toHaveProperty("x");
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
(0, _vitest.describe)("shortenEndpoint", () => {
|
|
350
|
+
(0, _vitest.it)("should shorten endpoint in the direction of source", () => {
|
|
351
|
+
const result = (0, _edge.shortenEndpoint)(100, 50, 0, 0, 10);
|
|
352
|
+
(0, _vitest.expect)(result.x).toBeLessThan(100);
|
|
353
|
+
(0, _vitest.expect)(result.y).toBeLessThan(50);
|
|
354
|
+
});
|
|
355
|
+
(0, _vitest.it)("should not shorten when distance is too small", () => {
|
|
356
|
+
const result = (0, _edge.shortenEndpoint)(5, 5, 0, 0, 10);
|
|
357
|
+
(0, _vitest.expect)(result.x).toBe(5);
|
|
358
|
+
(0, _vitest.expect)(result.y).toBe(5);
|
|
359
|
+
});
|
|
360
|
+
(0, _vitest.it)("should shorten towards source", () => {
|
|
361
|
+
const result = (0, _edge.shortenEndpoint)(200, 100, 100, 50, 10);
|
|
362
|
+
const dx = 200 - 100;
|
|
363
|
+
const dy = 100 - 50;
|
|
364
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
365
|
+
const factor = 10 / dist;
|
|
366
|
+
(0, _vitest.expect)(result.x).toBeCloseTo(200 - dx * factor, 5);
|
|
367
|
+
(0, _vitest.expect)(result.y).toBeCloseTo(100 - dy * factor, 5);
|
|
368
|
+
});
|
|
369
|
+
(0, _vitest.it)("should handle vertical movement", () => {
|
|
370
|
+
const result = (0, _edge.shortenEndpoint)(50, 100, 50, 0, 10);
|
|
371
|
+
(0, _vitest.expect)(result.x).toBe(50);
|
|
372
|
+
(0, _vitest.expect)(result.y).toBeCloseTo(90, 0);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|