@@ -41,40 +41,40 @@ describe('<Pagination />', () => {
4141 renderComponent ( { currentPage : 2 , totalPages : 4 } )
4242
4343 // Prev / Next
44- const prev = screen . getByRole ( 'button' , { name : 'Prev ' } )
45- const next = screen . getByRole ( 'button' , { name : 'Next ' } )
44+ const prev = screen . getByRole ( 'button' , { name : 'Go to previous page ' } )
45+ const next = screen . getByRole ( 'button' , { name : 'Go to next page ' } )
4646
4747 expect ( prev ) . toBeEnabled ( )
4848 expect ( next ) . toBeEnabled ( )
4949
5050 // Pages 1–4
5151 for ( let n = 1 ; n <= 4 ; n ++ ) {
52- expect ( screen . getByRole ( 'button' , { name : String ( n ) } ) ) . toBeInTheDocument ( )
52+ expect ( screen . getByRole ( 'button' , { name : `Go to page ${ n } ` } ) ) . toBeInTheDocument ( )
5353 }
5454 } )
5555
5656 it ( 'disables Prev on first page' , ( ) => {
5757 const { container } = renderComponent ( { currentPage : 1 , totalPages : 3 } )
58- const prevBtn = within ( container ) . getByRole ( 'button' , { name : 'Prev ' } )
58+ const prevBtn = within ( container ) . getByRole ( 'button' , { name : 'Go to previous page ' } )
5959 expect ( prevBtn ) . toBeDisabled ( )
6060 } )
6161
6262 it ( 'disables Next on last page' , ( ) => {
6363 const { container } = renderComponent ( { currentPage : 3 , totalPages : 3 } )
64- const nextBtn = within ( container ) . getByRole ( 'button' , { name : 'Next ' } )
64+ const nextBtn = within ( container ) . getByRole ( 'button' , { name : 'Go to next page ' } )
6565 expect ( nextBtn ) . toBeDisabled ( )
6666 } )
6767
6868 it ( 'calls onPageChange with correct page number on button clicks' , ( ) => {
6969 renderComponent ( { currentPage : 2 , totalPages : 5 } )
7070
71- fireEvent . click ( screen . getByRole ( 'button' , { name : 'Prev ' } ) )
71+ fireEvent . click ( screen . getByRole ( 'button' , { name : 'Go to previous page ' } ) )
7272 expect ( onPageChange ) . toHaveBeenCalledWith ( 1 )
7373
74- fireEvent . click ( screen . getByRole ( 'button' , { name : 'Next ' } ) )
74+ fireEvent . click ( screen . getByRole ( 'button' , { name : 'Go to next page ' } ) )
7575 expect ( onPageChange ) . toHaveBeenCalledWith ( 3 )
7676
77- fireEvent . click ( screen . getByRole ( 'button' , { name : '4' } ) )
77+ fireEvent . click ( screen . getByRole ( 'button' , { name : 'Go to page 4' } ) )
7878 expect ( onPageChange ) . toHaveBeenCalledWith ( 4 )
7979 } )
8080
@@ -83,26 +83,26 @@ describe('<Pagination />', () => {
8383
8484 // Should show first 3 pages
8585 for ( const n of [ 1 , 2 , 3 ] ) {
86- expect ( screen . getByRole ( 'button' , { name : String ( n ) } ) ) . toBeInTheDocument ( )
86+ expect ( screen . getByRole ( 'button' , { name : `Go to page ${ n } ` } ) ) . toBeInTheDocument ( )
8787 }
8888
89- // Should show exactly two “ More pages” indicators
89+ // Should show exactly two " More pages" indicators
9090 const ellipses = screen . getAllByLabelText ( 'More pages' )
9191 expect ( ellipses ) . toHaveLength ( 2 )
9292
9393 // Should show pages around currentPage: 9, 10, 11
9494 for ( const n of [ 9 , 10 , 11 ] ) {
95- expect ( screen . getByRole ( 'button' , { name : String ( n ) } ) ) . toBeInTheDocument ( )
95+ expect ( screen . getByRole ( 'button' , { name : `Go to page ${ n } ` } ) ) . toBeInTheDocument ( )
9696 }
9797
9898 // Last page
99- expect ( screen . getByRole ( 'button' , { name : '20' } ) ) . toBeInTheDocument ( )
99+ expect ( screen . getByRole ( 'button' , { name : 'Go to page 20' } ) ) . toBeInTheDocument ( )
100100 } )
101101
102102 it ( 'applies active styles and aria-current on the selected page' , ( ) => {
103103 renderComponent ( { currentPage : 3 , totalPages : 5 } )
104104
105- const activeBtn = screen . getByRole ( 'button' , { name : '3' } )
105+ const activeBtn = screen . getByRole ( 'button' , { name : 'Go to page 3' } )
106106 // check for class used in active state
107107 expect ( activeBtn ) . toHaveClass ( 'bg-[#83a6cc]' )
108108 // accessibility: mark current page
@@ -113,25 +113,25 @@ describe('<Pagination />', () => {
113113 // No overrides → currentPage=1, totalPages=5, isLoaded=true
114114 renderComponent ( )
115115
116- expect ( screen . getByRole ( 'button' , { name : 'Prev ' } ) ) . toBeDisabled ( )
117- expect ( screen . getByRole ( 'button' , { name : 'Next ' } ) ) . toBeEnabled ( )
118- expect ( screen . getByRole ( 'button' , { name : '5' } ) ) . toBeInTheDocument ( )
116+ expect ( screen . getByRole ( 'button' , { name : 'Go to previous page ' } ) ) . toBeDisabled ( )
117+ expect ( screen . getByRole ( 'button' , { name : 'Go to next page ' } ) ) . toBeEnabled ( )
118+ expect ( screen . getByRole ( 'button' , { name : 'Go to page 5' } ) ) . toBeInTheDocument ( )
119119 } )
120120
121121 // Edge-case: currentPage near the start of a large set
122122 it ( 'shows correct pages when currentPage = 4 of 10' , ( ) => {
123123 renderComponent ( { currentPage : 4 , totalPages : 10 } )
124124 // Should show 1,2,3,4,5 then ellipsis and 10
125125 for ( const n of [ 1 , 2 , 3 , 4 , 5 ] ) {
126- expect ( screen . getByRole ( 'button' , { name : String ( n ) } ) ) . toBeInTheDocument ( )
126+ expect ( screen . getByRole ( 'button' , { name : `Go to page ${ n } ` } ) ) . toBeInTheDocument ( )
127127 }
128128
129- expect ( screen . getByRole ( 'button' , { name : '10' } ) ) . toBeInTheDocument ( )
129+ expect ( screen . getByRole ( 'button' , { name : 'Go to page 10' } ) ) . toBeInTheDocument ( )
130130 } )
131131
132132 // Edge-case: very small totalPages (2)
133133 it ( 'renders exactly pages [1, 2] when totalPages = 2' , ( ) => {
134134 renderComponent ( { totalPages : 2 , currentPage : 2 } )
135- expect ( screen . getAllByRole ( 'button' , { name : / ^ ( 1 | 2 ) $ / } ) ) . toHaveLength ( 2 )
135+ expect ( screen . getAllByRole ( 'button' , { name : / ^ G o t o p a g e ( 1 | 2 ) $ / } ) ) . toHaveLength ( 2 )
136136 } )
137137} )
0 commit comments