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
+ const itemLabel = item . items . find ( ( item ) => item . label ) ;
60
+ const label = itemLabel ?. label ;
61
+ expect ( screen . getByText ( label || "" ) ) . toBeInTheDocument ( ) ;
62
+ } ) ;
63
+ } ) ;
64
+ } ) ;
65
+ } ) ;
0 commit comments