@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,184 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
describe("flow/types/events", () => {
|
|
3
|
+
describe("FlowEventCallback", () => {
|
|
4
|
+
it("should define callback type", () => {
|
|
5
|
+
const callback = (event) => {
|
|
6
|
+
expect(event).toBeDefined();
|
|
7
|
+
};
|
|
8
|
+
expect(typeof callback).toBe("function");
|
|
9
|
+
});
|
|
10
|
+
it("should accept void event type", () => {
|
|
11
|
+
const callback = () => {
|
|
12
|
+
};
|
|
13
|
+
expect(typeof callback).toBe("function");
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe("FlowEventKey", () => {
|
|
17
|
+
it("should define all event keys", () => {
|
|
18
|
+
const keys = [
|
|
19
|
+
"node:click",
|
|
20
|
+
"node:dblclick",
|
|
21
|
+
"node:dragstart",
|
|
22
|
+
"node:drag",
|
|
23
|
+
"node:dragend",
|
|
24
|
+
"node:selected",
|
|
25
|
+
"node:unselected",
|
|
26
|
+
"node:contextmenu",
|
|
27
|
+
"edge:click",
|
|
28
|
+
"edge:dblclick",
|
|
29
|
+
"edge:selected",
|
|
30
|
+
"edge:unselected",
|
|
31
|
+
"edge:contextmenu",
|
|
32
|
+
"edge:connect",
|
|
33
|
+
"edge:update",
|
|
34
|
+
"viewport:change",
|
|
35
|
+
"selection:change",
|
|
36
|
+
"selection:dragstart",
|
|
37
|
+
"selection:drag",
|
|
38
|
+
"selection:dragend",
|
|
39
|
+
"pane:click",
|
|
40
|
+
"pane:dblclick",
|
|
41
|
+
"pane:contextmenu",
|
|
42
|
+
"connect:start",
|
|
43
|
+
"connect:end",
|
|
44
|
+
"connect:cancel"
|
|
45
|
+
];
|
|
46
|
+
expect(keys.length).toBeGreaterThan(20);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("FlowEvents", () => {
|
|
50
|
+
it("should define node click event", () => {
|
|
51
|
+
const event = {
|
|
52
|
+
node: { id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} },
|
|
53
|
+
nativeEvent: new MouseEvent("click")
|
|
54
|
+
};
|
|
55
|
+
expect(event.node.id).toBe("n1");
|
|
56
|
+
});
|
|
57
|
+
it("should define node drag event", () => {
|
|
58
|
+
const event = {
|
|
59
|
+
node: { id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} },
|
|
60
|
+
nativeEvent: new MouseEvent("mousedown"),
|
|
61
|
+
position: { x: 100, y: 200 }
|
|
62
|
+
};
|
|
63
|
+
expect(event.position.x).toBe(100);
|
|
64
|
+
});
|
|
65
|
+
it("should define edge connect event", () => {
|
|
66
|
+
const event = {
|
|
67
|
+
connection: {
|
|
68
|
+
source: "n1",
|
|
69
|
+
target: "n2",
|
|
70
|
+
sourceHandle: "right",
|
|
71
|
+
targetHandle: "left"
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
expect(event.connection.source).toBe("n1");
|
|
75
|
+
expect(event.connection.target).toBe("n2");
|
|
76
|
+
});
|
|
77
|
+
it("should define viewport change event", () => {
|
|
78
|
+
const event = {
|
|
79
|
+
transform: { x: 100, y: 50, zoom: 1.5 }
|
|
80
|
+
};
|
|
81
|
+
expect(event.transform.zoom).toBe(1.5);
|
|
82
|
+
});
|
|
83
|
+
it("should define selection change event", () => {
|
|
84
|
+
const event = {
|
|
85
|
+
selectedNodes: [
|
|
86
|
+
{ id: "n1", type: "default", position: { x: 0, y: 0 }, data: {} }
|
|
87
|
+
],
|
|
88
|
+
selectedEdges: []
|
|
89
|
+
};
|
|
90
|
+
expect(event.selectedNodes.length).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
it("should define pane click event", () => {
|
|
93
|
+
const event = {
|
|
94
|
+
nativeEvent: new MouseEvent("click")
|
|
95
|
+
};
|
|
96
|
+
expect(event.nativeEvent).toBeDefined();
|
|
97
|
+
});
|
|
98
|
+
it("should define connect start event", () => {
|
|
99
|
+
const event = {
|
|
100
|
+
connection: { source: "n1", target: "n2" },
|
|
101
|
+
nativeEvent: new MouseEvent("mousedown")
|
|
102
|
+
};
|
|
103
|
+
expect(event.connection).toBeDefined();
|
|
104
|
+
});
|
|
105
|
+
it("should define connect cancel event", () => {
|
|
106
|
+
const event = void 0;
|
|
107
|
+
expect(event).toBeUndefined();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe("FlowEventHandler", () => {
|
|
111
|
+
it("should define handler for node click", () => {
|
|
112
|
+
const handler = (event) => {
|
|
113
|
+
expect(event.node.id).toBeDefined();
|
|
114
|
+
};
|
|
115
|
+
expect(typeof handler).toBe("function");
|
|
116
|
+
});
|
|
117
|
+
it("should define handler for void event", () => {
|
|
118
|
+
const handler = () => {
|
|
119
|
+
};
|
|
120
|
+
expect(typeof handler).toBe("function");
|
|
121
|
+
});
|
|
122
|
+
it("should define handler for viewport change", () => {
|
|
123
|
+
const handler = (event) => {
|
|
124
|
+
expect(event.transform).toBeDefined();
|
|
125
|
+
};
|
|
126
|
+
expect(typeof handler).toBe("function");
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
describe("EventBus", () => {
|
|
130
|
+
it("should define EventBus interface", () => {
|
|
131
|
+
const bus = {
|
|
132
|
+
on: () => {
|
|
133
|
+
},
|
|
134
|
+
off: () => {
|
|
135
|
+
},
|
|
136
|
+
emit: () => {
|
|
137
|
+
},
|
|
138
|
+
once: () => {
|
|
139
|
+
},
|
|
140
|
+
clear: () => {
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
expect(typeof bus.on).toBe("function");
|
|
144
|
+
expect(typeof bus.off).toBe("function");
|
|
145
|
+
expect(typeof bus.emit).toBe("function");
|
|
146
|
+
expect(typeof bus.once).toBe("function");
|
|
147
|
+
expect(typeof bus.clear).toBe("function");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe("SelectionRect", () => {
|
|
151
|
+
it("should define selection rectangle", () => {
|
|
152
|
+
const rect = {
|
|
153
|
+
x: 100,
|
|
154
|
+
y: 200,
|
|
155
|
+
width: 300,
|
|
156
|
+
height: 150
|
|
157
|
+
};
|
|
158
|
+
expect(rect.x).toBe(100);
|
|
159
|
+
expect(rect.y).toBe(200);
|
|
160
|
+
expect(rect.width).toBe(300);
|
|
161
|
+
expect(rect.height).toBe(150);
|
|
162
|
+
});
|
|
163
|
+
it("should allow negative coordinates", () => {
|
|
164
|
+
const rect = {
|
|
165
|
+
x: -50,
|
|
166
|
+
y: -100,
|
|
167
|
+
width: 200,
|
|
168
|
+
height: 100
|
|
169
|
+
};
|
|
170
|
+
expect(rect.x).toBe(-50);
|
|
171
|
+
expect(rect.y).toBe(-100);
|
|
172
|
+
});
|
|
173
|
+
it("should allow zero dimensions", () => {
|
|
174
|
+
const rect = {
|
|
175
|
+
x: 0,
|
|
176
|
+
y: 0,
|
|
177
|
+
width: 0,
|
|
178
|
+
height: 0
|
|
179
|
+
};
|
|
180
|
+
expect(rect.width).toBe(0);
|
|
181
|
+
expect(rect.height).toBe(0);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _vue = require("vue");
|
|
5
|
+
var _export = require("../plugins/plugins/export.cjs");
|
|
6
|
+
var screenshot = _interopRequireWildcard(require("../utils/screenshot.cjs"));
|
|
7
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
8
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
|
+
_vitest.vi.mock("../utils/screenshot", () => ({
|
|
10
|
+
captureElement: _vitest.vi.fn().mockResolvedValue({
|
|
11
|
+
dataUrl: "data:image/png;base64,xx",
|
|
12
|
+
blob: new Blob(),
|
|
13
|
+
extension: "png"
|
|
14
|
+
}),
|
|
15
|
+
triggerDownload: _vitest.vi.fn(),
|
|
16
|
+
copyBlobToClipboard: _vitest.vi.fn().mockResolvedValue(void 0)
|
|
17
|
+
}));
|
|
18
|
+
function createMockFlow(overrides = {}) {
|
|
19
|
+
const nodes = (0, _vue.ref)([]);
|
|
20
|
+
const edges = (0, _vue.ref)([]);
|
|
21
|
+
const viewport = (0, _vue.ref)({
|
|
22
|
+
x: 0,
|
|
23
|
+
y: 0,
|
|
24
|
+
zoom: 1
|
|
25
|
+
});
|
|
26
|
+
const el = document.createElement("div");
|
|
27
|
+
return {
|
|
28
|
+
nodes,
|
|
29
|
+
edges,
|
|
30
|
+
viewport,
|
|
31
|
+
draggingNodeId: (0, _vue.ref)(null),
|
|
32
|
+
addNode: _vitest.vi.fn(),
|
|
33
|
+
removeNode: _vitest.vi.fn(),
|
|
34
|
+
updateNode: _vitest.vi.fn(),
|
|
35
|
+
getNode: _vitest.vi.fn(),
|
|
36
|
+
addEdge: _vitest.vi.fn(),
|
|
37
|
+
removeEdge: _vitest.vi.fn(),
|
|
38
|
+
updateEdge: _vitest.vi.fn(),
|
|
39
|
+
getEdge: _vitest.vi.fn(),
|
|
40
|
+
setViewport: _vitest.vi.fn(),
|
|
41
|
+
fitView: _vitest.vi.fn(),
|
|
42
|
+
zoomIn: _vitest.vi.fn(),
|
|
43
|
+
zoomOut: _vitest.vi.fn(),
|
|
44
|
+
centerView: _vitest.vi.fn(),
|
|
45
|
+
selectNode: _vitest.vi.fn(),
|
|
46
|
+
selectEdge: _vitest.vi.fn(),
|
|
47
|
+
clearSelection: _vitest.vi.fn(),
|
|
48
|
+
getNodes: _vitest.vi.fn(() => nodes.value),
|
|
49
|
+
getEdges: _vitest.vi.fn(() => edges.value),
|
|
50
|
+
getViewport: _vitest.vi.fn(() => viewport.value),
|
|
51
|
+
screenToCanvas: _vitest.vi.fn(),
|
|
52
|
+
canvasToScreen: _vitest.vi.fn(),
|
|
53
|
+
on: _vitest.vi.fn(),
|
|
54
|
+
off: _vitest.vi.fn(),
|
|
55
|
+
emit: _vitest.vi.fn(),
|
|
56
|
+
isValidConnection: _vitest.vi.fn(() => true),
|
|
57
|
+
$el: el,
|
|
58
|
+
usePlugin: _vitest.vi.fn(),
|
|
59
|
+
removePlugin: _vitest.vi.fn(),
|
|
60
|
+
...overrides
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
(0, _vitest.describe)("flow export plugin exportImage", () => {
|
|
64
|
+
(0, _vitest.beforeEach)(() => {
|
|
65
|
+
_vitest.vi.mocked(screenshot.captureElement).mockClear();
|
|
66
|
+
_vitest.vi.mocked(screenshot.triggerDownload).mockClear();
|
|
67
|
+
_vitest.vi.mocked(screenshot.copyBlobToClipboard).mockClear();
|
|
68
|
+
});
|
|
69
|
+
(0, _vitest.afterEach)(() => {
|
|
70
|
+
_vitest.vi.clearAllMocks();
|
|
71
|
+
});
|
|
72
|
+
(0, _vitest.it)("captures viewport and triggers download by default", async () => {
|
|
73
|
+
const flow = createMockFlow();
|
|
74
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
75
|
+
fileName: "chart"
|
|
76
|
+
});
|
|
77
|
+
plugin.install(flow);
|
|
78
|
+
await flow.exportImage();
|
|
79
|
+
(0, _vitest.expect)(screenshot.captureElement).toHaveBeenCalled();
|
|
80
|
+
(0, _vitest.expect)(screenshot.triggerDownload).toHaveBeenCalled();
|
|
81
|
+
});
|
|
82
|
+
(0, _vitest.it)("throws when no container is available", async () => {
|
|
83
|
+
const flow = createMockFlow({
|
|
84
|
+
$el: void 0
|
|
85
|
+
});
|
|
86
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
87
|
+
plugin.install(flow);
|
|
88
|
+
await (0, _vitest.expect)(flow.exportImage()).rejects.toThrow(/No element found/);
|
|
89
|
+
});
|
|
90
|
+
(0, _vitest.it)("uses explicit HTMLElement as capture target", async () => {
|
|
91
|
+
const flow = createMockFlow({
|
|
92
|
+
$el: void 0
|
|
93
|
+
});
|
|
94
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
95
|
+
plugin.install(flow);
|
|
96
|
+
const box = document.createElement("div");
|
|
97
|
+
await flow.exportImage(box);
|
|
98
|
+
(0, _vitest.expect)(screenshot.captureElement).toHaveBeenCalledWith(box, _vitest.expect.objectContaining({
|
|
99
|
+
imageType: "png",
|
|
100
|
+
pixelRatio: 2
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
(0, _vitest.it)("skips download when download: false", async () => {
|
|
104
|
+
const flow = createMockFlow();
|
|
105
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
106
|
+
plugin.install(flow);
|
|
107
|
+
await flow.exportImage({
|
|
108
|
+
download: false
|
|
109
|
+
});
|
|
110
|
+
(0, _vitest.expect)(screenshot.triggerDownload).not.toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
(0, _vitest.it)("copies to clipboard when copyToClipboard is true", async () => {
|
|
113
|
+
const flow = createMockFlow();
|
|
114
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
115
|
+
plugin.install(flow);
|
|
116
|
+
await flow.exportImage({
|
|
117
|
+
copyToClipboard: true
|
|
118
|
+
});
|
|
119
|
+
(0, _vitest.expect)(screenshot.copyBlobToClipboard).toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
(0, _vitest.it)("uses full mode with fitView and restores viewport", async () => {
|
|
122
|
+
const vp = {
|
|
123
|
+
x: 1,
|
|
124
|
+
y: 2,
|
|
125
|
+
zoom: 1.5
|
|
126
|
+
};
|
|
127
|
+
const flow = createMockFlow({
|
|
128
|
+
getViewport: _vitest.vi.fn(() => vp),
|
|
129
|
+
fitView: _vitest.vi.fn()
|
|
130
|
+
});
|
|
131
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
132
|
+
plugin.install(flow);
|
|
133
|
+
await flow.exportImage({
|
|
134
|
+
mode: "full",
|
|
135
|
+
fullModePadding: 12
|
|
136
|
+
});
|
|
137
|
+
(0, _vitest.expect)(flow.fitView).toHaveBeenCalledWith({
|
|
138
|
+
padding: 12
|
|
139
|
+
});
|
|
140
|
+
(0, _vitest.expect)(flow.setViewport).toHaveBeenCalledWith(vp);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { createExportPlugin } from "../plugins/plugins/export.mjs";
|
|
4
|
+
import * as screenshot from "../utils/screenshot.mjs";
|
|
5
|
+
vi.mock("../utils/screenshot", () => ({
|
|
6
|
+
captureElement: vi.fn().mockResolvedValue({
|
|
7
|
+
dataUrl: "data:image/png;base64,xx",
|
|
8
|
+
blob: new Blob(),
|
|
9
|
+
extension: "png"
|
|
10
|
+
}),
|
|
11
|
+
triggerDownload: vi.fn(),
|
|
12
|
+
copyBlobToClipboard: vi.fn().mockResolvedValue(void 0)
|
|
13
|
+
}));
|
|
14
|
+
function createMockFlow(overrides = {}) {
|
|
15
|
+
const nodes = ref([]);
|
|
16
|
+
const edges = ref([]);
|
|
17
|
+
const viewport = ref({ x: 0, y: 0, zoom: 1 });
|
|
18
|
+
const el = document.createElement("div");
|
|
19
|
+
return {
|
|
20
|
+
nodes,
|
|
21
|
+
edges,
|
|
22
|
+
viewport,
|
|
23
|
+
draggingNodeId: ref(null),
|
|
24
|
+
addNode: vi.fn(),
|
|
25
|
+
removeNode: vi.fn(),
|
|
26
|
+
updateNode: vi.fn(),
|
|
27
|
+
getNode: vi.fn(),
|
|
28
|
+
addEdge: vi.fn(),
|
|
29
|
+
removeEdge: vi.fn(),
|
|
30
|
+
updateEdge: vi.fn(),
|
|
31
|
+
getEdge: vi.fn(),
|
|
32
|
+
setViewport: vi.fn(),
|
|
33
|
+
fitView: vi.fn(),
|
|
34
|
+
zoomIn: vi.fn(),
|
|
35
|
+
zoomOut: vi.fn(),
|
|
36
|
+
centerView: vi.fn(),
|
|
37
|
+
selectNode: vi.fn(),
|
|
38
|
+
selectEdge: vi.fn(),
|
|
39
|
+
clearSelection: vi.fn(),
|
|
40
|
+
getNodes: vi.fn(() => nodes.value),
|
|
41
|
+
getEdges: vi.fn(() => edges.value),
|
|
42
|
+
getViewport: vi.fn(() => viewport.value),
|
|
43
|
+
screenToCanvas: vi.fn(),
|
|
44
|
+
canvasToScreen: vi.fn(),
|
|
45
|
+
on: vi.fn(),
|
|
46
|
+
off: vi.fn(),
|
|
47
|
+
emit: vi.fn(),
|
|
48
|
+
isValidConnection: vi.fn(() => true),
|
|
49
|
+
$el: el,
|
|
50
|
+
usePlugin: vi.fn(),
|
|
51
|
+
removePlugin: vi.fn(),
|
|
52
|
+
...overrides
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
describe("flow export plugin exportImage", () => {
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
vi.mocked(screenshot.captureElement).mockClear();
|
|
58
|
+
vi.mocked(screenshot.triggerDownload).mockClear();
|
|
59
|
+
vi.mocked(screenshot.copyBlobToClipboard).mockClear();
|
|
60
|
+
});
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
vi.clearAllMocks();
|
|
63
|
+
});
|
|
64
|
+
it("captures viewport and triggers download by default", async () => {
|
|
65
|
+
const flow = createMockFlow();
|
|
66
|
+
const plugin = createExportPlugin({ fileName: "chart" });
|
|
67
|
+
plugin.install(flow);
|
|
68
|
+
await flow.exportImage();
|
|
69
|
+
expect(screenshot.captureElement).toHaveBeenCalled();
|
|
70
|
+
expect(screenshot.triggerDownload).toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
it("throws when no container is available", async () => {
|
|
73
|
+
const flow = createMockFlow({ $el: void 0 });
|
|
74
|
+
const plugin = createExportPlugin();
|
|
75
|
+
plugin.install(flow);
|
|
76
|
+
await expect(flow.exportImage()).rejects.toThrow(/No element found/);
|
|
77
|
+
});
|
|
78
|
+
it("uses explicit HTMLElement as capture target", async () => {
|
|
79
|
+
const flow = createMockFlow({ $el: void 0 });
|
|
80
|
+
const plugin = createExportPlugin();
|
|
81
|
+
plugin.install(flow);
|
|
82
|
+
const box = document.createElement("div");
|
|
83
|
+
await flow.exportImage(box);
|
|
84
|
+
expect(screenshot.captureElement).toHaveBeenCalledWith(
|
|
85
|
+
box,
|
|
86
|
+
expect.objectContaining({
|
|
87
|
+
imageType: "png",
|
|
88
|
+
pixelRatio: 2
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
it("skips download when download: false", async () => {
|
|
93
|
+
const flow = createMockFlow();
|
|
94
|
+
const plugin = createExportPlugin();
|
|
95
|
+
plugin.install(flow);
|
|
96
|
+
await flow.exportImage({ download: false });
|
|
97
|
+
expect(screenshot.triggerDownload).not.toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
it("copies to clipboard when copyToClipboard is true", async () => {
|
|
100
|
+
const flow = createMockFlow();
|
|
101
|
+
const plugin = createExportPlugin();
|
|
102
|
+
plugin.install(flow);
|
|
103
|
+
await flow.exportImage({ copyToClipboard: true });
|
|
104
|
+
expect(screenshot.copyBlobToClipboard).toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
it("uses full mode with fitView and restores viewport", async () => {
|
|
107
|
+
const vp = { x: 1, y: 2, zoom: 1.5 };
|
|
108
|
+
const flow = createMockFlow({
|
|
109
|
+
getViewport: vi.fn(() => vp),
|
|
110
|
+
fitView: vi.fn()
|
|
111
|
+
});
|
|
112
|
+
const plugin = createExportPlugin();
|
|
113
|
+
plugin.install(flow);
|
|
114
|
+
await flow.exportImage({ mode: "full", fullModePadding: 12 });
|
|
115
|
+
expect(flow.fitView).toHaveBeenCalledWith({ padding: 12 });
|
|
116
|
+
expect(flow.setViewport).toHaveBeenCalledWith(vp);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _vue = require("vue");
|
|
5
|
+
var _export = require("../plugins/plugins/export.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
|
+
(0, _vitest.describe)("flow/plugins/plugins/export", () => {
|
|
51
|
+
let consoleLogSpy;
|
|
52
|
+
(0, _vitest.beforeEach)(() => {
|
|
53
|
+
consoleLogSpy = _vitest.vi.spyOn(console, "log").mockImplementation(() => {});
|
|
54
|
+
_vitest.vi.useFakeTimers({
|
|
55
|
+
shouldAdvanceTime: false
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
(0, _vitest.afterEach)(() => {
|
|
59
|
+
consoleLogSpy.mockRestore();
|
|
60
|
+
_vitest.vi.useRealTimers();
|
|
61
|
+
});
|
|
62
|
+
(0, _vitest.describe)("createExportPlugin", () => {
|
|
63
|
+
(0, _vitest.it)("should create plugin with correct id and name", () => {
|
|
64
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
65
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
66
|
+
(0, _vitest.expect)(plugin.name).toBe("Export");
|
|
67
|
+
});
|
|
68
|
+
(0, _vitest.it)("should install exportJson method", () => {
|
|
69
|
+
const flow = createMockFlowInstance();
|
|
70
|
+
flow.nodes.value = [{
|
|
71
|
+
id: "n1",
|
|
72
|
+
type: "default",
|
|
73
|
+
position: {
|
|
74
|
+
x: 0,
|
|
75
|
+
y: 0
|
|
76
|
+
},
|
|
77
|
+
data: {
|
|
78
|
+
label: "Node 1"
|
|
79
|
+
}
|
|
80
|
+
}];
|
|
81
|
+
flow.edges.value = [{
|
|
82
|
+
id: "e1",
|
|
83
|
+
source: "n1",
|
|
84
|
+
target: "n2",
|
|
85
|
+
type: "default"
|
|
86
|
+
}];
|
|
87
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
88
|
+
plugin.install(flow);
|
|
89
|
+
(0, _vitest.expect)(typeof flow.exportJson).toBe("function");
|
|
90
|
+
});
|
|
91
|
+
(0, _vitest.it)("should exportJson return correct JSON structure", () => {
|
|
92
|
+
const flow = createMockFlowInstance();
|
|
93
|
+
const testNode = {
|
|
94
|
+
id: "n1",
|
|
95
|
+
type: "default",
|
|
96
|
+
position: {
|
|
97
|
+
x: 100,
|
|
98
|
+
y: 200
|
|
99
|
+
},
|
|
100
|
+
data: {}
|
|
101
|
+
};
|
|
102
|
+
flow.nodes.value = [testNode];
|
|
103
|
+
flow.edges.value = [{
|
|
104
|
+
id: "e1",
|
|
105
|
+
source: "n1",
|
|
106
|
+
target: "n2",
|
|
107
|
+
type: "default"
|
|
108
|
+
}];
|
|
109
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
110
|
+
plugin.install(flow);
|
|
111
|
+
const json = flow.exportJson();
|
|
112
|
+
const parsed = JSON.parse(json);
|
|
113
|
+
(0, _vitest.expect)(parsed.nodes).toHaveLength(1);
|
|
114
|
+
(0, _vitest.expect)(parsed.edges).toHaveLength(1);
|
|
115
|
+
(0, _vitest.expect)(parsed.nodes[0].id).toBe("n1");
|
|
116
|
+
});
|
|
117
|
+
(0, _vitest.it)("should exportJson with formatted output", () => {
|
|
118
|
+
const flow = createMockFlowInstance();
|
|
119
|
+
flow.nodes.value = [];
|
|
120
|
+
flow.edges.value = [];
|
|
121
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
122
|
+
plugin.install(flow);
|
|
123
|
+
const json = flow.exportJson();
|
|
124
|
+
(0, _vitest.expect)(json).toContain("\n");
|
|
125
|
+
});
|
|
126
|
+
(0, _vitest.it)("should include viewport in exportJson", () => {
|
|
127
|
+
const flow = createMockFlowInstance();
|
|
128
|
+
flow.viewport.value = {
|
|
129
|
+
x: 50,
|
|
130
|
+
y: 100,
|
|
131
|
+
zoom: 1.5
|
|
132
|
+
};
|
|
133
|
+
const plugin = (0, _export.createExportPlugin)();
|
|
134
|
+
plugin.install(flow);
|
|
135
|
+
const json = flow.exportJson();
|
|
136
|
+
const parsed = JSON.parse(json);
|
|
137
|
+
(0, _vitest.expect)(parsed.viewport).toEqual({
|
|
138
|
+
x: 50,
|
|
139
|
+
y: 100,
|
|
140
|
+
zoom: 1.5
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
(0, _vitest.it)("should support custom fileName option", () => {
|
|
144
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
145
|
+
fileName: "custom-flow-name"
|
|
146
|
+
});
|
|
147
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
148
|
+
});
|
|
149
|
+
(0, _vitest.it)("should support different image types", () => {
|
|
150
|
+
const pluginPng = (0, _export.createExportPlugin)({
|
|
151
|
+
imageType: "png"
|
|
152
|
+
});
|
|
153
|
+
const pluginJpeg = (0, _export.createExportPlugin)({
|
|
154
|
+
imageType: "jpeg"
|
|
155
|
+
});
|
|
156
|
+
const pluginWebp = (0, _export.createExportPlugin)({
|
|
157
|
+
imageType: "webp"
|
|
158
|
+
});
|
|
159
|
+
(0, _vitest.expect)(pluginPng.id).toBe("export");
|
|
160
|
+
(0, _vitest.expect)(pluginJpeg.id).toBe("export");
|
|
161
|
+
(0, _vitest.expect)(pluginWebp.id).toBe("export");
|
|
162
|
+
});
|
|
163
|
+
(0, _vitest.it)("should support custom imageQuality", () => {
|
|
164
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
165
|
+
imageQuality: 0.8
|
|
166
|
+
});
|
|
167
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
168
|
+
});
|
|
169
|
+
(0, _vitest.it)("should support custom pixelRatio", () => {
|
|
170
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
171
|
+
pixelRatio: 3
|
|
172
|
+
});
|
|
173
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
174
|
+
});
|
|
175
|
+
(0, _vitest.it)("should support custom backgroundColor", () => {
|
|
176
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
177
|
+
backgroundColor: "#f0f0f0"
|
|
178
|
+
});
|
|
179
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
180
|
+
});
|
|
181
|
+
(0, _vitest.it)("should support exportImage disabled", () => {
|
|
182
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
183
|
+
exportImage: false
|
|
184
|
+
});
|
|
185
|
+
const flow = createMockFlowInstance();
|
|
186
|
+
plugin.install(flow);
|
|
187
|
+
(0, _vitest.expect)(flow.exportImage).toBeUndefined();
|
|
188
|
+
});
|
|
189
|
+
(0, _vitest.it)("should support exportJson disabled", () => {
|
|
190
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
191
|
+
exportJson: false
|
|
192
|
+
});
|
|
193
|
+
const flow = createMockFlowInstance();
|
|
194
|
+
plugin.install(flow);
|
|
195
|
+
(0, _vitest.expect)(flow.exportJson).toBeUndefined();
|
|
196
|
+
});
|
|
197
|
+
(0, _vitest.it)("should not install when enabled is false", () => {
|
|
198
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
199
|
+
enabled: false
|
|
200
|
+
});
|
|
201
|
+
const flow = createMockFlowInstance();
|
|
202
|
+
plugin.install(flow);
|
|
203
|
+
(0, _vitest.expect)(flow.exportJson).toBeUndefined();
|
|
204
|
+
(0, _vitest.expect)(flow.exportImage).toBeUndefined();
|
|
205
|
+
});
|
|
206
|
+
(0, _vitest.it)("should merge default options with provided options", () => {
|
|
207
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
208
|
+
fileName: "test",
|
|
209
|
+
imageType: "jpeg"
|
|
210
|
+
});
|
|
211
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
212
|
+
(0, _vitest.expect)(plugin.name).toBe("Export");
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
(0, _vitest.describe)("ExportPluginOptions interface", () => {
|
|
216
|
+
(0, _vitest.it)("should accept all option fields", () => {
|
|
217
|
+
const options = {
|
|
218
|
+
enabled: true,
|
|
219
|
+
fileName: "my-flow",
|
|
220
|
+
exportImage: true,
|
|
221
|
+
exportJson: true,
|
|
222
|
+
imageType: "png",
|
|
223
|
+
imageQuality: 0.9,
|
|
224
|
+
pixelRatio: 2,
|
|
225
|
+
backgroundColor: "#ffffff"
|
|
226
|
+
};
|
|
227
|
+
const plugin = (0, _export.createExportPlugin)(options);
|
|
228
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
229
|
+
});
|
|
230
|
+
(0, _vitest.it)("should accept partial options", () => {
|
|
231
|
+
const plugin = (0, _export.createExportPlugin)({
|
|
232
|
+
fileName: "partial"
|
|
233
|
+
});
|
|
234
|
+
(0, _vitest.expect)(plugin.id).toBe("export");
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|