Skip to content

Commit d3c774f

Browse files
authored
Merge pull request #1242 from dacadeorg/test/section-bounties-testing
feat: add test for the section bounties
2 parents acf8bc6 + be6cb34 commit d3c774f

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import "@testing-library/jest-dom";
2+
import { screen } from "@testing-library/react";
3+
import BountiesNavigation from "@/components/sections/bounties/Navigation";
4+
import { renderWithRedux } from "../../../../__mocks__/renderWithRedux";
5+
import { List } from "@/utilities/CommunityNavigation";
6+
7+
jest.mock("next/router", () => ({
8+
useRouter: () => ({
9+
query: "/",
10+
}),
11+
}));
12+
13+
const expectedNavItems: Omit<List, "id">[] = [
14+
{
15+
title: "bounties.navigation",
16+
items: [
17+
{
18+
label: "bounties.navigation.all",
19+
exact: true,
20+
link: "/bounties",
21+
},
22+
],
23+
},
24+
];
25+
26+
describe("Navigation", () => {
27+
it("should render the navigation", () => {
28+
renderWithRedux(<BountiesNavigation testId="bountiesNavigationId" />);
29+
const bountiesNavigation = screen.getByTestId("bountiesNavigationId");
30+
expect(bountiesNavigation).toBeInTheDocument();
31+
});
32+
33+
it("should render menu items", () => {
34+
renderWithRedux(<BountiesNavigation />);
35+
const menuItems = screen.getAllByRole("listitem");
36+
menuItems.forEach(() => {
37+
expectedNavItems.forEach((menu) => {
38+
if (!menu.hideTitle) {
39+
const menuTitle = menu.title;
40+
expect(screen.getByText(menuTitle)).toBeInTheDocument();
41+
}
42+
});
43+
});
44+
});
45+
46+
it("renders links with href", () => {
47+
renderWithRedux(<BountiesNavigation />);
48+
const links = screen.getAllByRole("link");
49+
links.forEach((link) => {
50+
expect(link).toHaveAttribute("href");
51+
});
52+
});
53+
54+
it("renders the item label", () => {
55+
renderWithRedux(<BountiesNavigation />);
56+
const menuItems = screen.getAllByRole("listitem");
57+
menuItems.forEach(() => {
58+
expectedNavItems.forEach((item) => {
59+
expect(screen.getByRole("link")).toBeInTheDocument();
60+
const itemLabel = item.items.find((item) => item.label);
61+
const label = itemLabel?.label;
62+
if (label) {
63+
expect(screen.getByText(label)).toBeInTheDocument();
64+
expect(screen.getByText(label).textContent).toContain("bounties.navigation.all");
65+
}
66+
});
67+
});
68+
});
69+
});

src/components/sections/bounties/Navigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface BountiesNavigationMultiSelector {
3030
* @export
3131
* @returns {ReactElement}
3232
*/
33-
export default function BountiesNavigation(): ReactElement {
33+
export default function BountiesNavigation({testId}: {testId?: string}): ReactElement {
3434
const { t } = useTranslation();
3535
const router = useRouter();
3636
const { colors, bounties } = useMultiSelector<unknown, BountiesNavigationMultiSelector>({
@@ -70,7 +70,7 @@ export default function BountiesNavigation(): ReactElement {
7070

7171
return (
7272
<ThemeWrapper colors={colors}>
73-
<ul className="sticky top-10">
73+
<ul data-testid={testId} className="sticky top-10">
7474
{menus.map((menu, i) => (
7575
<li key={`bounties-menu-${i}`} className="relative mb-8">
7676
{!menu.hideTitle && <span className="relative text-xs font-semibold uppercase">{menu.title}</span>}

0 commit comments

Comments
 (0)