Skip to content

Commit 399d0b6

Browse files
committed
fix: fix CodeAccordion.spec.tsx and About.spec.tsx issues
1 parent 8283643 commit 399d0b6

2 files changed

Lines changed: 31 additions & 29 deletions

File tree

‎webview-ui/src/components/common/__tests__/CodeAccordion.spec.tsx‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@ import CodeAccordion from "../CodeAccordion"
44

55
vi.mock("@src/i18n/TranslationContext", () => ({
66
useAppTranslation: () => ({
7-
t: (key: string, options?: Record<string, unknown>) => {
8-
const translations: Record<string, string> = {
9-
"chat:codeAccordion.userEdits": "User Edits",
10-
"chat:codeAccordion.consoleLogs": "Console Logs",
11-
}
12-
return (
13-
translations[key] ??
14-
(key === "chat:codeAccordion.openFileAriaLabel" ? `${key} ${JSON.stringify(options)}` : key)
15-
)
16-
},
7+
// Echo keys so assertions fail if the component renders hardcoded English instead of calling t()
8+
t: (key: string, options?: Record<string, unknown>) =>
9+
key === "chat:codeAccordion.openFileAriaLabel" ? `${key} ${JSON.stringify(options)}` : key,
1710
}),
1811
}))
1912

@@ -50,6 +43,6 @@ describe("CodeAccordion", () => {
5043
/>,
5144
)
5245

53-
expect(screen.getByText("User Edits")).toBeInTheDocument()
46+
expect(screen.getByText("chat:codeAccordion.userEdits")).toBeInTheDocument()
5447
})
5548
})

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ import { vscode } from "@/utils/vscode"
77

88
import { About } from "../About"
99

10+
const { mockPackage, mockTranslate } = vi.hoisted(() => ({
11+
mockPackage: { version: "1.0.0", sha: "abc12345" as string | undefined },
12+
mockTranslate: vi.fn((key: string, options?: Record<string, unknown>) => {
13+
if (!options) return key
14+
// The version keys echo their options so the test can check what reaches the translator
15+
if (key.startsWith("settings:about.version")) return `${key} ${JSON.stringify(options)}`
16+
let result = key
17+
for (const [k, v] of Object.entries(options)) {
18+
result = result.replace(`{{${k}}}`, String(v))
19+
}
20+
return result
21+
}),
22+
}))
23+
1024
vi.mock("@/utils/vscode", () => ({
1125
vscode: { postMessage: vi.fn() },
1226
}))
@@ -39,27 +53,11 @@ vi.mock("@/i18n/TranslationContext", () => {
3953
const actual = vi.importActual("@/i18n/TranslationContext")
4054
return {
4155
...actual,
42-
useAppTranslation: () => ({
43-
t: (key: string, options?: Record<string, unknown>) => {
44-
if (!options) return key
45-
// The version keys echo their options so the test can check what reaches the translator
46-
if (key.startsWith("settings:about.version")) return `${key} ${JSON.stringify(options)}`
47-
let result = key
48-
for (const [k, v] of Object.entries(options)) {
49-
result = result.replace(`{{${k}}}`, String(v))
50-
}
51-
return result
52-
},
53-
}),
56+
useAppTranslation: () => ({ t: mockTranslate }),
5457
}
5558
})
5659

57-
vi.mock("@roo/package", () => ({
58-
Package: {
59-
version: "1.0.0",
60-
sha: "abc12345",
61-
},
62-
}))
60+
vi.mock("@roo/package", () => ({ Package: mockPackage }))
6361

6462
describe("About", () => {
6563
const defaultProps = {
@@ -94,6 +92,7 @@ describe("About", () => {
9492

9593
beforeEach(() => {
9694
vi.clearAllMocks()
95+
mockPackage.sha = "abc12345"
9796
})
9897

9998
it("renders the About section header", () => {
@@ -116,6 +115,16 @@ describe("About", () => {
116115
).toBeInTheDocument()
117116
})
118117

118+
it("displays the version without a commit when the package sha is unset", () => {
119+
mockPackage.sha = undefined
120+
121+
renderAbout()
122+
123+
expect(mockTranslate).toHaveBeenCalledWith("settings:about.version", { version: "1.0.0" })
124+
expect(mockTranslate).not.toHaveBeenCalledWith("settings:about.versionWithCommit", expect.anything())
125+
expect(screen.getByText('settings:about.version {"version":"1.0.0"}')).toBeInTheDocument()
126+
})
127+
119128
it("renders the bug report section with label and link text", () => {
120129
render(
121130
<TranslationProvider>

0 commit comments

Comments
 (0)