big cmap refactoring
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { DiagramGroup } from "../static/cmap/engine/diagram-group.js";
|
||||
import { DiagramComponent } from "../static/cmap/engine/diagram-component.js";
|
||||
import { DiagramEngine } from "../static/cmap/engine/diagram-engine.js";
|
||||
|
||||
function component(engine, attributes) {
|
||||
const state = { ...attributes };
|
||||
const drawing = {
|
||||
visible: true,
|
||||
redraw() {},
|
||||
x: () => state.x,
|
||||
y: () => state.y,
|
||||
width: () => state.width,
|
||||
height: () => state.height
|
||||
};
|
||||
return new DiagramComponent(engine, drawing, ["x", "y", "width", "height"]);
|
||||
}
|
||||
|
||||
test("DiagramGroup calculates bounds for nodes and nested groups", () => {
|
||||
const engine = { surfaceElement: () => null, applyFilter: (handle) => {
|
||||
handle.component.visible = handle.baseVisible;
|
||||
handle.component.redraw();
|
||||
}};
|
||||
const first = component(engine, { x: 10, y: 20, width: 100, height: 40 });
|
||||
const second = component(engine, { x: 150, y: 80, width: 50, height: 30 });
|
||||
const group = new DiagramGroup(engine, { padding: 10 });
|
||||
const nested = new DiagramGroup(engine, { padding: 5 });
|
||||
|
||||
nested.add(second);
|
||||
group.add(first).add(nested);
|
||||
|
||||
assert.deepEqual(group.bounds(), { left: 0, top: 10, right: 215, bottom: 125 });
|
||||
});
|
||||
|
||||
test("DiagramGroup collapse controls member visibility", () => {
|
||||
const engine = { surfaceElement: () => null, applyFilter: (handle) => {
|
||||
handle.component.visible = handle.baseVisible;
|
||||
handle.component.redraw();
|
||||
}};
|
||||
const item = component(engine, { x: 0, y: 0, width: 20, height: 20 });
|
||||
const group = new DiagramGroup(engine);
|
||||
group.add(item);
|
||||
|
||||
assert.equal(group.setExpanded(false), false);
|
||||
assert.equal(item.visible(), false);
|
||||
assert.equal(group.setExpanded(true), true);
|
||||
assert.equal(item.visible(), true);
|
||||
});
|
||||
|
||||
test("DiagramGroup updates frame appearance through its public API", () => {
|
||||
const engine = { surfaceElement: () => null };
|
||||
const group = new DiagramGroup(engine, { backgroundColor: "white", borderColor: "black" });
|
||||
|
||||
group.setAppearance({ label: "Nested", backgroundColor: "green", borderColor: "blue" });
|
||||
|
||||
assert.equal(group.label, "Nested");
|
||||
assert.equal(group.backgroundColor, "green");
|
||||
assert.equal(group.borderColor, "blue");
|
||||
});
|
||||
|
||||
test("nested DiagramGroups keep child frames above parent frames", () => {
|
||||
const engine = {
|
||||
surfaceElement: () => null,
|
||||
applyFilter: (handle) => {
|
||||
handle.component.visible = handle.baseVisible;
|
||||
handle.component.redraw();
|
||||
}
|
||||
};
|
||||
const item = component(engine, { x: 20, y: 20, width: 40, height: 30 });
|
||||
const child = new DiagramGroup(engine, { depth: 1 });
|
||||
const parent = new DiagramGroup(engine, { depth: 0 });
|
||||
child.add(item);
|
||||
parent.add(child);
|
||||
|
||||
assert.equal(child.depth > parent.depth, true);
|
||||
assert.equal(parent.bounds().left, -28);
|
||||
assert.equal(child.bounds().left, -4);
|
||||
});
|
||||
|
||||
test("DiagramEngine combines base visibility with an external filter", () => {
|
||||
const engine = Object.create(DiagramEngine.prototype);
|
||||
engine.filter = null;
|
||||
engine.handles = new Map();
|
||||
engine.groups = new Set();
|
||||
const item = component(engine, { x: 0, y: 0, width: 20, height: 20 });
|
||||
engine.handles.set(item.component, item);
|
||||
|
||||
engine.setFilter((handle) => handle === item);
|
||||
assert.equal(item.visible(), true);
|
||||
engine.setFilter(() => false);
|
||||
assert.equal(item.visible(), false);
|
||||
item.visible(true);
|
||||
assert.equal(item.visible(), false);
|
||||
engine.setFilter(null);
|
||||
assert.equal(item.visible(), true);
|
||||
});
|
||||
Reference in New Issue
Block a user