|
| 1 | +import React from "react" |
| 2 | +import { renderWithExtensionState, screen } from "@/utils/test-utils" |
| 3 | +import { ChatRowContent } from "../ChatRow" |
| 4 | + |
| 5 | +vi.mock("@src/i18n/TranslationContext", () => ({ |
| 6 | + useAppTranslation: () => ({ |
| 7 | + t: (key: string) => { |
| 8 | + const translations: Record<string, string> = { |
| 9 | + "chat:skill.wantsToLoad": "Roo wants to load a skill", |
| 10 | + "chat:arguments": "Arguments", |
| 11 | + "chat:codebaseSearch.displayError": "Error displaying search results.", |
| 12 | + } |
| 13 | + return translations[key] ?? key |
| 14 | + }, |
| 15 | + }), |
| 16 | +})) |
| 17 | + |
| 18 | +vi.mock("react-i18next", () => ({ |
| 19 | + Trans: ({ children }: { children?: React.ReactNode }) => <>{children}</>, |
| 20 | +})) |
| 21 | + |
| 22 | +vi.mock("@vscode/webview-ui-toolkit/react", () => ({ |
| 23 | + VSCodeBadge: ({ children }: { children?: React.ReactNode }) => <span>{children}</span>, |
| 24 | +})) |
| 25 | + |
| 26 | +vi.mock("@src/components/common/CodeBlock", () => ({ |
| 27 | + default: () => null, |
| 28 | +})) |
| 29 | + |
| 30 | +const renderChatRow = (message: any, isExpanded = false) => |
| 31 | + renderWithExtensionState( |
| 32 | + <ChatRowContent |
| 33 | + message={message} |
| 34 | + isExpanded={isExpanded} |
| 35 | + isLast={false} |
| 36 | + isStreaming={false} |
| 37 | + onToggleExpand={() => {}} |
| 38 | + onSuggestionClick={() => {}} |
| 39 | + onBatchFileResponse={() => {}} |
| 40 | + onFollowUpUnmount={() => {}} |
| 41 | + isFollowUpAnswered={false} |
| 42 | + />, |
| 43 | + ) |
| 44 | + |
| 45 | +describe("ChatRow - skill and codebase search", () => { |
| 46 | + it("renders the translated arguments label for a skill with args", () => { |
| 47 | + const message = { |
| 48 | + type: "ask", |
| 49 | + ask: "tool", |
| 50 | + ts: Date.now(), |
| 51 | + text: JSON.stringify({ |
| 52 | + tool: "skill", |
| 53 | + skill: "my-skill", |
| 54 | + args: "some args", |
| 55 | + description: "A skill", |
| 56 | + source: "project", |
| 57 | + }), |
| 58 | + partial: false, |
| 59 | + } |
| 60 | + |
| 61 | + renderChatRow(message, true) |
| 62 | + |
| 63 | + expect(screen.getByText("Arguments")).toBeInTheDocument() |
| 64 | + expect(screen.getByText("some args")).toBeInTheDocument() |
| 65 | + }) |
| 66 | + |
| 67 | + it("renders the translated error label for an invalid codebase search result", () => { |
| 68 | + const message = { |
| 69 | + type: "say", |
| 70 | + say: "codebase_search_result", |
| 71 | + ts: Date.now(), |
| 72 | + text: JSON.stringify({ notContent: true }), |
| 73 | + partial: false, |
| 74 | + } |
| 75 | + |
| 76 | + renderChatRow(message) |
| 77 | + |
| 78 | + expect(screen.getByText("Error displaying search results.")).toBeInTheDocument() |
| 79 | + }) |
| 80 | +}) |
0 commit comments