Skip to content

Commit 06d49bb

Browse files
committed
test: add unit test for announcement version template
1 parent 1e0c9ff commit 06d49bb

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { render, screen } from "@testing-library/react"
2+
import { jest } from "@jest/globals" // Or 'jest' if using Jest
3+
import { version } from "../../../../../package.json"
4+
5+
import Announcement from "../Announcement"
6+
7+
// Mock the components from @src/components/ui
8+
jest.mock("@src/components/ui", () => ({
9+
Dialog: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
10+
DialogContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
11+
DialogDescription: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
12+
DialogHeader: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
13+
DialogTitle: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
14+
}))
15+
16+
// Mock the useAppTranslation hook
17+
jest.mock("@src/i18n/TranslationContext", () => ({
18+
useAppTranslation: () => ({
19+
t: (key: string, options?: { version: string }) => {
20+
if (key === "chat:announcement.title") {
21+
return `🎉 Roo Code ${options?.version} Released`
22+
}
23+
if (key === "chat:announcement.description") {
24+
return `Roo Code ${options?.version} brings powerful new features and improvements based on your feedback.`
25+
}
26+
// Return key for other translations not relevant to this test
27+
return key
28+
},
29+
}),
30+
}))
31+
32+
describe("Announcement", () => {
33+
const mockHideAnnouncement = jest.fn()
34+
const expectedVersion = version
35+
36+
it("renders the announcement with the version number from package.json", () => {
37+
render(<Announcement hideAnnouncement={mockHideAnnouncement} />)
38+
39+
// Check if the mocked version number is present in the title and description
40+
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()
46+
})
47+
})

0 commit comments

Comments
 (0)