-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPaginator.test.tsx
61 lines (53 loc) · 1.73 KB
/
Paginator.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { act, render, screen } from '@testing-library/react';
import Paginator, { type Paginatable } from './Paginator';
describe('pagination', () => {
const pagination: Paginatable = {
has_next: false,
has_prev: false,
next_num: 5,
pages: 7,
prev_num: 3,
total: 7,
page: 4,
};
test('first', () => {
const onChange = jest.fn();
render(<Paginator navigateTo={onChange} pagination={pagination} />);
act(() => {
screen.getByTestId('paginator-first').click();
});
expect(onChange).toHaveBeenCalledWith(1);
});
test('prev', () => {
const onChange = jest.fn();
render(<Paginator navigateTo={onChange} pagination={pagination} />);
act(() => {
screen.getByTestId('paginator-prev').click();
});
expect(onChange).toHaveBeenCalledWith(3);
});
test('next', () => {
const onChange = jest.fn();
render(<Paginator navigateTo={onChange} pagination={pagination} />);
act(() => {
screen.getByTestId('paginator-next').click();
});
expect(onChange).toHaveBeenCalledWith(5);
});
test('last', () => {
const onChange = jest.fn();
render(<Paginator navigateTo={onChange} pagination={pagination} />);
act(() => {
screen.getByTestId('paginator-last').click();
});
expect(onChange).toHaveBeenCalledWith(7);
});
test('specific', () => {
const onChange = jest.fn();
render(<Paginator navigateTo={onChange} pagination={pagination} />);
act(() => {
screen.getByText('5').click();
});
expect(onChange).toHaveBeenCalledWith(5);
});
});