Skip to content

Commit d23d4a6

Browse files
committed
fix: increase code coverage
1 parent 763283a commit d23d4a6

8 files changed

Lines changed: 321 additions & 1 deletion

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { render, screen } from "@/utils/test-utils"
2+
3+
import CodeAccordion from "../CodeAccordion"
4+
5+
vi.mock("@src/i18n/TranslationContext", () => ({
6+
useAppTranslation: () => ({
7+
t: (key: string, options?: Record<string, unknown>) =>
8+
key === "chat:codeAccordion.openFileAriaLabel" ? `${key} ${JSON.stringify(options)}` : key,
9+
}),
10+
}))
11+
12+
vi.mock("@src/components/common/CodeBlock", () => ({
13+
default: () => null,
14+
}))
15+
16+
describe("CodeAccordion", () => {
17+
it("renders the translated open-file aria label when a jump-to-file handler is provided", () => {
18+
render(
19+
<CodeAccordion
20+
path="src/example.ts"
21+
code="const x = 1"
22+
language="typescript"
23+
isExpanded={false}
24+
onToggleExpand={() => {}}
25+
onJumpToFile={() => {}}
26+
/>,
27+
)
28+
29+
expect(
30+
screen.getByLabelText(`chat:codeAccordion.openFileAriaLabel ${JSON.stringify({ path: "src/example.ts" })}`),
31+
).toBeInTheDocument()
32+
})
33+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { render, screen } from "@/utils/test-utils"
2+
3+
import DiffView from "../DiffView"
4+
5+
vi.mock("@src/i18n/TranslationContext", () => ({
6+
useAppTranslation: () => ({
7+
t: (key: string, options?: Record<string, unknown>) =>
8+
key === "chat:diffView.hiddenLines" ? `${key} ${JSON.stringify(options)}` : key,
9+
}),
10+
}))
11+
12+
// A unified diff with two hunks separated by hidden lines produces a "gap" line
13+
// with a hiddenCount, which renders the translated hidden-lines label.
14+
const twoHunkDiff = `--- a/file.txt
15+
+++ b/file.txt
16+
@@ -1,3 +1,3 @@
17+
context
18+
-old
19+
+new
20+
context
21+
@@ -10,3 +10,3 @@
22+
context
23+
-old2
24+
+new2
25+
context
26+
`
27+
28+
describe("DiffView", () => {
29+
it("renders the translated hidden-lines label for gaps between hunks", () => {
30+
render(<DiffView source={twoHunkDiff} filePath="file.txt" />)
31+
32+
expect(screen.getByText(`chat:diffView.hiddenLines ${JSON.stringify({ count: 6 })}`)).toBeInTheDocument()
33+
})
34+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { render, screen } from "@/utils/test-utils"
2+
3+
import ImageBlock from "../ImageBlock"
4+
5+
vi.mock("@src/i18n/TranslationContext", () => ({
6+
useAppTranslation: () => ({
7+
t: (key: string) => (key === "common:image.generatedAlt" ? "AI Generated Image" : key),
8+
}),
9+
}))
10+
11+
vi.mock("../ImageViewer", () => ({
12+
ImageViewer: ({ alt }: { alt?: string }) => <img alt={alt} data-testid="image-viewer" />,
13+
}))
14+
15+
describe("ImageBlock", () => {
16+
it("passes the translated alt text to the image viewer", () => {
17+
render(<ImageBlock imageUri="vscode-webview://example.png" imagePath="/tmp/example.png" />)
18+
19+
expect(screen.getByTestId("image-viewer")).toHaveAttribute("alt", "AI Generated Image")
20+
})
21+
})
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { McpResource } from "@roo-code/types"
2+
3+
import { render, screen } from "@/utils/test-utils"
4+
5+
import McpResourceRow from "../McpResourceRow"
6+
7+
vi.mock("@src/i18n/TranslationContext", () => ({
8+
useAppTranslation: () => ({
9+
t: (key: string, options?: Record<string, unknown>) => {
10+
const translations: Record<string, string> = {
11+
"mcp:tool.noDescription": "No description",
12+
"mcp:resource.returns": "Returns",
13+
"mcp:resource.unknownMimeType": "Unknown",
14+
}
15+
return translations[key] ?? (options ? `${key} ${JSON.stringify(options)}` : key)
16+
},
17+
}),
18+
}))
19+
20+
describe("McpResourceRow", () => {
21+
it("renders the resource URI", () => {
22+
render(<McpResourceRow item={{ uri: "file:///tmp/example.txt", name: "Example", description: "An example" }} />)
23+
24+
expect(screen.getByText("file:///tmp/example.txt")).toBeInTheDocument()
25+
})
26+
27+
it("falls back to the translated no-description label when name and description are missing", () => {
28+
render(<McpResourceRow item={{ uri: "file:///tmp/example.txt", name: "" } as McpResource} />)
29+
30+
expect(screen.getByText("No description")).toBeInTheDocument()
31+
})
32+
33+
it("renders the translated returns label and unknown mime type fallback", () => {
34+
render(<McpResourceRow item={{ uri: "file:///tmp/example.txt", name: "Example" }} />)
35+
36+
expect(screen.getByText("Returns")).toBeInTheDocument()
37+
expect(screen.getByText("Unknown")).toBeInTheDocument()
38+
})
39+
40+
it("renders the mime type when provided", () => {
41+
render(<McpResourceRow item={{ uri: "file:///tmp/example.txt", name: "Example", mimeType: "text/plain" }} />)
42+
43+
expect(screen.getByText("text/plain")).toBeInTheDocument()
44+
expect(screen.queryByText("Unknown")).not.toBeInTheDocument()
45+
})
46+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { render, screen } from "@/utils/test-utils"
2+
3+
import { ModelDescriptionMarkdown } from "../ModelDescriptionMarkdown"
4+
5+
vi.mock("@src/i18n/TranslationContext", () => ({
6+
useAppTranslation: () => ({
7+
t: (key: string) => {
8+
const translations: Record<string, string> = {
9+
"settings:modelInfo.showLess": "Less",
10+
"settings:modelInfo.showMore": "More",
11+
}
12+
return translations[key] ?? key
13+
},
14+
}),
15+
}))
16+
17+
vi.mock("react-remark", () => ({
18+
useRemark: () => [null, vi.fn()],
19+
}))
20+
21+
vi.mock("@vscode/webview-ui-toolkit/react", () => ({
22+
VSCodeLink: ({ children }: { children?: React.ReactNode }) => <a>{children}</a>,
23+
}))
24+
25+
vi.mock("@/components/ui/collapsible", () => ({
26+
Collapsible: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
27+
CollapsibleTrigger: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
28+
}))
29+
30+
vi.mock("../styles", () => ({
31+
StyledMarkdown: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
32+
}))
33+
34+
describe("ModelDescriptionMarkdown", () => {
35+
it("shows the translated show-more label when collapsed", () => {
36+
render(
37+
<ModelDescriptionMarkdown
38+
key="description"
39+
markdown="Some description"
40+
isExpanded={false}
41+
setIsExpanded={() => {}}
42+
/>,
43+
)
44+
45+
expect(screen.getByText("More")).toBeInTheDocument()
46+
})
47+
48+
it("shows the translated show-less label when expanded", () => {
49+
render(
50+
<ModelDescriptionMarkdown
51+
key="description"
52+
markdown="Some description"
53+
isExpanded={true}
54+
setIsExpanded={() => {}}
55+
/>,
56+
)
57+
58+
expect(screen.getByText("Less")).toBeInTheDocument()
59+
})
60+
})

‎webview-ui/src/components/settings/__tests__/ModelInfoView.spec.tsx‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ vi.mock("@src/i18n/TranslationContext", () => ({
2525
"settings:serviceTier.standard": "Standard",
2626
"settings:serviceTier.flex": "Flex",
2727
"settings:serviceTier.priority": "Priority",
28-
})[key] ?? (key === "settings:modelInfo.tokensValue" ? `${key} ${JSON.stringify(options)}` : key),
28+
})[key] ??
29+
(key === "settings:modelInfo.tokensValue" || key === "settings:modelInfo.pricePerMillionTokens"
30+
? `${key} ${JSON.stringify(options)}`
31+
: key),
2932
}),
3033
}))
3134

@@ -306,4 +309,30 @@ describe("ModelInfoView service tier pricing", () => {
306309
expect(getPricingRowValues("Flex")).toEqual(["Flex", "—", "—", "—"])
307310
expect(getPricingRowValues("Priority")).toEqual(["Priority", "—", "—", "—"])
308311
})
312+
313+
it("renders per-million-token prices for input, output, cache reads, and cache writes", () => {
314+
render(
315+
<ModelInfoView
316+
{...defaultProps}
317+
apiProvider={providerIdentifiers.openai}
318+
modelInfo={{
319+
...baseModelInfo,
320+
cacheWritesPrice: 5,
321+
}}
322+
/>,
323+
)
324+
325+
expect(
326+
screen.getByText(`settings:modelInfo.pricePerMillionTokens ${JSON.stringify({ price: "$10.00" })}`),
327+
).toBeInTheDocument()
328+
expect(
329+
screen.getByText(`settings:modelInfo.pricePerMillionTokens ${JSON.stringify({ price: "$20.00" })}`),
330+
).toBeInTheDocument()
331+
expect(
332+
screen.getByText(`settings:modelInfo.pricePerMillionTokens ${JSON.stringify({ price: "$3.00" })}`),
333+
).toBeInTheDocument()
334+
expect(
335+
screen.getByText(`settings:modelInfo.pricePerMillionTokens ${JSON.stringify({ price: "$5.00" })}`),
336+
).toBeInTheDocument()
337+
})
309338
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { render, screen } from "@/utils/test-utils"
2+
3+
import RooHero from "../RooHero"
4+
5+
vi.mock("@src/i18n/TranslationContext", () => ({
6+
useAppTranslation: () => ({
7+
t: (key: string) => (key === "welcome:landing.logoAlt" ? "Roo logo" : key),
8+
}),
9+
}))
10+
11+
describe("RooHero", () => {
12+
it("renders the logo with the translated alt text", () => {
13+
render(<RooHero />)
14+
15+
expect(screen.getByAltText("Roo logo")).toBeInTheDocument()
16+
})
17+
})

0 commit comments

Comments
 (0)