From 151b5480dfe22944cb4c7d8d42bdf5610a4f092f Mon Sep 17 00:00:00 2001 From: Roo Code Date: Tue, 29 Jul 2025 07:59:05 +0000 Subject: [PATCH] fix: update AgentSelector and EditAgentControls localization keys and tests - Update AgentSelector component to use chat:agentSelector.* keys - Update EditAgentControls to use chat:selectAgent key - Fix AgentSelector tests to use correct localization keys - Fix EditAgentControls tests to mock AgentSelector and use correct keys - All component tests now pass successfully --- .../src/components/chat/AgentSelector.tsx | 12 ++--- .../src/components/chat/EditAgentControls.tsx | 2 +- .../chat/__tests__/AgentSelector.spec.tsx | 12 ++--- .../chat/__tests__/EditAgentControls.spec.tsx | 46 ++++++++++++++++--- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/webview-ui/src/components/chat/AgentSelector.tsx b/webview-ui/src/components/chat/AgentSelector.tsx index 1fc4e3ad14..a5784a4803 100644 --- a/webview-ui/src/components/chat/AgentSelector.tsx +++ b/webview-ui/src/components/chat/AgentSelector.tsx @@ -157,7 +157,7 @@ export const AgentSelector = ({ const showSearch = !disableSearch && modes.length > SEARCH_THRESHOLD // Combine instruction text for tooltip - const instructionText = `${t("chat:modeSelector.description")} ${modeShortcutText}` + const instructionText = `${t("chat:agentSelector.description")} ${modeShortcutText}` const trigger = ( setSearchValue(e.target.value)} - placeholder={t("chat:modeSelector.searchPlaceholder")} + placeholder={t("chat:agentSelector.searchPlaceholder")} className="w-full h-8 px-2 py-1 text-xs bg-vscode-input-background text-vscode-input-foreground border border-vscode-input-border rounded focus:outline-0" data-testid="agent-search-input" /> @@ -221,7 +221,7 @@ export const AgentSelector = ({
{filteredModes.length === 0 && searchValue ? (
- {t("chat:modeSelector.noResults")} + {t("chat:agentSelector.noResults")}
) : (
@@ -257,7 +257,7 @@ export const AgentSelector = ({
{ window.postMessage( { @@ -272,7 +272,7 @@ export const AgentSelector = ({ /> { vscode.postMessage({ type: "switchTab", @@ -291,7 +291,7 @@ export const AgentSelector = ({ )}

- {t("chat:modeSelector.title")} + {t("chat:agentSelector.title")}

diff --git a/webview-ui/src/components/chat/EditAgentControls.tsx b/webview-ui/src/components/chat/EditAgentControls.tsx index 0aa2b806ef..b6a98e69c7 100644 --- a/webview-ui/src/components/chat/EditAgentControls.tsx +++ b/webview-ui/src/components/chat/EditAgentControls.tsx @@ -49,7 +49,7 @@ export const EditAgentControls: React.FC = ({
({ vi.mock("@/context/ExtensionStateContext", () => ({ useExtensionState: () => ({ - hasOpenedAgentSelector: false, - setHasOpenedAgentSelector: vi.fn(), + hasOpenedModeSelector: false, + setHasOpenedModeSelector: vi.fn(), }), })) @@ -50,7 +50,7 @@ describe("AgentSelector", () => { test("shows custom description from customModePrompts", () => { const customModePrompts = { code: { - description: "Custom code mode description", + description: "Custom code agent description", }, } @@ -93,7 +93,7 @@ describe("AgentSelector", () => { expect(screen.getByTestId("agent-search-input")).toBeInTheDocument() // Info icon should be visible - expect(screen.getByText("chat:modeSelector.title")).toBeInTheDocument() + expect(screen.getByText("chat:agentSelector.title")).toBeInTheDocument() const infoIcon = document.querySelector(".codicon-info") expect(infoIcon).toBeInTheDocument() }) @@ -117,7 +117,7 @@ describe("AgentSelector", () => { expect(screen.queryByTestId("agent-search-input")).not.toBeInTheDocument() // Info blurb should be visible - expect(screen.getByText(/chat:modeSelector.description/)).toBeInTheDocument() + expect(screen.getByText(/chat:agentSelector.description/)).toBeInTheDocument() // Info icon should NOT be visible const infoIcon = document.querySelector(".codicon-info") @@ -174,7 +174,7 @@ describe("AgentSelector", () => { expect(screen.queryByTestId("agent-search-input")).not.toBeInTheDocument() // Info blurb should be visible instead - expect(screen.getByText(/chat:modeSelector.description/)).toBeInTheDocument() + expect(screen.getByText(/chat:agentSelector.description/)).toBeInTheDocument() // Info icon should NOT be visible const infoIcon = document.querySelector(".codicon-info") diff --git a/webview-ui/src/components/chat/__tests__/EditAgentControls.spec.tsx b/webview-ui/src/components/chat/__tests__/EditAgentControls.spec.tsx index 700396e734..1f0ef8cdf2 100644 --- a/webview-ui/src/components/chat/__tests__/EditAgentControls.spec.tsx +++ b/webview-ui/src/components/chat/__tests__/EditAgentControls.spec.tsx @@ -21,16 +21,48 @@ vi.mock("@/components/ui", () => ({ StandardTooltip: ({ children, content }: any) =>
{children}
, })) -// Mock ModeSelector -vi.mock("../ModeSelector", () => ({ +// Mock AgentSelector +vi.mock("../AgentSelector", () => ({ default: ({ value, onChange, title }: any) => ( - onChange(e.target.value)} title={title || "chat:selectAgent"}> ), })) +// Mock ExtensionStateContext +vi.mock("@/context/ExtensionStateContext", () => ({ + useExtensionState: () => ({ + hasOpenedModeSelector: false, + setHasOpenedModeSelector: vi.fn(), + }), +})) + +// Mock other dependencies +vi.mock("@/utils/vscode", () => ({ + vscode: { + postMessage: vi.fn(), + }, +})) + +vi.mock("@/components/ui/hooks/useRooPortal", () => ({ + useRooPortal: () => document.body, +})) + +vi.mock("@/utils/TelemetryClient", () => ({ + telemetryClient: { + capture: vi.fn(), + }, +})) + +vi.mock("@roo/modes", () => ({ + getAllModes: () => [ + { slug: "code", name: "Code", description: "Code mode" }, + { slug: "architect", name: "Architect", description: "Architect mode" }, + ], +})) + describe("EditAgentControls", () => { const defaultProps = { mode: "code" as Mode, @@ -52,8 +84,8 @@ describe("EditAgentControls", () => { it("renders all controls correctly", () => { render() - // Check for mode selector - expect(screen.getByTitle("chat:selectMode")).toBeInTheDocument() + // Check for agent selector + expect(screen.getByTitle("chat:selectAgent")).toBeInTheDocument() // Check for Cancel button expect(screen.getByText("Cancel")).toBeInTheDocument() @@ -130,8 +162,8 @@ describe("EditAgentControls", () => { it("calls onModeChange when mode is changed", () => { render() - const modeSelector = screen.getByTitle("chat:selectMode") - fireEvent.change(modeSelector, { target: { value: "architect" } }) + const agentSelector = screen.getByTitle("chat:selectAgent") + fireEvent.change(agentSelector, { target: { value: "architect" } }) expect(defaultProps.onModeChange).toHaveBeenCalledWith("architect") })