1
+ import { page } from '@vitest/browser/context'
2
+ import { beforeEach , describe , expect , it , vi } from 'vitest'
1
3
import React from 'react'
2
4
import { Pagination } from '../Pagination'
3
5
import { render , screen } from '@testing-library/react'
4
6
import userEvent from '@testing-library/user-event'
5
7
6
8
describe ( 'Table.Pagination' , ( ) => {
9
+ beforeEach ( async ( ) => {
10
+ await page . viewport ( 1400 , 728 )
11
+ } )
12
+
7
13
it ( 'should render a navigation landmark with an accessible name provided by `aria-label`' , ( ) => {
8
14
render ( < Pagination aria-label = "Pagination" totalCount = { 100 } /> )
9
15
expect (
@@ -36,7 +42,7 @@ describe('Table.Pagination', () => {
36
42
} )
37
43
38
44
it ( 'should warn if `defaultPageIndex` is not a valid `pageIndex`' , ( ) => {
39
- const spy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
45
+ const spy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
40
46
render ( < Pagination aria-label = "Pagination" defaultPageIndex = { 4 } pageSize = { 25 } totalCount = { 100 } /> )
41
47
expect ( spy ) . toHaveBeenCalledWith (
42
48
'Warning:' ,
@@ -67,7 +73,7 @@ describe('Table.Pagination', () => {
67
73
68
74
it ( 'should not call `onChange` when a page or action is interacted with' , async ( ) => {
69
75
const user = userEvent . setup ( )
70
- const onChange = jest . fn ( )
76
+ const onChange = vi . fn ( )
71
77
72
78
render ( < Pagination aria-label = "Test label" onChange = { onChange } pageSize = { 25 } totalCount = { 25 } /> )
73
79
@@ -86,7 +92,7 @@ describe('Table.Pagination', () => {
86
92
} )
87
93
88
94
it ( 'should rerender many pages correctly' , async ( ) => {
89
- const onChange = jest . fn ( )
95
+ const onChange = vi . fn ( )
90
96
91
97
const { rerender} = render (
92
98
< Pagination aria-label = "Test label" onChange = { onChange } defaultPageIndex = { 0 } pageSize = { 25 } totalCount = { 25 } /> ,
@@ -126,7 +132,7 @@ describe('Table.Pagination', () => {
126
132
127
133
it ( 'should call `onChange` when clicking on pages' , async ( ) => {
128
134
const user = userEvent . setup ( )
129
- const onChange = jest . fn ( )
135
+ const onChange = vi . fn ( )
130
136
131
137
render ( < Pagination aria-label = "Test label" onChange = { onChange } pageSize = { 25 } totalCount = { 50 } /> )
132
138
@@ -145,7 +151,7 @@ describe('Table.Pagination', () => {
145
151
146
152
it ( 'should rerender pager with correct page highlighted when clicking on pages and defaultPageIndex set' , async ( ) => {
147
153
const user = userEvent . setup ( )
148
- const onChange = jest . fn ( )
154
+ const onChange = vi . fn ( )
149
155
150
156
render (
151
157
< Pagination aria-label = "Test label" onChange = { onChange } defaultPageIndex = { 3 } pageSize = { 25 } totalCount = { 200 } /> ,
@@ -171,7 +177,7 @@ describe('Table.Pagination', () => {
171
177
172
178
it ( 'should call `onChange` when using the keyboard to interact with pages' , async ( ) => {
173
179
const user = userEvent . setup ( )
174
- const onChange = jest . fn ( )
180
+ const onChange = vi . fn ( )
175
181
176
182
render ( < Pagination aria-label = "Test label" onChange = { onChange } pageSize = { 25 } totalCount = { 50 } /> )
177
183
@@ -202,7 +208,7 @@ describe('Table.Pagination', () => {
202
208
203
209
it ( 'should call `onChange` when clicking on previous or next' , async ( ) => {
204
210
const user = userEvent . setup ( )
205
- const onChange = jest . fn ( )
211
+ const onChange = vi . fn ( )
206
212
207
213
render ( < Pagination aria-label = "Test label" onChange = { onChange } pageSize = { 25 } totalCount = { 50 } /> )
208
214
@@ -222,7 +228,7 @@ describe('Table.Pagination', () => {
222
228
223
229
it ( 'should rerender pager with correct page highlighted when clicking on previous or next and defaultPageIndex set' , async ( ) => {
224
230
const user = userEvent . setup ( )
225
- const onChange = jest . fn ( )
231
+ const onChange = vi . fn ( )
226
232
227
233
render (
228
234
< Pagination aria-label = "Test label" onChange = { onChange } defaultPageIndex = { 3 } pageSize = { 25 } totalCount = { 200 } /> ,
@@ -247,7 +253,7 @@ describe('Table.Pagination', () => {
247
253
248
254
it ( 'should call `onChange` when using the keyboard to interact with previous or next' , async ( ) => {
249
255
const user = userEvent . setup ( )
250
- const onChange = jest . fn ( )
256
+ const onChange = vi . fn ( )
251
257
252
258
render ( < Pagination aria-label = "Test label" onChange = { onChange } pageSize = { 25 } totalCount = { 50 } /> )
253
259
@@ -279,7 +285,7 @@ describe('Table.Pagination', () => {
279
285
} )
280
286
281
287
it ( 'should rerender many pages correctly' , async ( ) => {
282
- const onChange = jest . fn ( )
288
+ const onChange = vi . fn ( )
283
289
284
290
const { rerender} = render (
285
291
< Pagination aria-label = "Test label" onChange = { onChange } defaultPageIndex = { 1 } pageSize = { 25 } totalCount = { 50 } /> ,
@@ -345,7 +351,7 @@ describe('Table.Pagination', () => {
345
351
} )
346
352
347
353
it ( 'should rerender many pages correctly' , async ( ) => {
348
- const onChange = jest . fn ( )
354
+ const onChange = vi . fn ( )
349
355
const { rerender} = render (
350
356
< Pagination aria-label = "Test label" onChange = { onChange } defaultPageIndex = { 1 } pageSize = { 10 } totalCount = { 1000 } /> ,
351
357
)
@@ -365,7 +371,7 @@ describe('Table.Pagination', () => {
365
371
} )
366
372
367
373
it ( 'when rendering 3 pages and the second page is selected we should render a page number not ...' , async ( ) => {
368
- const onChange = jest . fn ( )
374
+ const onChange = vi . fn ( )
369
375
render ( < Pagination aria-label = "Test label" onChange = { onChange } defaultPageIndex = { 1 } pageSize = { 2 } totalCount = { 6 } /> )
370
376
expect ( getPageRange ( ) ) . toEqual ( '3 through 4 of 6' )
371
377
expect ( getCurrentPage ( ) ) . toEqual ( getPage ( 1 ) )
0 commit comments