Integrate Canvas V2 subgraphs, editable edges and AI runs
This commit is contained in:
+39
-26
@@ -38,8 +38,10 @@ globalThis.ResizeObserver = window.ResizeObserver = class {
|
||||
observe(element) { this.callback([{ target: element, contentRect: element.getBoundingClientRect() }]); }
|
||||
unobserve() {} disconnect() {}
|
||||
};
|
||||
let apiMock = null;
|
||||
const requests = [];
|
||||
globalThis.fetch = async (url, options) => {
|
||||
if (apiMock && String(url).startsWith("/api/foundry/")) return apiMock(url, options);
|
||||
requests.push(String(url));
|
||||
assert.ok(String(url).startsWith("/canvas-icons/"), `Unexpected network request ${url}`);
|
||||
if (options?.signal?.aborted) throw new DOMException("Aborted", "AbortError");
|
||||
@@ -64,7 +66,7 @@ try {
|
||||
const event = async (target, type, init = {}) => { assert.ok(target, `Missing target for ${type}`); await act(async () => { const Type = type.startsWith("pointer") ? PointerEvent : type.startsWith("key") ? window.KeyboardEvent : window.MouseEvent; target.dispatchEvent(new Type(type, { bubbles: true, cancelable: true, view: window, ...init })); await tick(); }); };
|
||||
const node = makeCanvasNode("text", { x: 100, y: 100 }); node.id = "text-one";
|
||||
const frameNode = makeCanvasNode("frame", { x: 500, y: 100 }); frameNode.id = "frame-one"; frameNode.data.title = "分区 A";
|
||||
localStorage.setItem("endoleap_canvas_v1:w:b", JSON.stringify({ ...emptyCanvas(), nodes: [node, frameNode] }));
|
||||
localStorage.setItem("endoleap_canvas_v1:w:b", JSON.stringify({ ...emptyCanvas(), nodes: [node, frameNode, { ...makeCanvasNode("text", { x: 900, y: 100 }), id: "text-two" }], edges: [{ id: "edge-test", source: "text-one", target: "text-two", sourceHandle: "right", targetHandle: "left" }] }));
|
||||
await act(async () => { root.render(h(GraphCanvas, { board: { id: "b", workspace_id: "w", kind: "board", title: "test", version: 1 } })); await tick(); });
|
||||
await event(document.querySelector('[data-id="text-one"]'), "click");
|
||||
const toggle = () => document.querySelector('[aria-label="旋转模式"]');
|
||||
@@ -96,7 +98,7 @@ try {
|
||||
await event(window, "mouseup", { clientX: 700, clientY: 200, button: 0 });
|
||||
assert.ok(document.querySelector('[title="属于:分区 A"]'));
|
||||
assert.ok(document.querySelector('[role="status"]').textContent.includes("已加入「分区 A」"));
|
||||
assert.ok(document.querySelector('.react-flow__node[data-id="frame-one"]').textContent.includes("1 项"));
|
||||
assert.ok(!document.querySelector('.react-flow__node[data-id="frame-one"]').textContent.includes("1 项"));
|
||||
await event(textNode, "mousedown", { clientX: 700, clientY: 200, button: 0, buttons: 1 });
|
||||
await event(window, "mousemove", { clientX: 690, clientY: 200, buttons: 1 });
|
||||
await event(window, "mousemove", { clientX: 200, clientY: 200, buttons: 1 });
|
||||
@@ -108,34 +110,39 @@ try {
|
||||
|
||||
const frameElement = document.querySelector('.react-flow__node[data-id="frame-one"]');
|
||||
await event(frameElement, "click");
|
||||
const modeButton = () => document.querySelector('[aria-label="分区名称显示模式"]');
|
||||
assert.equal(modeButton().tagName, "BUTTON", "Frame options must use a custom control");
|
||||
await event(modeButton(), "click");
|
||||
assert.equal(document.querySelectorAll('[role="menuitemradio"]').length, 3);
|
||||
assert.equal(document.querySelector('[role="menuitemradio"][aria-checked="true"] strong').textContent, "固定字号");
|
||||
await event(document.querySelector('[role="menuitemradio"]'), "click");
|
||||
assert.equal(modeButton().textContent, "隐藏名称");
|
||||
const group = document.querySelector('[role="radiogroup"][aria-label="分区名称显示模式"]');
|
||||
assert.ok(group); assert.equal(group.querySelectorAll('[role="radio"]').length, 3);
|
||||
assert.equal(group.querySelector('[aria-checked="true"]').getAttribute("aria-label"), "固定字号");
|
||||
await event(group.querySelector('[aria-label="隐藏名称"]'), "click");
|
||||
assert.equal(frameElement.querySelector('[title="分区 A"]'), null);
|
||||
assert.equal(document.querySelector('[role="menu"]'), null);
|
||||
assert.equal(document.activeElement, modeButton());
|
||||
await event(modeButton(), "keydown", { key: "ArrowDown" });
|
||||
await event(document.activeElement, "keydown", { key: "End" });
|
||||
assert.equal(document.activeElement.querySelector("strong").textContent, "随画布缩放");
|
||||
await event(document.activeElement, "click");
|
||||
assert.equal(modeButton().textContent, "随画布缩放");
|
||||
await event(group.querySelector('[aria-label="隐藏名称"]'), "keydown", { key: "End" });
|
||||
assert.equal(group.querySelector('[aria-checked="true"]').getAttribute("aria-label"), "随画布缩放");
|
||||
assert.ok(frameElement.querySelector('[title="分区 A"]'));
|
||||
await event(document.querySelector('[aria-label="撤销"]'), "click");
|
||||
assert.equal(modeButton().textContent, "隐藏名称");
|
||||
assert.equal(group.querySelector('[aria-checked="true"]').getAttribute("aria-label"), "隐藏名称");
|
||||
await event(document.querySelector('[aria-label="重做"]'), "click");
|
||||
assert.equal(modeButton().textContent, "随画布缩放");
|
||||
await event(modeButton(), "click");
|
||||
await event(document.activeElement, "keydown", { key: "Escape" });
|
||||
assert.equal(document.querySelector('[role="menu"]'), null);
|
||||
assert.equal(document.activeElement, modeButton());
|
||||
await event(modeButton(), "click");
|
||||
await event(document.body, "pointerdown");
|
||||
assert.equal(document.querySelector('[role="menu"]'), null);
|
||||
console.log("PASS frame menu: custom options, selection, keyboard focus, Escape, outside dismissal and undo/redo");
|
||||
assert.equal(group.querySelector('[aria-checked="true"]').getAttribute("aria-label"), "随画布缩放");
|
||||
await event(document.querySelector('[aria-label="八向拉伸模式"]'), "click");
|
||||
assert.equal(document.querySelectorAll('[data-resize-handle]').length, 8);
|
||||
await event(window, "keydown", { key: "Escape" });
|
||||
assert.equal(document.querySelectorAll('[data-resize-handle]').length, 0);
|
||||
console.log("PASS frames: icon segments, no member count, keyboard choice, undo/redo and eight resize handles");
|
||||
|
||||
await event(document.querySelector('.react-flow__edge[data-id="edge-test"]'), "click");
|
||||
assert.ok(document.querySelector('[aria-label="连线编辑"]'));
|
||||
await event(document.querySelector('[aria-label="添加曲线点"]'), "click");
|
||||
assert.ok(document.querySelector('[aria-label="曲线点 1"]'));
|
||||
const arrow = document.querySelector('[aria-label="箭头类型"]');
|
||||
await act(async () => { arrow.value = "triangle"; arrow.dispatchEvent(new window.Event("change", { bubbles: true })); await tick(); });
|
||||
assert.ok(document.querySelector('.react-flow__edge[data-id="edge-test"] .react-flow__edge-path').getAttribute("marker-end"));
|
||||
const animation = document.querySelector('[aria-label="动画播放时机"]');
|
||||
await act(async () => { animation.value = "always"; animation.dispatchEvent(new window.Event("change", { bubbles: true })); await tick(); });
|
||||
assert.ok(document.querySelector("animateMotion"));
|
||||
await act(async () => { animation.value = "executing"; animation.dispatchEvent(new window.Event("change", { bubbles: true })); await tick(); });
|
||||
assert.equal(document.querySelector("animateMotion"), null, "Execution-only animation remains stopped without a running edge");
|
||||
await event(document.querySelector('[aria-label="删除选中曲线点"]'), "click");
|
||||
assert.equal(document.querySelector('[aria-label="曲线点 1"]'), null);
|
||||
console.log("PASS edges: select, add/remove curve knot, markers and always/execution-only animation");
|
||||
|
||||
let choice;
|
||||
await act(async () => { root.render(h(IconPicker, { close() {}, choose(name) { choice = name; } })); await tick(); });
|
||||
@@ -160,6 +167,12 @@ try {
|
||||
assert.equal(grid.querySelector("button").dataset.index, "0", "Category change resets virtual window");
|
||||
console.log("PASS picker: bounded DOM, on-demand data, shared Tabler load and selection");
|
||||
}
|
||||
if (process.env.ROTATION_BASELINE !== "1") {
|
||||
let scenario;
|
||||
await act(async () => { scenario = await import("./canvas-v2-scenario.mjs"); await tick(); });
|
||||
const { canvasV2Scenario } = scenario;
|
||||
await canvasV2Scenario({ root, act, h, GraphCanvas, window, makeCanvasNode, emptyCanvas, event, tick, mock: (handler) => { apiMock = handler; } });
|
||||
}
|
||||
await act(async () => { root.unmount(); await tick(); });
|
||||
} finally {
|
||||
await rm(folder, { recursive: true, force: true }); window.close(); stop();
|
||||
|
||||
Reference in New Issue
Block a user