π OpenHands: AI-Driven Development
fix: use SPA navigation for Start a conversation CTA (#540)
Hiep Le48552f5777c8
diff --git a/__tests__/components/automations/create-instructions.test.tsx b/__tests__/components/automations/create-instructions.test.tsxnew file mode 100644index 0000000000..fbfbe0f7e7--- /dev/null+++ b/__tests__/components/automations/create-instructions.test.tsx@@ -0,0 +1,48 @@+import { render, screen, fireEvent } from "@testing-library/react";+import { describe, it, expect, vi } from "vitest";+import {+ NavigationProvider,+ type NavigationContextValue,+} from "#/context/navigation-context";+import { CreateInstructions } from "#/components/features/automations/create-instructions";+import { I18nKey } from "#/i18n/declaration";++vi.mock("react-i18next", () => ({+ useTranslation: () => ({+ t: (key: string) => {+ const translations: Record<string, string> = {+ [I18nKey.AUTOMATIONS$EMPTY_START_CONVERSATION]: "Start a conversation",+ };+ return translations[key] || key;+ },+ }),+}));++function renderCreateInstructions() {+ const value: NavigationContextValue = {+ currentPath: "/automations",+ conversationId: null,+ isNavigating: false,+ navigate: vi.fn(),+ };++ const result = render(+ <NavigationProvider value={value}>+ <CreateInstructions />+ </NavigationProvider>,+ );++ return { ...result, navigate: value.navigate };+}++describe("CreateInstructions", () => {+ it("navigates to the home route via SPA routing when 'Start a conversation' is clicked", () => {+ const { navigate } = renderCreateInstructions();++ const link = screen.getByRole("link", { name: /start a conversation/i });+ const clickEvent = fireEvent.click(link);++ expect(navigate).toHaveBeenCalledWith("/", { replace: false });+ expect(clickEvent).toBe(false);+ });+});diff --git a/src/components/features/automations/create-instructions.tsx b/src/components/features/automations/create-instructions.tsxindex 297132f8ac..a19685d040 100644--- a/src/components/features/automations/create-instructions.tsx+++ b/src/components/features/automations/create-instructions.tsx@@ -4,6 +4,7 @@ import { I18nKey } from "#/i18n/declaration";import TerminalIcon from "#/icons/terminal.svg?react";import SparkleIcon from "#/icons/sparkle.svg?react";import ChevronDownIcon from "#/icons/chevron-down.svg?react";+import { NavigationLink } from "#/components/shared/navigation-link";const DOCS_URL ="https://docs.openhands.dev/openhands/usage/automations/overview";@@ -61,13 +62,13 @@ export function CreateInstructions({<p className="mt-2 text-sm text-muted">{t(I18nKey.AUTOMATIONS$EMPTY_OPTION_CONVERSATION_DESC)}</p>- <a- href={NEW_CONVERSATION_URL}+ <NavigationLink+ to={NEW_CONVERSATION_URL}className="mt-2 inline-flex items-center gap-1 rounded-md bg-surface-raised px-3 py-2 text-xs font-medium text-content hover:bg-surface-raised transition-colors">{t(I18nKey.AUTOMATIONS$EMPTY_START_CONVERSATION)}<span aria-hidden="true">β</span>- </a>+ </NavigationLink></div></div>