From f995b90a854e97d274794ddfcff5be78896a798f Mon Sep 17 00:00:00 2001 From: Hongming Wang Date: Fri, 24 Apr 2026 15:55:52 -0700 Subject: [PATCH] test(canvas-events): expect both pan-to-node AND fit-deploying-org on NEW root provision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../store/__tests__/canvas-events-pan.test.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/canvas/src/store/__tests__/canvas-events-pan.test.ts b/canvas/src/store/__tests__/canvas-events-pan.test.ts index 77c687fc..499014c0 100644 --- a/canvas/src/store/__tests__/canvas-events-pan.test.ts +++ b/canvas/src/store/__tests__/canvas-events-pan.test.ts @@ -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", () => {