@yh-ui/flow 0.1.56 → 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.
Files changed (70) hide show
  1. package/dist/__tests__/bpmn-engine.test.cjs +357 -0
  2. package/dist/__tests__/bpmn-engine.test.d.ts +1 -0
  3. package/dist/__tests__/bpmn-engine.test.mjs +406 -0
  4. package/dist/__tests__/bpmn-utils.test.cjs +268 -0
  5. package/dist/__tests__/bpmn-utils.test.d.ts +1 -0
  6. package/dist/__tests__/bpmn-utils.test.mjs +227 -0
  7. package/dist/__tests__/bpmn-xml.test.cjs +150 -0
  8. package/dist/__tests__/bpmn-xml.test.d.ts +1 -0
  9. package/dist/__tests__/bpmn-xml.test.mjs +112 -0
  10. package/dist/__tests__/collaboration.test.cjs +487 -0
  11. package/dist/__tests__/collaboration.test.d.ts +1 -0
  12. package/dist/__tests__/collaboration.test.mjs +424 -0
  13. package/dist/__tests__/edge-types.test.cjs +275 -0
  14. package/dist/__tests__/edge-types.test.d.ts +1 -0
  15. package/dist/__tests__/edge-types.test.mjs +234 -0
  16. package/dist/__tests__/edge-utils.test.cjs +375 -0
  17. package/dist/__tests__/edge-utils.test.d.ts +1 -0
  18. package/dist/__tests__/edge-utils.test.mjs +376 -0
  19. package/dist/__tests__/events-types.test.cjs +184 -0
  20. package/dist/__tests__/events-types.test.d.ts +1 -0
  21. package/dist/__tests__/events-types.test.mjs +184 -0
  22. package/dist/__tests__/export-image-plugin.test.cjs +142 -0
  23. package/dist/__tests__/export-image-plugin.test.d.ts +1 -0
  24. package/dist/__tests__/export-image-plugin.test.mjs +118 -0
  25. package/dist/__tests__/export.test.cjs +237 -0
  26. package/dist/__tests__/export.test.d.ts +1 -0
  27. package/dist/__tests__/export.test.mjs +171 -0
  28. package/dist/__tests__/flow-context.test.cjs +16 -0
  29. package/dist/__tests__/flow-context.test.d.ts +1 -0
  30. package/dist/__tests__/flow-context.test.mjs +16 -0
  31. package/dist/__tests__/flow-props.test.cjs +94 -0
  32. package/dist/__tests__/flow-props.test.d.ts +1 -0
  33. package/dist/__tests__/flow-props.test.mjs +92 -0
  34. package/dist/__tests__/layout-plugin.test.cjs +233 -0
  35. package/dist/__tests__/layout-plugin.test.d.ts +1 -0
  36. package/dist/__tests__/layout-plugin.test.mjs +215 -0
  37. package/dist/__tests__/node-types.test.cjs +368 -0
  38. package/dist/__tests__/node-types.test.d.ts +1 -0
  39. package/dist/__tests__/node-types.test.mjs +292 -0
  40. package/dist/__tests__/performance.test.cjs +313 -0
  41. package/dist/__tests__/performance.test.d.ts +1 -0
  42. package/dist/__tests__/performance.test.mjs +218 -0
  43. package/dist/__tests__/plugin-advanced.test.cjs +301 -0
  44. package/dist/__tests__/plugin-advanced.test.d.ts +1 -0
  45. package/dist/__tests__/plugin-advanced.test.mjs +225 -0
  46. package/dist/__tests__/plugins.test.cjs +412 -0
  47. package/dist/__tests__/plugins.test.d.ts +1 -0
  48. package/dist/__tests__/plugins.test.mjs +402 -0
  49. package/dist/__tests__/screenshot-capture.test.cjs +183 -0
  50. package/dist/__tests__/screenshot-capture.test.d.ts +1 -0
  51. package/dist/__tests__/screenshot-capture.test.mjs +124 -0
  52. package/dist/__tests__/screenshot.test.cjs +74 -0
  53. package/dist/__tests__/screenshot.test.d.ts +1 -0
  54. package/dist/__tests__/screenshot.test.mjs +69 -0
  55. package/dist/__tests__/theme.test.cjs +185 -0
  56. package/dist/__tests__/theme.test.d.ts +1 -0
  57. package/dist/__tests__/theme.test.mjs +191 -0
  58. package/dist/__tests__/transform.test.cjs +376 -50
  59. package/dist/__tests__/transform.test.mjs +229 -28
  60. package/dist/__tests__/useAlignment.test.cjs +37 -0
  61. package/dist/__tests__/useAlignment.test.mjs +20 -0
  62. package/dist/__tests__/useNodeDistribution.test.cjs +643 -0
  63. package/dist/__tests__/useNodeDistribution.test.d.ts +1 -0
  64. package/dist/__tests__/useNodeDistribution.test.mjs +297 -0
  65. package/dist/__tests__/viewport-types.test.cjs +324 -0
  66. package/dist/__tests__/viewport-types.test.d.ts +1 -0
  67. package/dist/__tests__/viewport-types.test.mjs +207 -0
  68. package/dist/utils/bpmn.cjs +27 -16
  69. package/dist/utils/bpmn.mjs +27 -19
  70. package/package.json +3 -3
@@ -0,0 +1,171 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { ref } from "vue";
3
+ import { createExportPlugin } from "../plugins/plugins/export.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/plugins/export", () => {
45
+ let consoleLogSpy;
46
+ beforeEach(() => {
47
+ consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {
48
+ });
49
+ vi.useFakeTimers({ shouldAdvanceTime: false });
50
+ });
51
+ afterEach(() => {
52
+ consoleLogSpy.mockRestore();
53
+ vi.useRealTimers();
54
+ });
55
+ describe("createExportPlugin", () => {
56
+ it("should create plugin with correct id and name", () => {
57
+ const plugin = createExportPlugin();
58
+ expect(plugin.id).toBe("export");
59
+ expect(plugin.name).toBe("Export");
60
+ });
61
+ it("should install exportJson method", () => {
62
+ const flow = createMockFlowInstance();
63
+ flow.nodes.value = [
64
+ { id: "n1", type: "default", position: { x: 0, y: 0 }, data: { label: "Node 1" } }
65
+ ];
66
+ flow.edges.value = [{ id: "e1", source: "n1", target: "n2", type: "default" }];
67
+ const plugin = createExportPlugin();
68
+ plugin.install(flow);
69
+ expect(typeof flow.exportJson).toBe("function");
70
+ });
71
+ it("should exportJson return correct JSON structure", () => {
72
+ const flow = createMockFlowInstance();
73
+ const testNode = { id: "n1", type: "default", position: { x: 100, y: 200 }, data: {} };
74
+ flow.nodes.value = [testNode];
75
+ flow.edges.value = [{ id: "e1", source: "n1", target: "n2", type: "default" }];
76
+ const plugin = createExportPlugin();
77
+ plugin.install(flow);
78
+ const json = flow.exportJson();
79
+ const parsed = JSON.parse(json);
80
+ expect(parsed.nodes).toHaveLength(1);
81
+ expect(parsed.edges).toHaveLength(1);
82
+ expect(parsed.nodes[0].id).toBe("n1");
83
+ });
84
+ it("should exportJson with formatted output", () => {
85
+ const flow = createMockFlowInstance();
86
+ flow.nodes.value = [];
87
+ flow.edges.value = [];
88
+ const plugin = createExportPlugin();
89
+ plugin.install(flow);
90
+ const json = flow.exportJson();
91
+ expect(json).toContain("\n");
92
+ });
93
+ it("should include viewport in exportJson", () => {
94
+ const flow = createMockFlowInstance();
95
+ flow.viewport.value = { x: 50, y: 100, zoom: 1.5 };
96
+ const plugin = createExportPlugin();
97
+ plugin.install(flow);
98
+ const json = flow.exportJson();
99
+ const parsed = JSON.parse(json);
100
+ expect(parsed.viewport).toEqual({ x: 50, y: 100, zoom: 1.5 });
101
+ });
102
+ it("should support custom fileName option", () => {
103
+ const plugin = createExportPlugin({ fileName: "custom-flow-name" });
104
+ expect(plugin.id).toBe("export");
105
+ });
106
+ it("should support different image types", () => {
107
+ const pluginPng = createExportPlugin({ imageType: "png" });
108
+ const pluginJpeg = createExportPlugin({ imageType: "jpeg" });
109
+ const pluginWebp = createExportPlugin({ imageType: "webp" });
110
+ expect(pluginPng.id).toBe("export");
111
+ expect(pluginJpeg.id).toBe("export");
112
+ expect(pluginWebp.id).toBe("export");
113
+ });
114
+ it("should support custom imageQuality", () => {
115
+ const plugin = createExportPlugin({ imageQuality: 0.8 });
116
+ expect(plugin.id).toBe("export");
117
+ });
118
+ it("should support custom pixelRatio", () => {
119
+ const plugin = createExportPlugin({ pixelRatio: 3 });
120
+ expect(plugin.id).toBe("export");
121
+ });
122
+ it("should support custom backgroundColor", () => {
123
+ const plugin = createExportPlugin({ backgroundColor: "#f0f0f0" });
124
+ expect(plugin.id).toBe("export");
125
+ });
126
+ it("should support exportImage disabled", () => {
127
+ const plugin = createExportPlugin({ exportImage: false });
128
+ const flow = createMockFlowInstance();
129
+ plugin.install(flow);
130
+ expect(flow.exportImage).toBeUndefined();
131
+ });
132
+ it("should support exportJson disabled", () => {
133
+ const plugin = createExportPlugin({ exportJson: false });
134
+ const flow = createMockFlowInstance();
135
+ plugin.install(flow);
136
+ expect(flow.exportJson).toBeUndefined();
137
+ });
138
+ it("should not install when enabled is false", () => {
139
+ const plugin = createExportPlugin({ enabled: false });
140
+ const flow = createMockFlowInstance();
141
+ plugin.install(flow);
142
+ expect(flow.exportJson).toBeUndefined();
143
+ expect(flow.exportImage).toBeUndefined();
144
+ });
145
+ it("should merge default options with provided options", () => {
146
+ const plugin = createExportPlugin({ fileName: "test", imageType: "jpeg" });
147
+ expect(plugin.id).toBe("export");
148
+ expect(plugin.name).toBe("Export");
149
+ });
150
+ });
151
+ describe("ExportPluginOptions interface", () => {
152
+ it("should accept all option fields", () => {
153
+ const options = {
154
+ enabled: true,
155
+ fileName: "my-flow",
156
+ exportImage: true,
157
+ exportJson: true,
158
+ imageType: "png",
159
+ imageQuality: 0.9,
160
+ pixelRatio: 2,
161
+ backgroundColor: "#ffffff"
162
+ };
163
+ const plugin = createExportPlugin(options);
164
+ expect(plugin.id).toBe("export");
165
+ });
166
+ it("should accept partial options", () => {
167
+ const plugin = createExportPlugin({ fileName: "partial" });
168
+ expect(plugin.id).toBe("export");
169
+ });
170
+ });
171
+ });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _FlowContext = require("../core/FlowContext.cjs");
5
+ (0, _vitest.describe)("flow/core/FlowContext", () => {
6
+ (0, _vitest.describe)("provideFlowContext", () => {
7
+ (0, _vitest.it)("should accept null without error", () => {
8
+ (0, _vitest.expect)(() => (0, _FlowContext.provideFlowContext)(null)).not.toThrow();
9
+ });
10
+ });
11
+ (0, _vitest.describe)("useFlowContext", () => {
12
+ (0, _vitest.it)("should throw when used outside provider", () => {
13
+ (0, _vitest.expect)(() => (0, _FlowContext.useFlowContext)()).toThrow("[YhFlow] FlowContext is not provided");
14
+ });
15
+ });
16
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { useFlowContext, provideFlowContext } from "../core/FlowContext.mjs";
3
+ describe("flow/core/FlowContext", () => {
4
+ describe("provideFlowContext", () => {
5
+ it("should accept null without error", () => {
6
+ expect(() => provideFlowContext(null)).not.toThrow();
7
+ });
8
+ });
9
+ describe("useFlowContext", () => {
10
+ it("should throw when used outside provider", () => {
11
+ expect(() => useFlowContext()).toThrow(
12
+ "[YhFlow] FlowContext is not provided"
13
+ );
14
+ });
15
+ });
16
+ });
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _flow = require("../flow.cjs");
5
+ (0, _vitest.describe)("flow/flow", () => {
6
+ (0, _vitest.describe)("flowProps", () => {
7
+ (0, _vitest.it)("should have all required prop definitions", () => {
8
+ (0, _vitest.expect)(_flow.flowProps.nodes).toBeDefined();
9
+ (0, _vitest.expect)(_flow.flowProps.edges).toBeDefined();
10
+ (0, _vitest.expect)(_flow.flowProps.modelValue).toBeDefined();
11
+ (0, _vitest.expect)(_flow.flowProps.minZoom).toBeDefined();
12
+ (0, _vitest.expect)(_flow.flowProps.maxZoom).toBeDefined();
13
+ (0, _vitest.expect)(_flow.flowProps.zoomStep).toBeDefined();
14
+ (0, _vitest.expect)(_flow.flowProps.nodesDraggable).toBeDefined();
15
+ (0, _vitest.expect)(_flow.flowProps.edgesConnectable).toBeDefined();
16
+ (0, _vitest.expect)(_flow.flowProps.selectable).toBeDefined();
17
+ (0, _vitest.expect)(_flow.flowProps.background).toBeDefined();
18
+ (0, _vitest.expect)(_flow.flowProps.gridSize).toBeDefined();
19
+ (0, _vitest.expect)(_flow.flowProps.snapToGrid).toBeDefined();
20
+ (0, _vitest.expect)(_flow.flowProps.readonly).toBeDefined();
21
+ (0, _vitest.expect)(_flow.flowProps.keyboardShortcuts).toBeDefined();
22
+ (0, _vitest.expect)(_flow.flowProps.showControls).toBeDefined();
23
+ (0, _vitest.expect)(_flow.flowProps.showMinimap).toBeDefined();
24
+ (0, _vitest.expect)(_flow.flowProps.history).toBeDefined();
25
+ (0, _vitest.expect)(_flow.flowProps.maxHistory).toBeDefined();
26
+ });
27
+ (0, _vitest.it)("should have correct default values for numbers", () => {
28
+ (0, _vitest.expect)(_flow.flowProps.minZoom.default).toBe(0.1);
29
+ (0, _vitest.expect)(_flow.flowProps.maxZoom.default).toBe(5);
30
+ (0, _vitest.expect)(_flow.flowProps.zoomStep.default).toBe(0.1);
31
+ (0, _vitest.expect)(_flow.flowProps.panZoomSpeed.default).toBe(1);
32
+ (0, _vitest.expect)(_flow.flowProps.gridSize.default).toBe(20);
33
+ (0, _vitest.expect)(_flow.flowProps.maxHistory.default).toBe(50);
34
+ (0, _vitest.expect)(_flow.flowProps.virtualizationThreshold.default).toBe(100);
35
+ });
36
+ (0, _vitest.it)("should have correct default values for booleans", () => {
37
+ (0, _vitest.expect)(_flow.flowProps.nodesDraggable.default).toBe(true);
38
+ (0, _vitest.expect)(_flow.flowProps.edgesConnectable.default).toBe(true);
39
+ (0, _vitest.expect)(_flow.flowProps.selectable.default).toBe(true);
40
+ (0, _vitest.expect)(_flow.flowProps.snapToGrid.default).toBe(false);
41
+ (0, _vitest.expect)(_flow.flowProps.readonly.default).toBe(false);
42
+ (0, _vitest.expect)(_flow.flowProps.keyboardShortcuts.default).toBe(true);
43
+ (0, _vitest.expect)(_flow.flowProps.showControls.default).toBe(true);
44
+ (0, _vitest.expect)(_flow.flowProps.showMinimap.default).toBe(false);
45
+ (0, _vitest.expect)(_flow.flowProps.history.default).toBe(true);
46
+ (0, _vitest.expect)(_flow.flowProps.showAlignmentGuides.default).toBe(true);
47
+ (0, _vitest.expect)(_flow.flowProps.virtualized.default).toBe(false);
48
+ });
49
+ (0, _vitest.it)("should have correct default values for strings", () => {
50
+ (0, _vitest.expect)(_flow.flowProps.background.default).toBe("dots");
51
+ (0, _vitest.expect)(_flow.flowProps.backgroundColor.default).toBe("#f8f9fa");
52
+ (0, _vitest.expect)(_flow.flowProps.defaultNodeType.default).toBe("default");
53
+ (0, _vitest.expect)(_flow.flowProps.defaultEdgeType.default).toBe("bezier");
54
+ (0, _vitest.expect)(_flow.flowProps.multiSelectKey.default).toBe("Shift");
55
+ (0, _vitest.expect)(_flow.flowProps.minimapNodeColor.default).toBe("#b1b1b7");
56
+ });
57
+ (0, _vitest.it)("should have isValidConnection defaulting to null", () => {
58
+ (0, _vitest.expect)(_flow.flowProps.isValidConnection.default).toBe(null);
59
+ });
60
+ (0, _vitest.it)("should have themeOverrides defaulting to undefined", () => {
61
+ (0, _vitest.expect)(_flow.flowProps.themeOverrides.default).toBeUndefined();
62
+ });
63
+ });
64
+ (0, _vitest.describe)("flowEmits", () => {
65
+ (0, _vitest.it)("should have update:modelValue emit", () => {
66
+ (0, _vitest.expect)(_flow.flowEmits["update:modelValue"]).toBeDefined();
67
+ });
68
+ (0, _vitest.it)("should have update:nodes emit", () => {
69
+ (0, _vitest.expect)(_flow.flowEmits["update:nodes"]).toBeDefined();
70
+ });
71
+ (0, _vitest.it)("should have update:edges emit", () => {
72
+ (0, _vitest.expect)(_flow.flowEmits["update:edges"]).toBeDefined();
73
+ });
74
+ (0, _vitest.it)("should have node event emits", () => {
75
+ (0, _vitest.expect)(_flow.flowEmits.nodeClick).toBeDefined();
76
+ (0, _vitest.expect)(_flow.flowEmits.nodeDblClick).toBeDefined();
77
+ (0, _vitest.expect)(_flow.flowEmits.nodeDragStart).toBeDefined();
78
+ (0, _vitest.expect)(_flow.flowEmits.nodeDrag).toBeDefined();
79
+ (0, _vitest.expect)(_flow.flowEmits.nodeDragEnd).toBeDefined();
80
+ (0, _vitest.expect)(_flow.flowEmits.nodeContextMenu).toBeDefined();
81
+ });
82
+ (0, _vitest.it)("should have edge event emits", () => {
83
+ (0, _vitest.expect)(_flow.flowEmits.edgeClick).toBeDefined();
84
+ (0, _vitest.expect)(_flow.flowEmits.edgeDblClick).toBeDefined();
85
+ (0, _vitest.expect)(_flow.flowEmits.edgeContextMenu).toBeDefined();
86
+ });
87
+ (0, _vitest.it)("should have connection emits", () => {
88
+ (0, _vitest.expect)(_flow.flowEmits.edgeConnect).toBeDefined();
89
+ (0, _vitest.expect)(_flow.flowEmits.selectionChange).toBeDefined();
90
+ (0, _vitest.expect)(_flow.flowEmits.historyChange).toBeDefined();
91
+ (0, _vitest.expect)(_flow.flowEmits.viewportChange).toBeDefined();
92
+ });
93
+ });
94
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { flowProps, flowEmits } from "../flow.mjs";
3
+ describe("flow/flow", () => {
4
+ describe("flowProps", () => {
5
+ it("should have all required prop definitions", () => {
6
+ expect(flowProps.nodes).toBeDefined();
7
+ expect(flowProps.edges).toBeDefined();
8
+ expect(flowProps.modelValue).toBeDefined();
9
+ expect(flowProps.minZoom).toBeDefined();
10
+ expect(flowProps.maxZoom).toBeDefined();
11
+ expect(flowProps.zoomStep).toBeDefined();
12
+ expect(flowProps.nodesDraggable).toBeDefined();
13
+ expect(flowProps.edgesConnectable).toBeDefined();
14
+ expect(flowProps.selectable).toBeDefined();
15
+ expect(flowProps.background).toBeDefined();
16
+ expect(flowProps.gridSize).toBeDefined();
17
+ expect(flowProps.snapToGrid).toBeDefined();
18
+ expect(flowProps.readonly).toBeDefined();
19
+ expect(flowProps.keyboardShortcuts).toBeDefined();
20
+ expect(flowProps.showControls).toBeDefined();
21
+ expect(flowProps.showMinimap).toBeDefined();
22
+ expect(flowProps.history).toBeDefined();
23
+ expect(flowProps.maxHistory).toBeDefined();
24
+ });
25
+ it("should have correct default values for numbers", () => {
26
+ expect(flowProps.minZoom.default).toBe(0.1);
27
+ expect(flowProps.maxZoom.default).toBe(5);
28
+ expect(flowProps.zoomStep.default).toBe(0.1);
29
+ expect(flowProps.panZoomSpeed.default).toBe(1);
30
+ expect(flowProps.gridSize.default).toBe(20);
31
+ expect(flowProps.maxHistory.default).toBe(50);
32
+ expect(flowProps.virtualizationThreshold.default).toBe(100);
33
+ });
34
+ it("should have correct default values for booleans", () => {
35
+ expect(flowProps.nodesDraggable.default).toBe(true);
36
+ expect(flowProps.edgesConnectable.default).toBe(true);
37
+ expect(flowProps.selectable.default).toBe(true);
38
+ expect(flowProps.snapToGrid.default).toBe(false);
39
+ expect(flowProps.readonly.default).toBe(false);
40
+ expect(flowProps.keyboardShortcuts.default).toBe(true);
41
+ expect(flowProps.showControls.default).toBe(true);
42
+ expect(flowProps.showMinimap.default).toBe(false);
43
+ expect(flowProps.history.default).toBe(true);
44
+ expect(flowProps.showAlignmentGuides.default).toBe(true);
45
+ expect(flowProps.virtualized.default).toBe(false);
46
+ });
47
+ it("should have correct default values for strings", () => {
48
+ expect(flowProps.background.default).toBe("dots");
49
+ expect(flowProps.backgroundColor.default).toBe("#f8f9fa");
50
+ expect(flowProps.defaultNodeType.default).toBe("default");
51
+ expect(flowProps.defaultEdgeType.default).toBe("bezier");
52
+ expect(flowProps.multiSelectKey.default).toBe("Shift");
53
+ expect(flowProps.minimapNodeColor.default).toBe("#b1b1b7");
54
+ });
55
+ it("should have isValidConnection defaulting to null", () => {
56
+ expect(flowProps.isValidConnection.default).toBe(null);
57
+ });
58
+ it("should have themeOverrides defaulting to undefined", () => {
59
+ expect(flowProps.themeOverrides.default).toBeUndefined();
60
+ });
61
+ });
62
+ describe("flowEmits", () => {
63
+ it("should have update:modelValue emit", () => {
64
+ expect(flowEmits["update:modelValue"]).toBeDefined();
65
+ });
66
+ it("should have update:nodes emit", () => {
67
+ expect(flowEmits["update:nodes"]).toBeDefined();
68
+ });
69
+ it("should have update:edges emit", () => {
70
+ expect(flowEmits["update:edges"]).toBeDefined();
71
+ });
72
+ it("should have node event emits", () => {
73
+ expect(flowEmits.nodeClick).toBeDefined();
74
+ expect(flowEmits.nodeDblClick).toBeDefined();
75
+ expect(flowEmits.nodeDragStart).toBeDefined();
76
+ expect(flowEmits.nodeDrag).toBeDefined();
77
+ expect(flowEmits.nodeDragEnd).toBeDefined();
78
+ expect(flowEmits.nodeContextMenu).toBeDefined();
79
+ });
80
+ it("should have edge event emits", () => {
81
+ expect(flowEmits.edgeClick).toBeDefined();
82
+ expect(flowEmits.edgeDblClick).toBeDefined();
83
+ expect(flowEmits.edgeContextMenu).toBeDefined();
84
+ });
85
+ it("should have connection emits", () => {
86
+ expect(flowEmits.edgeConnect).toBeDefined();
87
+ expect(flowEmits.selectionChange).toBeDefined();
88
+ expect(flowEmits.historyChange).toBeDefined();
89
+ expect(flowEmits.viewportChange).toBeDefined();
90
+ });
91
+ });
92
+ });
@@ -0,0 +1,233 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};