145 lines
4.8 KiB
JavaScript
145 lines
4.8 KiB
JavaScript
// Parallel recorded relationships rendered through the real main renderer; no persistence calls.
|
|
const { chromium } = require("playwright"),
|
|
fs = require("fs"),
|
|
path = require("path"),
|
|
assert = require("assert/strict");
|
|
(async () => {
|
|
const b = await chromium.launch();
|
|
try {
|
|
const c = await b.newContext({ viewport: { width: 1920, height: 1080 } }),
|
|
p = await c.newPage(),
|
|
errors = [];
|
|
p.on("pageerror", (e) => errors.push(e.message));
|
|
await c.route("https://cdn.jsdelivr.net/**", (r) =>
|
|
r.fulfill({
|
|
contentType: "application/javascript",
|
|
body: fs.readFileSync(
|
|
path.join(
|
|
__dirname,
|
|
"node_modules",
|
|
r.request().url().includes("cytoscape")
|
|
? "cytoscape/dist/cytoscape.min.js"
|
|
: r.request().url().includes("chart.umd")
|
|
? "chart.js/dist/chart.umd.js"
|
|
: "@microsoft/signalr/dist/browser/signalr.min.js",
|
|
),
|
|
),
|
|
}),
|
|
);
|
|
await c.route("**/CharacterAttributes/Directory?*", (r) =>
|
|
r.fulfill({ json: { canEdit: true, characters: [] } }),
|
|
);
|
|
await p.goto(
|
|
"http://127.0.0.1:5238/fixture?page=relationships&layout=full&cast=20&network=clusters",
|
|
);
|
|
const ready = () =>
|
|
p.waitForFunction(() => {
|
|
const m = window.PlotDirectorRelationshipWorkspace?.mainCommands;
|
|
return m?.initialised && !m.busy && !m.routing;
|
|
});
|
|
await ready();
|
|
const model = await (
|
|
await p.request.get(
|
|
"http://127.0.0.1:5238/relationship-main-state-fixture?cast=20&network=clusters",
|
|
)
|
|
).json(),
|
|
record = model.relationships[0],
|
|
link = model.links.find(
|
|
(e) => e.characterRelationshipID === record.characterRelationshipID,
|
|
);
|
|
model.relationships.push({
|
|
...record,
|
|
characterRelationshipID: 900,
|
|
relationshipTypeName: "Rival",
|
|
relationshipCategoryName: "Hostile / Conflict",
|
|
cssClass: "relationship-category-hostile",
|
|
});
|
|
model.links.push({
|
|
...link,
|
|
characterRelationshipID: 900,
|
|
relationshipLabel: "Rival",
|
|
categoryName: "Hostile / Conflict",
|
|
cssClass: "relationship-category-hostile",
|
|
});
|
|
await p.evaluate(
|
|
(model) => window.PlotDirectorRelationshipWorkspace.update(model),
|
|
model,
|
|
);
|
|
await ready();
|
|
for (const style of ["straight", "curved", "orthogonal"]) {
|
|
await p.locator(".rw-display > summary").click();
|
|
await p.locator("#rwConnector").selectOption(style);
|
|
await p.keyboard.press("Escape");
|
|
await ready();
|
|
const geometry = await p.evaluate(
|
|
({ first, style }) => {
|
|
const cy = window.PlotDirectorRelationshipWorkspace.cy,
|
|
edges = [cy.$id("r-" + first), cy.$id("r-900")];
|
|
return edges.map((e) => ({
|
|
path:
|
|
style === "orthogonal"
|
|
? e.renderedSegmentPoints()
|
|
: style === "straight"
|
|
? [e.renderedSourceEndpoint(), e.renderedTargetEndpoint()]
|
|
: e.renderedControlPoints(),
|
|
color: e.style("line-color"),
|
|
id: e.data("relationshipID"),
|
|
}));
|
|
},
|
|
{ first: record.characterRelationshipID, style },
|
|
);
|
|
assert.notDeepEqual(
|
|
geometry[0].path,
|
|
geometry[1].path,
|
|
style + " visible parallel paths",
|
|
);
|
|
assert.notEqual(
|
|
geometry[0].color,
|
|
geometry[1].color,
|
|
"category colours preserved",
|
|
);
|
|
for (const id of [record.characterRelationshipID, 900]) {
|
|
const pt = await p.evaluate((id) => {
|
|
const cy = window.PlotDirectorRelationshipWorkspace.cy,
|
|
e = cy.$id("r-" + id);
|
|
cy.center(e);
|
|
const box = document
|
|
.getElementById("relationshipMapGraph")
|
|
.getBoundingClientRect(),
|
|
point = e.renderedMidpoint();
|
|
return { x: box.x + point.x, y: box.y + point.y };
|
|
}, id);
|
|
await p.mouse.click(pt.x, pt.y, { button: "right" });
|
|
await p
|
|
.getByRole("menuitem", {
|
|
name: "View relationship details",
|
|
exact: true,
|
|
})
|
|
.click();
|
|
assert.equal(
|
|
await p.evaluate(
|
|
() =>
|
|
window.PlotDirectorRelationshipWorkspace.selectedRelationship
|
|
.characterRelationshipID,
|
|
),
|
|
id,
|
|
style + " separately selects " + id,
|
|
);
|
|
}
|
|
if (style === "curved")
|
|
await p.screenshot({
|
|
path: "/tmp/pd-main-relationships-after/parallel-curved.png",
|
|
});
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
console.log(
|
|
"PASS rendered parallel straight/curved/orthogonal paths, category colours and individual native pointer selection",
|
|
);
|
|
} finally {
|
|
await b.close();
|
|
}
|
|
})().catch((e) => {
|
|
console.error(e.stack);
|
|
process.exitCode = 1;
|
|
});
|