@yh-ui/flow 1.0.26 → 1.0.36
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 +6 -6
- package/dist/__tests__/ai-workflow.ssr.test.cjs +0 -352
- package/dist/__tests__/ai-workflow.ssr.test.d.ts +0 -1
- package/dist/__tests__/ai-workflow.ssr.test.mjs +0 -283
- package/dist/__tests__/ai-workflow.test.cjs +0 -109
- package/dist/__tests__/ai-workflow.test.d.ts +0 -1
- package/dist/__tests__/ai-workflow.test.mjs +0 -112
- package/dist/__tests__/bpmn-engine.test.cjs +0 -357
- package/dist/__tests__/bpmn-engine.test.d.ts +0 -1
- package/dist/__tests__/bpmn-engine.test.mjs +0 -406
- package/dist/__tests__/bpmn-utils.test.cjs +0 -268
- package/dist/__tests__/bpmn-utils.test.d.ts +0 -1
- package/dist/__tests__/bpmn-utils.test.mjs +0 -227
- package/dist/__tests__/bpmn-xml.test.cjs +0 -150
- package/dist/__tests__/bpmn-xml.test.d.ts +0 -1
- package/dist/__tests__/bpmn-xml.test.mjs +0 -112
- package/dist/__tests__/bpmn.ssr.test.cjs +0 -278
- package/dist/__tests__/bpmn.ssr.test.d.ts +0 -1
- package/dist/__tests__/bpmn.ssr.test.mjs +0 -237
- package/dist/__tests__/bpmn.test.cjs +0 -103
- package/dist/__tests__/bpmn.test.d.ts +0 -1
- package/dist/__tests__/bpmn.test.mjs +0 -106
- package/dist/__tests__/collaboration.test.cjs +0 -487
- package/dist/__tests__/collaboration.test.d.ts +0 -1
- package/dist/__tests__/collaboration.test.mjs +0 -424
- package/dist/__tests__/custom-types.test.cjs +0 -300
- package/dist/__tests__/custom-types.test.d.ts +0 -1
- package/dist/__tests__/custom-types.test.mjs +0 -248
- package/dist/__tests__/edge-types.test.cjs +0 -275
- package/dist/__tests__/edge-types.test.d.ts +0 -1
- package/dist/__tests__/edge-types.test.mjs +0 -234
- package/dist/__tests__/edge-utils.test.cjs +0 -375
- package/dist/__tests__/edge-utils.test.d.ts +0 -1
- package/dist/__tests__/edge-utils.test.mjs +0 -376
- package/dist/__tests__/edge.test.cjs +0 -56
- package/dist/__tests__/edge.test.d.ts +0 -1
- package/dist/__tests__/edge.test.mjs +0 -69
- package/dist/__tests__/event-bus.test.cjs +0 -80
- package/dist/__tests__/event-bus.test.d.ts +0 -1
- package/dist/__tests__/event-bus.test.mjs +0 -51
- package/dist/__tests__/events-types.test.cjs +0 -184
- package/dist/__tests__/events-types.test.d.ts +0 -1
- package/dist/__tests__/events-types.test.mjs +0 -184
- package/dist/__tests__/export-image-plugin.test.cjs +0 -142
- package/dist/__tests__/export-image-plugin.test.d.ts +0 -1
- package/dist/__tests__/export-image-plugin.test.mjs +0 -118
- package/dist/__tests__/export.test.cjs +0 -237
- package/dist/__tests__/export.test.d.ts +0 -1
- package/dist/__tests__/export.test.mjs +0 -171
- package/dist/__tests__/flow-context.test.cjs +0 -16
- package/dist/__tests__/flow-context.test.d.ts +0 -1
- package/dist/__tests__/flow-context.test.mjs +0 -16
- package/dist/__tests__/flow-props.test.cjs +0 -94
- package/dist/__tests__/flow-props.test.d.ts +0 -1
- package/dist/__tests__/flow-props.test.mjs +0 -92
- package/dist/__tests__/flow.ssr.test.cjs +0 -156
- package/dist/__tests__/flow.ssr.test.d.ts +0 -1
- package/dist/__tests__/flow.ssr.test.mjs +0 -112
- package/dist/__tests__/geometry.test.cjs +0 -191
- package/dist/__tests__/geometry.test.d.ts +0 -1
- package/dist/__tests__/geometry.test.mjs +0 -105
- package/dist/__tests__/graph.test.cjs +0 -115
- package/dist/__tests__/graph.test.d.ts +0 -1
- package/dist/__tests__/graph.test.mjs +0 -85
- package/dist/__tests__/history-plugin.test.cjs +0 -191
- package/dist/__tests__/history-plugin.test.d.ts +0 -1
- package/dist/__tests__/history-plugin.test.mjs +0 -161
- package/dist/__tests__/history.test.cjs +0 -81
- package/dist/__tests__/history.test.d.ts +0 -1
- package/dist/__tests__/history.test.mjs +0 -43
- package/dist/__tests__/layout-plugin.test.cjs +0 -233
- package/dist/__tests__/layout-plugin.test.d.ts +0 -1
- package/dist/__tests__/layout-plugin.test.mjs +0 -215
- package/dist/__tests__/layout.test.cjs +0 -213
- package/dist/__tests__/layout.test.d.ts +0 -1
- package/dist/__tests__/layout.test.mjs +0 -170
- package/dist/__tests__/node-edit-panel.ssr.test.cjs +0 -168
- package/dist/__tests__/node-edit-panel.ssr.test.d.ts +0 -1
- package/dist/__tests__/node-edit-panel.ssr.test.mjs +0 -118
- package/dist/__tests__/node-group-plugin.test.cjs +0 -235
- package/dist/__tests__/node-group-plugin.test.d.ts +0 -1
- package/dist/__tests__/node-group-plugin.test.mjs +0 -187
- package/dist/__tests__/node-handles.test.cjs +0 -340
- package/dist/__tests__/node-handles.test.d.ts +0 -1
- package/dist/__tests__/node-handles.test.mjs +0 -230
- package/dist/__tests__/node-types.test.cjs +0 -368
- package/dist/__tests__/node-types.test.d.ts +0 -1
- package/dist/__tests__/node-types.test.mjs +0 -292
- package/dist/__tests__/performance.test.cjs +0 -313
- package/dist/__tests__/performance.test.d.ts +0 -1
- package/dist/__tests__/performance.test.mjs +0 -218
- package/dist/__tests__/plugin-advanced.test.cjs +0 -301
- package/dist/__tests__/plugin-advanced.test.d.ts +0 -1
- package/dist/__tests__/plugin-advanced.test.mjs +0 -225
- package/dist/__tests__/plugin.test.cjs +0 -151
- package/dist/__tests__/plugin.test.d.ts +0 -1
- package/dist/__tests__/plugin.test.mjs +0 -116
- package/dist/__tests__/plugins.test.cjs +0 -412
- package/dist/__tests__/plugins.test.d.ts +0 -1
- package/dist/__tests__/plugins.test.mjs +0 -402
- package/dist/__tests__/screenshot-capture.test.cjs +0 -183
- package/dist/__tests__/screenshot-capture.test.d.ts +0 -1
- package/dist/__tests__/screenshot-capture.test.mjs +0 -124
- package/dist/__tests__/screenshot.test.cjs +0 -74
- package/dist/__tests__/screenshot.test.d.ts +0 -1
- package/dist/__tests__/screenshot.test.mjs +0 -69
- package/dist/__tests__/theme.test.cjs +0 -185
- package/dist/__tests__/theme.test.d.ts +0 -1
- package/dist/__tests__/theme.test.mjs +0 -191
- package/dist/__tests__/transform.test.cjs +0 -384
- package/dist/__tests__/transform.test.d.ts +0 -1
- package/dist/__tests__/transform.test.mjs +0 -239
- package/dist/__tests__/useAlignment.test.cjs +0 -128
- package/dist/__tests__/useAlignment.test.d.ts +0 -1
- package/dist/__tests__/useAlignment.test.mjs +0 -72
- package/dist/__tests__/useEdges.test.cjs +0 -117
- package/dist/__tests__/useEdges.test.d.ts +0 -1
- package/dist/__tests__/useEdges.test.mjs +0 -80
- package/dist/__tests__/useKeyboard.test.cjs +0 -88
- package/dist/__tests__/useKeyboard.test.d.ts +0 -1
- package/dist/__tests__/useKeyboard.test.mjs +0 -56
- package/dist/__tests__/useNodeDistribution.test.cjs +0 -643
- package/dist/__tests__/useNodeDistribution.test.d.ts +0 -1
- package/dist/__tests__/useNodeDistribution.test.mjs +0 -297
- package/dist/__tests__/useNodes.test.cjs +0 -150
- package/dist/__tests__/useNodes.test.d.ts +0 -1
- package/dist/__tests__/useNodes.test.mjs +0 -80
- package/dist/__tests__/useSelection.test.cjs +0 -112
- package/dist/__tests__/useSelection.test.d.ts +0 -1
- package/dist/__tests__/useSelection.test.mjs +0 -76
- package/dist/__tests__/useViewport.test.cjs +0 -171
- package/dist/__tests__/useViewport.test.d.ts +0 -1
- package/dist/__tests__/useViewport.test.mjs +0 -82
- package/dist/__tests__/utils/ssr.cjs +0 -124
- package/dist/__tests__/utils/ssr.d.ts +0 -33
- package/dist/__tests__/utils/ssr.mjs +0 -129
- package/dist/__tests__/validation.test.cjs +0 -95
- package/dist/__tests__/validation.test.d.ts +0 -1
- package/dist/__tests__/validation.test.mjs +0 -36
- package/dist/__tests__/viewport-types.test.cjs +0 -324
- package/dist/__tests__/viewport-types.test.d.ts +0 -1
- package/dist/__tests__/viewport-types.test.mjs +0 -207
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
ReactiveGraph,
|
|
4
|
-
generateId,
|
|
5
|
-
debounce,
|
|
6
|
-
throttle,
|
|
7
|
-
memo,
|
|
8
|
-
clearMemoCache
|
|
9
|
-
} from "../utils/performance.mjs";
|
|
10
|
-
describe("flow/utils/performance", () => {
|
|
11
|
-
describe("ReactiveGraph", () => {
|
|
12
|
-
it("should initialize with empty nodes and edges", () => {
|
|
13
|
-
const graph = new ReactiveGraph();
|
|
14
|
-
expect(graph.nodes).toEqual([]);
|
|
15
|
-
expect(graph.edges).toEqual([]);
|
|
16
|
-
});
|
|
17
|
-
it("should set and get nodes", () => {
|
|
18
|
-
const graph = new ReactiveGraph();
|
|
19
|
-
const nodes = [{ id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} }];
|
|
20
|
-
graph.nodes = nodes;
|
|
21
|
-
expect(graph.nodes).toBe(nodes);
|
|
22
|
-
});
|
|
23
|
-
it("should set and get edges", () => {
|
|
24
|
-
const graph = new ReactiveGraph();
|
|
25
|
-
const edges = [{ id: "e1", source: "n1", target: "n2", type: "default" }];
|
|
26
|
-
graph.edges = edges;
|
|
27
|
-
expect(graph.edges).toBe(edges);
|
|
28
|
-
});
|
|
29
|
-
it("should get connected edges for a node", () => {
|
|
30
|
-
const graph = new ReactiveGraph();
|
|
31
|
-
graph.nodes = [
|
|
32
|
-
{ id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} },
|
|
33
|
-
{ id: "n2", type: "default", position: { x: 100, y: 0 }, data: {} },
|
|
34
|
-
{ id: "n3", type: "default", position: { x: 200, y: 0 }, data: {} }
|
|
35
|
-
];
|
|
36
|
-
graph.edges = [
|
|
37
|
-
{ id: "e1", source: "n1", target: "n2", type: "default" },
|
|
38
|
-
{ id: "e2", source: "n2", target: "n3", type: "default" }
|
|
39
|
-
];
|
|
40
|
-
const connectedEdges = graph.getConnectedEdges("n2");
|
|
41
|
-
expect(connectedEdges).toHaveLength(2);
|
|
42
|
-
});
|
|
43
|
-
it("should get connected nodes for a node", () => {
|
|
44
|
-
const graph = new ReactiveGraph();
|
|
45
|
-
graph.nodes = [
|
|
46
|
-
{ id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} },
|
|
47
|
-
{ id: "n2", type: "default", position: { x: 100, y: 0 }, data: {} },
|
|
48
|
-
{ id: "n3", type: "default", position: { x: 200, y: 0 }, data: {} }
|
|
49
|
-
];
|
|
50
|
-
graph.edges = [
|
|
51
|
-
{ id: "e1", source: "n1", target: "n2", type: "default" },
|
|
52
|
-
{ id: "e2", source: "n2", target: "n3", type: "default" }
|
|
53
|
-
];
|
|
54
|
-
const connectedNodes = graph.getConnectedNodes("n1");
|
|
55
|
-
expect(connectedNodes).toHaveLength(1);
|
|
56
|
-
expect(connectedNodes[0].id).toBe("n2");
|
|
57
|
-
});
|
|
58
|
-
it("should return empty array for node with no connections", () => {
|
|
59
|
-
const graph = new ReactiveGraph();
|
|
60
|
-
graph.nodes = [
|
|
61
|
-
{ id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} },
|
|
62
|
-
{ id: "n2", type: "default", position: { x: 100, y: 0 }, data: {} }
|
|
63
|
-
];
|
|
64
|
-
graph.edges = [];
|
|
65
|
-
const connected = graph.getConnectedNodes("n1");
|
|
66
|
-
expect(connected).toHaveLength(0);
|
|
67
|
-
});
|
|
68
|
-
it("should batch update nodes", () => {
|
|
69
|
-
const graph = new ReactiveGraph();
|
|
70
|
-
graph.nodes = [{ id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} }];
|
|
71
|
-
graph.batchUpdateNodes((nodes) => [
|
|
72
|
-
...nodes,
|
|
73
|
-
{ id: "n2", type: "default", position: { x: 100, y: 0 }, data: {} }
|
|
74
|
-
]);
|
|
75
|
-
expect(graph.nodes).toHaveLength(2);
|
|
76
|
-
});
|
|
77
|
-
it("should batch update edges", () => {
|
|
78
|
-
const graph = new ReactiveGraph();
|
|
79
|
-
graph.edges = [{ id: "e1", source: "n1", target: "n2", type: "default" }];
|
|
80
|
-
graph.batchUpdateEdges((edges) => [
|
|
81
|
-
...edges,
|
|
82
|
-
{ id: "e2", source: "n2", target: "n3", type: "default" }
|
|
83
|
-
]);
|
|
84
|
-
expect(graph.edges).toHaveLength(2);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
describe("generateId", () => {
|
|
88
|
-
it("should generate id with default prefix", () => {
|
|
89
|
-
const id = generateId();
|
|
90
|
-
expect(id).toMatch(/^id-\d+-\d+$/);
|
|
91
|
-
});
|
|
92
|
-
it("should generate id with custom prefix", () => {
|
|
93
|
-
const id = generateId("node");
|
|
94
|
-
expect(id).toMatch(/^node-\d+-\d+$/);
|
|
95
|
-
});
|
|
96
|
-
it("should generate unique ids", () => {
|
|
97
|
-
const id1 = generateId("test");
|
|
98
|
-
const id2 = generateId("test");
|
|
99
|
-
expect(id1).not.toBe(id2);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe("debounce", () => {
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
vi.useFakeTimers();
|
|
105
|
-
});
|
|
106
|
-
afterEach(() => {
|
|
107
|
-
vi.useRealTimers();
|
|
108
|
-
});
|
|
109
|
-
it("should debounce function calls", () => {
|
|
110
|
-
const fn = vi.fn();
|
|
111
|
-
const debounced = debounce(fn, 100);
|
|
112
|
-
debounced("a");
|
|
113
|
-
debounced("b");
|
|
114
|
-
debounced("c");
|
|
115
|
-
expect(fn).not.toHaveBeenCalled();
|
|
116
|
-
vi.advanceTimersByTime(100);
|
|
117
|
-
expect(fn).toHaveBeenCalledTimes(1);
|
|
118
|
-
expect(fn).toHaveBeenCalledWith("c");
|
|
119
|
-
});
|
|
120
|
-
it("should pass arguments correctly", () => {
|
|
121
|
-
const fn = vi.fn();
|
|
122
|
-
const debounced = debounce(fn, 50);
|
|
123
|
-
debounced("hello", 123);
|
|
124
|
-
vi.advanceTimersByTime(50);
|
|
125
|
-
expect(fn).toHaveBeenCalledWith("hello", 123);
|
|
126
|
-
});
|
|
127
|
-
it("should only call once for multiple rapid calls", () => {
|
|
128
|
-
const fn = vi.fn();
|
|
129
|
-
const debounced = debounce(fn, 200);
|
|
130
|
-
for (let i = 0; i < 10; i++) {
|
|
131
|
-
debounced(i);
|
|
132
|
-
}
|
|
133
|
-
vi.advanceTimersByTime(200);
|
|
134
|
-
expect(fn).toHaveBeenCalledTimes(1);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
describe("throttle", () => {
|
|
138
|
-
beforeEach(() => {
|
|
139
|
-
vi.useFakeTimers();
|
|
140
|
-
});
|
|
141
|
-
afterEach(() => {
|
|
142
|
-
vi.useRealTimers();
|
|
143
|
-
});
|
|
144
|
-
it("should throttle function calls", () => {
|
|
145
|
-
const fn = vi.fn();
|
|
146
|
-
const throttled = throttle(fn, 100);
|
|
147
|
-
throttled("a");
|
|
148
|
-
throttled("b");
|
|
149
|
-
throttled("c");
|
|
150
|
-
expect(fn).toHaveBeenCalledTimes(1);
|
|
151
|
-
expect(fn).toHaveBeenCalledWith("a");
|
|
152
|
-
vi.advanceTimersByTime(50);
|
|
153
|
-
throttled("d");
|
|
154
|
-
expect(fn).toHaveBeenCalledTimes(1);
|
|
155
|
-
vi.advanceTimersByTime(60);
|
|
156
|
-
throttled("e");
|
|
157
|
-
expect(fn).toHaveBeenCalledTimes(2);
|
|
158
|
-
expect(fn).toHaveBeenCalledWith("e");
|
|
159
|
-
});
|
|
160
|
-
it("should pass arguments correctly", () => {
|
|
161
|
-
const fn = vi.fn();
|
|
162
|
-
const throttled = throttle(fn, 100);
|
|
163
|
-
throttled("test", true, 42);
|
|
164
|
-
expect(fn).toHaveBeenCalledWith("test", true, 42);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe("memo", () => {
|
|
168
|
-
beforeEach(() => {
|
|
169
|
-
clearMemoCache();
|
|
170
|
-
});
|
|
171
|
-
it("should memoize function results", () => {
|
|
172
|
-
let callCount = 0;
|
|
173
|
-
const memoized = memo("key1", () => {
|
|
174
|
-
callCount++;
|
|
175
|
-
return "result";
|
|
176
|
-
});
|
|
177
|
-
const result1 = memoized;
|
|
178
|
-
const result2 = memoized;
|
|
179
|
-
expect(callCount).toBe(1);
|
|
180
|
-
expect(result1).toBe("result");
|
|
181
|
-
expect(result2).toBe("result");
|
|
182
|
-
});
|
|
183
|
-
it("should cache different keys separately", () => {
|
|
184
|
-
const fn = vi.fn().mockImplementation((key) => `result-${key}`);
|
|
185
|
-
const result1 = memo("key-a", () => fn("a"));
|
|
186
|
-
const result2 = memo("key-b", () => fn("b"));
|
|
187
|
-
expect(fn).toHaveBeenCalledTimes(2);
|
|
188
|
-
expect(result1).toBe("result-a");
|
|
189
|
-
expect(result2).toBe("result-b");
|
|
190
|
-
});
|
|
191
|
-
it("should return cached result without calling function", () => {
|
|
192
|
-
let callCount = 0;
|
|
193
|
-
const cached = memo("cache-key", () => {
|
|
194
|
-
callCount++;
|
|
195
|
-
return "cached";
|
|
196
|
-
});
|
|
197
|
-
const result1 = cached;
|
|
198
|
-
const result2 = cached;
|
|
199
|
-
const result3 = cached;
|
|
200
|
-
expect(callCount).toBe(1);
|
|
201
|
-
expect(result1).toBe("cached");
|
|
202
|
-
expect(result2).toBe("cached");
|
|
203
|
-
expect(result3).toBe("cached");
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
describe("clearMemoCache", () => {
|
|
207
|
-
it("should clear memo cache", () => {
|
|
208
|
-
const fn = vi.fn().mockReturnValue("value");
|
|
209
|
-
memo("key-x", fn);
|
|
210
|
-
memo("key-y", fn);
|
|
211
|
-
expect(fn).toHaveBeenCalledTimes(2);
|
|
212
|
-
clearMemoCache();
|
|
213
|
-
memo("key-x", fn);
|
|
214
|
-
memo("key-y", fn);
|
|
215
|
-
expect(fn).toHaveBeenCalledTimes(4);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _vitest = require("vitest");
|
|
4
|
-
var _vue = require("vue");
|
|
5
|
-
var _plugin = require("../plugins/plugin.cjs");
|
|
6
|
-
function createMockFlowInstance() {
|
|
7
|
-
const nodes = (0, _vue.ref)([]);
|
|
8
|
-
const edges = (0, _vue.ref)([]);
|
|
9
|
-
const viewport = (0, _vue.ref)({
|
|
10
|
-
x: 0,
|
|
11
|
-
y: 0,
|
|
12
|
-
zoom: 1
|
|
13
|
-
});
|
|
14
|
-
const draggingNodeId = (0, _vue.ref)(null);
|
|
15
|
-
return {
|
|
16
|
-
nodes,
|
|
17
|
-
edges,
|
|
18
|
-
viewport,
|
|
19
|
-
draggingNodeId,
|
|
20
|
-
addNode: _vitest.vi.fn(),
|
|
21
|
-
removeNode: _vitest.vi.fn(),
|
|
22
|
-
updateNode: _vitest.vi.fn(),
|
|
23
|
-
getNode: _vitest.vi.fn(),
|
|
24
|
-
addEdge: _vitest.vi.fn(),
|
|
25
|
-
removeEdge: _vitest.vi.fn(),
|
|
26
|
-
updateEdge: _vitest.vi.fn(),
|
|
27
|
-
getEdge: _vitest.vi.fn(),
|
|
28
|
-
setViewport: _vitest.vi.fn(),
|
|
29
|
-
fitView: _vitest.vi.fn(),
|
|
30
|
-
zoomIn: _vitest.vi.fn(),
|
|
31
|
-
zoomOut: _vitest.vi.fn(),
|
|
32
|
-
centerView: _vitest.vi.fn(),
|
|
33
|
-
selectNode: _vitest.vi.fn(),
|
|
34
|
-
selectEdge: _vitest.vi.fn(),
|
|
35
|
-
clearSelection: _vitest.vi.fn(),
|
|
36
|
-
getNodes: _vitest.vi.fn(() => nodes.value),
|
|
37
|
-
getEdges: _vitest.vi.fn(() => edges.value),
|
|
38
|
-
getViewport: _vitest.vi.fn(() => viewport.value),
|
|
39
|
-
screenToCanvas: _vitest.vi.fn(),
|
|
40
|
-
canvasToScreen: _vitest.vi.fn(),
|
|
41
|
-
on: _vitest.vi.fn(),
|
|
42
|
-
off: _vitest.vi.fn(),
|
|
43
|
-
emit: _vitest.vi.fn(),
|
|
44
|
-
isValidConnection: _vitest.vi.fn(() => true),
|
|
45
|
-
$el: void 0,
|
|
46
|
-
usePlugin: _vitest.vi.fn(),
|
|
47
|
-
removePlugin: _vitest.vi.fn()
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
(0, _vitest.describe)("flow/plugins/plugin - withHooks", () => {
|
|
51
|
-
let consoleLogSpy;
|
|
52
|
-
let consoleWarnSpy;
|
|
53
|
-
let consoleErrorSpy;
|
|
54
|
-
(0, _vitest.beforeEach)(() => {
|
|
55
|
-
consoleLogSpy = _vitest.vi.spyOn(console, "log").mockImplementation(() => {});
|
|
56
|
-
consoleWarnSpy = _vitest.vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
57
|
-
consoleErrorSpy = _vitest.vi.spyOn(console, "error").mockImplementation(() => {});
|
|
58
|
-
});
|
|
59
|
-
(0, _vitest.afterEach)(() => {
|
|
60
|
-
consoleLogSpy.mockRestore();
|
|
61
|
-
consoleWarnSpy.mockRestore();
|
|
62
|
-
consoleErrorSpy.mockRestore();
|
|
63
|
-
});
|
|
64
|
-
(0, _vitest.describe)("PluginManager - edge cases", () => {
|
|
65
|
-
(0, _vitest.it)("should warn when unregistering non-existent plugin", () => {
|
|
66
|
-
const pm = new _plugin.PluginManager();
|
|
67
|
-
pm.unregister("non-existent");
|
|
68
|
-
(0, _vitest.expect)(consoleWarnSpy).toHaveBeenCalledWith("[YhFlow] Plugin non-existent not found");
|
|
69
|
-
});
|
|
70
|
-
(0, _vitest.it)("should warn when registering without init and no options", () => {
|
|
71
|
-
const pm = new _plugin.PluginManager();
|
|
72
|
-
const install = _vitest.vi.fn();
|
|
73
|
-
pm.register({
|
|
74
|
-
id: "n",
|
|
75
|
-
name: "N",
|
|
76
|
-
install
|
|
77
|
-
});
|
|
78
|
-
(0, _vitest.expect)(consoleErrorSpy).toHaveBeenCalledWith("[YhFlow] PluginManager not initialized, call init() first or provide flow instance");
|
|
79
|
-
(0, _vitest.expect)(install).not.toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
(0, _vitest.it)("should register with options as flow instance fallback", () => {
|
|
82
|
-
const pm = new _plugin.PluginManager();
|
|
83
|
-
const flow = createMockFlowInstance();
|
|
84
|
-
const install = _vitest.vi.fn();
|
|
85
|
-
pm.register({
|
|
86
|
-
id: "fallback",
|
|
87
|
-
name: "Fallback",
|
|
88
|
-
install
|
|
89
|
-
}, flow);
|
|
90
|
-
(0, _vitest.expect)(install).toHaveBeenCalledWith(flow, flow);
|
|
91
|
-
});
|
|
92
|
-
(0, _vitest.it)("should log when plugin is registered", () => {
|
|
93
|
-
const pm = new _plugin.PluginManager();
|
|
94
|
-
const flow = createMockFlowInstance();
|
|
95
|
-
pm.init(flow);
|
|
96
|
-
pm.register({
|
|
97
|
-
id: "log-test",
|
|
98
|
-
name: "LogTest",
|
|
99
|
-
install: _vitest.vi.fn()
|
|
100
|
-
});
|
|
101
|
-
(0, _vitest.expect)(consoleLogSpy).toHaveBeenCalledWith("[YhFlow] Plugin LogTest (log-test) registered");
|
|
102
|
-
});
|
|
103
|
-
(0, _vitest.it)("should log when plugin is unregistered", () => {
|
|
104
|
-
const pm = new _plugin.PluginManager();
|
|
105
|
-
const flow = createMockFlowInstance();
|
|
106
|
-
pm.init(flow);
|
|
107
|
-
pm.register({
|
|
108
|
-
id: "ul",
|
|
109
|
-
name: "UL",
|
|
110
|
-
install: _vitest.vi.fn()
|
|
111
|
-
});
|
|
112
|
-
pm.unregister("ul");
|
|
113
|
-
(0, _vitest.expect)(consoleLogSpy).toHaveBeenCalledWith("[YhFlow] Plugin UL (ul) unregistered");
|
|
114
|
-
});
|
|
115
|
-
(0, _vitest.it)("should not call destroy if plugin has no destroy method", () => {
|
|
116
|
-
const pm = new _plugin.PluginManager();
|
|
117
|
-
const flow = createMockFlowInstance();
|
|
118
|
-
pm.init(flow);
|
|
119
|
-
pm.register({
|
|
120
|
-
id: "no-destroy",
|
|
121
|
-
name: "NoDestroy",
|
|
122
|
-
install: _vitest.vi.fn()
|
|
123
|
-
});
|
|
124
|
-
(0, _vitest.expect)(() => pm.unregister("no-destroy")).not.toThrow();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
(0, _vitest.describe)("withHooks", () => {
|
|
128
|
-
(0, _vitest.it)("should wrap plugin with onInit hook", () => {
|
|
129
|
-
const pm = new _plugin.PluginManager();
|
|
130
|
-
const flow = createMockFlowInstance();
|
|
131
|
-
pm.init(flow);
|
|
132
|
-
const onInit = _vitest.vi.fn();
|
|
133
|
-
const install = _vitest.vi.fn();
|
|
134
|
-
const hooks = {
|
|
135
|
-
onInit
|
|
136
|
-
};
|
|
137
|
-
const basePlugin = (0, _plugin.createPlugin)({
|
|
138
|
-
id: "hooks-test",
|
|
139
|
-
name: "HooksTest"
|
|
140
|
-
}, install);
|
|
141
|
-
const hookedPlugin = (0, _plugin.withHooks)(basePlugin, hooks);
|
|
142
|
-
hookedPlugin.install(flow);
|
|
143
|
-
(0, _vitest.expect)(onInit).toHaveBeenCalled();
|
|
144
|
-
});
|
|
145
|
-
(0, _vitest.it)("should register onViewportChange hook", () => {
|
|
146
|
-
const flow = createMockFlowInstance();
|
|
147
|
-
const onViewportChange = _vitest.vi.fn();
|
|
148
|
-
const basePlugin = (0, _plugin.createPlugin)({
|
|
149
|
-
id: "vp-hook",
|
|
150
|
-
name: "VpHook"
|
|
151
|
-
}, _vitest.vi.fn());
|
|
152
|
-
const hookedPlugin = (0, _plugin.withHooks)(basePlugin, {
|
|
153
|
-
onViewportChange
|
|
154
|
-
});
|
|
155
|
-
hookedPlugin.install(flow);
|
|
156
|
-
const onHandler = flow.on.mock.calls.find(call => call[0] === "viewport:change");
|
|
157
|
-
(0, _vitest.expect)(onHandler).toBeDefined();
|
|
158
|
-
const handler = onHandler[1];
|
|
159
|
-
handler({
|
|
160
|
-
transform: {
|
|
161
|
-
x: 100,
|
|
162
|
-
y: 200,
|
|
163
|
-
zoom: 2
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
(0, _vitest.expect)(onViewportChange).toHaveBeenCalledWith({
|
|
167
|
-
x: 100,
|
|
168
|
-
y: 200,
|
|
169
|
-
zoom: 2
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
(0, _vitest.it)("should register onNodesChange hook", () => {
|
|
173
|
-
const flow = createMockFlowInstance();
|
|
174
|
-
const onNodesChange = _vitest.vi.fn();
|
|
175
|
-
const basePlugin = (0, _plugin.createPlugin)({
|
|
176
|
-
id: "nodes-hook",
|
|
177
|
-
name: "NodesHook"
|
|
178
|
-
}, _vitest.vi.fn());
|
|
179
|
-
const hookedPlugin = (0, _plugin.withHooks)(basePlugin, {
|
|
180
|
-
onNodesChange
|
|
181
|
-
});
|
|
182
|
-
hookedPlugin.install(flow);
|
|
183
|
-
const onHandler = flow.on.mock.calls.find(call => call[0] === "node:selected");
|
|
184
|
-
(0, _vitest.expect)(onHandler).toBeDefined();
|
|
185
|
-
});
|
|
186
|
-
(0, _vitest.it)("should register onEdgesChange hook", () => {
|
|
187
|
-
const flow = createMockFlowInstance();
|
|
188
|
-
const onEdgesChange = _vitest.vi.fn();
|
|
189
|
-
const basePlugin = (0, _plugin.createPlugin)({
|
|
190
|
-
id: "edges-hook",
|
|
191
|
-
name: "EdgesHook"
|
|
192
|
-
}, _vitest.vi.fn());
|
|
193
|
-
const hookedPlugin = (0, _plugin.withHooks)(basePlugin, {
|
|
194
|
-
onEdgesChange
|
|
195
|
-
});
|
|
196
|
-
hookedPlugin.install(flow);
|
|
197
|
-
const onHandler = flow.on.mock.calls.find(call => call[0] === "edge:selected");
|
|
198
|
-
(0, _vitest.expect)(onHandler).toBeDefined();
|
|
199
|
-
});
|
|
200
|
-
(0, _vitest.it)("should call onDestroy when hooked plugin is destroyed", () => {
|
|
201
|
-
const flow = createMockFlowInstance();
|
|
202
|
-
const onDestroy = _vitest.vi.fn();
|
|
203
|
-
const baseDestroy = _vitest.vi.fn();
|
|
204
|
-
const basePlugin = (0, _plugin.createPlugin)({
|
|
205
|
-
id: "destroy-hook",
|
|
206
|
-
name: "DestroyHook"
|
|
207
|
-
}, _vitest.vi.fn());
|
|
208
|
-
basePlugin.destroy = baseDestroy;
|
|
209
|
-
const hookedPlugin = (0, _plugin.withHooks)(basePlugin, {
|
|
210
|
-
onDestroy
|
|
211
|
-
});
|
|
212
|
-
hookedPlugin.destroy();
|
|
213
|
-
(0, _vitest.expect)(onDestroy).toHaveBeenCalled();
|
|
214
|
-
(0, _vitest.expect)(baseDestroy).toHaveBeenCalled();
|
|
215
|
-
});
|
|
216
|
-
(0, _vitest.it)("should only register hooks that are provided", () => {
|
|
217
|
-
const flow = createMockFlowInstance();
|
|
218
|
-
const onInit = _vitest.vi.fn();
|
|
219
|
-
const hooks = {
|
|
220
|
-
onInit
|
|
221
|
-
};
|
|
222
|
-
const basePlugin = (0, _plugin.createPlugin)({
|
|
223
|
-
id: "partial-hooks",
|
|
224
|
-
name: "PartialHooks"
|
|
225
|
-
}, _vitest.vi.fn());
|
|
226
|
-
const hookedPlugin = (0, _plugin.withHooks)(basePlugin, hooks);
|
|
227
|
-
hookedPlugin.install(flow);
|
|
228
|
-
(0, _vitest.expect)(onInit).toHaveBeenCalled();
|
|
229
|
-
});
|
|
230
|
-
(0, _vitest.it)("should keep plugin metadata from base plugin", () => {
|
|
231
|
-
const basePlugin = (0, _plugin.createPlugin)({
|
|
232
|
-
id: "meta",
|
|
233
|
-
name: "Meta",
|
|
234
|
-
version: "1.0.0",
|
|
235
|
-
description: "Test plugin"
|
|
236
|
-
}, _vitest.vi.fn());
|
|
237
|
-
const hookedPlugin = (0, _plugin.withHooks)(basePlugin, {});
|
|
238
|
-
(0, _vitest.expect)(hookedPlugin.id).toBe("meta");
|
|
239
|
-
(0, _vitest.expect)(hookedPlugin.name).toBe("Meta");
|
|
240
|
-
(0, _vitest.expect)(hookedPlugin.version).toBe("1.0.0");
|
|
241
|
-
(0, _vitest.expect)(hookedPlugin.description).toBe("Test plugin");
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
(0, _vitest.describe)("createPlugin", () => {
|
|
245
|
-
(0, _vitest.it)("should create plugin with default enabled true", () => {
|
|
246
|
-
const installFn = _vitest.vi.fn();
|
|
247
|
-
const plugin = (0, _plugin.createPlugin)({
|
|
248
|
-
id: "default-enabled",
|
|
249
|
-
name: "DefaultEnabled"
|
|
250
|
-
}, installFn);
|
|
251
|
-
(0, _vitest.expect)(plugin.enabled).toBe(true);
|
|
252
|
-
});
|
|
253
|
-
(0, _vitest.it)("should create plugin with explicit enabled false", () => {
|
|
254
|
-
const installFn = _vitest.vi.fn();
|
|
255
|
-
const plugin = (0, _plugin.createPlugin)({
|
|
256
|
-
id: "explicit-disabled",
|
|
257
|
-
name: "ExplicitDisabled",
|
|
258
|
-
enabled: false
|
|
259
|
-
}, installFn);
|
|
260
|
-
(0, _vitest.expect)(plugin.enabled).toBe(false);
|
|
261
|
-
plugin.install(createMockFlowInstance());
|
|
262
|
-
(0, _vitest.expect)(installFn).not.toHaveBeenCalled();
|
|
263
|
-
});
|
|
264
|
-
(0, _vitest.it)("should pass options to install function", () => {
|
|
265
|
-
const installFn = _vitest.vi.fn();
|
|
266
|
-
const plugin = (0, _plugin.createPlugin)({
|
|
267
|
-
id: "opts-pass",
|
|
268
|
-
name: "OptsPass",
|
|
269
|
-
version: "2.0.0"
|
|
270
|
-
}, installFn);
|
|
271
|
-
const flow = createMockFlowInstance();
|
|
272
|
-
plugin.install(flow, {
|
|
273
|
-
customOption: true
|
|
274
|
-
});
|
|
275
|
-
(0, _vitest.expect)(installFn).toHaveBeenCalledWith(flow, {
|
|
276
|
-
id: "opts-pass",
|
|
277
|
-
name: "OptsPass",
|
|
278
|
-
version: "2.0.0"
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
(0, _vitest.describe)("getPlugins", () => {
|
|
283
|
-
(0, _vitest.it)("should return all registered plugins", () => {
|
|
284
|
-
const pm = new _plugin.PluginManager();
|
|
285
|
-
const flow = createMockFlowInstance();
|
|
286
|
-
pm.init(flow);
|
|
287
|
-
pm.register({
|
|
288
|
-
id: "p1",
|
|
289
|
-
name: "P1",
|
|
290
|
-
install: _vitest.vi.fn()
|
|
291
|
-
});
|
|
292
|
-
pm.register({
|
|
293
|
-
id: "p2",
|
|
294
|
-
name: "P2",
|
|
295
|
-
install: _vitest.vi.fn()
|
|
296
|
-
});
|
|
297
|
-
const plugins = pm.getPlugins();
|
|
298
|
-
(0, _vitest.expect)(plugins).toHaveLength(2);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|