test(canvas-events): expect both pan-to-node AND fit-deploying-org on NEW root provision
Commit 5adc8a74 (part of this PR) intentionally made
molecule:fit-deploying-org fire for root-level workspaces too — it
used to only fire for children, which meant a standalone create
didn't center the viewport until the first child arrived ~2s later.
The existing regression test still expected ONLY the
molecule:pan-to-node event for a new root, so it started failing
with "expected length 1, got 2". The product behavior is correct
(centering on the root immediately is better UX); the test was
pinning the old single-dispatch shape.
Fix: assert BOTH events fire, each with the right detail payload,
so a future regression that drops either one (or duplicates) trips
the test. Single-test update, no production code change. 953/953
canvas tests pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5adc8a74d5
commit
f995b90a85
@ -67,7 +67,19 @@ describe("canvas-events – molecule:pan-to-node dispatch", () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("dispatches molecule:pan-to-node with the new nodeId for a NEW provision", () => {
|
||||
it("dispatches both molecule:pan-to-node AND molecule:fit-deploying-org for a NEW root-level provision", () => {
|
||||
// Two custom events are dispatched on NEW root-level provision:
|
||||
// 1. molecule:fit-deploying-org — tells useCanvasViewport to
|
||||
// frame the whole deploying subtree. Fires for root nodes
|
||||
// too (commit 5adc8a74) so the canvas centers the just-
|
||||
// landed root immediately instead of waiting for the
|
||||
// first child to arrive.
|
||||
// 2. molecule:pan-to-node — pans/zooms to the single node;
|
||||
// only for standalone creates (no parent), so org-import
|
||||
// children don't chase the spawn animation.
|
||||
// A previous version of this test expected only #2 and failed
|
||||
// when #1 was added for roots. If only one of these ever fires
|
||||
// again, this test should flag the regression.
|
||||
const { get, set } = makeStore([]);
|
||||
const dispatched: Event[] = [];
|
||||
const spy = vi.spyOn(window, "dispatchEvent").mockImplementation((e) => {
|
||||
@ -81,9 +93,15 @@ describe("canvas-events – molecule:pan-to-node dispatch", () => {
|
||||
set
|
||||
);
|
||||
|
||||
expect(dispatched).toHaveLength(1);
|
||||
expect(dispatched[0].type).toBe("molecule:pan-to-node");
|
||||
expect((dispatched[0] as CustomEvent).detail?.nodeId).toBe("ws-new");
|
||||
expect(dispatched).toHaveLength(2);
|
||||
const panEvent = dispatched.find((e) => e.type === "molecule:pan-to-node");
|
||||
const fitEvent = dispatched.find((e) => e.type === "molecule:fit-deploying-org");
|
||||
expect(panEvent, "molecule:pan-to-node should fire for standalone create").toBeDefined();
|
||||
expect(fitEvent, "molecule:fit-deploying-org should fire so the viewport frames the root").toBeDefined();
|
||||
expect((panEvent as CustomEvent).detail?.nodeId).toBe("ws-new");
|
||||
expect((fitEvent as CustomEvent).detail?.rootId).toBe("ws-new");
|
||||
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it("does NOT dispatch molecule:pan-to-node when restarting an existing node", () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user