@yh-ui/flow 1.0.26 → 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 +4 -4
- 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,424 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { FlowCollaborationEngine, createCollaborationEngine } from "../utils/collaboration.mjs";
|
|
3
|
-
function createMockNode(id) {
|
|
4
|
-
return {
|
|
5
|
-
id,
|
|
6
|
-
type: "default",
|
|
7
|
-
position: { x: 0, y: 0 },
|
|
8
|
-
data: {},
|
|
9
|
-
selected: false,
|
|
10
|
-
dragging: false
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function createMockEdge(id, source, target) {
|
|
14
|
-
return {
|
|
15
|
-
id,
|
|
16
|
-
source,
|
|
17
|
-
target,
|
|
18
|
-
type: "default",
|
|
19
|
-
selected: false,
|
|
20
|
-
animated: false
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
describe("flow/utils/collaboration", () => {
|
|
24
|
-
let engine;
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
engine = new FlowCollaborationEngine();
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
engine.disconnect();
|
|
30
|
-
});
|
|
31
|
-
describe("constructor", () => {
|
|
32
|
-
it("should create engine instance", () => {
|
|
33
|
-
expect(engine).toBeDefined();
|
|
34
|
-
});
|
|
35
|
-
it("should start in disconnected state", () => {
|
|
36
|
-
expect(engine.getConnectionState()).toBe("disconnected");
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("createCollaborationEngine factory", () => {
|
|
40
|
-
it("should create engine instance", () => {
|
|
41
|
-
const e = createCollaborationEngine();
|
|
42
|
-
expect(e).toBeInstanceOf(FlowCollaborationEngine);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe("getState", () => {
|
|
46
|
-
it("should return empty state initially", () => {
|
|
47
|
-
const state = engine.getState();
|
|
48
|
-
expect(state.nodes).toEqual([]);
|
|
49
|
-
expect(state.edges).toEqual([]);
|
|
50
|
-
expect(state.viewport).toEqual({ x: 0, y: 0, zoom: 1 });
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe("getCursors", () => {
|
|
54
|
-
it("should return empty cursors map initially", () => {
|
|
55
|
-
const cursors = engine.getCursors();
|
|
56
|
-
expect(cursors.size).toBe(0);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe("event listeners", () => {
|
|
60
|
-
it("should register event listener", () => {
|
|
61
|
-
const handler = vi.fn();
|
|
62
|
-
engine.on("test-event", handler);
|
|
63
|
-
const handlers = engine.eventListeners.get("test-event");
|
|
64
|
-
expect(handlers).toBeDefined();
|
|
65
|
-
expect(handlers.length).toBe(1);
|
|
66
|
-
});
|
|
67
|
-
it("should unregister event listener", () => {
|
|
68
|
-
const handler = vi.fn();
|
|
69
|
-
engine.on("test-event", handler);
|
|
70
|
-
engine.off("test-event", handler);
|
|
71
|
-
const handlers = engine.eventListeners.get("test-event");
|
|
72
|
-
expect(handlers.length).toBe(0);
|
|
73
|
-
});
|
|
74
|
-
it("should trigger wildcard listeners", () => {
|
|
75
|
-
const handler = vi.fn();
|
|
76
|
-
engine.on("*", handler);
|
|
77
|
-
engine.emitEvent(
|
|
78
|
-
"any",
|
|
79
|
-
{
|
|
80
|
-
type: "any"
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
expect(handler).toHaveBeenCalled();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
describe("isValidWSMessage", () => {
|
|
87
|
-
it("should validate correct message structure", () => {
|
|
88
|
-
const msg = {
|
|
89
|
-
type: "join",
|
|
90
|
-
roomId: "room1",
|
|
91
|
-
userId: "user1",
|
|
92
|
-
payload: {},
|
|
93
|
-
timestamp: Date.now()
|
|
94
|
-
};
|
|
95
|
-
const result = engine.isValidWSMessage(msg);
|
|
96
|
-
expect(result).toBe(true);
|
|
97
|
-
});
|
|
98
|
-
it("should reject message without type", () => {
|
|
99
|
-
const msg = { roomId: "room1", userId: "user1", payload: {} };
|
|
100
|
-
const result = engine.isValidWSMessage(msg);
|
|
101
|
-
expect(result).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
it("should reject message without roomId", () => {
|
|
104
|
-
const msg = { type: "join", userId: "user1", payload: {} };
|
|
105
|
-
const result = engine.isValidWSMessage(msg);
|
|
106
|
-
expect(result).toBe(false);
|
|
107
|
-
});
|
|
108
|
-
it("should reject message without userId", () => {
|
|
109
|
-
const msg = { type: "join", roomId: "room1", payload: {} };
|
|
110
|
-
const result = engine.isValidWSMessage(msg);
|
|
111
|
-
expect(result).toBe(false);
|
|
112
|
-
});
|
|
113
|
-
it("should reject message without payload", () => {
|
|
114
|
-
const msg = { type: "join", roomId: "room1", userId: "user1" };
|
|
115
|
-
const result = engine.isValidWSMessage(msg);
|
|
116
|
-
expect(result).toBe(false);
|
|
117
|
-
});
|
|
118
|
-
it("should reject non-object messages", () => {
|
|
119
|
-
const result = engine.isValidWSMessage(null);
|
|
120
|
-
expect(result).toBe(false);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe("addNode", () => {
|
|
124
|
-
it("should add node to state", () => {
|
|
125
|
-
const node = createMockNode("n1");
|
|
126
|
-
engine.addNode(node);
|
|
127
|
-
const state = engine.getState();
|
|
128
|
-
expect(state.nodes).toContainEqual(expect.objectContaining({ id: "n1" }));
|
|
129
|
-
});
|
|
130
|
-
it("should track version after add", () => {
|
|
131
|
-
const node = createMockNode("n1");
|
|
132
|
-
const initialVersion = engine.state.version;
|
|
133
|
-
engine.addNode(node);
|
|
134
|
-
expect(engine.state.version).toBeGreaterThan(
|
|
135
|
-
initialVersion
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe("updateNode", () => {
|
|
140
|
-
it("should update node in state", () => {
|
|
141
|
-
const node = createMockNode("n1");
|
|
142
|
-
engine.addNode(node);
|
|
143
|
-
engine.updateNode("n1", { position: { x: 100, y: 200 } });
|
|
144
|
-
const state = engine.getState();
|
|
145
|
-
const updated = state.nodes.find((n) => n.id === "n1");
|
|
146
|
-
expect(updated?.position).toEqual({ x: 100, y: 200 });
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe("deleteNode", () => {
|
|
150
|
-
it("should remove node from state", () => {
|
|
151
|
-
const node = createMockNode("n1");
|
|
152
|
-
engine.addNode(node);
|
|
153
|
-
engine.deleteNode("n1");
|
|
154
|
-
const state = engine.getState();
|
|
155
|
-
expect(state.nodes.find((n) => n.id === "n1")).toBeUndefined();
|
|
156
|
-
});
|
|
157
|
-
it("should also delete associated edges", () => {
|
|
158
|
-
const node1 = createMockNode("n1");
|
|
159
|
-
const node2 = createMockNode("n2");
|
|
160
|
-
const edge = createMockEdge("e1", "n1", "n2");
|
|
161
|
-
engine.addNode(node1);
|
|
162
|
-
engine.addNode(node2);
|
|
163
|
-
engine.applyOperation({
|
|
164
|
-
id: "op1",
|
|
165
|
-
type: "edge_add",
|
|
166
|
-
timestamp: Date.now(),
|
|
167
|
-
userId: "user1",
|
|
168
|
-
edgeId: "e1",
|
|
169
|
-
data: edge,
|
|
170
|
-
version: 1
|
|
171
|
-
});
|
|
172
|
-
engine.deleteNode("n1");
|
|
173
|
-
const state = engine.getState();
|
|
174
|
-
expect(state.edges.find((e) => e.id === "e1")).toBeUndefined();
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe("addEdge", () => {
|
|
178
|
-
it("should add edge to state", () => {
|
|
179
|
-
const edge = createMockEdge("e1", "n1", "n2");
|
|
180
|
-
engine.addEdge(edge);
|
|
181
|
-
const state = engine.getState();
|
|
182
|
-
expect(state.edges).toContainEqual(expect.objectContaining({ id: "e1" }));
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
describe("updateEdge", () => {
|
|
186
|
-
it("should update edge in state", () => {
|
|
187
|
-
const edge = createMockEdge("e1", "n1", "n2");
|
|
188
|
-
engine.addEdge(edge);
|
|
189
|
-
engine.updateEdge("e1", { type: "bezier" });
|
|
190
|
-
const state = engine.getState();
|
|
191
|
-
const updated = state.edges.find((e) => e.id === "e1");
|
|
192
|
-
expect(updated?.type).toBe("bezier");
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe("deleteEdge", () => {
|
|
196
|
-
it("should remove edge from state", () => {
|
|
197
|
-
const edge = createMockEdge("e1", "n1", "n2");
|
|
198
|
-
engine.addEdge(edge);
|
|
199
|
-
engine.deleteEdge("e1");
|
|
200
|
-
const state = engine.getState();
|
|
201
|
-
expect(state.edges.find((e) => e.id === "e1")).toBeUndefined();
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
describe("updateViewport", () => {
|
|
205
|
-
it("should update viewport in state", () => {
|
|
206
|
-
const viewport = { x: 50, y: 100, zoom: 1.5 };
|
|
207
|
-
engine.updateViewport(viewport);
|
|
208
|
-
const state = engine.getState();
|
|
209
|
-
expect(state.viewport).toEqual(viewport);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
describe("updateCursor", () => {
|
|
213
|
-
it("should not throw when disconnected", () => {
|
|
214
|
-
expect(() => engine.updateCursor(100, 200)).not.toThrow();
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
describe("updateSelection", () => {
|
|
218
|
-
it("should not throw when disconnected", () => {
|
|
219
|
-
expect(() => engine.updateSelection(["n1", "n2"])).not.toThrow();
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
describe("disconnect", () => {
|
|
223
|
-
it("should not throw when called multiple times", () => {
|
|
224
|
-
engine.disconnect();
|
|
225
|
-
expect(() => engine.disconnect()).not.toThrow();
|
|
226
|
-
});
|
|
227
|
-
it("should be idempotent", () => {
|
|
228
|
-
engine.disconnect();
|
|
229
|
-
expect(engine.getConnectionState()).toBe("disconnected");
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
describe("handleRemoteOperation", () => {
|
|
233
|
-
it("should ignore operations from self", () => {
|
|
234
|
-
;
|
|
235
|
-
engine.userId = "user1";
|
|
236
|
-
const state = engine.getState();
|
|
237
|
-
const node = createMockNode("n1");
|
|
238
|
-
engine.state.nodes.set("n1", node);
|
|
239
|
-
engine.applyOperation({
|
|
240
|
-
id: "op1",
|
|
241
|
-
type: "node_add",
|
|
242
|
-
timestamp: Date.now(),
|
|
243
|
-
userId: "user1",
|
|
244
|
-
nodeId: "n1",
|
|
245
|
-
data: node,
|
|
246
|
-
version: 1
|
|
247
|
-
});
|
|
248
|
-
expect(engine.getState().nodes.length).toBe(1);
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
describe("generateUserColor", () => {
|
|
252
|
-
it("should generate consistent color for same user id", () => {
|
|
253
|
-
const color1 = engine.generateUserColor("user1");
|
|
254
|
-
const color2 = engine.generateUserColor("user1");
|
|
255
|
-
expect(color1).toBe(color2);
|
|
256
|
-
});
|
|
257
|
-
it("should generate different colors for different user ids", () => {
|
|
258
|
-
const color1 = engine.generateUserColor("user1");
|
|
259
|
-
const color2 = engine.generateUserColor("user2");
|
|
260
|
-
expect(color1).not.toBe(color2);
|
|
261
|
-
});
|
|
262
|
-
it("should generate valid hex color", () => {
|
|
263
|
-
const color = engine.generateUserColor("test");
|
|
264
|
-
expect(color).toMatch(/^#[0-9a-f]{6}$/);
|
|
265
|
-
});
|
|
266
|
-
it("should generate color for empty string", () => {
|
|
267
|
-
const color = engine.generateUserColor("");
|
|
268
|
-
expect(color).toMatch(/^#[0-9a-f]{6}$/);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
describe("applyOperation", () => {
|
|
272
|
-
it("should apply node_update operation", () => {
|
|
273
|
-
const node = createMockNode("n1");
|
|
274
|
-
engine.applyOperation({
|
|
275
|
-
id: "op1",
|
|
276
|
-
type: "node_update",
|
|
277
|
-
timestamp: Date.now(),
|
|
278
|
-
userId: "user1",
|
|
279
|
-
nodeId: "n1",
|
|
280
|
-
data: { position: { x: 50, y: 50 } },
|
|
281
|
-
version: 1
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
it("should apply edge_update operation", () => {
|
|
285
|
-
;
|
|
286
|
-
engine.applyOperation({
|
|
287
|
-
id: "op1",
|
|
288
|
-
type: "edge_update",
|
|
289
|
-
timestamp: Date.now(),
|
|
290
|
-
userId: "user1",
|
|
291
|
-
edgeId: "e1",
|
|
292
|
-
data: { type: "bezier" },
|
|
293
|
-
version: 1
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
it("should apply edge_delete operation", () => {
|
|
297
|
-
const edge = createMockEdge("e1", "n1", "n2");
|
|
298
|
-
engine.state.edges.set("e1", edge);
|
|
299
|
-
engine.applyOperation({
|
|
300
|
-
id: "op1",
|
|
301
|
-
type: "edge_delete",
|
|
302
|
-
timestamp: Date.now(),
|
|
303
|
-
userId: "user1",
|
|
304
|
-
edgeId: "e1",
|
|
305
|
-
version: 1
|
|
306
|
-
});
|
|
307
|
-
expect(engine.getState().edges.find((e) => e.id === "e1")).toBeUndefined();
|
|
308
|
-
});
|
|
309
|
-
it("should apply viewport_change operation", () => {
|
|
310
|
-
const viewport = { x: 10, y: 20, zoom: 0.5 };
|
|
311
|
-
engine.applyOperation({
|
|
312
|
-
id: "op1",
|
|
313
|
-
type: "viewport_change",
|
|
314
|
-
timestamp: Date.now(),
|
|
315
|
-
userId: "user1",
|
|
316
|
-
data: viewport,
|
|
317
|
-
version: 1
|
|
318
|
-
});
|
|
319
|
-
expect(engine.getState().viewport).toEqual(viewport);
|
|
320
|
-
});
|
|
321
|
-
it("should update version vector on apply", () => {
|
|
322
|
-
const vv = engine.versionVector;
|
|
323
|
-
engine.applyOperation({
|
|
324
|
-
id: "op1",
|
|
325
|
-
type: "node_add",
|
|
326
|
-
timestamp: Date.now(),
|
|
327
|
-
userId: "user1",
|
|
328
|
-
nodeId: "n1",
|
|
329
|
-
data: createMockNode("n1"),
|
|
330
|
-
version: 1
|
|
331
|
-
});
|
|
332
|
-
expect(vv.get("user1")).toBe(1);
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
describe("handleCursorUpdate", () => {
|
|
336
|
-
it("should update cursor in cursors map", () => {
|
|
337
|
-
;
|
|
338
|
-
engine.handleCursorUpdate("user2", { x: 100, y: 200, name: "User 2", color: "#ff0000" });
|
|
339
|
-
const cursors = engine.getCursors();
|
|
340
|
-
expect(cursors.get("user2")).toEqual({
|
|
341
|
-
x: 100,
|
|
342
|
-
y: 200,
|
|
343
|
-
name: "User 2",
|
|
344
|
-
color: "#ff0000"
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
it("should emit cursor_update event", () => {
|
|
348
|
-
const handler = vi.fn();
|
|
349
|
-
engine.on("cursor_update", handler);
|
|
350
|
-
engine.handleCursorUpdate("user2", { x: 100, y: 200, name: "User 2", color: "#ff0000" });
|
|
351
|
-
expect(handler).toHaveBeenCalled();
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
describe("handleUserJoin", () => {
|
|
355
|
-
it("should emit user_joined event", () => {
|
|
356
|
-
const handler = vi.fn();
|
|
357
|
-
engine.on("user_joined", handler);
|
|
358
|
-
engine.handleUserJoin("user2", {
|
|
359
|
-
userName: "User 2",
|
|
360
|
-
userColor: "#ff0000"
|
|
361
|
-
});
|
|
362
|
-
expect(handler).toHaveBeenCalled();
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
describe("handleUserLeave", () => {
|
|
366
|
-
it("should remove cursor from cursors map", () => {
|
|
367
|
-
;
|
|
368
|
-
engine.handleCursorUpdate("user2", { x: 100, y: 200, name: "User 2", color: "#ff0000" });
|
|
369
|
-
engine.handleUserLeave("user2");
|
|
370
|
-
const cursors = engine.getCursors();
|
|
371
|
-
expect(cursors.get("user2")).toBeUndefined();
|
|
372
|
-
});
|
|
373
|
-
it("should emit user_left event", () => {
|
|
374
|
-
const handler = vi.fn();
|
|
375
|
-
engine.on("user_left", handler);
|
|
376
|
-
engine.handleUserLeave("user2");
|
|
377
|
-
expect(handler).toHaveBeenCalled();
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
describe("handleSync", () => {
|
|
381
|
-
it("should sync state from payload", () => {
|
|
382
|
-
const nodes = [createMockNode("n1"), createMockNode("n2")];
|
|
383
|
-
const edges = [createMockEdge("e1", "n1", "n2")];
|
|
384
|
-
const viewport = { x: 50, y: 50, zoom: 1.2 };
|
|
385
|
-
engine.handleSync({
|
|
386
|
-
nodes,
|
|
387
|
-
edges,
|
|
388
|
-
viewport,
|
|
389
|
-
version: 5
|
|
390
|
-
});
|
|
391
|
-
const state = engine.getState();
|
|
392
|
-
expect(state.nodes).toHaveLength(2);
|
|
393
|
-
expect(state.edges).toHaveLength(1);
|
|
394
|
-
expect(state.viewport).toEqual(viewport);
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
describe("setConnectionState", () => {
|
|
398
|
-
it("should emit connection state event", () => {
|
|
399
|
-
const handler = vi.fn();
|
|
400
|
-
engine.on("connected", handler);
|
|
401
|
-
engine.setConnectionState(
|
|
402
|
-
"connected"
|
|
403
|
-
);
|
|
404
|
-
expect(handler).toHaveBeenCalled();
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
describe("broadcastOperation", () => {
|
|
408
|
-
it("should add operation to pending operations", () => {
|
|
409
|
-
const pending = engine.pendingOperations;
|
|
410
|
-
engine.broadcastOperation(
|
|
411
|
-
{
|
|
412
|
-
id: "op1",
|
|
413
|
-
type: "node_add",
|
|
414
|
-
timestamp: Date.now(),
|
|
415
|
-
userId: "user1",
|
|
416
|
-
nodeId: "n1",
|
|
417
|
-
data: createMockNode("n1"),
|
|
418
|
-
version: 1
|
|
419
|
-
},
|
|
420
|
-
true
|
|
421
|
-
);
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
});
|