AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend/builder): highlight node output in builder tutorial run step (#13483)
Abhimanyu Yadav67aa12d4c9b9
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/__tests__/run.test.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/__tests__/run.test.tsnew file mode 100644index 0000000000..6a20e83d26--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/__tests__/run.test.ts@@ -0,0 +1,81 @@+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";++vi.mock(+ "@/app/(platform)/build/components/FlowEditor/tutorial/helpers",+ () => ({+ waitForElement: vi.fn(),+ fitViewToScreen: vi.fn(),+ highlightElement: vi.fn(),+ removeAllHighlights: vi.fn(),+ }),+);++// Must import after mocks+import {+ waitForElement,+ fitViewToScreen,+ highlightElement,+ removeAllHighlights,+} from "@/app/(platform)/build/components/FlowEditor/tutorial/helpers";+import { createRunSteps } from "../run";++const NODE_OUTPUT_SELECTOR = '[data-tutorial-id="node-output"]';++type StepLike = {+ id?: string;+ beforeShowPromise?: () => Promise<unknown>;+ when?: { show?: () => void; hide?: () => void };+};++function getStep(id: string): StepLike {+ const tour = { next: vi.fn() };+ const steps = createRunSteps(tour) as StepLike[];+ const step = steps.find((s) => s.id === id);+ if (!step) throw new Error(`step "${id}" not found`);+ return step;+}++describe("createRunSteps – show-output step", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ vi.useFakeTimers();+ });++ afterEach(() => {+ vi.useRealTimers();+ });++ it("waits for the animated fitView to settle before resolving", async () => {+ vi.mocked(waitForElement).mockResolvedValue(document.createElement("div"));++ const step = getStep("show-output");+ const promise = step.beforeShowPromise!();++ // fitView animates the viewport for 800ms; the step awaits a settle delay+ // before resolving so Shepherd measures the output at its final position.+ await vi.runAllTimersAsync();+ await promise;++ expect(waitForElement).toHaveBeenCalledWith(NODE_OUTPUT_SELECTOR, 20000);+ expect(fitViewToScreen).toHaveBeenCalledTimes(1);+ });++ it("resolves without throwing when the output never appears", async () => {+ vi.mocked(waitForElement).mockRejectedValue(new Error("not found"));++ const step = getStep("show-output");++ await expect(step.beforeShowPromise!()).resolves.toBeUndefined();+ expect(fitViewToScreen).not.toHaveBeenCalled();+ });++ it("highlights the node output on show and clears it on hide", () => {+ const step = getStep("show-output");++ step.when!.show!();+ expect(highlightElement).toHaveBeenCalledWith(NODE_OUTPUT_SELECTOR);++ step.when!.hide!();+ expect(removeAllHighlights).toHaveBeenCalled();+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/run.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/run.tsindex bebe69480d..f30c4a1950 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/run.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/tutorial/steps/run.ts@@ -69,16 +69,16 @@ export const createRunSteps = (tour: any): StepOptions[] => [on: "top",},beforeShowPromise: () =>- new Promise((resolve) => {- setTimeout(() => {- waitForElement(TUTORIAL_SELECTORS.FIRST_CALCULATOR_NODE_OUTPUT, 5000)- .then(() => {- fitViewToScreen();- resolve(undefined);- })- .catch(resolve);- }, 300);- }),+ waitForElement(TUTORIAL_SELECTORS.FIRST_CALCULATOR_NODE_OUTPUT, 20000)+ .then(async () => {+ fitViewToScreen();+ // fitView animates the viewport over 800ms. Wait for it to settle so+ // Shepherd measures the output at its final position before opening+ // the overlay — otherwise the spotlight lands where the output used+ // to be and the output stays hidden under the dimmed overlay.+ await new Promise((resolve) => setTimeout(resolve, 900));+ })+ .catch(() => {}),when: {show: () => {highlightElement(TUTORIAL_SELECTORS.FIRST_CALCULATOR_NODE_OUTPUT);