big cmap refactoring
This commit is contained in:
@@ -75,6 +75,7 @@ function fakeLink(attributes) {
|
||||
}
|
||||
|
||||
async function loadEditorFactory() {
|
||||
const previousFactory = global.window && global.window.RacketWikiCmap;
|
||||
global.Element = class Element {};
|
||||
global.document = {
|
||||
currentScript: null,
|
||||
@@ -83,12 +84,12 @@ async function loadEditorFactory() {
|
||||
createElement: () => fakeElement()
|
||||
};
|
||||
global.window = {
|
||||
Cmap: null,
|
||||
setTimeout,
|
||||
clearTimeout,
|
||||
requestAnimationFrame: (callback) => callback()
|
||||
};
|
||||
await import("../static/cmap/cmap-racket-wiki.js");
|
||||
global.window.RacketWikiCmap = global.window.RacketWikiCmap || previousFactory;
|
||||
return global.window.RacketWikiCmap;
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ test("a dragged connector endpoint survives collapsing and expanding its submap"
|
||||
scrollTop: 0,
|
||||
isConnected: true
|
||||
};
|
||||
const editor = factory.createEditor(canvas, { Cmap: () => map });
|
||||
const editor = factory.createEditor(canvas, { createDiagramEngine: () => map });
|
||||
const submap = editor.addItem({
|
||||
id: 1,
|
||||
kind: "submap",
|
||||
@@ -173,3 +174,47 @@ test("a dragged connector endpoint survives collapsing and expanding its submap"
|
||||
lineWidth: 2
|
||||
}]);
|
||||
});
|
||||
|
||||
test("moving a concept also moves connected concepts that link to another CMap", async () => {
|
||||
const factory = await loadEditorFactory();
|
||||
const map = {
|
||||
onSelection() {},
|
||||
onActivation() {},
|
||||
node: (attributes) => fakeNode(attributes),
|
||||
link: (attributes) => fakeLink(attributes)
|
||||
};
|
||||
const canvas = {
|
||||
addEventListener() {},
|
||||
querySelector: () => null,
|
||||
clientWidth: 1200,
|
||||
clientHeight: 800,
|
||||
scrollLeft: 0,
|
||||
scrollTop: 0,
|
||||
isConnected: true
|
||||
};
|
||||
const editor = factory.createEditor(canvas, { createDiagramEngine: () => map });
|
||||
const owner = editor.addItem({ id: 1, label: "Owner", x: 100, y: 100 });
|
||||
const phrase = editor.addItem({ id: 2, kind: "phrase", label: "relates to", x: 260, y: 100 });
|
||||
const linked = editor.addItem({
|
||||
id: 3,
|
||||
label: "Linked CMap concept",
|
||||
cmapSlug: "other-map",
|
||||
x: 420,
|
||||
y: 100
|
||||
});
|
||||
editor.addConnector(owner, phrase, true, { id: 1 });
|
||||
editor.addConnector(phrase, linked, true, { id: 2 });
|
||||
|
||||
editor.selectItem(owner);
|
||||
editor.handleItemMove(owner, 180, 140);
|
||||
|
||||
assert.deepEqual({
|
||||
owner: [owner.node.attr("x"), owner.node.attr("y")],
|
||||
phrase: [phrase.node.attr("x"), phrase.node.attr("y")],
|
||||
linked: [linked.node.attr("x"), linked.node.attr("y")]
|
||||
}, {
|
||||
owner: [180, 140],
|
||||
phrase: [340, 140],
|
||||
linked: [500, 140]
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user