Skip to content

Commit 2b104a7

Browse files
committed
fix: test the sidebar
1 parent ce42343 commit 2b104a7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

__tests__/components/sections/communities/overview/Courses.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import { renderWithRedux } from "@__mocks__/renderWithRedux";
55
import { mockCourse } from "@__mocks__/fixtures/course";
66
import { mockCommunity } from "@__mocks__/fixtures/community";
77

8+
9+
jest.mock("next/router", () => ({
10+
useRouter: () => ({
11+
asPath: "next",
12+
}),
13+
}));
14+
815
describe("CoursesOverview", () => {
916
it("renders the courses overview section with course cards", () => {
1017
renderWithRedux(<CoursesOverview />, {

__tests__/components/sections/communities/overview/Sidebar.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ describe("Sidebar", () => {
1616
renderWithRedux(<Sidebar />, { communities: { current: mockCommunity, list: [mockCommunity], courses: [mockCourse], status: "succeeded", error: "" } });
1717
});
1818
const mainLink = `/communities/${mockCommunity.slug}`;
19-
const scoreboardLink = `/communities/${mockCommunity.slug}/scoreboard`;
19+
const learningMaterialsLink = `/communities/${mockCommunity.slug}/learning-materials`;
20+
const scoreboardLink = `/communities/${mockCommunity.slug}/scoreboard`;
2021

2122
it("displays the sidebar", () => {
2223
expect(screen.getByText("communities.overview.challenges.title")).toBeInTheDocument();
@@ -26,7 +27,8 @@ describe("Sidebar", () => {
2627
});
2728

2829
it("renders the links correctly", () => {
29-
expect(screen.getByRole("link", { name: "main link" })).toHaveAttribute("href", mainLink);
30-
expect(screen.getByRole("link", { name: "scoreboard link" })).toHaveAttribute("href", scoreboardLink);
30+
expect(screen.getByText("communities.overview.challenges.title").closest("a")).toHaveAttribute("href", mainLink);
31+
expect(screen.getByText("communities.overview.learning-materials.title").closest("a")).toHaveAttribute("href", learningMaterialsLink);
32+
expect(screen.getByText("communities.overview.scoreboard.title").closest("a")).toHaveAttribute("href", scoreboardLink);
3133
});
3234
});

0 commit comments

Comments
 (0)