diff --git a/src/components/__tests__/BaseNode.test.tsx b/src/components/__tests__/BaseNode.test.tsx index c3e461e4..7124f9aa 100644 --- a/src/components/__tests__/BaseNode.test.tsx +++ b/src/components/__tests__/BaseNode.test.tsx @@ -220,7 +220,8 @@ describe("BaseNode", () => { expect(mockZoomNodeById).toHaveBeenCalledWith("test-node-1"); }); - it("should request smart text editing instead of node zoom when smart text content is double-clicked", () => { + it("should request node zoom and smart text editing when smart text content is double-clicked", () => { + vi.useFakeTimers(); mockUseWorkflowStore.mockImplementation((selector) => { const state = { currentNodeIds: [] as string[], @@ -244,11 +245,14 @@ describe("BaseNode", () => { fireEvent.doubleClick(screen.getByTestId("smart-text-content")); - expect(mockZoomNodeById).not.toHaveBeenCalled(); + expect(mockZoomNodeById).toHaveBeenCalledWith("text-node-1"); + expect(editListener).not.toHaveBeenCalled(); + vi.advanceTimersByTime(80); expect(editListener).toHaveBeenCalledTimes(1); expect((editListener.mock.calls[0][0] as CustomEvent).detail).toEqual({ nodeId: "text-node-1" }); } finally { window.removeEventListener(REQUEST_SMART_TEXT_EDIT_EVENT, editListener); + vi.useRealTimers(); } }); diff --git a/src/components/__tests__/WorkflowCanvas.test.tsx b/src/components/__tests__/WorkflowCanvas.test.tsx index 800cebed..2915e610 100644 --- a/src/components/__tests__/WorkflowCanvas.test.tsx +++ b/src/components/__tests__/WorkflowCanvas.test.tsx @@ -423,7 +423,7 @@ describe("WorkflowCanvas", () => { expect(document.querySelector("textarea")).not.toBeInTheDocument(); }); - it("should let smart text enter editing without opening the canvas node menu when preview text is double-clicked", async () => { + it("should center, zoom, and let smart text enter editing without opening the canvas node menu when preview text is double-clicked", async () => { mockGetViewport.mockReturnValue({ x: 0, y: 0, zoom: 0.6 }); mockUseWorkflowStore.mockImplementation((selector) => { return selector(createDefaultState({ @@ -457,10 +457,16 @@ describe("WorkflowCanvas", () => { fireEvent.doubleClick(renderedText); - expect(mockSelectSingleNode).not.toHaveBeenCalledWith("text-1"); - expect(mockSetCenter).not.toHaveBeenCalled(); - expect(document.querySelector('[role="textbox"]')).toBeInTheDocument(); + expect(mockSelectSingleNode).toHaveBeenCalledWith("text-1"); + expect(mockSetCenter).toHaveBeenCalledWith(360, 230, { + duration: 260, + zoom: 2, + }); expect(screen.queryByTestId("canvas-node-menu")).not.toBeInTheDocument(); + + await waitFor(() => { + expect(document.querySelector('[role="textbox"]')).toBeInTheDocument(); + }); }); it("should reduce double-click zoom so large media nodes fit within the viewport", async () => { diff --git a/src/components/nodes/BaseNode.tsx b/src/components/nodes/BaseNode.tsx index f66f32c6..f635dc80 100644 --- a/src/components/nodes/BaseNode.tsx +++ b/src/components/nodes/BaseNode.tsx @@ -322,9 +322,12 @@ export function BaseNode({ event.stopPropagation(); if (node?.type === "smartText") { - window.dispatchEvent(new CustomEvent(REQUEST_SMART_TEXT_EDIT_EVENT, { - detail: { nodeId: id }, - })); + nodeDoubleClickZoom?.zoomNodeById(id); + window.setTimeout(() => { + window.dispatchEvent(new CustomEvent(REQUEST_SMART_TEXT_EDIT_EVENT, { + detail: { nodeId: id }, + })); + }, 80); return; }