File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed
Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 1+ import { render , screen } from '@testing-library/react' ;
2+ import { describe , expect , it } from 'vitest' ;
3+
4+ import { ClientTable } from './ClientTable' ;
5+
6+ const TEST_ID = 'ClientTable' ;
7+ const FIRST_BUTTON_ID = 'first-page-button' ;
8+ const PREVIOUS_BUTTON_ID = 'previous-page-button' ;
9+ const NEXT_BUTTON_ID = 'next-page-button' ;
10+ const LAST_BUTTON_ID = 'last-page-button' ;
11+
12+ describe ( 'ClientTable' , ( ) => {
13+ it ( 'should render' , ( ) => {
14+ render ( < ClientTable columns = { [ ] } data = { [ ] } minRows = { 10 } /> ) ;
15+ expect ( screen . getByTestId ( TEST_ID ) ) . toBeInTheDocument ( ) ;
16+ expect ( screen . getByTestId ( FIRST_BUTTON_ID ) ) . toBeInTheDocument ( ) ;
17+ expect ( screen . getByTestId ( PREVIOUS_BUTTON_ID ) ) . toBeInTheDocument ( ) ;
18+ expect ( screen . getByTestId ( NEXT_BUTTON_ID ) ) . toBeInTheDocument ( ) ;
19+ expect ( screen . getByTestId ( LAST_BUTTON_ID ) ) . toBeInTheDocument ( ) ;
20+ } ) ;
21+ it ( 'should contain a custom class name' , ( ) => {
22+ render ( < ClientTable className = "foo" columns = { [ ] } data = { [ ] } minRows = { 10 } /> ) ;
23+ expect ( screen . getByTestId ( TEST_ID ) ) . toHaveClass ( 'foo' ) ;
24+ } ) ;
25+ } ) ;
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export const ClientTable = <T extends ClientTableEntry>({
8585 const nRows = Math . max ( currentEntries . length , minRows ?? - 1 ) ;
8686
8787 return (
88- < div className = { className } { ...props } >
88+ < div className = { className } { ...props } data-testid = "ClientTable" >
8989 < div className = "rounded-md border bg-card tracking-tight text-muted-foreground shadow-sm" >
9090 < Table >
9191 < Table . Header >
Original file line number Diff line number Diff line change @@ -27,6 +27,18 @@ export const ClientTablePagination = ({
2727 </ div >
2828 < div className = "flex flex-1 justify-between gap-3 sm:justify-end" >
2929 < Button
30+ data-testid = "first-page-button"
31+ disabled = { currentPage === 1 }
32+ type = "button"
33+ variant = "outline"
34+ onClick = { ( ) => {
35+ setCurrentPage ( 1 ) ;
36+ } }
37+ >
38+ { t ( 'pagination.firstPage' ) }
39+ </ Button >
40+ < Button
41+ data-testid = "previous-page-button"
3042 disabled = { currentPage === 1 }
3143 type = "button"
3244 variant = "outline"
@@ -37,6 +49,7 @@ export const ClientTablePagination = ({
3749 { t ( 'pagination.previous' ) }
3850 </ Button >
3951 < Button
52+ data-testid = "next-page-button"
4053 disabled = { currentPage === pageCount }
4154 type = "button"
4255 variant = "outline"
@@ -46,6 +59,17 @@ export const ClientTablePagination = ({
4659 >
4760 { t ( 'pagination.next' ) }
4861 </ Button >
62+ < Button
63+ data-testid = "last-page-button"
64+ disabled = { currentPage === pageCount }
65+ type = "button"
66+ variant = "outline"
67+ onClick = { ( ) => {
68+ setCurrentPage ( pageCount ) ;
69+ } }
70+ >
71+ { t ( 'pagination.lastPage' ) }
72+ </ Button >
4973 </ div >
5074 </ div >
5175 ) ;
Original file line number Diff line number Diff line change 143143 "previous" : {
144144 "en" : " Previous" ,
145145 "fr" : " Précédent"
146+ },
147+ "firstPage" : {
148+ "en" : " << First" ,
149+ "fr" : " << Première"
150+ },
151+ "lastPage" : {
152+ "en" : " Last >>" ,
153+ "fr" : " Dernière >>"
146154 }
147155 },
148156 "searchBar" : {
You can’t perform that action at this time.
0 commit comments