@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,225 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { ref } from "vue";
|
|
3
|
-
import { PluginManager, createPlugin, withHooks } from "../plugins/plugin.mjs";
|
|
4
|
-
function createMockFlowInstance() {
|
|
5
|
-
const nodes = ref([]);
|
|
6
|
-
const edges = ref([]);
|
|
7
|
-
const viewport = ref({ x: 0, y: 0, zoom: 1 });
|
|
8
|
-
const draggingNodeId = ref(null);
|
|
9
|
-
return {
|
|
10
|
-
nodes,
|
|
11
|
-
edges,
|
|
12
|
-
viewport,
|
|
13
|
-
draggingNodeId,
|
|
14
|
-
addNode: vi.fn(),
|
|
15
|
-
removeNode: vi.fn(),
|
|
16
|
-
updateNode: vi.fn(),
|
|
17
|
-
getNode: vi.fn(),
|
|
18
|
-
addEdge: vi.fn(),
|
|
19
|
-
removeEdge: vi.fn(),
|
|
20
|
-
updateEdge: vi.fn(),
|
|
21
|
-
getEdge: vi.fn(),
|
|
22
|
-
setViewport: vi.fn(),
|
|
23
|
-
fitView: vi.fn(),
|
|
24
|
-
zoomIn: vi.fn(),
|
|
25
|
-
zoomOut: vi.fn(),
|
|
26
|
-
centerView: vi.fn(),
|
|
27
|
-
selectNode: vi.fn(),
|
|
28
|
-
selectEdge: vi.fn(),
|
|
29
|
-
clearSelection: vi.fn(),
|
|
30
|
-
getNodes: vi.fn(() => nodes.value),
|
|
31
|
-
getEdges: vi.fn(() => edges.value),
|
|
32
|
-
getViewport: vi.fn(() => viewport.value),
|
|
33
|
-
screenToCanvas: vi.fn(),
|
|
34
|
-
canvasToScreen: vi.fn(),
|
|
35
|
-
on: vi.fn(),
|
|
36
|
-
off: vi.fn(),
|
|
37
|
-
emit: vi.fn(),
|
|
38
|
-
isValidConnection: vi.fn(() => true),
|
|
39
|
-
$el: void 0,
|
|
40
|
-
usePlugin: vi.fn(),
|
|
41
|
-
removePlugin: vi.fn()
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
describe("flow/plugins/plugin - withHooks", () => {
|
|
45
|
-
let consoleLogSpy;
|
|
46
|
-
let consoleWarnSpy;
|
|
47
|
-
let consoleErrorSpy;
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
|
|
50
|
-
});
|
|
51
|
-
consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {
|
|
52
|
-
});
|
|
53
|
-
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
afterEach(() => {
|
|
57
|
-
consoleLogSpy.mockRestore();
|
|
58
|
-
consoleWarnSpy.mockRestore();
|
|
59
|
-
consoleErrorSpy.mockRestore();
|
|
60
|
-
});
|
|
61
|
-
describe("PluginManager - edge cases", () => {
|
|
62
|
-
it("should warn when unregistering non-existent plugin", () => {
|
|
63
|
-
const pm = new PluginManager();
|
|
64
|
-
pm.unregister("non-existent");
|
|
65
|
-
expect(consoleWarnSpy).toHaveBeenCalledWith("[YhFlow] Plugin non-existent not found");
|
|
66
|
-
});
|
|
67
|
-
it("should warn when registering without init and no options", () => {
|
|
68
|
-
const pm = new PluginManager();
|
|
69
|
-
const install = vi.fn();
|
|
70
|
-
pm.register({ id: "n", name: "N", install });
|
|
71
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
72
|
-
"[YhFlow] PluginManager not initialized, call init() first or provide flow instance"
|
|
73
|
-
);
|
|
74
|
-
expect(install).not.toHaveBeenCalled();
|
|
75
|
-
});
|
|
76
|
-
it("should register with options as flow instance fallback", () => {
|
|
77
|
-
const pm = new PluginManager();
|
|
78
|
-
const flow = createMockFlowInstance();
|
|
79
|
-
const install = vi.fn();
|
|
80
|
-
pm.register({ id: "fallback", name: "Fallback", install }, flow);
|
|
81
|
-
expect(install).toHaveBeenCalledWith(flow, flow);
|
|
82
|
-
});
|
|
83
|
-
it("should log when plugin is registered", () => {
|
|
84
|
-
const pm = new PluginManager();
|
|
85
|
-
const flow = createMockFlowInstance();
|
|
86
|
-
pm.init(flow);
|
|
87
|
-
pm.register({ id: "log-test", name: "LogTest", install: vi.fn() });
|
|
88
|
-
expect(consoleLogSpy).toHaveBeenCalledWith("[YhFlow] Plugin LogTest (log-test) registered");
|
|
89
|
-
});
|
|
90
|
-
it("should log when plugin is unregistered", () => {
|
|
91
|
-
const pm = new PluginManager();
|
|
92
|
-
const flow = createMockFlowInstance();
|
|
93
|
-
pm.init(flow);
|
|
94
|
-
pm.register({ id: "ul", name: "UL", install: vi.fn() });
|
|
95
|
-
pm.unregister("ul");
|
|
96
|
-
expect(consoleLogSpy).toHaveBeenCalledWith("[YhFlow] Plugin UL (ul) unregistered");
|
|
97
|
-
});
|
|
98
|
-
it("should not call destroy if plugin has no destroy method", () => {
|
|
99
|
-
const pm = new PluginManager();
|
|
100
|
-
const flow = createMockFlowInstance();
|
|
101
|
-
pm.init(flow);
|
|
102
|
-
pm.register({ id: "no-destroy", name: "NoDestroy", install: vi.fn() });
|
|
103
|
-
expect(() => pm.unregister("no-destroy")).not.toThrow();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe("withHooks", () => {
|
|
107
|
-
it("should wrap plugin with onInit hook", () => {
|
|
108
|
-
const pm = new PluginManager();
|
|
109
|
-
const flow = createMockFlowInstance();
|
|
110
|
-
pm.init(flow);
|
|
111
|
-
const onInit = vi.fn();
|
|
112
|
-
const install = vi.fn();
|
|
113
|
-
const hooks = { onInit };
|
|
114
|
-
const basePlugin = createPlugin({ id: "hooks-test", name: "HooksTest" }, install);
|
|
115
|
-
const hookedPlugin = withHooks(basePlugin, hooks);
|
|
116
|
-
hookedPlugin.install(flow);
|
|
117
|
-
expect(onInit).toHaveBeenCalled();
|
|
118
|
-
});
|
|
119
|
-
it("should register onViewportChange hook", () => {
|
|
120
|
-
const flow = createMockFlowInstance();
|
|
121
|
-
const onViewportChange = vi.fn();
|
|
122
|
-
const basePlugin = createPlugin({ id: "vp-hook", name: "VpHook" }, vi.fn());
|
|
123
|
-
const hookedPlugin = withHooks(basePlugin, { onViewportChange });
|
|
124
|
-
hookedPlugin.install(flow);
|
|
125
|
-
const onHandler = flow.on.mock.calls.find(
|
|
126
|
-
(call) => call[0] === "viewport:change"
|
|
127
|
-
);
|
|
128
|
-
expect(onHandler).toBeDefined();
|
|
129
|
-
const handler = onHandler[1];
|
|
130
|
-
handler({ transform: { x: 100, y: 200, zoom: 2 } });
|
|
131
|
-
expect(onViewportChange).toHaveBeenCalledWith({ x: 100, y: 200, zoom: 2 });
|
|
132
|
-
});
|
|
133
|
-
it("should register onNodesChange hook", () => {
|
|
134
|
-
const flow = createMockFlowInstance();
|
|
135
|
-
const onNodesChange = vi.fn();
|
|
136
|
-
const basePlugin = createPlugin({ id: "nodes-hook", name: "NodesHook" }, vi.fn());
|
|
137
|
-
const hookedPlugin = withHooks(basePlugin, { onNodesChange });
|
|
138
|
-
hookedPlugin.install(flow);
|
|
139
|
-
const onHandler = flow.on.mock.calls.find(
|
|
140
|
-
(call) => call[0] === "node:selected"
|
|
141
|
-
);
|
|
142
|
-
expect(onHandler).toBeDefined();
|
|
143
|
-
});
|
|
144
|
-
it("should register onEdgesChange hook", () => {
|
|
145
|
-
const flow = createMockFlowInstance();
|
|
146
|
-
const onEdgesChange = vi.fn();
|
|
147
|
-
const basePlugin = createPlugin({ id: "edges-hook", name: "EdgesHook" }, vi.fn());
|
|
148
|
-
const hookedPlugin = withHooks(basePlugin, { onEdgesChange });
|
|
149
|
-
hookedPlugin.install(flow);
|
|
150
|
-
const onHandler = flow.on.mock.calls.find(
|
|
151
|
-
(call) => call[0] === "edge:selected"
|
|
152
|
-
);
|
|
153
|
-
expect(onHandler).toBeDefined();
|
|
154
|
-
});
|
|
155
|
-
it("should call onDestroy when hooked plugin is destroyed", () => {
|
|
156
|
-
const flow = createMockFlowInstance();
|
|
157
|
-
const onDestroy = vi.fn();
|
|
158
|
-
const baseDestroy = vi.fn();
|
|
159
|
-
const basePlugin = createPlugin({ id: "destroy-hook", name: "DestroyHook" }, vi.fn());
|
|
160
|
-
basePlugin.destroy = baseDestroy;
|
|
161
|
-
const hookedPlugin = withHooks(basePlugin, { onDestroy });
|
|
162
|
-
hookedPlugin.destroy();
|
|
163
|
-
expect(onDestroy).toHaveBeenCalled();
|
|
164
|
-
expect(baseDestroy).toHaveBeenCalled();
|
|
165
|
-
});
|
|
166
|
-
it("should only register hooks that are provided", () => {
|
|
167
|
-
const flow = createMockFlowInstance();
|
|
168
|
-
const onInit = vi.fn();
|
|
169
|
-
const hooks = { onInit };
|
|
170
|
-
const basePlugin = createPlugin({ id: "partial-hooks", name: "PartialHooks" }, vi.fn());
|
|
171
|
-
const hookedPlugin = withHooks(basePlugin, hooks);
|
|
172
|
-
hookedPlugin.install(flow);
|
|
173
|
-
expect(onInit).toHaveBeenCalled();
|
|
174
|
-
});
|
|
175
|
-
it("should keep plugin metadata from base plugin", () => {
|
|
176
|
-
const basePlugin = createPlugin(
|
|
177
|
-
{ id: "meta", name: "Meta", version: "1.0.0", description: "Test plugin" },
|
|
178
|
-
vi.fn()
|
|
179
|
-
);
|
|
180
|
-
const hookedPlugin = withHooks(basePlugin, {});
|
|
181
|
-
expect(hookedPlugin.id).toBe("meta");
|
|
182
|
-
expect(hookedPlugin.name).toBe("Meta");
|
|
183
|
-
expect(hookedPlugin.version).toBe("1.0.0");
|
|
184
|
-
expect(hookedPlugin.description).toBe("Test plugin");
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
describe("createPlugin", () => {
|
|
188
|
-
it("should create plugin with default enabled true", () => {
|
|
189
|
-
const installFn = vi.fn();
|
|
190
|
-
const plugin = createPlugin({ id: "default-enabled", name: "DefaultEnabled" }, installFn);
|
|
191
|
-
expect(plugin.enabled).toBe(true);
|
|
192
|
-
});
|
|
193
|
-
it("should create plugin with explicit enabled false", () => {
|
|
194
|
-
const installFn = vi.fn();
|
|
195
|
-
const plugin = createPlugin(
|
|
196
|
-
{ id: "explicit-disabled", name: "ExplicitDisabled", enabled: false },
|
|
197
|
-
installFn
|
|
198
|
-
);
|
|
199
|
-
expect(plugin.enabled).toBe(false);
|
|
200
|
-
plugin.install(createMockFlowInstance());
|
|
201
|
-
expect(installFn).not.toHaveBeenCalled();
|
|
202
|
-
});
|
|
203
|
-
it("should pass options to install function", () => {
|
|
204
|
-
const installFn = vi.fn();
|
|
205
|
-
const plugin = createPlugin(
|
|
206
|
-
{ id: "opts-pass", name: "OptsPass", version: "2.0.0" },
|
|
207
|
-
installFn
|
|
208
|
-
);
|
|
209
|
-
const flow = createMockFlowInstance();
|
|
210
|
-
plugin.install(flow, { customOption: true });
|
|
211
|
-
expect(installFn).toHaveBeenCalledWith(flow, { id: "opts-pass", name: "OptsPass", version: "2.0.0" });
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
describe("getPlugins", () => {
|
|
215
|
-
it("should return all registered plugins", () => {
|
|
216
|
-
const pm = new PluginManager();
|
|
217
|
-
const flow = createMockFlowInstance();
|
|
218
|
-
pm.init(flow);
|
|
219
|
-
pm.register({ id: "p1", name: "P1", install: vi.fn() });
|
|
220
|
-
pm.register({ id: "p2", name: "P2", install: vi.fn() });
|
|
221
|
-
const plugins = pm.getPlugins();
|
|
222
|
-
expect(plugins).toHaveLength(2);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
});
|
|
@@ -1,151 +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(node => {
|
|
21
|
-
nodes.value = [...nodes.value, node];
|
|
22
|
-
}),
|
|
23
|
-
removeNode: _vitest.vi.fn(),
|
|
24
|
-
updateNode: _vitest.vi.fn(),
|
|
25
|
-
getNode: _vitest.vi.fn(id => nodes.value.find(n => n.id === id)),
|
|
26
|
-
addEdge: _vitest.vi.fn(),
|
|
27
|
-
removeEdge: _vitest.vi.fn(),
|
|
28
|
-
updateEdge: _vitest.vi.fn(),
|
|
29
|
-
getEdge: _vitest.vi.fn(),
|
|
30
|
-
setViewport: _vitest.vi.fn(),
|
|
31
|
-
fitView: _vitest.vi.fn(),
|
|
32
|
-
zoomIn: _vitest.vi.fn(),
|
|
33
|
-
zoomOut: _vitest.vi.fn(),
|
|
34
|
-
centerView: _vitest.vi.fn(),
|
|
35
|
-
selectNode: _vitest.vi.fn(),
|
|
36
|
-
selectEdge: _vitest.vi.fn(),
|
|
37
|
-
clearSelection: _vitest.vi.fn(),
|
|
38
|
-
getNodes: _vitest.vi.fn(() => nodes.value),
|
|
39
|
-
getEdges: _vitest.vi.fn(() => edges.value),
|
|
40
|
-
getViewport: _vitest.vi.fn(() => viewport.value),
|
|
41
|
-
screenToCanvas: _vitest.vi.fn((x, y) => ({
|
|
42
|
-
x,
|
|
43
|
-
y
|
|
44
|
-
})),
|
|
45
|
-
canvasToScreen: _vitest.vi.fn((x, y) => ({
|
|
46
|
-
x,
|
|
47
|
-
y
|
|
48
|
-
})),
|
|
49
|
-
on: _vitest.vi.fn(),
|
|
50
|
-
off: _vitest.vi.fn(),
|
|
51
|
-
emit: _vitest.vi.fn(),
|
|
52
|
-
isValidConnection: _vitest.vi.fn(() => true),
|
|
53
|
-
$el: void 0,
|
|
54
|
-
usePlugin: _vitest.vi.fn(),
|
|
55
|
-
removePlugin: _vitest.vi.fn()
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
(0, _vitest.describe)("flow/plugins/plugin", () => {
|
|
59
|
-
(0, _vitest.it)("PluginManager should register and unregister plugin", () => {
|
|
60
|
-
const flow = createMockFlowInstance();
|
|
61
|
-
const pm = new _plugin.PluginManager();
|
|
62
|
-
pm.init(flow);
|
|
63
|
-
const install = _vitest.vi.fn();
|
|
64
|
-
const plugin = {
|
|
65
|
-
id: "test-plugin",
|
|
66
|
-
name: "Test",
|
|
67
|
-
install
|
|
68
|
-
};
|
|
69
|
-
pm.register(plugin);
|
|
70
|
-
(0, _vitest.expect)(install).toHaveBeenCalledWith(flow, void 0);
|
|
71
|
-
(0, _vitest.expect)(pm.hasPlugin("test-plugin")).toBe(true);
|
|
72
|
-
(0, _vitest.expect)(pm.getPlugin("test-plugin")).toBe(plugin);
|
|
73
|
-
pm.unregister("test-plugin");
|
|
74
|
-
(0, _vitest.expect)(pm.hasPlugin("test-plugin")).toBe(false);
|
|
75
|
-
(0, _vitest.expect)(pm.getPlugin("test-plugin")).toBeUndefined();
|
|
76
|
-
});
|
|
77
|
-
(0, _vitest.it)("PluginManager should call destroy on unregister", () => {
|
|
78
|
-
const flow = createMockFlowInstance();
|
|
79
|
-
const pm = new _plugin.PluginManager();
|
|
80
|
-
pm.init(flow);
|
|
81
|
-
const destroy = _vitest.vi.fn();
|
|
82
|
-
pm.register({
|
|
83
|
-
id: "d",
|
|
84
|
-
name: "D",
|
|
85
|
-
install: _vitest.vi.fn(),
|
|
86
|
-
destroy
|
|
87
|
-
});
|
|
88
|
-
pm.unregister("d");
|
|
89
|
-
(0, _vitest.expect)(destroy).toHaveBeenCalledTimes(1);
|
|
90
|
-
});
|
|
91
|
-
(0, _vitest.it)("PluginManager should not register same id twice", () => {
|
|
92
|
-
const flow = createMockFlowInstance();
|
|
93
|
-
const pm = new _plugin.PluginManager();
|
|
94
|
-
pm.init(flow);
|
|
95
|
-
const install = _vitest.vi.fn();
|
|
96
|
-
const plugin = {
|
|
97
|
-
id: "dup",
|
|
98
|
-
name: "Dup",
|
|
99
|
-
install
|
|
100
|
-
};
|
|
101
|
-
pm.register(plugin);
|
|
102
|
-
pm.register(plugin);
|
|
103
|
-
(0, _vitest.expect)(install).toHaveBeenCalledTimes(1);
|
|
104
|
-
});
|
|
105
|
-
(0, _vitest.it)("createPlugin should produce plugin with install", () => {
|
|
106
|
-
const flow = createMockFlowInstance();
|
|
107
|
-
const installFn = _vitest.vi.fn();
|
|
108
|
-
const plugin = (0, _plugin.createPlugin)({
|
|
109
|
-
id: "factory",
|
|
110
|
-
name: "Factory"
|
|
111
|
-
}, installFn);
|
|
112
|
-
(0, _vitest.expect)(plugin.id).toBe("factory");
|
|
113
|
-
(0, _vitest.expect)(plugin.name).toBe("Factory");
|
|
114
|
-
plugin.install(flow);
|
|
115
|
-
(0, _vitest.expect)(installFn).toHaveBeenCalledWith(flow, {
|
|
116
|
-
id: "factory",
|
|
117
|
-
name: "Factory"
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
(0, _vitest.it)("createPlugin with enabled false should not call install", () => {
|
|
121
|
-
const flow = createMockFlowInstance();
|
|
122
|
-
const installFn = _vitest.vi.fn();
|
|
123
|
-
const plugin = (0, _plugin.createPlugin)({
|
|
124
|
-
id: "disabled",
|
|
125
|
-
name: "Disabled",
|
|
126
|
-
enabled: false
|
|
127
|
-
}, installFn);
|
|
128
|
-
plugin.install(flow);
|
|
129
|
-
(0, _vitest.expect)(installFn).not.toHaveBeenCalled();
|
|
130
|
-
});
|
|
131
|
-
(0, _vitest.it)("destroyAll should clear all and call destroy", () => {
|
|
132
|
-
const flow = createMockFlowInstance();
|
|
133
|
-
const pm = new _plugin.PluginManager();
|
|
134
|
-
pm.init(flow);
|
|
135
|
-
const destroy = _vitest.vi.fn();
|
|
136
|
-
pm.register({
|
|
137
|
-
id: "a",
|
|
138
|
-
name: "A",
|
|
139
|
-
install: _vitest.vi.fn(),
|
|
140
|
-
destroy
|
|
141
|
-
});
|
|
142
|
-
pm.register({
|
|
143
|
-
id: "b",
|
|
144
|
-
name: "B",
|
|
145
|
-
install: _vitest.vi.fn()
|
|
146
|
-
});
|
|
147
|
-
pm.destroyAll();
|
|
148
|
-
(0, _vitest.expect)(destroy).toHaveBeenCalledTimes(1);
|
|
149
|
-
(0, _vitest.expect)(pm.getPlugins()).toHaveLength(0);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { ref } from "vue";
|
|
3
|
-
import { PluginManager, createPlugin } from "../plugins/plugin.mjs";
|
|
4
|
-
function createMockFlowInstance() {
|
|
5
|
-
const nodes = ref([]);
|
|
6
|
-
const edges = ref([]);
|
|
7
|
-
const viewport = ref({ x: 0, y: 0, zoom: 1 });
|
|
8
|
-
const draggingNodeId = ref(null);
|
|
9
|
-
return {
|
|
10
|
-
nodes,
|
|
11
|
-
edges,
|
|
12
|
-
viewport,
|
|
13
|
-
draggingNodeId,
|
|
14
|
-
addNode: vi.fn((node) => {
|
|
15
|
-
nodes.value = [...nodes.value, node];
|
|
16
|
-
}),
|
|
17
|
-
removeNode: vi.fn(),
|
|
18
|
-
updateNode: vi.fn(),
|
|
19
|
-
getNode: vi.fn((id) => nodes.value.find((n) => n.id === id)),
|
|
20
|
-
addEdge: vi.fn(),
|
|
21
|
-
removeEdge: vi.fn(),
|
|
22
|
-
updateEdge: vi.fn(),
|
|
23
|
-
getEdge: vi.fn(),
|
|
24
|
-
setViewport: vi.fn(),
|
|
25
|
-
fitView: vi.fn(),
|
|
26
|
-
zoomIn: vi.fn(),
|
|
27
|
-
zoomOut: vi.fn(),
|
|
28
|
-
centerView: vi.fn(),
|
|
29
|
-
selectNode: vi.fn(),
|
|
30
|
-
selectEdge: vi.fn(),
|
|
31
|
-
clearSelection: vi.fn(),
|
|
32
|
-
getNodes: vi.fn(() => nodes.value),
|
|
33
|
-
getEdges: vi.fn(() => edges.value),
|
|
34
|
-
getViewport: vi.fn(() => viewport.value),
|
|
35
|
-
screenToCanvas: vi.fn((x, y) => ({ x, y })),
|
|
36
|
-
canvasToScreen: vi.fn((x, y) => ({ x, y })),
|
|
37
|
-
on: vi.fn(),
|
|
38
|
-
off: vi.fn(),
|
|
39
|
-
emit: vi.fn(),
|
|
40
|
-
isValidConnection: vi.fn(() => true),
|
|
41
|
-
$el: void 0,
|
|
42
|
-
usePlugin: vi.fn(),
|
|
43
|
-
removePlugin: vi.fn()
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
describe("flow/plugins/plugin", () => {
|
|
47
|
-
it("PluginManager should register and unregister plugin", () => {
|
|
48
|
-
const flow = createMockFlowInstance();
|
|
49
|
-
const pm = new PluginManager();
|
|
50
|
-
pm.init(flow);
|
|
51
|
-
const install = vi.fn();
|
|
52
|
-
const plugin = {
|
|
53
|
-
id: "test-plugin",
|
|
54
|
-
name: "Test",
|
|
55
|
-
install
|
|
56
|
-
};
|
|
57
|
-
pm.register(plugin);
|
|
58
|
-
expect(install).toHaveBeenCalledWith(flow, void 0);
|
|
59
|
-
expect(pm.hasPlugin("test-plugin")).toBe(true);
|
|
60
|
-
expect(pm.getPlugin("test-plugin")).toBe(plugin);
|
|
61
|
-
pm.unregister("test-plugin");
|
|
62
|
-
expect(pm.hasPlugin("test-plugin")).toBe(false);
|
|
63
|
-
expect(pm.getPlugin("test-plugin")).toBeUndefined();
|
|
64
|
-
});
|
|
65
|
-
it("PluginManager should call destroy on unregister", () => {
|
|
66
|
-
const flow = createMockFlowInstance();
|
|
67
|
-
const pm = new PluginManager();
|
|
68
|
-
pm.init(flow);
|
|
69
|
-
const destroy = vi.fn();
|
|
70
|
-
pm.register({
|
|
71
|
-
id: "d",
|
|
72
|
-
name: "D",
|
|
73
|
-
install: vi.fn(),
|
|
74
|
-
destroy
|
|
75
|
-
});
|
|
76
|
-
pm.unregister("d");
|
|
77
|
-
expect(destroy).toHaveBeenCalledTimes(1);
|
|
78
|
-
});
|
|
79
|
-
it("PluginManager should not register same id twice", () => {
|
|
80
|
-
const flow = createMockFlowInstance();
|
|
81
|
-
const pm = new PluginManager();
|
|
82
|
-
pm.init(flow);
|
|
83
|
-
const install = vi.fn();
|
|
84
|
-
const plugin = { id: "dup", name: "Dup", install };
|
|
85
|
-
pm.register(plugin);
|
|
86
|
-
pm.register(plugin);
|
|
87
|
-
expect(install).toHaveBeenCalledTimes(1);
|
|
88
|
-
});
|
|
89
|
-
it("createPlugin should produce plugin with install", () => {
|
|
90
|
-
const flow = createMockFlowInstance();
|
|
91
|
-
const installFn = vi.fn();
|
|
92
|
-
const plugin = createPlugin({ id: "factory", name: "Factory" }, installFn);
|
|
93
|
-
expect(plugin.id).toBe("factory");
|
|
94
|
-
expect(plugin.name).toBe("Factory");
|
|
95
|
-
plugin.install(flow);
|
|
96
|
-
expect(installFn).toHaveBeenCalledWith(flow, { id: "factory", name: "Factory" });
|
|
97
|
-
});
|
|
98
|
-
it("createPlugin with enabled false should not call install", () => {
|
|
99
|
-
const flow = createMockFlowInstance();
|
|
100
|
-
const installFn = vi.fn();
|
|
101
|
-
const plugin = createPlugin({ id: "disabled", name: "Disabled", enabled: false }, installFn);
|
|
102
|
-
plugin.install(flow);
|
|
103
|
-
expect(installFn).not.toHaveBeenCalled();
|
|
104
|
-
});
|
|
105
|
-
it("destroyAll should clear all and call destroy", () => {
|
|
106
|
-
const flow = createMockFlowInstance();
|
|
107
|
-
const pm = new PluginManager();
|
|
108
|
-
pm.init(flow);
|
|
109
|
-
const destroy = vi.fn();
|
|
110
|
-
pm.register({ id: "a", name: "A", install: vi.fn(), destroy });
|
|
111
|
-
pm.register({ id: "b", name: "B", install: vi.fn() });
|
|
112
|
-
pm.destroyAll();
|
|
113
|
-
expect(destroy).toHaveBeenCalledTimes(1);
|
|
114
|
-
expect(pm.getPlugins()).toHaveLength(0);
|
|
115
|
-
});
|
|
116
|
-
});
|