@@ -7,46 +7,42 @@ import { renderWithAuth } from "testHelpers/renderHelpers";
7
7
import userEvent from "@testing-library/user-event" ;
8
8
9
9
type SampleProps = Omit < PaginationWidgetBaseProps , "onPageChange" > ;
10
- const sampleProps : SampleProps [ ] = [
11
- { currentPage : 1 , pageSize : 5 , totalRecords : 6 } ,
12
- { currentPage : 1 , pageSize : 50 , totalRecords : 200 } ,
13
- { currentPage : 2 , pageSize : 20 , totalRecords : 3000 } ,
14
- ] ;
15
10
16
11
describe ( PaginationWidgetBase . name , ( ) => {
17
12
it ( "Should have its previous button be aria-disabled while on page 1" , async ( ) => {
13
+ const sampleProps : SampleProps [ ] = [
14
+ { currentPage : 1 , pageSize : 5 , totalRecords : 6 } ,
15
+ { currentPage : 1 , pageSize : 50 , totalRecords : 200 } ,
16
+ { currentPage : 1 , pageSize : 20 , totalRecords : 3000 } ,
17
+ ] ;
18
+
18
19
for ( const props of sampleProps ) {
19
20
const onPageChange = jest . fn ( ) ;
20
-
21
21
const { unmount } = renderWithAuth (
22
- < PaginationWidgetBase
23
- { ...props }
24
- currentPage = { 1 }
25
- onPageChange = { onPageChange }
26
- /> ,
22
+ < PaginationWidgetBase { ...props } onPageChange = { onPageChange } /> ,
27
23
) ;
28
24
29
- const button = await screen . findByLabelText ( "Previous page" ) ;
30
- expect ( button ) . not . toBeDisabled ( ) ;
31
- expect ( button ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
25
+ const prevButton = await screen . findByLabelText ( "Previous page" ) ;
26
+ expect ( prevButton ) . not . toBeDisabled ( ) ;
27
+ expect ( prevButton ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
32
28
33
- await userEvent . click ( button ) ;
29
+ await userEvent . click ( prevButton ) ;
34
30
expect ( onPageChange ) . not . toHaveBeenCalled ( ) ;
35
31
unmount ( ) ;
36
32
}
37
33
} ) ;
38
34
39
35
it ( "Should have its next button be aria-disabled while on last page" , async ( ) => {
36
+ const sampleProps : SampleProps [ ] = [
37
+ { currentPage : 2 , pageSize : 5 , totalRecords : 6 } ,
38
+ { currentPage : 4 , pageSize : 50 , totalRecords : 200 } ,
39
+ { currentPage : 10 , pageSize : 100 , totalRecords : 1000 } ,
40
+ ] ;
41
+
40
42
for ( const props of sampleProps ) {
41
43
const onPageChange = jest . fn ( ) ;
42
- const lastPage = Math . ceil ( props . totalRecords / props . pageSize ) ;
43
-
44
44
const { unmount } = renderWithAuth (
45
- < PaginationWidgetBase
46
- { ...props }
47
- currentPage = { lastPage }
48
- onPageChange = { onPageChange }
49
- /> ,
45
+ < PaginationWidgetBase { ...props } onPageChange = { onPageChange } /> ,
50
46
) ;
51
47
52
48
const button = await screen . findByLabelText ( "Next page" ) ;
@@ -58,4 +54,33 @@ describe(PaginationWidgetBase.name, () => {
58
54
unmount ( ) ;
59
55
}
60
56
} ) ;
57
+
58
+ it ( "Should have neither button be disabled for all other pages" , async ( ) => {
59
+ const sampleProps : SampleProps [ ] = [
60
+ { currentPage : 11 , pageSize : 5 , totalRecords : 60 } ,
61
+ { currentPage : 2 , pageSize : 50 , totalRecords : 200 } ,
62
+ { currentPage : 3 , pageSize : 20 , totalRecords : 100 } ,
63
+ ] ;
64
+
65
+ for ( const props of sampleProps ) {
66
+ const onPageChange = jest . fn ( ) ;
67
+ const { unmount } = renderWithAuth (
68
+ < PaginationWidgetBase { ...props } onPageChange = { onPageChange } /> ,
69
+ ) ;
70
+
71
+ const prevButton = await screen . findByLabelText ( "Previous page" ) ;
72
+ const nextButton = await screen . findByLabelText ( "Next page" ) ;
73
+
74
+ expect ( prevButton ) . not . toBeDisabled ( ) ;
75
+ expect ( prevButton ) . toHaveAttribute ( "aria-disabled" , "false" ) ;
76
+
77
+ expect ( nextButton ) . not . toBeDisabled ( ) ;
78
+ expect ( nextButton ) . toHaveAttribute ( "aria-disabled" , "false" ) ;
79
+
80
+ await userEvent . click ( prevButton ) ;
81
+ await userEvent . click ( nextButton ) ;
82
+ expect ( onPageChange ) . toHaveBeenCalledTimes ( 2 ) ;
83
+ unmount ( ) ;
84
+ }
85
+ } ) ;
61
86
} ) ;
0 commit comments