Skip to content

Commit ba4925f

Browse files
committed
Fix tests
1 parent 9461749 commit ba4925f

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

webview-ui/src/components/chat/__tests__/Announcement.spec.tsx

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,79 @@ vi.mock("@src/components/ui", () => ({
1111
DialogDescription: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
1212
DialogHeader: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
1313
DialogTitle: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
14+
DialogFooter: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
15+
Button: ({ children, onClick }: { children: React.ReactNode; onClick?: () => void }) => (
16+
<button onClick={onClick}>{children}</button>
17+
),
1418
}))
1519

16-
// Mock the useAppTranslation hook
20+
// Mock the useAppTranslation hook and Trans component
1721
vi.mock("@src/i18n/TranslationContext", () => ({
1822
useAppTranslation: () => ({
1923
t: (key: string, options?: { version: string }) => {
2024
if (key === "chat:announcement.title") {
2125
return `🎉 Roo Code ${options?.version} Released`
2226
}
23-
if (key === "chat:announcement.description") {
24-
return `Roo Code ${options?.version} brings powerful new features and improvements based on your feedback.`
27+
if (key === "chat:announcement.stealthModel.feature") {
28+
return "Stealth reasoning model with advanced capabilities"
29+
}
30+
if (key === "chat:announcement.stealthModel.note") {
31+
return "Note: This is an experimental feature"
32+
}
33+
if (key === "chat:announcement.stealthModel.connectButton") {
34+
return "Connect to Roo Code Cloud"
2535
}
2636
// Return key for other translations not relevant to this test
2737
return key
2838
},
2939
}),
3040
}))
3141

42+
// Mock react-i18next Trans component
43+
vi.mock("react-i18next", () => ({
44+
Trans: ({ i18nKey, children }: { i18nKey?: string; children: React.ReactNode }) => {
45+
if (i18nKey === "chat:announcement.stealthModel.feature") {
46+
return <>Stealth reasoning model with advanced capabilities</>
47+
}
48+
if (i18nKey === "chat:announcement.stealthModel.selectModel") {
49+
return <>Please select the roo/sonic model in settings</>
50+
}
51+
return <>{children}</>
52+
},
53+
}))
54+
55+
// Mock VSCodeLink
56+
vi.mock("@vscode/webview-ui-toolkit/react", () => ({
57+
VSCodeLink: ({ children, onClick }: { children: React.ReactNode; onClick?: () => void }) => (
58+
<a onClick={onClick}>{children}</a>
59+
),
60+
}))
61+
62+
// Mock the useExtensionState hook
63+
vi.mock("@src/context/ExtensionStateContext", () => ({
64+
useExtensionState: () => ({
65+
apiConfiguration: null,
66+
cloudIsAuthenticated: false,
67+
}),
68+
}))
69+
3270
describe("Announcement", () => {
3371
const mockHideAnnouncement = vi.fn()
3472
const expectedVersion = Package.version
3573

3674
it("renders the announcement with the version number from package.json", () => {
3775
render(<Announcement hideAnnouncement={mockHideAnnouncement} />)
3876

39-
// Check if the mocked version number is present in the title and description
77+
// Check if the mocked version number is present in the title
4078
expect(screen.getByText(`🎉 Roo Code ${expectedVersion} Released`)).toBeInTheDocument()
41-
expect(
42-
screen.getByText(
43-
`Roo Code ${expectedVersion} brings powerful new features and improvements based on your feedback.`,
44-
),
45-
).toBeInTheDocument()
79+
80+
// Check if the stealth model feature is displayed (using partial match due to bullet point)
81+
expect(screen.getByText(/Stealth reasoning model with advanced capabilities/)).toBeInTheDocument()
82+
83+
// Check if the note is displayed
84+
expect(screen.getByText("Note: This is an experimental feature")).toBeInTheDocument()
85+
86+
// Check if the connect button is displayed (since cloudIsAuthenticated is false in the mock)
87+
expect(screen.getByText("Connect to Roo Code Cloud")).toBeInTheDocument()
4688
})
4789
})

0 commit comments

Comments
 (0)