|
| 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 | +}); |
0 commit comments