docs(tests): explain legacy history and subgraph synchronization fixtures

This commit is contained in:
2026-11-12 17:17:43 +08:00
parent 2dbe68c6aa
commit ad20013f0f
3 changed files with 16 additions and 0 deletions
+4
View File
@@ -18,6 +18,7 @@ function seeded() {
test("node dragging updates its position; undo and redo retain the current viewport", () => {
let state = seeded();
const id = state.present.nodes[0].id;
// 显式 checkpoint 模拟手势开始;位置通知本身不构成完整手势生命周期测试。
state = canvasReducer(state, { type: "checkpoint" });
state = canvasReducer(state, { type: "nodes", changes: [{ id, type: "position", position: { x: 220, y: -30 }, dragging: true }] });
assert.deepEqual(state.present.nodes[0].position, { x: 220, y: -30 });
@@ -37,6 +38,7 @@ test("deleting a node removes attached edges and undo restores both", () => {
assert.equal(removed.present.edges.length, 0);
const afterEdgeNotification = canvasReducer(removed, { type: "edges", changes: [{ id: "edge", type: "remove" }] });
assert.equal(afterEdgeNotification.past.length, 1);
// 重复删除通知与节点删除属于同一结果,一次撤销应从原历史快照恢复二者。
const restored = canvasReducer(afterEdgeNotification, { type: "undo" });
assert.equal(restored.present.nodes.length, 2);
assert.equal(restored.present.edges.length, 1);
@@ -77,6 +79,7 @@ test("import rejects dangling connections, duplicate nodes, unsafe images and in
(doc) => { doc.nodes.push(makeCanvasNode("image", { x: 0, y: 0 }, "javascript:alert(1)")); },
(doc) => { doc.viewport.zoom = 0; },
]) {
// 每种破坏都使用新文档,避免上一种错误残留导致本轮因错误原因而通过。
const document = seeded().present;
mutate(document);
assert.throws(() => decodeCanvas(JSON.stringify(document)));
@@ -92,6 +95,7 @@ test("draft storage is isolated by workspace and graph", () => {
// 50 次 replace 后 past 受限为 40;undo 产生 redo,新 add 必须清空 redo。
test("undo history is bounded and new edits clear the redo stack", () => {
let state = seeded();
// replace 即使内容等价也在这条旧 reducer 路径记录历史;本例验证条目上限,不测字节容量。
for (let i = 0; i < 50; i++) state = canvasReducer(state, { type: "replace", document: { ...state.present, edges: [] } });
assert.equal(state.past.length, 40);
state = canvasReducer(state, { type: "undo" });