@yh-ui/flow 1.0.1 → 1.0.5
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,376 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
getHandlePosition,
|
|
4
|
+
getBezierPath,
|
|
5
|
+
getStraightPath,
|
|
6
|
+
getStepPath,
|
|
7
|
+
getSmoothStepPath,
|
|
8
|
+
getEdgePath,
|
|
9
|
+
getEdgeCenter,
|
|
10
|
+
shortenEndpoint
|
|
11
|
+
} from "../utils/edge.mjs";
|
|
12
|
+
function createMockNode(x, y, width = 150, height = 80, style) {
|
|
13
|
+
return {
|
|
14
|
+
id: "test",
|
|
15
|
+
type: "default",
|
|
16
|
+
position: { x, y },
|
|
17
|
+
width,
|
|
18
|
+
height,
|
|
19
|
+
style,
|
|
20
|
+
data: {},
|
|
21
|
+
selected: false,
|
|
22
|
+
dragging: false
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
describe("flow/utils/edge", () => {
|
|
26
|
+
describe("getHandlePosition", () => {
|
|
27
|
+
it("should return center for unknown position", () => {
|
|
28
|
+
const node = createMockNode(0, 0, 100, 50);
|
|
29
|
+
const result = getHandlePosition(node, "unknown");
|
|
30
|
+
expect(result.x).toBe(50);
|
|
31
|
+
expect(result.y).toBe(25);
|
|
32
|
+
});
|
|
33
|
+
it("should return top handle position", () => {
|
|
34
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
35
|
+
const result = getHandlePosition(node, "top");
|
|
36
|
+
expect(result.x).toBe(60);
|
|
37
|
+
expect(result.y).toBe(20);
|
|
38
|
+
});
|
|
39
|
+
it("should return bottom handle position", () => {
|
|
40
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
41
|
+
const result = getHandlePosition(node, "bottom");
|
|
42
|
+
expect(result.x).toBe(60);
|
|
43
|
+
expect(result.y).toBe(70);
|
|
44
|
+
});
|
|
45
|
+
it("should return left handle position", () => {
|
|
46
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
47
|
+
const result = getHandlePosition(node, "left");
|
|
48
|
+
expect(result.x).toBe(10);
|
|
49
|
+
expect(result.y).toBe(45);
|
|
50
|
+
});
|
|
51
|
+
it("should return right handle position", () => {
|
|
52
|
+
const node = createMockNode(10, 20, 100, 50);
|
|
53
|
+
const result = getHandlePosition(node, "right");
|
|
54
|
+
expect(result.x).toBe(110);
|
|
55
|
+
expect(result.y).toBe(45);
|
|
56
|
+
});
|
|
57
|
+
it("should fallback to default dimensions when width/height are undefined", () => {
|
|
58
|
+
const node = {
|
|
59
|
+
position: { x: 0, y: 0 },
|
|
60
|
+
data: {},
|
|
61
|
+
selected: false,
|
|
62
|
+
dragging: false
|
|
63
|
+
};
|
|
64
|
+
const result = getHandlePosition(node, "right");
|
|
65
|
+
expect(result.x).toBe(150);
|
|
66
|
+
expect(result.y).toBe(20);
|
|
67
|
+
});
|
|
68
|
+
it("should use right as default position", () => {
|
|
69
|
+
const node = createMockNode(0, 0, 100, 50);
|
|
70
|
+
const result = getHandlePosition(node);
|
|
71
|
+
expect(result.x).toBe(100);
|
|
72
|
+
expect(result.y).toBe(25);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe("getBezierPath", () => {
|
|
76
|
+
it("should generate bezier path", () => {
|
|
77
|
+
const result = getBezierPath({
|
|
78
|
+
sourceX: 0,
|
|
79
|
+
sourceY: 0,
|
|
80
|
+
targetX: 100,
|
|
81
|
+
targetY: 50,
|
|
82
|
+
sourcePosition: "right",
|
|
83
|
+
targetPosition: "left"
|
|
84
|
+
});
|
|
85
|
+
expect(result).toContain("M0,0");
|
|
86
|
+
expect(result).toContain("100,50");
|
|
87
|
+
expect(result).toContain("C");
|
|
88
|
+
});
|
|
89
|
+
it("should use custom curvature", () => {
|
|
90
|
+
const result = getBezierPath({
|
|
91
|
+
sourceX: 0,
|
|
92
|
+
sourceY: 0,
|
|
93
|
+
targetX: 100,
|
|
94
|
+
targetY: 50,
|
|
95
|
+
sourcePosition: "right",
|
|
96
|
+
targetPosition: "left",
|
|
97
|
+
curvature: 0.5
|
|
98
|
+
});
|
|
99
|
+
expect(result).toContain("M0,0");
|
|
100
|
+
expect(result).toContain("100,50");
|
|
101
|
+
});
|
|
102
|
+
it("should handle vertical movement", () => {
|
|
103
|
+
const result = getBezierPath({
|
|
104
|
+
sourceX: 50,
|
|
105
|
+
sourceY: 0,
|
|
106
|
+
targetX: 50,
|
|
107
|
+
targetY: 100,
|
|
108
|
+
sourcePosition: "bottom",
|
|
109
|
+
targetPosition: "top"
|
|
110
|
+
});
|
|
111
|
+
expect(result).toContain("M50,0");
|
|
112
|
+
expect(result).toContain("50,100");
|
|
113
|
+
});
|
|
114
|
+
it("should handle top to bottom direction", () => {
|
|
115
|
+
const result = getBezierPath({
|
|
116
|
+
sourceX: 50,
|
|
117
|
+
sourceY: 0,
|
|
118
|
+
targetX: 50,
|
|
119
|
+
targetY: 100,
|
|
120
|
+
sourcePosition: "top",
|
|
121
|
+
targetPosition: "bottom"
|
|
122
|
+
});
|
|
123
|
+
expect(result).toContain("M50,0");
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe("getStraightPath", () => {
|
|
127
|
+
it("should generate straight line path", () => {
|
|
128
|
+
const result = getStraightPath({
|
|
129
|
+
sourceX: 0,
|
|
130
|
+
sourceY: 0,
|
|
131
|
+
targetX: 100,
|
|
132
|
+
targetY: 50,
|
|
133
|
+
sourcePosition: "right",
|
|
134
|
+
targetPosition: "left"
|
|
135
|
+
});
|
|
136
|
+
expect(result).toBe("M0,0 L100,50");
|
|
137
|
+
});
|
|
138
|
+
it("should handle diagonal line", () => {
|
|
139
|
+
const result = getStraightPath({
|
|
140
|
+
sourceX: 10,
|
|
141
|
+
sourceY: 20,
|
|
142
|
+
targetX: 300,
|
|
143
|
+
targetY: 400,
|
|
144
|
+
sourcePosition: "right",
|
|
145
|
+
targetPosition: "left"
|
|
146
|
+
});
|
|
147
|
+
expect(result).toBe("M10,20 L300,400");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe("getStepPath", () => {
|
|
151
|
+
it("should generate step path when source is horizontal and target is vertical", () => {
|
|
152
|
+
const result = getStepPath({
|
|
153
|
+
sourceX: 0,
|
|
154
|
+
sourceY: 0,
|
|
155
|
+
targetX: 100,
|
|
156
|
+
targetY: 50,
|
|
157
|
+
sourcePosition: "right",
|
|
158
|
+
targetPosition: "top"
|
|
159
|
+
});
|
|
160
|
+
expect(result).toContain("M0,0");
|
|
161
|
+
expect(result).toContain("L");
|
|
162
|
+
expect(result).toContain("100,50");
|
|
163
|
+
});
|
|
164
|
+
it("should generate step path when source is vertical and target is horizontal", () => {
|
|
165
|
+
const result = getStepPath({
|
|
166
|
+
sourceX: 0,
|
|
167
|
+
sourceY: 0,
|
|
168
|
+
targetX: 100,
|
|
169
|
+
targetY: 50,
|
|
170
|
+
sourcePosition: "top",
|
|
171
|
+
targetPosition: "right"
|
|
172
|
+
});
|
|
173
|
+
expect(result).toContain("M0,0");
|
|
174
|
+
expect(result).toContain("L");
|
|
175
|
+
});
|
|
176
|
+
it("should handle both horizontal", () => {
|
|
177
|
+
const result = getStepPath({
|
|
178
|
+
sourceX: 0,
|
|
179
|
+
sourceY: 50,
|
|
180
|
+
targetX: 100,
|
|
181
|
+
targetY: 50,
|
|
182
|
+
sourcePosition: "right",
|
|
183
|
+
targetPosition: "left"
|
|
184
|
+
});
|
|
185
|
+
expect(result).toContain("M0,50");
|
|
186
|
+
expect(result).toContain("L");
|
|
187
|
+
});
|
|
188
|
+
it("should handle both vertical", () => {
|
|
189
|
+
const result = getStepPath({
|
|
190
|
+
sourceX: 50,
|
|
191
|
+
sourceY: 0,
|
|
192
|
+
targetX: 50,
|
|
193
|
+
targetY: 100,
|
|
194
|
+
sourcePosition: "bottom",
|
|
195
|
+
targetPosition: "top"
|
|
196
|
+
});
|
|
197
|
+
expect(result).toContain("M50,0");
|
|
198
|
+
expect(result).toContain("L");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
describe("getSmoothStepPath", () => {
|
|
202
|
+
it("should generate smooth step path for horizontal source", () => {
|
|
203
|
+
const result = getSmoothStepPath({
|
|
204
|
+
sourceX: 0,
|
|
205
|
+
sourceY: 0,
|
|
206
|
+
targetX: 100,
|
|
207
|
+
targetY: 50,
|
|
208
|
+
sourcePosition: "right",
|
|
209
|
+
targetPosition: "top"
|
|
210
|
+
});
|
|
211
|
+
expect(result).toContain("M0,0");
|
|
212
|
+
expect(result).toContain("Q");
|
|
213
|
+
expect(result).toContain("100,50");
|
|
214
|
+
});
|
|
215
|
+
it("should generate smooth step path for vertical source", () => {
|
|
216
|
+
const result = getSmoothStepPath({
|
|
217
|
+
sourceX: 0,
|
|
218
|
+
sourceY: 0,
|
|
219
|
+
targetX: 100,
|
|
220
|
+
targetY: 50,
|
|
221
|
+
sourcePosition: "bottom",
|
|
222
|
+
targetPosition: "right"
|
|
223
|
+
});
|
|
224
|
+
expect(result).toContain("M0,0");
|
|
225
|
+
expect(result).toContain("Q");
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
describe("getEdgePath", () => {
|
|
229
|
+
it("should return bezier path for bezier type", () => {
|
|
230
|
+
const result = getEdgePath("bezier", {
|
|
231
|
+
sourceX: 0,
|
|
232
|
+
sourceY: 0,
|
|
233
|
+
targetX: 100,
|
|
234
|
+
targetY: 50,
|
|
235
|
+
sourcePosition: "right",
|
|
236
|
+
targetPosition: "left"
|
|
237
|
+
});
|
|
238
|
+
expect(result).toContain("C");
|
|
239
|
+
});
|
|
240
|
+
it("should return straight path for straight type", () => {
|
|
241
|
+
const result = getEdgePath("straight", {
|
|
242
|
+
sourceX: 0,
|
|
243
|
+
sourceY: 0,
|
|
244
|
+
targetX: 100,
|
|
245
|
+
targetY: 50,
|
|
246
|
+
sourcePosition: "right",
|
|
247
|
+
targetPosition: "left"
|
|
248
|
+
});
|
|
249
|
+
expect(result).toBe("M0,0 L100,50");
|
|
250
|
+
});
|
|
251
|
+
it("should return step path for step type", () => {
|
|
252
|
+
const result = getEdgePath("step", {
|
|
253
|
+
sourceX: 0,
|
|
254
|
+
sourceY: 0,
|
|
255
|
+
targetX: 100,
|
|
256
|
+
targetY: 50,
|
|
257
|
+
sourcePosition: "right",
|
|
258
|
+
targetPosition: "top"
|
|
259
|
+
});
|
|
260
|
+
expect(result).toContain("L");
|
|
261
|
+
});
|
|
262
|
+
it("should return smooth step path for smoothstep type", () => {
|
|
263
|
+
const result = getEdgePath("smoothstep", {
|
|
264
|
+
sourceX: 0,
|
|
265
|
+
sourceY: 0,
|
|
266
|
+
targetX: 100,
|
|
267
|
+
targetY: 50,
|
|
268
|
+
sourcePosition: "right",
|
|
269
|
+
targetPosition: "top"
|
|
270
|
+
});
|
|
271
|
+
expect(result).toContain("Q");
|
|
272
|
+
});
|
|
273
|
+
it("should default to bezier for unknown type", () => {
|
|
274
|
+
const result = getEdgePath("unknown", {
|
|
275
|
+
sourceX: 0,
|
|
276
|
+
sourceY: 0,
|
|
277
|
+
targetX: 100,
|
|
278
|
+
targetY: 50,
|
|
279
|
+
sourcePosition: "right",
|
|
280
|
+
targetPosition: "left"
|
|
281
|
+
});
|
|
282
|
+
expect(result).toContain("C");
|
|
283
|
+
});
|
|
284
|
+
it("should default to bezier for default type", () => {
|
|
285
|
+
const result = getEdgePath("default", {
|
|
286
|
+
sourceX: 0,
|
|
287
|
+
sourceY: 0,
|
|
288
|
+
targetX: 100,
|
|
289
|
+
targetY: 50,
|
|
290
|
+
sourcePosition: "right",
|
|
291
|
+
targetPosition: "left"
|
|
292
|
+
});
|
|
293
|
+
expect(result).toContain("C");
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
describe("getEdgeCenter", () => {
|
|
297
|
+
it("should return center for bezier type", () => {
|
|
298
|
+
const result = getEdgeCenter({
|
|
299
|
+
sourceX: 0,
|
|
300
|
+
sourceY: 0,
|
|
301
|
+
targetX: 100,
|
|
302
|
+
targetY: 50,
|
|
303
|
+
sourcePosition: "right",
|
|
304
|
+
targetPosition: "left",
|
|
305
|
+
type: "bezier"
|
|
306
|
+
});
|
|
307
|
+
expect(result).toHaveProperty("x");
|
|
308
|
+
expect(result).toHaveProperty("y");
|
|
309
|
+
expect(result).toHaveProperty("ox");
|
|
310
|
+
expect(result).toHaveProperty("oy");
|
|
311
|
+
});
|
|
312
|
+
it("should return center for straight type", () => {
|
|
313
|
+
const result = getEdgeCenter({
|
|
314
|
+
sourceX: 0,
|
|
315
|
+
sourceY: 0,
|
|
316
|
+
targetX: 100,
|
|
317
|
+
targetY: 50,
|
|
318
|
+
sourcePosition: "right",
|
|
319
|
+
targetPosition: "left",
|
|
320
|
+
type: "straight"
|
|
321
|
+
});
|
|
322
|
+
expect(result.x).toBe(50);
|
|
323
|
+
expect(result.y).toBe(25);
|
|
324
|
+
});
|
|
325
|
+
it("should return center for step type", () => {
|
|
326
|
+
const result = getEdgeCenter({
|
|
327
|
+
sourceX: 0,
|
|
328
|
+
sourceY: 0,
|
|
329
|
+
targetX: 100,
|
|
330
|
+
targetY: 50,
|
|
331
|
+
sourcePosition: "right",
|
|
332
|
+
targetPosition: "left",
|
|
333
|
+
type: "step"
|
|
334
|
+
});
|
|
335
|
+
expect(result.x).toBe(50);
|
|
336
|
+
expect(result.y).toBe(25);
|
|
337
|
+
});
|
|
338
|
+
it("should default to bezier when type is undefined", () => {
|
|
339
|
+
const result = getEdgeCenter({
|
|
340
|
+
sourceX: 0,
|
|
341
|
+
sourceY: 0,
|
|
342
|
+
targetX: 100,
|
|
343
|
+
targetY: 50,
|
|
344
|
+
sourcePosition: "right",
|
|
345
|
+
targetPosition: "left"
|
|
346
|
+
});
|
|
347
|
+
expect(result).toHaveProperty("x");
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
describe("shortenEndpoint", () => {
|
|
351
|
+
it("should shorten endpoint in the direction of source", () => {
|
|
352
|
+
const result = shortenEndpoint(100, 50, 0, 0, 10);
|
|
353
|
+
expect(result.x).toBeLessThan(100);
|
|
354
|
+
expect(result.y).toBeLessThan(50);
|
|
355
|
+
});
|
|
356
|
+
it("should not shorten when distance is too small", () => {
|
|
357
|
+
const result = shortenEndpoint(5, 5, 0, 0, 10);
|
|
358
|
+
expect(result.x).toBe(5);
|
|
359
|
+
expect(result.y).toBe(5);
|
|
360
|
+
});
|
|
361
|
+
it("should shorten towards source", () => {
|
|
362
|
+
const result = shortenEndpoint(200, 100, 100, 50, 10);
|
|
363
|
+
const dx = 200 - 100;
|
|
364
|
+
const dy = 100 - 50;
|
|
365
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
366
|
+
const factor = 10 / dist;
|
|
367
|
+
expect(result.x).toBeCloseTo(200 - dx * factor, 5);
|
|
368
|
+
expect(result.y).toBeCloseTo(100 - dy * factor, 5);
|
|
369
|
+
});
|
|
370
|
+
it("should handle vertical movement", () => {
|
|
371
|
+
const result = shortenEndpoint(50, 100, 50, 0, 10);
|
|
372
|
+
expect(result.x).toBe(50);
|
|
373
|
+
expect(result.y).toBeCloseTo(90, 0);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
(0, _vitest.describe)("flow/types/events", () => {
|
|
5
|
+
(0, _vitest.describe)("FlowEventCallback", () => {
|
|
6
|
+
(0, _vitest.it)("should define callback type", () => {
|
|
7
|
+
const callback = event => {
|
|
8
|
+
(0, _vitest.expect)(event).toBeDefined();
|
|
9
|
+
};
|
|
10
|
+
(0, _vitest.expect)(typeof callback).toBe("function");
|
|
11
|
+
});
|
|
12
|
+
(0, _vitest.it)("should accept void event type", () => {
|
|
13
|
+
const callback = () => {};
|
|
14
|
+
(0, _vitest.expect)(typeof callback).toBe("function");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
(0, _vitest.describe)("FlowEventKey", () => {
|
|
18
|
+
(0, _vitest.it)("should define all event keys", () => {
|
|
19
|
+
const keys = ["node:click", "node:dblclick", "node:dragstart", "node:drag", "node:dragend", "node:selected", "node:unselected", "node:contextmenu", "edge:click", "edge:dblclick", "edge:selected", "edge:unselected", "edge:contextmenu", "edge:connect", "edge:update", "viewport:change", "selection:change", "selection:dragstart", "selection:drag", "selection:dragend", "pane:click", "pane:dblclick", "pane:contextmenu", "connect:start", "connect:end", "connect:cancel"];
|
|
20
|
+
(0, _vitest.expect)(keys.length).toBeGreaterThan(20);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
(0, _vitest.describe)("FlowEvents", () => {
|
|
24
|
+
(0, _vitest.it)("should define node click event", () => {
|
|
25
|
+
const event = {
|
|
26
|
+
node: {
|
|
27
|
+
id: "n1",
|
|
28
|
+
type: "default",
|
|
29
|
+
position: {
|
|
30
|
+
x: 0,
|
|
31
|
+
y: 0
|
|
32
|
+
},
|
|
33
|
+
data: {}
|
|
34
|
+
},
|
|
35
|
+
nativeEvent: new MouseEvent("click")
|
|
36
|
+
};
|
|
37
|
+
(0, _vitest.expect)(event.node.id).toBe("n1");
|
|
38
|
+
});
|
|
39
|
+
(0, _vitest.it)("should define node drag event", () => {
|
|
40
|
+
const event = {
|
|
41
|
+
node: {
|
|
42
|
+
id: "n1",
|
|
43
|
+
type: "default",
|
|
44
|
+
position: {
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0
|
|
47
|
+
},
|
|
48
|
+
data: {}
|
|
49
|
+
},
|
|
50
|
+
nativeEvent: new MouseEvent("mousedown"),
|
|
51
|
+
position: {
|
|
52
|
+
x: 100,
|
|
53
|
+
y: 200
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
(0, _vitest.expect)(event.position.x).toBe(100);
|
|
57
|
+
});
|
|
58
|
+
(0, _vitest.it)("should define edge connect event", () => {
|
|
59
|
+
const event = {
|
|
60
|
+
connection: {
|
|
61
|
+
source: "n1",
|
|
62
|
+
target: "n2",
|
|
63
|
+
sourceHandle: "right",
|
|
64
|
+
targetHandle: "left"
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
(0, _vitest.expect)(event.connection.source).toBe("n1");
|
|
68
|
+
(0, _vitest.expect)(event.connection.target).toBe("n2");
|
|
69
|
+
});
|
|
70
|
+
(0, _vitest.it)("should define viewport change event", () => {
|
|
71
|
+
const event = {
|
|
72
|
+
transform: {
|
|
73
|
+
x: 100,
|
|
74
|
+
y: 50,
|
|
75
|
+
zoom: 1.5
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
(0, _vitest.expect)(event.transform.zoom).toBe(1.5);
|
|
79
|
+
});
|
|
80
|
+
(0, _vitest.it)("should define selection change event", () => {
|
|
81
|
+
const event = {
|
|
82
|
+
selectedNodes: [{
|
|
83
|
+
id: "n1",
|
|
84
|
+
type: "default",
|
|
85
|
+
position: {
|
|
86
|
+
x: 0,
|
|
87
|
+
y: 0
|
|
88
|
+
},
|
|
89
|
+
data: {}
|
|
90
|
+
}],
|
|
91
|
+
selectedEdges: []
|
|
92
|
+
};
|
|
93
|
+
(0, _vitest.expect)(event.selectedNodes.length).toBe(1);
|
|
94
|
+
});
|
|
95
|
+
(0, _vitest.it)("should define pane click event", () => {
|
|
96
|
+
const event = {
|
|
97
|
+
nativeEvent: new MouseEvent("click")
|
|
98
|
+
};
|
|
99
|
+
(0, _vitest.expect)(event.nativeEvent).toBeDefined();
|
|
100
|
+
});
|
|
101
|
+
(0, _vitest.it)("should define connect start event", () => {
|
|
102
|
+
const event = {
|
|
103
|
+
connection: {
|
|
104
|
+
source: "n1",
|
|
105
|
+
target: "n2"
|
|
106
|
+
},
|
|
107
|
+
nativeEvent: new MouseEvent("mousedown")
|
|
108
|
+
};
|
|
109
|
+
(0, _vitest.expect)(event.connection).toBeDefined();
|
|
110
|
+
});
|
|
111
|
+
(0, _vitest.it)("should define connect cancel event", () => {
|
|
112
|
+
const event = void 0;
|
|
113
|
+
(0, _vitest.expect)(event).toBeUndefined();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
(0, _vitest.describe)("FlowEventHandler", () => {
|
|
117
|
+
(0, _vitest.it)("should define handler for node click", () => {
|
|
118
|
+
const handler = event => {
|
|
119
|
+
(0, _vitest.expect)(event.node.id).toBeDefined();
|
|
120
|
+
};
|
|
121
|
+
(0, _vitest.expect)(typeof handler).toBe("function");
|
|
122
|
+
});
|
|
123
|
+
(0, _vitest.it)("should define handler for void event", () => {
|
|
124
|
+
const handler = () => {};
|
|
125
|
+
(0, _vitest.expect)(typeof handler).toBe("function");
|
|
126
|
+
});
|
|
127
|
+
(0, _vitest.it)("should define handler for viewport change", () => {
|
|
128
|
+
const handler = event => {
|
|
129
|
+
(0, _vitest.expect)(event.transform).toBeDefined();
|
|
130
|
+
};
|
|
131
|
+
(0, _vitest.expect)(typeof handler).toBe("function");
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
(0, _vitest.describe)("EventBus", () => {
|
|
135
|
+
(0, _vitest.it)("should define EventBus interface", () => {
|
|
136
|
+
const bus = {
|
|
137
|
+
on: () => {},
|
|
138
|
+
off: () => {},
|
|
139
|
+
emit: () => {},
|
|
140
|
+
once: () => {},
|
|
141
|
+
clear: () => {}
|
|
142
|
+
};
|
|
143
|
+
(0, _vitest.expect)(typeof bus.on).toBe("function");
|
|
144
|
+
(0, _vitest.expect)(typeof bus.off).toBe("function");
|
|
145
|
+
(0, _vitest.expect)(typeof bus.emit).toBe("function");
|
|
146
|
+
(0, _vitest.expect)(typeof bus.once).toBe("function");
|
|
147
|
+
(0, _vitest.expect)(typeof bus.clear).toBe("function");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
(0, _vitest.describe)("SelectionRect", () => {
|
|
151
|
+
(0, _vitest.it)("should define selection rectangle", () => {
|
|
152
|
+
const rect = {
|
|
153
|
+
x: 100,
|
|
154
|
+
y: 200,
|
|
155
|
+
width: 300,
|
|
156
|
+
height: 150
|
|
157
|
+
};
|
|
158
|
+
(0, _vitest.expect)(rect.x).toBe(100);
|
|
159
|
+
(0, _vitest.expect)(rect.y).toBe(200);
|
|
160
|
+
(0, _vitest.expect)(rect.width).toBe(300);
|
|
161
|
+
(0, _vitest.expect)(rect.height).toBe(150);
|
|
162
|
+
});
|
|
163
|
+
(0, _vitest.it)("should allow negative coordinates", () => {
|
|
164
|
+
const rect = {
|
|
165
|
+
x: -50,
|
|
166
|
+
y: -100,
|
|
167
|
+
width: 200,
|
|
168
|
+
height: 100
|
|
169
|
+
};
|
|
170
|
+
(0, _vitest.expect)(rect.x).toBe(-50);
|
|
171
|
+
(0, _vitest.expect)(rect.y).toBe(-100);
|
|
172
|
+
});
|
|
173
|
+
(0, _vitest.it)("should allow zero dimensions", () => {
|
|
174
|
+
const rect = {
|
|
175
|
+
x: 0,
|
|
176
|
+
y: 0,
|
|
177
|
+
width: 0,
|
|
178
|
+
height: 0
|
|
179
|
+
};
|
|
180
|
+
(0, _vitest.expect)(rect.width).toBe(0);
|
|
181
|
+
(0, _vitest.expect)(rect.height).toBe(0);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|