@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,292 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
isNode
|
|
4
|
+
} from "../types/node.mjs";
|
|
5
|
+
describe("flow/types/node", () => {
|
|
6
|
+
describe("NodeHandle", () => {
|
|
7
|
+
it("should define handle with type and position", () => {
|
|
8
|
+
const handle = {
|
|
9
|
+
type: "source",
|
|
10
|
+
position: "right"
|
|
11
|
+
};
|
|
12
|
+
expect(handle.type).toBe("source");
|
|
13
|
+
expect(handle.position).toBe("right");
|
|
14
|
+
});
|
|
15
|
+
it("should support optional properties", () => {
|
|
16
|
+
const handle = {
|
|
17
|
+
type: "target",
|
|
18
|
+
position: "left",
|
|
19
|
+
id: "handle-1",
|
|
20
|
+
style: { background: "#fff" },
|
|
21
|
+
class: "custom-handle",
|
|
22
|
+
isConnectable: true
|
|
23
|
+
};
|
|
24
|
+
expect(handle.id).toBe("handle-1");
|
|
25
|
+
expect(handle.class).toBe("custom-handle");
|
|
26
|
+
expect(handle.isConnectable).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe("NodeStyle", () => {
|
|
30
|
+
it("should allow CSS-like properties", () => {
|
|
31
|
+
const style = {
|
|
32
|
+
background: "#f0f0f0",
|
|
33
|
+
border: "1px solid #ccc",
|
|
34
|
+
width: 200
|
|
35
|
+
};
|
|
36
|
+
expect(style.background).toBe("#f0f0f0");
|
|
37
|
+
expect(style.width).toBe(200);
|
|
38
|
+
});
|
|
39
|
+
it("should support undefined values", () => {
|
|
40
|
+
const style = {
|
|
41
|
+
background: "#fff",
|
|
42
|
+
border: void 0
|
|
43
|
+
};
|
|
44
|
+
expect(style.border).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe("NodeData", () => {
|
|
48
|
+
it("should define basic node data", () => {
|
|
49
|
+
const data = {
|
|
50
|
+
label: "Test Node"
|
|
51
|
+
};
|
|
52
|
+
expect(data.label).toBe("Test Node");
|
|
53
|
+
});
|
|
54
|
+
it("should support extended data fields", () => {
|
|
55
|
+
const data = {
|
|
56
|
+
label: "AI Node",
|
|
57
|
+
style: { background: "#e0f7fa" },
|
|
58
|
+
class: "ai-node",
|
|
59
|
+
icon: "robot",
|
|
60
|
+
description: "An AI processing node"
|
|
61
|
+
};
|
|
62
|
+
expect(data.icon).toBe("robot");
|
|
63
|
+
expect(data.description).toBe("An AI processing node");
|
|
64
|
+
});
|
|
65
|
+
it("should support AI workflow specific fields", () => {
|
|
66
|
+
const data = {
|
|
67
|
+
label: "LLM Node",
|
|
68
|
+
model: "gpt-4",
|
|
69
|
+
prompt: "You are a helpful assistant",
|
|
70
|
+
temperature: 0.7,
|
|
71
|
+
maxTokens: 2e3,
|
|
72
|
+
tools: ["search", "calculator"],
|
|
73
|
+
toolName: "web_search",
|
|
74
|
+
condition: 'status == "success"',
|
|
75
|
+
memoryType: "vector",
|
|
76
|
+
status: "running",
|
|
77
|
+
streamOutput: "partial"
|
|
78
|
+
};
|
|
79
|
+
expect(data.model).toBe("gpt-4");
|
|
80
|
+
expect(data.temperature).toBe(0.7);
|
|
81
|
+
expect(data.status).toBe("running");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe("NodePosition", () => {
|
|
85
|
+
it("should define position with x and y", () => {
|
|
86
|
+
const pos = { x: 100, y: 200 };
|
|
87
|
+
expect(pos.x).toBe(100);
|
|
88
|
+
expect(pos.y).toBe(200);
|
|
89
|
+
});
|
|
90
|
+
it("should support negative coordinates", () => {
|
|
91
|
+
const pos = { x: -50, y: -100 };
|
|
92
|
+
expect(pos.x).toBe(-50);
|
|
93
|
+
expect(pos.y).toBe(-100);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("NodeDimension", () => {
|
|
97
|
+
it("should define width and height", () => {
|
|
98
|
+
const dim = { width: 150, height: 80 };
|
|
99
|
+
expect(dim.width).toBe(150);
|
|
100
|
+
expect(dim.height).toBe(80);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe("NodeHandleBounds", () => {
|
|
104
|
+
it("should define handle bounds", () => {
|
|
105
|
+
const bounds = {
|
|
106
|
+
top: [{ type: "source", position: "top" }],
|
|
107
|
+
right: [{ type: "target", position: "right" }]
|
|
108
|
+
};
|
|
109
|
+
expect(bounds.top).toHaveLength(1);
|
|
110
|
+
expect(bounds.right).toHaveLength(1);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe("Node", () => {
|
|
114
|
+
it("should create basic node", () => {
|
|
115
|
+
const node = {
|
|
116
|
+
id: "node-1",
|
|
117
|
+
type: "default",
|
|
118
|
+
position: { x: 0, y: 0 },
|
|
119
|
+
data: { label: "Basic Node" }
|
|
120
|
+
};
|
|
121
|
+
expect(node.id).toBe("node-1");
|
|
122
|
+
expect(node.type).toBe("default");
|
|
123
|
+
});
|
|
124
|
+
it("should support all optional properties", () => {
|
|
125
|
+
const node = {
|
|
126
|
+
id: "node-1",
|
|
127
|
+
type: "custom",
|
|
128
|
+
position: { x: 100, y: 200 },
|
|
129
|
+
data: { label: "Test" },
|
|
130
|
+
style: { background: "#fff" },
|
|
131
|
+
class: "custom-node",
|
|
132
|
+
draggable: true,
|
|
133
|
+
selectable: true,
|
|
134
|
+
connectable: true,
|
|
135
|
+
resizable: true,
|
|
136
|
+
deletable: true,
|
|
137
|
+
hidden: false,
|
|
138
|
+
selected: false,
|
|
139
|
+
dragging: false,
|
|
140
|
+
width: 200,
|
|
141
|
+
height: 100,
|
|
142
|
+
parentId: "parent-1",
|
|
143
|
+
zIndex: 1,
|
|
144
|
+
extent: "parent",
|
|
145
|
+
expandParent: true,
|
|
146
|
+
positionAbsolute: { x: 150, y: 250 },
|
|
147
|
+
handleBounds: {
|
|
148
|
+
top: [{ type: "source", position: "top" }],
|
|
149
|
+
right: [{ type: "target", position: "right" }]
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
expect(node.draggable).toBe(true);
|
|
153
|
+
expect(node.width).toBe(200);
|
|
154
|
+
expect(node.parentId).toBe("parent-1");
|
|
155
|
+
});
|
|
156
|
+
it("should support nested children", () => {
|
|
157
|
+
const node = {
|
|
158
|
+
id: "parent",
|
|
159
|
+
type: "group",
|
|
160
|
+
position: { x: 0, y: 0 },
|
|
161
|
+
data: { label: "Parent" },
|
|
162
|
+
children: ["child-1", "child-2"],
|
|
163
|
+
computed: true
|
|
164
|
+
};
|
|
165
|
+
expect(node.children).toEqual(["child-1", "child-2"]);
|
|
166
|
+
expect(node.computed).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe("NodeChangeType", () => {
|
|
170
|
+
it("should define all change types", () => {
|
|
171
|
+
const types = [
|
|
172
|
+
"select",
|
|
173
|
+
"position",
|
|
174
|
+
"remove",
|
|
175
|
+
"dimensions",
|
|
176
|
+
"style",
|
|
177
|
+
"data",
|
|
178
|
+
"selectMulti",
|
|
179
|
+
"unselect"
|
|
180
|
+
];
|
|
181
|
+
expect(types).toContain("select");
|
|
182
|
+
expect(types).toContain("position");
|
|
183
|
+
expect(types).toContain("remove");
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
describe("NodeChange", () => {
|
|
187
|
+
it("should create select change", () => {
|
|
188
|
+
const node = {
|
|
189
|
+
id: "node-1",
|
|
190
|
+
type: "default",
|
|
191
|
+
position: { x: 0, y: 0 },
|
|
192
|
+
data: {}
|
|
193
|
+
};
|
|
194
|
+
const change = {
|
|
195
|
+
type: "select",
|
|
196
|
+
id: "node-1",
|
|
197
|
+
item: node,
|
|
198
|
+
selected: true
|
|
199
|
+
};
|
|
200
|
+
expect(change.type).toBe("select");
|
|
201
|
+
expect(change.selected).toBe(true);
|
|
202
|
+
});
|
|
203
|
+
it("should create position change", () => {
|
|
204
|
+
const node = {
|
|
205
|
+
id: "node-1",
|
|
206
|
+
type: "default",
|
|
207
|
+
position: { x: 0, y: 0 },
|
|
208
|
+
data: {}
|
|
209
|
+
};
|
|
210
|
+
const change = {
|
|
211
|
+
type: "position",
|
|
212
|
+
id: "node-1",
|
|
213
|
+
item: node,
|
|
214
|
+
position: { x: 100, y: 200 }
|
|
215
|
+
};
|
|
216
|
+
expect(change.position?.x).toBe(100);
|
|
217
|
+
expect(change.position?.y).toBe(200);
|
|
218
|
+
});
|
|
219
|
+
it("should create dimensions change", () => {
|
|
220
|
+
const node = {
|
|
221
|
+
id: "node-1",
|
|
222
|
+
type: "default",
|
|
223
|
+
position: { x: 0, y: 0 },
|
|
224
|
+
data: {}
|
|
225
|
+
};
|
|
226
|
+
const change = {
|
|
227
|
+
type: "dimensions",
|
|
228
|
+
id: "node-1",
|
|
229
|
+
item: node,
|
|
230
|
+
dimensions: { width: 200, height: 100 }
|
|
231
|
+
};
|
|
232
|
+
expect(change.dimensions?.width).toBe(200);
|
|
233
|
+
});
|
|
234
|
+
it("should create drag change", () => {
|
|
235
|
+
const node = {
|
|
236
|
+
id: "node-1",
|
|
237
|
+
type: "default",
|
|
238
|
+
position: { x: 0, y: 0 },
|
|
239
|
+
data: {}
|
|
240
|
+
};
|
|
241
|
+
const change = {
|
|
242
|
+
type: "position",
|
|
243
|
+
id: "node-1",
|
|
244
|
+
item: node,
|
|
245
|
+
drag: true
|
|
246
|
+
};
|
|
247
|
+
expect(change.drag).toBe(true);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
describe("isNode", () => {
|
|
251
|
+
it("should return true for valid node objects", () => {
|
|
252
|
+
const node = {
|
|
253
|
+
id: "node-1",
|
|
254
|
+
type: "default",
|
|
255
|
+
position: { x: 0, y: 0 },
|
|
256
|
+
data: {}
|
|
257
|
+
};
|
|
258
|
+
expect(isNode(node)).toBe(true);
|
|
259
|
+
});
|
|
260
|
+
it("should return true for node with extended properties", () => {
|
|
261
|
+
const node = {
|
|
262
|
+
id: "node-1",
|
|
263
|
+
type: "custom",
|
|
264
|
+
position: { x: 100, y: 200 },
|
|
265
|
+
data: { label: "Test" },
|
|
266
|
+
width: 200,
|
|
267
|
+
height: 100
|
|
268
|
+
};
|
|
269
|
+
expect(isNode(node)).toBe(true);
|
|
270
|
+
});
|
|
271
|
+
it("should return false for null", () => {
|
|
272
|
+
expect(isNode(null)).toBe(false);
|
|
273
|
+
});
|
|
274
|
+
it("should return false for undefined", () => {
|
|
275
|
+
expect(isNode(void 0)).toBe(false);
|
|
276
|
+
});
|
|
277
|
+
it("should return false for object missing id", () => {
|
|
278
|
+
expect(isNode({ type: "default", position: { x: 0, y: 0 }, data: {} })).toBe(false);
|
|
279
|
+
});
|
|
280
|
+
it("should return false for object missing type", () => {
|
|
281
|
+
expect(isNode({ id: "node-1", position: { x: 0, y: 0 }, data: {} })).toBe(false);
|
|
282
|
+
});
|
|
283
|
+
it("should return false for primitive values", () => {
|
|
284
|
+
expect(isNode("node")).toBe(false);
|
|
285
|
+
expect(isNode(123)).toBe(false);
|
|
286
|
+
expect(isNode(true)).toBe(false);
|
|
287
|
+
});
|
|
288
|
+
it("should return false for arrays", () => {
|
|
289
|
+
expect(isNode([])).toBe(false);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _performance = require("../utils/performance.cjs");
|
|
5
|
+
(0, _vitest.describe)("flow/utils/performance", () => {
|
|
6
|
+
(0, _vitest.describe)("ReactiveGraph", () => {
|
|
7
|
+
(0, _vitest.it)("should initialize with empty nodes and edges", () => {
|
|
8
|
+
const graph = new _performance.ReactiveGraph();
|
|
9
|
+
(0, _vitest.expect)(graph.nodes).toEqual([]);
|
|
10
|
+
(0, _vitest.expect)(graph.edges).toEqual([]);
|
|
11
|
+
});
|
|
12
|
+
(0, _vitest.it)("should set and get nodes", () => {
|
|
13
|
+
const graph = new _performance.ReactiveGraph();
|
|
14
|
+
const nodes = [{
|
|
15
|
+
id: "n1",
|
|
16
|
+
type: "default",
|
|
17
|
+
position: {
|
|
18
|
+
x: 0,
|
|
19
|
+
y: 0
|
|
20
|
+
},
|
|
21
|
+
data: {}
|
|
22
|
+
}];
|
|
23
|
+
graph.nodes = nodes;
|
|
24
|
+
(0, _vitest.expect)(graph.nodes).toBe(nodes);
|
|
25
|
+
});
|
|
26
|
+
(0, _vitest.it)("should set and get edges", () => {
|
|
27
|
+
const graph = new _performance.ReactiveGraph();
|
|
28
|
+
const edges = [{
|
|
29
|
+
id: "e1",
|
|
30
|
+
source: "n1",
|
|
31
|
+
target: "n2",
|
|
32
|
+
type: "default"
|
|
33
|
+
}];
|
|
34
|
+
graph.edges = edges;
|
|
35
|
+
(0, _vitest.expect)(graph.edges).toBe(edges);
|
|
36
|
+
});
|
|
37
|
+
(0, _vitest.it)("should get connected edges for a node", () => {
|
|
38
|
+
const graph = new _performance.ReactiveGraph();
|
|
39
|
+
graph.nodes = [{
|
|
40
|
+
id: "n1",
|
|
41
|
+
type: "default",
|
|
42
|
+
position: {
|
|
43
|
+
x: 0,
|
|
44
|
+
y: 0
|
|
45
|
+
},
|
|
46
|
+
data: {}
|
|
47
|
+
}, {
|
|
48
|
+
id: "n2",
|
|
49
|
+
type: "default",
|
|
50
|
+
position: {
|
|
51
|
+
x: 100,
|
|
52
|
+
y: 0
|
|
53
|
+
},
|
|
54
|
+
data: {}
|
|
55
|
+
}, {
|
|
56
|
+
id: "n3",
|
|
57
|
+
type: "default",
|
|
58
|
+
position: {
|
|
59
|
+
x: 200,
|
|
60
|
+
y: 0
|
|
61
|
+
},
|
|
62
|
+
data: {}
|
|
63
|
+
}];
|
|
64
|
+
graph.edges = [{
|
|
65
|
+
id: "e1",
|
|
66
|
+
source: "n1",
|
|
67
|
+
target: "n2",
|
|
68
|
+
type: "default"
|
|
69
|
+
}, {
|
|
70
|
+
id: "e2",
|
|
71
|
+
source: "n2",
|
|
72
|
+
target: "n3",
|
|
73
|
+
type: "default"
|
|
74
|
+
}];
|
|
75
|
+
const connectedEdges = graph.getConnectedEdges("n2");
|
|
76
|
+
(0, _vitest.expect)(connectedEdges).toHaveLength(2);
|
|
77
|
+
});
|
|
78
|
+
(0, _vitest.it)("should get connected nodes for a node", () => {
|
|
79
|
+
const graph = new _performance.ReactiveGraph();
|
|
80
|
+
graph.nodes = [{
|
|
81
|
+
id: "n1",
|
|
82
|
+
type: "default",
|
|
83
|
+
position: {
|
|
84
|
+
x: 0,
|
|
85
|
+
y: 0
|
|
86
|
+
},
|
|
87
|
+
data: {}
|
|
88
|
+
}, {
|
|
89
|
+
id: "n2",
|
|
90
|
+
type: "default",
|
|
91
|
+
position: {
|
|
92
|
+
x: 100,
|
|
93
|
+
y: 0
|
|
94
|
+
},
|
|
95
|
+
data: {}
|
|
96
|
+
}, {
|
|
97
|
+
id: "n3",
|
|
98
|
+
type: "default",
|
|
99
|
+
position: {
|
|
100
|
+
x: 200,
|
|
101
|
+
y: 0
|
|
102
|
+
},
|
|
103
|
+
data: {}
|
|
104
|
+
}];
|
|
105
|
+
graph.edges = [{
|
|
106
|
+
id: "e1",
|
|
107
|
+
source: "n1",
|
|
108
|
+
target: "n2",
|
|
109
|
+
type: "default"
|
|
110
|
+
}, {
|
|
111
|
+
id: "e2",
|
|
112
|
+
source: "n2",
|
|
113
|
+
target: "n3",
|
|
114
|
+
type: "default"
|
|
115
|
+
}];
|
|
116
|
+
const connectedNodes = graph.getConnectedNodes("n1");
|
|
117
|
+
(0, _vitest.expect)(connectedNodes).toHaveLength(1);
|
|
118
|
+
(0, _vitest.expect)(connectedNodes[0].id).toBe("n2");
|
|
119
|
+
});
|
|
120
|
+
(0, _vitest.it)("should return empty array for node with no connections", () => {
|
|
121
|
+
const graph = new _performance.ReactiveGraph();
|
|
122
|
+
graph.nodes = [{
|
|
123
|
+
id: "n1",
|
|
124
|
+
type: "default",
|
|
125
|
+
position: {
|
|
126
|
+
x: 0,
|
|
127
|
+
y: 0
|
|
128
|
+
},
|
|
129
|
+
data: {}
|
|
130
|
+
}, {
|
|
131
|
+
id: "n2",
|
|
132
|
+
type: "default",
|
|
133
|
+
position: {
|
|
134
|
+
x: 100,
|
|
135
|
+
y: 0
|
|
136
|
+
},
|
|
137
|
+
data: {}
|
|
138
|
+
}];
|
|
139
|
+
graph.edges = [];
|
|
140
|
+
const connected = graph.getConnectedNodes("n1");
|
|
141
|
+
(0, _vitest.expect)(connected).toHaveLength(0);
|
|
142
|
+
});
|
|
143
|
+
(0, _vitest.it)("should batch update nodes", () => {
|
|
144
|
+
const graph = new _performance.ReactiveGraph();
|
|
145
|
+
graph.nodes = [{
|
|
146
|
+
id: "n1",
|
|
147
|
+
type: "default",
|
|
148
|
+
position: {
|
|
149
|
+
x: 0,
|
|
150
|
+
y: 0
|
|
151
|
+
},
|
|
152
|
+
data: {}
|
|
153
|
+
}];
|
|
154
|
+
graph.batchUpdateNodes(nodes => [...nodes, {
|
|
155
|
+
id: "n2",
|
|
156
|
+
type: "default",
|
|
157
|
+
position: {
|
|
158
|
+
x: 100,
|
|
159
|
+
y: 0
|
|
160
|
+
},
|
|
161
|
+
data: {}
|
|
162
|
+
}]);
|
|
163
|
+
(0, _vitest.expect)(graph.nodes).toHaveLength(2);
|
|
164
|
+
});
|
|
165
|
+
(0, _vitest.it)("should batch update edges", () => {
|
|
166
|
+
const graph = new _performance.ReactiveGraph();
|
|
167
|
+
graph.edges = [{
|
|
168
|
+
id: "e1",
|
|
169
|
+
source: "n1",
|
|
170
|
+
target: "n2",
|
|
171
|
+
type: "default"
|
|
172
|
+
}];
|
|
173
|
+
graph.batchUpdateEdges(edges => [...edges, {
|
|
174
|
+
id: "e2",
|
|
175
|
+
source: "n2",
|
|
176
|
+
target: "n3",
|
|
177
|
+
type: "default"
|
|
178
|
+
}]);
|
|
179
|
+
(0, _vitest.expect)(graph.edges).toHaveLength(2);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
(0, _vitest.describe)("generateId", () => {
|
|
183
|
+
(0, _vitest.it)("should generate id with default prefix", () => {
|
|
184
|
+
const id = (0, _performance.generateId)();
|
|
185
|
+
(0, _vitest.expect)(id).toMatch(/^id-\d+-\d+$/);
|
|
186
|
+
});
|
|
187
|
+
(0, _vitest.it)("should generate id with custom prefix", () => {
|
|
188
|
+
const id = (0, _performance.generateId)("node");
|
|
189
|
+
(0, _vitest.expect)(id).toMatch(/^node-\d+-\d+$/);
|
|
190
|
+
});
|
|
191
|
+
(0, _vitest.it)("should generate unique ids", () => {
|
|
192
|
+
const id1 = (0, _performance.generateId)("test");
|
|
193
|
+
const id2 = (0, _performance.generateId)("test");
|
|
194
|
+
(0, _vitest.expect)(id1).not.toBe(id2);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
(0, _vitest.describe)("debounce", () => {
|
|
198
|
+
(0, _vitest.beforeEach)(() => {
|
|
199
|
+
_vitest.vi.useFakeTimers();
|
|
200
|
+
});
|
|
201
|
+
(0, _vitest.afterEach)(() => {
|
|
202
|
+
_vitest.vi.useRealTimers();
|
|
203
|
+
});
|
|
204
|
+
(0, _vitest.it)("should debounce function calls", () => {
|
|
205
|
+
const fn = _vitest.vi.fn();
|
|
206
|
+
const debounced = (0, _performance.debounce)(fn, 100);
|
|
207
|
+
debounced("a");
|
|
208
|
+
debounced("b");
|
|
209
|
+
debounced("c");
|
|
210
|
+
(0, _vitest.expect)(fn).not.toHaveBeenCalled();
|
|
211
|
+
_vitest.vi.advanceTimersByTime(100);
|
|
212
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(1);
|
|
213
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledWith("c");
|
|
214
|
+
});
|
|
215
|
+
(0, _vitest.it)("should pass arguments correctly", () => {
|
|
216
|
+
const fn = _vitest.vi.fn();
|
|
217
|
+
const debounced = (0, _performance.debounce)(fn, 50);
|
|
218
|
+
debounced("hello", 123);
|
|
219
|
+
_vitest.vi.advanceTimersByTime(50);
|
|
220
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledWith("hello", 123);
|
|
221
|
+
});
|
|
222
|
+
(0, _vitest.it)("should only call once for multiple rapid calls", () => {
|
|
223
|
+
const fn = _vitest.vi.fn();
|
|
224
|
+
const debounced = (0, _performance.debounce)(fn, 200);
|
|
225
|
+
for (let i = 0; i < 10; i++) {
|
|
226
|
+
debounced(i);
|
|
227
|
+
}
|
|
228
|
+
_vitest.vi.advanceTimersByTime(200);
|
|
229
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(1);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
(0, _vitest.describe)("throttle", () => {
|
|
233
|
+
(0, _vitest.beforeEach)(() => {
|
|
234
|
+
_vitest.vi.useFakeTimers();
|
|
235
|
+
});
|
|
236
|
+
(0, _vitest.afterEach)(() => {
|
|
237
|
+
_vitest.vi.useRealTimers();
|
|
238
|
+
});
|
|
239
|
+
(0, _vitest.it)("should throttle function calls", () => {
|
|
240
|
+
const fn = _vitest.vi.fn();
|
|
241
|
+
const throttled = (0, _performance.throttle)(fn, 100);
|
|
242
|
+
throttled("a");
|
|
243
|
+
throttled("b");
|
|
244
|
+
throttled("c");
|
|
245
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(1);
|
|
246
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledWith("a");
|
|
247
|
+
_vitest.vi.advanceTimersByTime(50);
|
|
248
|
+
throttled("d");
|
|
249
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(1);
|
|
250
|
+
_vitest.vi.advanceTimersByTime(60);
|
|
251
|
+
throttled("e");
|
|
252
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(2);
|
|
253
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledWith("e");
|
|
254
|
+
});
|
|
255
|
+
(0, _vitest.it)("should pass arguments correctly", () => {
|
|
256
|
+
const fn = _vitest.vi.fn();
|
|
257
|
+
const throttled = (0, _performance.throttle)(fn, 100);
|
|
258
|
+
throttled("test", true, 42);
|
|
259
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledWith("test", true, 42);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
(0, _vitest.describe)("memo", () => {
|
|
263
|
+
(0, _vitest.beforeEach)(() => {
|
|
264
|
+
(0, _performance.clearMemoCache)();
|
|
265
|
+
});
|
|
266
|
+
(0, _vitest.it)("should memoize function results", () => {
|
|
267
|
+
let callCount = 0;
|
|
268
|
+
const memoized = (0, _performance.memo)("key1", () => {
|
|
269
|
+
callCount++;
|
|
270
|
+
return "result";
|
|
271
|
+
});
|
|
272
|
+
const result1 = memoized;
|
|
273
|
+
const result2 = memoized;
|
|
274
|
+
(0, _vitest.expect)(callCount).toBe(1);
|
|
275
|
+
(0, _vitest.expect)(result1).toBe("result");
|
|
276
|
+
(0, _vitest.expect)(result2).toBe("result");
|
|
277
|
+
});
|
|
278
|
+
(0, _vitest.it)("should cache different keys separately", () => {
|
|
279
|
+
const fn = _vitest.vi.fn().mockImplementation(key => `result-${key}`);
|
|
280
|
+
const result1 = (0, _performance.memo)("key-a", () => fn("a"));
|
|
281
|
+
const result2 = (0, _performance.memo)("key-b", () => fn("b"));
|
|
282
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(2);
|
|
283
|
+
(0, _vitest.expect)(result1).toBe("result-a");
|
|
284
|
+
(0, _vitest.expect)(result2).toBe("result-b");
|
|
285
|
+
});
|
|
286
|
+
(0, _vitest.it)("should return cached result without calling function", () => {
|
|
287
|
+
let callCount = 0;
|
|
288
|
+
const cached = (0, _performance.memo)("cache-key", () => {
|
|
289
|
+
callCount++;
|
|
290
|
+
return "cached";
|
|
291
|
+
});
|
|
292
|
+
const result1 = cached;
|
|
293
|
+
const result2 = cached;
|
|
294
|
+
const result3 = cached;
|
|
295
|
+
(0, _vitest.expect)(callCount).toBe(1);
|
|
296
|
+
(0, _vitest.expect)(result1).toBe("cached");
|
|
297
|
+
(0, _vitest.expect)(result2).toBe("cached");
|
|
298
|
+
(0, _vitest.expect)(result3).toBe("cached");
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
(0, _vitest.describe)("clearMemoCache", () => {
|
|
302
|
+
(0, _vitest.it)("should clear memo cache", () => {
|
|
303
|
+
const fn = _vitest.vi.fn().mockReturnValue("value");
|
|
304
|
+
(0, _performance.memo)("key-x", fn);
|
|
305
|
+
(0, _performance.memo)("key-y", fn);
|
|
306
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(2);
|
|
307
|
+
(0, _performance.clearMemoCache)();
|
|
308
|
+
(0, _performance.memo)("key-x", fn);
|
|
309
|
+
(0, _performance.memo)("key-y", fn);
|
|
310
|
+
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(4);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|