@yh-ui/flow 1.0.1 → 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,215 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _node = require("../types/node.cjs");
|
|
5
|
+
(0, _vitest.describe)("flow/types/node", () => {
|
|
6
|
+
(0, _vitest.describe)("NodeHandle", () => {
|
|
7
|
+
(0, _vitest.it)("should define handle with type and position", () => {
|
|
8
|
+
const handle = {
|
|
9
|
+
type: "source",
|
|
10
|
+
position: "right"
|
|
11
|
+
};
|
|
12
|
+
(0, _vitest.expect)(handle.type).toBe("source");
|
|
13
|
+
(0, _vitest.expect)(handle.position).toBe("right");
|
|
14
|
+
});
|
|
15
|
+
(0, _vitest.it)("should support optional properties", () => {
|
|
16
|
+
const handle = {
|
|
17
|
+
type: "target",
|
|
18
|
+
position: "left",
|
|
19
|
+
id: "handle-1",
|
|
20
|
+
style: {
|
|
21
|
+
background: "#fff"
|
|
22
|
+
},
|
|
23
|
+
class: "custom-handle",
|
|
24
|
+
isConnectable: true
|
|
25
|
+
};
|
|
26
|
+
(0, _vitest.expect)(handle.id).toBe("handle-1");
|
|
27
|
+
(0, _vitest.expect)(handle.class).toBe("custom-handle");
|
|
28
|
+
(0, _vitest.expect)(handle.isConnectable).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
(0, _vitest.describe)("NodeStyle", () => {
|
|
32
|
+
(0, _vitest.it)("should allow CSS-like properties", () => {
|
|
33
|
+
const style = {
|
|
34
|
+
background: "#f0f0f0",
|
|
35
|
+
border: "1px solid #ccc",
|
|
36
|
+
width: 200
|
|
37
|
+
};
|
|
38
|
+
(0, _vitest.expect)(style.background).toBe("#f0f0f0");
|
|
39
|
+
(0, _vitest.expect)(style.width).toBe(200);
|
|
40
|
+
});
|
|
41
|
+
(0, _vitest.it)("should support undefined values", () => {
|
|
42
|
+
const style = {
|
|
43
|
+
background: "#fff",
|
|
44
|
+
border: void 0
|
|
45
|
+
};
|
|
46
|
+
(0, _vitest.expect)(style.border).toBeUndefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
(0, _vitest.describe)("NodeData", () => {
|
|
50
|
+
(0, _vitest.it)("should define basic node data", () => {
|
|
51
|
+
const data = {
|
|
52
|
+
label: "Test Node"
|
|
53
|
+
};
|
|
54
|
+
(0, _vitest.expect)(data.label).toBe("Test Node");
|
|
55
|
+
});
|
|
56
|
+
(0, _vitest.it)("should support extended data fields", () => {
|
|
57
|
+
const data = {
|
|
58
|
+
label: "AI Node",
|
|
59
|
+
style: {
|
|
60
|
+
background: "#e0f7fa"
|
|
61
|
+
},
|
|
62
|
+
class: "ai-node",
|
|
63
|
+
icon: "robot",
|
|
64
|
+
description: "An AI processing node"
|
|
65
|
+
};
|
|
66
|
+
(0, _vitest.expect)(data.icon).toBe("robot");
|
|
67
|
+
(0, _vitest.expect)(data.description).toBe("An AI processing node");
|
|
68
|
+
});
|
|
69
|
+
(0, _vitest.it)("should support AI workflow specific fields", () => {
|
|
70
|
+
const data = {
|
|
71
|
+
label: "LLM Node",
|
|
72
|
+
model: "gpt-4",
|
|
73
|
+
prompt: "You are a helpful assistant",
|
|
74
|
+
temperature: 0.7,
|
|
75
|
+
maxTokens: 2e3,
|
|
76
|
+
tools: ["search", "calculator"],
|
|
77
|
+
toolName: "web_search",
|
|
78
|
+
condition: 'status == "success"',
|
|
79
|
+
memoryType: "vector",
|
|
80
|
+
status: "running",
|
|
81
|
+
streamOutput: "partial"
|
|
82
|
+
};
|
|
83
|
+
(0, _vitest.expect)(data.model).toBe("gpt-4");
|
|
84
|
+
(0, _vitest.expect)(data.temperature).toBe(0.7);
|
|
85
|
+
(0, _vitest.expect)(data.status).toBe("running");
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
(0, _vitest.describe)("NodePosition", () => {
|
|
89
|
+
(0, _vitest.it)("should define position with x and y", () => {
|
|
90
|
+
const pos = {
|
|
91
|
+
x: 100,
|
|
92
|
+
y: 200
|
|
93
|
+
};
|
|
94
|
+
(0, _vitest.expect)(pos.x).toBe(100);
|
|
95
|
+
(0, _vitest.expect)(pos.y).toBe(200);
|
|
96
|
+
});
|
|
97
|
+
(0, _vitest.it)("should support negative coordinates", () => {
|
|
98
|
+
const pos = {
|
|
99
|
+
x: -50,
|
|
100
|
+
y: -100
|
|
101
|
+
};
|
|
102
|
+
(0, _vitest.expect)(pos.x).toBe(-50);
|
|
103
|
+
(0, _vitest.expect)(pos.y).toBe(-100);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
(0, _vitest.describe)("NodeDimension", () => {
|
|
107
|
+
(0, _vitest.it)("should define width and height", () => {
|
|
108
|
+
const dim = {
|
|
109
|
+
width: 150,
|
|
110
|
+
height: 80
|
|
111
|
+
};
|
|
112
|
+
(0, _vitest.expect)(dim.width).toBe(150);
|
|
113
|
+
(0, _vitest.expect)(dim.height).toBe(80);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
(0, _vitest.describe)("NodeHandleBounds", () => {
|
|
117
|
+
(0, _vitest.it)("should define handle bounds", () => {
|
|
118
|
+
const bounds = {
|
|
119
|
+
top: [{
|
|
120
|
+
type: "source",
|
|
121
|
+
position: "top"
|
|
122
|
+
}],
|
|
123
|
+
right: [{
|
|
124
|
+
type: "target",
|
|
125
|
+
position: "right"
|
|
126
|
+
}]
|
|
127
|
+
};
|
|
128
|
+
(0, _vitest.expect)(bounds.top).toHaveLength(1);
|
|
129
|
+
(0, _vitest.expect)(bounds.right).toHaveLength(1);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
(0, _vitest.describe)("Node", () => {
|
|
133
|
+
(0, _vitest.it)("should create basic node", () => {
|
|
134
|
+
const node = {
|
|
135
|
+
id: "node-1",
|
|
136
|
+
type: "default",
|
|
137
|
+
position: {
|
|
138
|
+
x: 0,
|
|
139
|
+
y: 0
|
|
140
|
+
},
|
|
141
|
+
data: {
|
|
142
|
+
label: "Basic Node"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
(0, _vitest.expect)(node.id).toBe("node-1");
|
|
146
|
+
(0, _vitest.expect)(node.type).toBe("default");
|
|
147
|
+
});
|
|
148
|
+
(0, _vitest.it)("should support all optional properties", () => {
|
|
149
|
+
const node = {
|
|
150
|
+
id: "node-1",
|
|
151
|
+
type: "custom",
|
|
152
|
+
position: {
|
|
153
|
+
x: 100,
|
|
154
|
+
y: 200
|
|
155
|
+
},
|
|
156
|
+
data: {
|
|
157
|
+
label: "Test"
|
|
158
|
+
},
|
|
159
|
+
style: {
|
|
160
|
+
background: "#fff"
|
|
161
|
+
},
|
|
162
|
+
class: "custom-node",
|
|
163
|
+
draggable: true,
|
|
164
|
+
selectable: true,
|
|
165
|
+
connectable: true,
|
|
166
|
+
resizable: true,
|
|
167
|
+
deletable: true,
|
|
168
|
+
hidden: false,
|
|
169
|
+
selected: false,
|
|
170
|
+
dragging: false,
|
|
171
|
+
width: 200,
|
|
172
|
+
height: 100,
|
|
173
|
+
parentId: "parent-1",
|
|
174
|
+
zIndex: 1,
|
|
175
|
+
extent: "parent",
|
|
176
|
+
expandParent: true,
|
|
177
|
+
positionAbsolute: {
|
|
178
|
+
x: 150,
|
|
179
|
+
y: 250
|
|
180
|
+
},
|
|
181
|
+
handleBounds: {
|
|
182
|
+
top: [{
|
|
183
|
+
type: "source",
|
|
184
|
+
position: "top"
|
|
185
|
+
}],
|
|
186
|
+
right: [{
|
|
187
|
+
type: "target",
|
|
188
|
+
position: "right"
|
|
189
|
+
}]
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
(0, _vitest.expect)(node.draggable).toBe(true);
|
|
193
|
+
(0, _vitest.expect)(node.width).toBe(200);
|
|
194
|
+
(0, _vitest.expect)(node.parentId).toBe("parent-1");
|
|
195
|
+
});
|
|
196
|
+
(0, _vitest.it)("should support nested children", () => {
|
|
197
|
+
const node = {
|
|
198
|
+
id: "parent",
|
|
199
|
+
type: "group",
|
|
200
|
+
position: {
|
|
201
|
+
x: 0,
|
|
202
|
+
y: 0
|
|
203
|
+
},
|
|
204
|
+
data: {
|
|
205
|
+
label: "Parent"
|
|
206
|
+
},
|
|
207
|
+
children: ["child-1", "child-2"],
|
|
208
|
+
computed: true
|
|
209
|
+
};
|
|
210
|
+
(0, _vitest.expect)(node.children).toEqual(["child-1", "child-2"]);
|
|
211
|
+
(0, _vitest.expect)(node.computed).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
(0, _vitest.describe)("NodeChangeType", () => {
|
|
215
|
+
(0, _vitest.it)("should define all change types", () => {
|
|
216
|
+
const types = ["select", "position", "remove", "dimensions", "style", "data", "selectMulti", "unselect"];
|
|
217
|
+
(0, _vitest.expect)(types).toContain("select");
|
|
218
|
+
(0, _vitest.expect)(types).toContain("position");
|
|
219
|
+
(0, _vitest.expect)(types).toContain("remove");
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
(0, _vitest.describe)("NodeChange", () => {
|
|
223
|
+
(0, _vitest.it)("should create select change", () => {
|
|
224
|
+
const node = {
|
|
225
|
+
id: "node-1",
|
|
226
|
+
type: "default",
|
|
227
|
+
position: {
|
|
228
|
+
x: 0,
|
|
229
|
+
y: 0
|
|
230
|
+
},
|
|
231
|
+
data: {}
|
|
232
|
+
};
|
|
233
|
+
const change = {
|
|
234
|
+
type: "select",
|
|
235
|
+
id: "node-1",
|
|
236
|
+
item: node,
|
|
237
|
+
selected: true
|
|
238
|
+
};
|
|
239
|
+
(0, _vitest.expect)(change.type).toBe("select");
|
|
240
|
+
(0, _vitest.expect)(change.selected).toBe(true);
|
|
241
|
+
});
|
|
242
|
+
(0, _vitest.it)("should create position change", () => {
|
|
243
|
+
const node = {
|
|
244
|
+
id: "node-1",
|
|
245
|
+
type: "default",
|
|
246
|
+
position: {
|
|
247
|
+
x: 0,
|
|
248
|
+
y: 0
|
|
249
|
+
},
|
|
250
|
+
data: {}
|
|
251
|
+
};
|
|
252
|
+
const change = {
|
|
253
|
+
type: "position",
|
|
254
|
+
id: "node-1",
|
|
255
|
+
item: node,
|
|
256
|
+
position: {
|
|
257
|
+
x: 100,
|
|
258
|
+
y: 200
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
(0, _vitest.expect)(change.position?.x).toBe(100);
|
|
262
|
+
(0, _vitest.expect)(change.position?.y).toBe(200);
|
|
263
|
+
});
|
|
264
|
+
(0, _vitest.it)("should create dimensions change", () => {
|
|
265
|
+
const node = {
|
|
266
|
+
id: "node-1",
|
|
267
|
+
type: "default",
|
|
268
|
+
position: {
|
|
269
|
+
x: 0,
|
|
270
|
+
y: 0
|
|
271
|
+
},
|
|
272
|
+
data: {}
|
|
273
|
+
};
|
|
274
|
+
const change = {
|
|
275
|
+
type: "dimensions",
|
|
276
|
+
id: "node-1",
|
|
277
|
+
item: node,
|
|
278
|
+
dimensions: {
|
|
279
|
+
width: 200,
|
|
280
|
+
height: 100
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
(0, _vitest.expect)(change.dimensions?.width).toBe(200);
|
|
284
|
+
});
|
|
285
|
+
(0, _vitest.it)("should create drag change", () => {
|
|
286
|
+
const node = {
|
|
287
|
+
id: "node-1",
|
|
288
|
+
type: "default",
|
|
289
|
+
position: {
|
|
290
|
+
x: 0,
|
|
291
|
+
y: 0
|
|
292
|
+
},
|
|
293
|
+
data: {}
|
|
294
|
+
};
|
|
295
|
+
const change = {
|
|
296
|
+
type: "position",
|
|
297
|
+
id: "node-1",
|
|
298
|
+
item: node,
|
|
299
|
+
drag: true
|
|
300
|
+
};
|
|
301
|
+
(0, _vitest.expect)(change.drag).toBe(true);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
(0, _vitest.describe)("isNode", () => {
|
|
305
|
+
(0, _vitest.it)("should return true for valid node objects", () => {
|
|
306
|
+
const node = {
|
|
307
|
+
id: "node-1",
|
|
308
|
+
type: "default",
|
|
309
|
+
position: {
|
|
310
|
+
x: 0,
|
|
311
|
+
y: 0
|
|
312
|
+
},
|
|
313
|
+
data: {}
|
|
314
|
+
};
|
|
315
|
+
(0, _vitest.expect)((0, _node.isNode)(node)).toBe(true);
|
|
316
|
+
});
|
|
317
|
+
(0, _vitest.it)("should return true for node with extended properties", () => {
|
|
318
|
+
const node = {
|
|
319
|
+
id: "node-1",
|
|
320
|
+
type: "custom",
|
|
321
|
+
position: {
|
|
322
|
+
x: 100,
|
|
323
|
+
y: 200
|
|
324
|
+
},
|
|
325
|
+
data: {
|
|
326
|
+
label: "Test"
|
|
327
|
+
},
|
|
328
|
+
width: 200,
|
|
329
|
+
height: 100
|
|
330
|
+
};
|
|
331
|
+
(0, _vitest.expect)((0, _node.isNode)(node)).toBe(true);
|
|
332
|
+
});
|
|
333
|
+
(0, _vitest.it)("should return false for null", () => {
|
|
334
|
+
(0, _vitest.expect)((0, _node.isNode)(null)).toBe(false);
|
|
335
|
+
});
|
|
336
|
+
(0, _vitest.it)("should return false for undefined", () => {
|
|
337
|
+
(0, _vitest.expect)((0, _node.isNode)(void 0)).toBe(false);
|
|
338
|
+
});
|
|
339
|
+
(0, _vitest.it)("should return false for object missing id", () => {
|
|
340
|
+
(0, _vitest.expect)((0, _node.isNode)({
|
|
341
|
+
type: "default",
|
|
342
|
+
position: {
|
|
343
|
+
x: 0,
|
|
344
|
+
y: 0
|
|
345
|
+
},
|
|
346
|
+
data: {}
|
|
347
|
+
})).toBe(false);
|
|
348
|
+
});
|
|
349
|
+
(0, _vitest.it)("should return false for object missing type", () => {
|
|
350
|
+
(0, _vitest.expect)((0, _node.isNode)({
|
|
351
|
+
id: "node-1",
|
|
352
|
+
position: {
|
|
353
|
+
x: 0,
|
|
354
|
+
y: 0
|
|
355
|
+
},
|
|
356
|
+
data: {}
|
|
357
|
+
})).toBe(false);
|
|
358
|
+
});
|
|
359
|
+
(0, _vitest.it)("should return false for primitive values", () => {
|
|
360
|
+
(0, _vitest.expect)((0, _node.isNode)("node")).toBe(false);
|
|
361
|
+
(0, _vitest.expect)((0, _node.isNode)(123)).toBe(false);
|
|
362
|
+
(0, _vitest.expect)((0, _node.isNode)(true)).toBe(false);
|
|
363
|
+
});
|
|
364
|
+
(0, _vitest.it)("should return false for arrays", () => {
|
|
365
|
+
(0, _vitest.expect)((0, _node.isNode)([])).toBe(false);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|