@yh-ui/flow 1.0.25 → 1.0.30
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 +13 -11
- package/LICENSE +0 -21
- 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,233 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _vitest = require("vitest");
|
|
4
|
-
var _vue = require("vue");
|
|
5
|
-
var _layout = require("../plugins/plugins/layout.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
|
-
function createMockNode(id, type = "default") {
|
|
51
|
-
return {
|
|
52
|
-
id,
|
|
53
|
-
type,
|
|
54
|
-
position: {
|
|
55
|
-
x: 0,
|
|
56
|
-
y: 0
|
|
57
|
-
},
|
|
58
|
-
width: 100,
|
|
59
|
-
height: 50,
|
|
60
|
-
data: {},
|
|
61
|
-
selected: false,
|
|
62
|
-
dragging: false
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function createMockEdge(id, source, target) {
|
|
66
|
-
return {
|
|
67
|
-
id,
|
|
68
|
-
source,
|
|
69
|
-
target,
|
|
70
|
-
type: "smoothstep",
|
|
71
|
-
selected: false,
|
|
72
|
-
animated: false
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
(0, _vitest.describe)("flow/plugins/plugins/layout", () => {
|
|
76
|
-
let consoleLogSpy;
|
|
77
|
-
let consoleWarnSpy;
|
|
78
|
-
let consoleErrorSpy;
|
|
79
|
-
(0, _vitest.beforeEach)(() => {
|
|
80
|
-
consoleLogSpy = _vitest.vi.spyOn(console, "log").mockImplementation(() => {});
|
|
81
|
-
consoleWarnSpy = _vitest.vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
82
|
-
consoleErrorSpy = _vitest.vi.spyOn(console, "error").mockImplementation(() => {});
|
|
83
|
-
});
|
|
84
|
-
(0, _vitest.afterEach)(() => {
|
|
85
|
-
consoleLogSpy.mockRestore();
|
|
86
|
-
consoleWarnSpy.mockRestore();
|
|
87
|
-
consoleErrorSpy.mockRestore();
|
|
88
|
-
_vitest.vi.restoreAllMocks();
|
|
89
|
-
});
|
|
90
|
-
(0, _vitest.describe)("createLayoutPlugin", () => {
|
|
91
|
-
(0, _vitest.it)("should create plugin with correct id and name", () => {
|
|
92
|
-
const plugin = (0, _layout.createLayoutPlugin)();
|
|
93
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
94
|
-
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
95
|
-
(0, _vitest.expect)(plugin.version).toBe("1.0.0");
|
|
96
|
-
});
|
|
97
|
-
(0, _vitest.it)("should install without crashing", () => {
|
|
98
|
-
const flow = createMockFlowInstance();
|
|
99
|
-
const plugin = (0, _layout.createLayoutPlugin)();
|
|
100
|
-
plugin.install(flow);
|
|
101
|
-
(0, _vitest.expect)(flow.applyLayout).toBeDefined();
|
|
102
|
-
});
|
|
103
|
-
(0, _vitest.it)("should not install applyLayout when enabled is false", () => {
|
|
104
|
-
const flow = createMockFlowInstance();
|
|
105
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
106
|
-
enabled: false
|
|
107
|
-
});
|
|
108
|
-
plugin.install(flow);
|
|
109
|
-
(0, _vitest.expect)(flow.applyLayout).toBeUndefined();
|
|
110
|
-
});
|
|
111
|
-
(0, _vitest.it)("should use default layout options", () => {
|
|
112
|
-
const plugin = (0, _layout.createLayoutPlugin)();
|
|
113
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
114
|
-
});
|
|
115
|
-
(0, _vitest.it)("should merge custom options", () => {
|
|
116
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
117
|
-
type: "grid",
|
|
118
|
-
direction: "LR",
|
|
119
|
-
nodeSpacing: 100,
|
|
120
|
-
rankSpacing: 200,
|
|
121
|
-
animate: false
|
|
122
|
-
});
|
|
123
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
124
|
-
});
|
|
125
|
-
(0, _vitest.it)("should support all layout types", () => {
|
|
126
|
-
const types = ["dagre", "elk", "force", "grid"];
|
|
127
|
-
for (const type of types) {
|
|
128
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
129
|
-
type
|
|
130
|
-
});
|
|
131
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
(0, _vitest.it)("should support all directions", () => {
|
|
135
|
-
const directions = ["TB", "BT", "LR", "RL"];
|
|
136
|
-
for (const direction of directions) {
|
|
137
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
138
|
-
direction
|
|
139
|
-
});
|
|
140
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
(0, _vitest.it)("should support elk options", () => {
|
|
144
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
145
|
-
type: "elk",
|
|
146
|
-
elkOptions: {
|
|
147
|
-
algorithm: "layered",
|
|
148
|
-
direction: "DOWN",
|
|
149
|
-
spacing: 50,
|
|
150
|
-
edgeRouting: "POLYLINE"
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
154
|
-
});
|
|
155
|
-
(0, _vitest.it)("should support force options", () => {
|
|
156
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
157
|
-
type: "force",
|
|
158
|
-
forceOptions: {
|
|
159
|
-
strength: -500,
|
|
160
|
-
distance: 150,
|
|
161
|
-
theta: 0.5,
|
|
162
|
-
iterations: 500
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
166
|
-
});
|
|
167
|
-
(0, _vitest.it)("should support grid options", () => {
|
|
168
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
169
|
-
type: "grid",
|
|
170
|
-
gridOptions: {
|
|
171
|
-
columns: 6,
|
|
172
|
-
startX: 100,
|
|
173
|
-
startY: 100
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
(0, _vitest.describe)("applyLayout with grid", () => {
|
|
180
|
-
(0, _vitest.it)("should apply grid layout", async () => {
|
|
181
|
-
const flow = createMockFlowInstance();
|
|
182
|
-
flow.nodes.value = [createMockNode("n1"), createMockNode("n2"), createMockNode("n3"), createMockNode("n4")];
|
|
183
|
-
flow.edges.value = [createMockEdge("e1", "n1", "n2"), createMockEdge("e2", "n2", "n3")];
|
|
184
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
185
|
-
type: "grid",
|
|
186
|
-
animate: false
|
|
187
|
-
});
|
|
188
|
-
plugin.install(flow);
|
|
189
|
-
await flow.applyLayout({
|
|
190
|
-
type: "grid",
|
|
191
|
-
gridOptions: {
|
|
192
|
-
columns: 2
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
(0, _vitest.expect)(flow.updateNode).toHaveBeenCalled();
|
|
196
|
-
(0, _vitest.expect)(consoleLogSpy).toHaveBeenCalledWith("[Layout Plugin] Grid layout applied successfully");
|
|
197
|
-
});
|
|
198
|
-
(0, _vitest.it)("should warn for unknown layout type", async () => {
|
|
199
|
-
const flow = createMockFlowInstance();
|
|
200
|
-
flow.nodes.value = [createMockNode("n1")];
|
|
201
|
-
const plugin = (0, _layout.createLayoutPlugin)();
|
|
202
|
-
plugin.install(flow);
|
|
203
|
-
await flow.applyLayout({
|
|
204
|
-
type: "unknown"
|
|
205
|
-
});
|
|
206
|
-
(0, _vitest.expect)(consoleWarnSpy).toHaveBeenCalledWith(_vitest.expect.stringContaining("Unknown layout type"));
|
|
207
|
-
});
|
|
208
|
-
(0, _vitest.it)("should handle layout with empty nodes", async () => {
|
|
209
|
-
const flow = createMockFlowInstance();
|
|
210
|
-
flow.nodes.value = [];
|
|
211
|
-
flow.edges.value = [];
|
|
212
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
213
|
-
type: "grid"
|
|
214
|
-
});
|
|
215
|
-
plugin.install(flow);
|
|
216
|
-
await flow.applyLayout();
|
|
217
|
-
(0, _vitest.expect)(flow.updateNode).not.toHaveBeenCalled();
|
|
218
|
-
});
|
|
219
|
-
(0, _vitest.it)("should use override options from applyLayout call", async () => {
|
|
220
|
-
const flow = createMockFlowInstance();
|
|
221
|
-
flow.nodes.value = [createMockNode("n1")];
|
|
222
|
-
flow.edges.value = [];
|
|
223
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
224
|
-
type: "grid"
|
|
225
|
-
});
|
|
226
|
-
plugin.install(flow);
|
|
227
|
-
await flow.applyLayout({
|
|
228
|
-
direction: "LR"
|
|
229
|
-
});
|
|
230
|
-
(0, _vitest.expect)(flow.updateNode).toHaveBeenCalled();
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { ref } from "vue";
|
|
3
|
-
import { createLayoutPlugin } from "../plugins/plugins/layout.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
|
-
function createMockNode(id, type = "default") {
|
|
45
|
-
return {
|
|
46
|
-
id,
|
|
47
|
-
type,
|
|
48
|
-
position: { x: 0, y: 0 },
|
|
49
|
-
width: 100,
|
|
50
|
-
height: 50,
|
|
51
|
-
data: {},
|
|
52
|
-
selected: false,
|
|
53
|
-
dragging: false
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function createMockEdge(id, source, target) {
|
|
57
|
-
return {
|
|
58
|
-
id,
|
|
59
|
-
source,
|
|
60
|
-
target,
|
|
61
|
-
type: "smoothstep",
|
|
62
|
-
selected: false,
|
|
63
|
-
animated: false
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
describe("flow/plugins/plugins/layout", () => {
|
|
67
|
-
let consoleLogSpy;
|
|
68
|
-
let consoleWarnSpy;
|
|
69
|
-
let consoleErrorSpy;
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
|
|
72
|
-
});
|
|
73
|
-
consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {
|
|
74
|
-
});
|
|
75
|
-
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
consoleLogSpy.mockRestore();
|
|
80
|
-
consoleWarnSpy.mockRestore();
|
|
81
|
-
consoleErrorSpy.mockRestore();
|
|
82
|
-
vi.restoreAllMocks();
|
|
83
|
-
});
|
|
84
|
-
describe("createLayoutPlugin", () => {
|
|
85
|
-
it("should create plugin with correct id and name", () => {
|
|
86
|
-
const plugin = createLayoutPlugin();
|
|
87
|
-
expect(plugin.id).toBe("layout");
|
|
88
|
-
expect(plugin.name).toBe("Layout");
|
|
89
|
-
expect(plugin.version).toBe("1.0.0");
|
|
90
|
-
});
|
|
91
|
-
it("should install without crashing", () => {
|
|
92
|
-
const flow = createMockFlowInstance();
|
|
93
|
-
const plugin = createLayoutPlugin();
|
|
94
|
-
plugin.install(flow);
|
|
95
|
-
expect(flow.applyLayout).toBeDefined();
|
|
96
|
-
});
|
|
97
|
-
it("should not install applyLayout when enabled is false", () => {
|
|
98
|
-
const flow = createMockFlowInstance();
|
|
99
|
-
const plugin = createLayoutPlugin({ enabled: false });
|
|
100
|
-
plugin.install(flow);
|
|
101
|
-
expect(flow.applyLayout).toBeUndefined();
|
|
102
|
-
});
|
|
103
|
-
it("should use default layout options", () => {
|
|
104
|
-
const plugin = createLayoutPlugin();
|
|
105
|
-
expect(plugin.id).toBe("layout");
|
|
106
|
-
});
|
|
107
|
-
it("should merge custom options", () => {
|
|
108
|
-
const plugin = createLayoutPlugin({
|
|
109
|
-
type: "grid",
|
|
110
|
-
direction: "LR",
|
|
111
|
-
nodeSpacing: 100,
|
|
112
|
-
rankSpacing: 200,
|
|
113
|
-
animate: false
|
|
114
|
-
});
|
|
115
|
-
expect(plugin.id).toBe("layout");
|
|
116
|
-
});
|
|
117
|
-
it("should support all layout types", () => {
|
|
118
|
-
const types = ["dagre", "elk", "force", "grid"];
|
|
119
|
-
for (const type of types) {
|
|
120
|
-
const plugin = createLayoutPlugin({ type });
|
|
121
|
-
expect(plugin.id).toBe("layout");
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
it("should support all directions", () => {
|
|
125
|
-
const directions = ["TB", "BT", "LR", "RL"];
|
|
126
|
-
for (const direction of directions) {
|
|
127
|
-
const plugin = createLayoutPlugin({ direction });
|
|
128
|
-
expect(plugin.id).toBe("layout");
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
it("should support elk options", () => {
|
|
132
|
-
const plugin = createLayoutPlugin({
|
|
133
|
-
type: "elk",
|
|
134
|
-
elkOptions: {
|
|
135
|
-
algorithm: "layered",
|
|
136
|
-
direction: "DOWN",
|
|
137
|
-
spacing: 50,
|
|
138
|
-
edgeRouting: "POLYLINE"
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
expect(plugin.id).toBe("layout");
|
|
142
|
-
});
|
|
143
|
-
it("should support force options", () => {
|
|
144
|
-
const plugin = createLayoutPlugin({
|
|
145
|
-
type: "force",
|
|
146
|
-
forceOptions: {
|
|
147
|
-
strength: -500,
|
|
148
|
-
distance: 150,
|
|
149
|
-
theta: 0.5,
|
|
150
|
-
iterations: 500
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
expect(plugin.id).toBe("layout");
|
|
154
|
-
});
|
|
155
|
-
it("should support grid options", () => {
|
|
156
|
-
const plugin = createLayoutPlugin({
|
|
157
|
-
type: "grid",
|
|
158
|
-
gridOptions: {
|
|
159
|
-
columns: 6,
|
|
160
|
-
startX: 100,
|
|
161
|
-
startY: 100
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
expect(plugin.id).toBe("layout");
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe("applyLayout with grid", () => {
|
|
168
|
-
it("should apply grid layout", async () => {
|
|
169
|
-
const flow = createMockFlowInstance();
|
|
170
|
-
flow.nodes.value = [
|
|
171
|
-
createMockNode("n1"),
|
|
172
|
-
createMockNode("n2"),
|
|
173
|
-
createMockNode("n3"),
|
|
174
|
-
createMockNode("n4")
|
|
175
|
-
];
|
|
176
|
-
flow.edges.value = [
|
|
177
|
-
createMockEdge("e1", "n1", "n2"),
|
|
178
|
-
createMockEdge("e2", "n2", "n3")
|
|
179
|
-
];
|
|
180
|
-
const plugin = createLayoutPlugin({ type: "grid", animate: false });
|
|
181
|
-
plugin.install(flow);
|
|
182
|
-
await flow.applyLayout({ type: "grid", gridOptions: { columns: 2 } });
|
|
183
|
-
expect(flow.updateNode).toHaveBeenCalled();
|
|
184
|
-
expect(consoleLogSpy).toHaveBeenCalledWith("[Layout Plugin] Grid layout applied successfully");
|
|
185
|
-
});
|
|
186
|
-
it("should warn for unknown layout type", async () => {
|
|
187
|
-
const flow = createMockFlowInstance();
|
|
188
|
-
flow.nodes.value = [createMockNode("n1")];
|
|
189
|
-
const plugin = createLayoutPlugin();
|
|
190
|
-
plugin.install(flow);
|
|
191
|
-
await flow.applyLayout({ type: "unknown" });
|
|
192
|
-
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
193
|
-
expect.stringContaining("Unknown layout type")
|
|
194
|
-
);
|
|
195
|
-
});
|
|
196
|
-
it("should handle layout with empty nodes", async () => {
|
|
197
|
-
const flow = createMockFlowInstance();
|
|
198
|
-
flow.nodes.value = [];
|
|
199
|
-
flow.edges.value = [];
|
|
200
|
-
const plugin = createLayoutPlugin({ type: "grid" });
|
|
201
|
-
plugin.install(flow);
|
|
202
|
-
await flow.applyLayout();
|
|
203
|
-
expect(flow.updateNode).not.toHaveBeenCalled();
|
|
204
|
-
});
|
|
205
|
-
it("should use override options from applyLayout call", async () => {
|
|
206
|
-
const flow = createMockFlowInstance();
|
|
207
|
-
flow.nodes.value = [createMockNode("n1")];
|
|
208
|
-
flow.edges.value = [];
|
|
209
|
-
const plugin = createLayoutPlugin({ type: "grid" });
|
|
210
|
-
plugin.install(flow);
|
|
211
|
-
await flow.applyLayout({ direction: "LR" });
|
|
212
|
-
expect(flow.updateNode).toHaveBeenCalled();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _vitest = require("vitest");
|
|
4
|
-
var _vue = require("vue");
|
|
5
|
-
var _layout = require("../plugins/plugins/layout.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((id, data) => {
|
|
23
|
-
const node = nodes.value.find(n => n.id === id);
|
|
24
|
-
if (node) Object.assign(node, data);
|
|
25
|
-
}),
|
|
26
|
-
getNode: _vitest.vi.fn(id => nodes.value.find(n => n.id === id)),
|
|
27
|
-
addEdge: _vitest.vi.fn(),
|
|
28
|
-
removeEdge: _vitest.vi.fn(),
|
|
29
|
-
updateEdge: _vitest.vi.fn(),
|
|
30
|
-
getEdge: _vitest.vi.fn(),
|
|
31
|
-
setViewport: _vitest.vi.fn(),
|
|
32
|
-
fitView: _vitest.vi.fn(),
|
|
33
|
-
zoomIn: _vitest.vi.fn(),
|
|
34
|
-
zoomOut: _vitest.vi.fn(),
|
|
35
|
-
centerView: _vitest.vi.fn(),
|
|
36
|
-
selectNode: _vitest.vi.fn(),
|
|
37
|
-
selectEdge: _vitest.vi.fn(),
|
|
38
|
-
clearSelection: _vitest.vi.fn(),
|
|
39
|
-
getNodes: _vitest.vi.fn(() => nodes.value),
|
|
40
|
-
getEdges: _vitest.vi.fn(() => edges.value),
|
|
41
|
-
getViewport: _vitest.vi.fn(() => viewport.value),
|
|
42
|
-
screenToCanvas: _vitest.vi.fn((x, y) => ({
|
|
43
|
-
x,
|
|
44
|
-
y
|
|
45
|
-
})),
|
|
46
|
-
canvasToScreen: _vitest.vi.fn((x, y) => ({
|
|
47
|
-
x,
|
|
48
|
-
y
|
|
49
|
-
})),
|
|
50
|
-
on: _vitest.vi.fn(),
|
|
51
|
-
off: _vitest.vi.fn(),
|
|
52
|
-
emit: _vitest.vi.fn(),
|
|
53
|
-
isValidConnection: _vitest.vi.fn(() => true),
|
|
54
|
-
$el: void 0,
|
|
55
|
-
usePlugin: _vitest.vi.fn(),
|
|
56
|
-
removePlugin: _vitest.vi.fn()
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
(0, _vitest.describe)("flow/plugins/plugins/layout", () => {
|
|
60
|
-
(0, _vitest.describe)("LayoutOptions", () => {
|
|
61
|
-
(0, _vitest.it)("should have correct default options", () => {
|
|
62
|
-
const plugin = (0, _layout.createLayoutPlugin)();
|
|
63
|
-
const flow = createMockFlowInstance();
|
|
64
|
-
plugin.install(flow);
|
|
65
|
-
(0, _vitest.expect)(flow.applyLayout).toBeDefined();
|
|
66
|
-
});
|
|
67
|
-
(0, _vitest.it)("should support dagre layout type", () => {
|
|
68
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
69
|
-
type: "dagre"
|
|
70
|
-
});
|
|
71
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
72
|
-
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
73
|
-
});
|
|
74
|
-
(0, _vitest.it)("should support elk layout type", () => {
|
|
75
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
76
|
-
type: "elk"
|
|
77
|
-
});
|
|
78
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
79
|
-
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
80
|
-
});
|
|
81
|
-
(0, _vitest.it)("should support force layout type", () => {
|
|
82
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
83
|
-
type: "force"
|
|
84
|
-
});
|
|
85
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
86
|
-
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
87
|
-
});
|
|
88
|
-
(0, _vitest.it)("should support grid layout type", () => {
|
|
89
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
90
|
-
type: "grid"
|
|
91
|
-
});
|
|
92
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
93
|
-
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
94
|
-
});
|
|
95
|
-
(0, _vitest.it)("should accept direction option TB", () => {
|
|
96
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
97
|
-
direction: "TB"
|
|
98
|
-
});
|
|
99
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
100
|
-
});
|
|
101
|
-
(0, _vitest.it)("should accept direction option LR", () => {
|
|
102
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
103
|
-
direction: "LR"
|
|
104
|
-
});
|
|
105
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
106
|
-
});
|
|
107
|
-
(0, _vitest.it)("should accept node spacing option", () => {
|
|
108
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
109
|
-
nodeSpacing: 100
|
|
110
|
-
});
|
|
111
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
112
|
-
});
|
|
113
|
-
(0, _vitest.it)("should accept rank spacing option", () => {
|
|
114
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
115
|
-
rankSpacing: 150
|
|
116
|
-
});
|
|
117
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
118
|
-
});
|
|
119
|
-
(0, _vitest.it)("should accept elk options", () => {
|
|
120
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
121
|
-
type: "elk",
|
|
122
|
-
elkOptions: {
|
|
123
|
-
algorithm: "layered",
|
|
124
|
-
direction: "DOWN",
|
|
125
|
-
spacing: 50,
|
|
126
|
-
edgeRouting: "POLYLINE"
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
130
|
-
});
|
|
131
|
-
(0, _vitest.it)("should accept force options", () => {
|
|
132
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
133
|
-
type: "force",
|
|
134
|
-
forceOptions: {
|
|
135
|
-
strength: -500,
|
|
136
|
-
distance: 200,
|
|
137
|
-
iterations: 500
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
141
|
-
});
|
|
142
|
-
(0, _vitest.it)("should accept grid options", () => {
|
|
143
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
144
|
-
type: "grid",
|
|
145
|
-
gridOptions: {
|
|
146
|
-
columns: 3,
|
|
147
|
-
startX: 100,
|
|
148
|
-
startY: 100
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
(0, _vitest.describe)("Layout execution", () => {
|
|
155
|
-
(0, _vitest.it)("should add applyLayout method to flow instance", () => {
|
|
156
|
-
const plugin = (0, _layout.createLayoutPlugin)();
|
|
157
|
-
const flow = createMockFlowInstance();
|
|
158
|
-
plugin.install(flow);
|
|
159
|
-
(0, _vitest.expect)(typeof flow.applyLayout).toBe("function");
|
|
160
|
-
});
|
|
161
|
-
(0, _vitest.it)("should return function when calling applyLayout", async () => {
|
|
162
|
-
const plugin = (0, _layout.createLayoutPlugin)({
|
|
163
|
-
type: "dagre"
|
|
164
|
-
});
|
|
165
|
-
const flow = createMockFlowInstance();
|
|
166
|
-
flow.nodes.value = [{
|
|
167
|
-
id: "1",
|
|
168
|
-
type: "default",
|
|
169
|
-
position: {
|
|
170
|
-
x: 0,
|
|
171
|
-
y: 0
|
|
172
|
-
},
|
|
173
|
-
data: {
|
|
174
|
-
label: "Node 1"
|
|
175
|
-
},
|
|
176
|
-
width: 150,
|
|
177
|
-
height: 50
|
|
178
|
-
}];
|
|
179
|
-
flow.edges.value = [];
|
|
180
|
-
plugin.install(flow);
|
|
181
|
-
const result = flow.applyLayout({
|
|
182
|
-
type: "dagre"
|
|
183
|
-
});
|
|
184
|
-
(0, _vitest.expect)(result === void 0 || result instanceof Promise).toBe(true);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
(0, _vitest.describe)("LayoutOptions interface", () => {
|
|
188
|
-
(0, _vitest.it)("should validate LayoutOptions type field accepts dagre", () => {
|
|
189
|
-
const options = {
|
|
190
|
-
type: "dagre"
|
|
191
|
-
};
|
|
192
|
-
(0, _vitest.expect)(options.type).toBe("dagre");
|
|
193
|
-
});
|
|
194
|
-
(0, _vitest.it)("should validate LayoutOptions type field accepts elk", () => {
|
|
195
|
-
const options = {
|
|
196
|
-
type: "elk"
|
|
197
|
-
};
|
|
198
|
-
(0, _vitest.expect)(options.type).toBe("elk");
|
|
199
|
-
});
|
|
200
|
-
(0, _vitest.it)("should validate LayoutOptions type field accepts force", () => {
|
|
201
|
-
const options = {
|
|
202
|
-
type: "force"
|
|
203
|
-
};
|
|
204
|
-
(0, _vitest.expect)(options.type).toBe("force");
|
|
205
|
-
});
|
|
206
|
-
(0, _vitest.it)("should validate LayoutOptions type field accepts grid", () => {
|
|
207
|
-
const options = {
|
|
208
|
-
type: "grid"
|
|
209
|
-
};
|
|
210
|
-
(0, _vitest.expect)(options.type).toBe("grid");
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|