@patternfly/react-core 4.202.30 → 4.202.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +5 -5
- package/src/components/Dropdown/__tests__/DropdownToggleCheckbox.test.tsx +1 -1
- package/src/components/Page/__tests__/Page.test.tsx +225 -205
- package/src/components/Page/__tests__/__snapshots__/Page.test.tsx.snap +1088 -2059
- package/src/components/Pagination/__tests__/Pagination.test.tsx +235 -283
- package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +143 -577
- package/src/components/Radio/__tests__/Radio.test.tsx +38 -44
- package/src/components/Radio/__tests__/__snapshots__/Radio.test.tsx.snap +30 -30
- package/src/components/SearchInput/__tests__/SearchInput.test.tsx +87 -68
- package/src/components/SearchInput/__tests__/__snapshots__/SearchInput.test.tsx.snap +230 -137
- package/src/components/Select/__tests__/Select.test.tsx +238 -195
- package/src/components/Select/__tests__/SelectToggle.test.tsx +68 -130
- package/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +978 -2149
- package/src/components/Select/__tests__/__snapshots__/SelectToggle.test.tsx.snap +3 -3
- package/src/components/SimpleList/__tests__/SimpleList.test.tsx +29 -32
- package/src/components/SimpleList/__tests__/__snapshots__/SimpleList.test.tsx.snap +4 -366
- package/src/components/Switch/__tests__/Switch.test.tsx +85 -75
- package/src/components/Switch/__tests__/__snapshots__/Switch.test.tsx.snap +30 -40
- package/src/components/TextArea/__tests__/TextArea.test.tsx +98 -103
- package/src/components/TextArea/__tests__/__snapshots__/TextArea.test.tsx.snap +24 -103
- package/src/components/TextInput/__tests__/TextInput.test.tsx +71 -70
- package/src/components/TextInput/__tests__/__snapshots__/TextInput.test.tsx.snap +15 -103
- package/src/components/TextInputGroup/__tests__/TextInputGroup.test.tsx +65 -39
- package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroup.test.tsx.snap +53 -14
- package/src/components/TimePicker/__tests__/TimePicker.test.tsx +113 -110
- package/src/components/Title/__tests__/Title.test.tsx +21 -20
- package/src/components/Title/__tests__/__snapshots__/Title.test.tsx.snap +24 -30
- package/src/components/ToggleGroup/__tests__/ToggleGroup.test.tsx +43 -39
- package/src/components/ToggleGroup/__tests__/__snapshots__/ToggleGroup.test.tsx.snap +20 -19
- package/src/components/Wizard/__tests__/Wizard.test.tsx +195 -189
- package/src/components/Wizard/__tests__/__snapshots__/Wizard.test.tsx.snap +131 -10
- package/src/helpers/__tests__/util.test.ts +113 -0
- package/src/layouts/Bullseye/__tests__/Bullseye.test.tsx +25 -25
- package/src/layouts/Bullseye/__tests__/__snapshots__/Bullseye.test.tsx.snap +3 -5
- package/src/layouts/Flex/__tests__/Flex.test.tsx +159 -96
- package/src/layouts/Flex/__tests__/__snapshots__/Flex.test.tsx.snap +9 -17
- package/src/components/Page/__tests__/Generated/Page.test.tsx +0 -28
- package/src/components/Page/__tests__/Generated/__snapshots__/Page.test.tsx.snap +0 -19
- package/src/components/Pagination/__tests__/Generated/Pagination.test.tsx +0 -58
- package/src/components/Pagination/__tests__/Generated/__snapshots__/Pagination.test.tsx.snap +0 -205
- package/src/components/Radio/__tests__/Generated/Radio.test.tsx +0 -29
- package/src/components/Radio/__tests__/Generated/__snapshots__/Radio.test.tsx.snap +0 -36
- package/src/components/Select/__tests__/Generated/Select.test.tsx +0 -49
- package/src/components/Select/__tests__/Generated/SelectToggle.test.tsx +0 -34
- package/src/components/Select/__tests__/Generated/__snapshots__/Select.test.tsx.snap +0 -48
- package/src/components/Select/__tests__/Generated/__snapshots__/SelectToggle.test.tsx.snap +0 -36
- package/src/components/SimpleList/__tests__/Generated/SimpleList.test.tsx +0 -22
- package/src/components/SimpleList/__tests__/Generated/__snapshots__/SimpleList.test.tsx.snap +0 -13
- package/src/components/Switch/__tests__/Generated/Switch.test.tsx +0 -24
- package/src/components/Switch/__tests__/Generated/__snapshots__/Switch.test.tsx.snap +0 -36
- package/src/components/TextArea/__tests__/Generated/TextArea.test.tsx +0 -23
- package/src/components/TextArea/__tests__/Generated/__snapshots__/TextArea.test.tsx.snap +0 -13
- package/src/components/Title/__tests__/Generated/Title.test.tsx +0 -13
- package/src/components/Title/__tests__/Generated/__snapshots__/Title.test.tsx.snap +0 -12
- package/src/helpers/__tests__/util.test.js +0 -235
|
@@ -1,332 +1,284 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { mount } from 'enzyme';
|
|
4
|
-
import { Pagination, PaginationVariant } from '../index';
|
|
5
|
-
|
|
6
|
-
describe('component render', () => {
|
|
7
|
-
test('should render correctly top', () => {
|
|
8
|
-
const wrapper = render(<Pagination itemCount={20} />);
|
|
9
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
10
|
-
});
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('should render correctly compact', () => {
|
|
18
|
-
const wrapper = render(<Pagination itemCount={20} isCompact />);
|
|
19
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
20
|
-
});
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
21
6
|
|
|
22
|
-
|
|
23
|
-
const wrapper = render(<Pagination itemCount={20} isSticky />);
|
|
24
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('should render correctly bottom sticky', () => {
|
|
28
|
-
const wrapper = render(<Pagination itemCount={20} variant={PaginationVariant.bottom} isSticky />);
|
|
29
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('should render correctly disabled', () => {
|
|
33
|
-
const wrapper = render(<Pagination itemCount={20} isDisabled />);
|
|
34
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('limited number of pages', () => {
|
|
38
|
-
const wrapper = render(<Pagination itemCount={20} perPage={20} />);
|
|
39
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('zero results', () => {
|
|
43
|
-
const wrapper = render(<Pagination itemCount={0} />);
|
|
44
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('last page', () => {
|
|
48
|
-
const wrapper = render(<Pagination itemCount={20} perPage={10} page={2} />);
|
|
49
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('custom perPageOptions', () => {
|
|
53
|
-
const wrapper = render(<Pagination itemCount={40} perPageOptions={[{ title: 'some', value: 1 }]} />);
|
|
54
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('empty per page options', () => {
|
|
58
|
-
const wrapper = render(<Pagination itemCount={40} perPageOptions={[]} />);
|
|
59
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('no items', () => {
|
|
63
|
-
const wrapper = render(<Pagination itemCount={0} />);
|
|
64
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('custom start end', () => {
|
|
68
|
-
const wrapper = render(<Pagination itemCount={40} itemsStart={5} itemsEnd={15} />);
|
|
69
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('titles', () => {
|
|
73
|
-
const wrapper = render(<Pagination itemCount={40} titles={{ items: 'values', page: 'books' }} />);
|
|
74
|
-
expect(wrapper.container).toMatchSnapshot();
|
|
75
|
-
});
|
|
7
|
+
import { Pagination, PaginationVariant } from '../index';
|
|
76
8
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
9
|
+
describe('Pagination', () => {
|
|
10
|
+
describe('component render', () => {
|
|
11
|
+
test('should render correctly top', () => {
|
|
12
|
+
const { asFragment } = render(<Pagination itemCount={20} />);
|
|
13
|
+
expect(asFragment()).toMatchSnapshot();
|
|
14
|
+
});
|
|
84
15
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
16
|
+
test('should render correctly bottom', () => {
|
|
17
|
+
const { asFragment } = render(<Pagination itemCount={20} variant={PaginationVariant.bottom} />);
|
|
18
|
+
expect(asFragment()).toMatchSnapshot();
|
|
19
|
+
});
|
|
89
20
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
)
|
|
94
|
-
expect(toggle.find('b').at(0).text()).toBe('1 - 10');
|
|
95
|
-
expect(toggle).toMatchSnapshot();
|
|
96
|
-
});
|
|
21
|
+
test('should render correctly compact', () => {
|
|
22
|
+
const { asFragment } = render(<Pagination itemCount={20} isCompact />);
|
|
23
|
+
expect(asFragment()).toMatchSnapshot();
|
|
24
|
+
});
|
|
97
25
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
)
|
|
102
|
-
expect(toggle.find('div').text()).toBe('1 - 10 of many');
|
|
103
|
-
expect(toggle).toMatchSnapshot();
|
|
104
|
-
});
|
|
26
|
+
test('should render correctly sticky', () => {
|
|
27
|
+
const { asFragment } = render(<Pagination itemCount={20} isSticky />);
|
|
28
|
+
expect(asFragment()).toMatchSnapshot();
|
|
29
|
+
});
|
|
105
30
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
expect(toggle.text()).toBe('I am a string');
|
|
111
|
-
expect(toggle).toMatchSnapshot();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
31
|
+
test('should render correctly bottom sticky', () => {
|
|
32
|
+
const { asFragment } = render(<Pagination itemCount={20} variant={PaginationVariant.bottom} isSticky />);
|
|
33
|
+
expect(asFragment()).toMatchSnapshot();
|
|
34
|
+
});
|
|
114
35
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
test('should call first', () => {
|
|
120
|
-
const wrapper = mount(<Pagination onSetPage={onSetPage} itemCount={40} page={2} />);
|
|
121
|
-
wrapper
|
|
122
|
-
.find('[data-action="first"]')
|
|
123
|
-
.first()
|
|
124
|
-
.simulate('click');
|
|
125
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
126
|
-
expect(onSetPage.mock.calls[0][1]).toBe(1);
|
|
36
|
+
test('should render correctly disabled', () => {
|
|
37
|
+
const { asFragment } = render(<Pagination itemCount={20} isDisabled />);
|
|
38
|
+
expect(asFragment()).toMatchSnapshot();
|
|
127
39
|
});
|
|
128
40
|
|
|
129
|
-
test('
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
.find('[data-action="previous"]')
|
|
133
|
-
.first()
|
|
134
|
-
.simulate('click');
|
|
135
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
136
|
-
expect(onSetPage.mock.calls[0][1]).toBe(2);
|
|
41
|
+
test('limited number of pages', () => {
|
|
42
|
+
const { asFragment } = render(<Pagination itemCount={20} perPage={20} />);
|
|
43
|
+
expect(asFragment()).toMatchSnapshot();
|
|
137
44
|
});
|
|
138
45
|
|
|
139
|
-
test('
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
.find('[data-action="next"]')
|
|
143
|
-
.first()
|
|
144
|
-
.simulate('click');
|
|
145
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
146
|
-
expect(onSetPage.mock.calls[0][1]).toBe(2);
|
|
46
|
+
test('zero results', () => {
|
|
47
|
+
const { asFragment } = render(<Pagination itemCount={0} />);
|
|
48
|
+
expect(asFragment()).toMatchSnapshot();
|
|
147
49
|
});
|
|
148
50
|
|
|
149
|
-
test('
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
.find('[data-action="last"]')
|
|
153
|
-
.first()
|
|
154
|
-
.simulate('click');
|
|
155
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
156
|
-
expect(onSetPage.mock.calls[0][1]).toBe(4);
|
|
51
|
+
test('last page', () => {
|
|
52
|
+
const { asFragment } = render(<Pagination itemCount={20} perPage={10} page={2} />);
|
|
53
|
+
expect(asFragment()).toMatchSnapshot();
|
|
157
54
|
});
|
|
158
55
|
|
|
159
|
-
test('
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
.find('input')
|
|
163
|
-
.first()
|
|
164
|
-
.simulate('change', { target: { value: '1' } })
|
|
165
|
-
.simulate('keydown', { keyCode: 13 });
|
|
166
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
167
|
-
expect(onSetPage.mock.calls[0][1]).toBe(1);
|
|
56
|
+
test('custom perPageOptions', () => {
|
|
57
|
+
const { asFragment } = render(<Pagination itemCount={40} perPageOptions={[{ title: 'some', value: 1 }]} />);
|
|
58
|
+
expect(asFragment()).toMatchSnapshot();
|
|
168
59
|
});
|
|
169
60
|
|
|
170
|
-
test('
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
.find('input')
|
|
174
|
-
.first()
|
|
175
|
-
.simulate('change', { target: { value: 'a' } })
|
|
176
|
-
.simulate('keydown', { keyCode: 13 });
|
|
177
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
178
|
-
expect(onSetPage.mock.calls[0][1]).toBe(1);
|
|
61
|
+
test('empty per page options', () => {
|
|
62
|
+
const { asFragment } = render(<Pagination itemCount={40} perPageOptions={[]} />);
|
|
63
|
+
expect(asFragment()).toMatchSnapshot();
|
|
179
64
|
});
|
|
180
65
|
|
|
181
|
-
test('
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
.find('input')
|
|
185
|
-
.first()
|
|
186
|
-
.simulate('change', { target: { value: '10' } })
|
|
187
|
-
.simulate('keydown', { keyCode: 13 });
|
|
188
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
189
|
-
expect(onSetPage.mock.calls[0][1]).toBe(4);
|
|
66
|
+
test('custom start end', () => {
|
|
67
|
+
const { asFragment } = render(<Pagination itemCount={40} itemsStart={5} itemsEnd={15} />);
|
|
68
|
+
expect(asFragment()).toMatchSnapshot();
|
|
190
69
|
});
|
|
191
70
|
|
|
192
|
-
test('
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
.find('input')
|
|
196
|
-
.first()
|
|
197
|
-
.simulate('change', { target: { value: '-10' } })
|
|
198
|
-
.simulate('keydown', { keyCode: 13 });
|
|
199
|
-
expect(onSetPage.mock.calls).toHaveLength(1);
|
|
200
|
-
expect(onSetPage.mock.calls[0][1]).toBe(1);
|
|
71
|
+
test('titles', () => {
|
|
72
|
+
const { asFragment } = render(<Pagination itemCount={40} titles={{ items: 'values', page: 'books' }} />);
|
|
73
|
+
expect(asFragment()).toMatchSnapshot();
|
|
201
74
|
});
|
|
202
75
|
|
|
203
|
-
test('
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
76
|
+
test('custom pagination toggle', () => {
|
|
77
|
+
const { asFragment } = render(
|
|
78
|
+
<Pagination
|
|
79
|
+
itemCount={40}
|
|
80
|
+
toggleTemplate={'${firstIndex} - ${lastIndex} - ${itemCount} - ${itemsTitle}'}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
expect(asFragment()).toMatchSnapshot();
|
|
210
84
|
});
|
|
211
|
-
});
|
|
212
85
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const wrapper = mount(<Pagination onFirstClick={onFirst} itemCount={40} page={2} />);
|
|
217
|
-
wrapper
|
|
218
|
-
.find('[data-action="first"]')
|
|
219
|
-
.first()
|
|
220
|
-
.simulate('click');
|
|
221
|
-
expect(onFirst.mock.calls).toHaveLength(1);
|
|
222
|
-
expect(onFirst.mock.calls[0][1]).toBe(1);
|
|
86
|
+
test('up drop direction', () => {
|
|
87
|
+
const { asFragment } = render(<Pagination itemCount={40} dropDirection="up" />);
|
|
88
|
+
expect(asFragment()).toMatchSnapshot();
|
|
223
89
|
});
|
|
224
90
|
|
|
225
|
-
test('
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
.find('[data-action="first"]')
|
|
229
|
-
.first()
|
|
230
|
-
.simulate('click');
|
|
231
|
-
expect(onFirst.mock.calls).toHaveLength(0);
|
|
91
|
+
test('indeterminate count (no item count)', () => {
|
|
92
|
+
render(<Pagination />);
|
|
93
|
+
expect(screen.getAllByText('1 - 10')[0]).toBeInTheDocument();
|
|
232
94
|
});
|
|
233
|
-
});
|
|
234
95
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
96
|
+
test('toggleTemplate toggle text with function', () => {
|
|
97
|
+
render(
|
|
98
|
+
<Pagination
|
|
99
|
+
toggleTemplate={({ firstIndex, lastIndex }) => (
|
|
100
|
+
<div>
|
|
101
|
+
{firstIndex} - {lastIndex} of many
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
expect(screen.getAllByText('1 - 10 of many')[0]).toBeInTheDocument();
|
|
245
107
|
});
|
|
246
108
|
|
|
247
|
-
test('
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
.find('[data-action="last"]')
|
|
251
|
-
.first()
|
|
252
|
-
.simulate('click');
|
|
253
|
-
expect(onLast.mock.calls).toHaveLength(0);
|
|
109
|
+
test('toggleTemplate toggle text with string', () => {
|
|
110
|
+
render(<Pagination toggleTemplate={'I am a string'} />);
|
|
111
|
+
expect(screen.getAllByText('I am a string')[0]).toBeInTheDocument();
|
|
254
112
|
});
|
|
255
113
|
});
|
|
256
114
|
|
|
257
|
-
describe('
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
.
|
|
265
|
-
|
|
266
|
-
|
|
115
|
+
describe('API', () => {
|
|
116
|
+
describe('onSetPage', () => {
|
|
117
|
+
const onSetPage = jest.fn();
|
|
118
|
+
|
|
119
|
+
test('should call first', () => {
|
|
120
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} page={2} />);
|
|
121
|
+
|
|
122
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to first page' }));
|
|
123
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('should call previous', () => {
|
|
127
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} page={3} />);
|
|
128
|
+
|
|
129
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
130
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('should call next', () => {
|
|
134
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
135
|
+
|
|
136
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to next page' }));
|
|
137
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('should call last', () => {
|
|
141
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
142
|
+
|
|
143
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
144
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('should call input', () => {
|
|
148
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
149
|
+
|
|
150
|
+
const input = screen.getByLabelText('Current page');
|
|
151
|
+
userEvent.type(input, '1');
|
|
152
|
+
userEvent.type(input, '{enter}');
|
|
153
|
+
|
|
154
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('should call input wrong value', () => {
|
|
158
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
159
|
+
|
|
160
|
+
const input = screen.getByLabelText('Current page');
|
|
161
|
+
userEvent.type(input, 'a');
|
|
162
|
+
userEvent.type(input, '{enter}');
|
|
163
|
+
|
|
164
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('should call input huge page number', () => {
|
|
168
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
169
|
+
|
|
170
|
+
const input = screen.getByLabelText('Current page');
|
|
171
|
+
userEvent.type(input, '10');
|
|
172
|
+
userEvent.type(input, '{enter}');
|
|
173
|
+
|
|
174
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('should call input small page number', () => {
|
|
178
|
+
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
179
|
+
|
|
180
|
+
const input = screen.getByLabelText('Current page');
|
|
181
|
+
userEvent.type(input, '-10');
|
|
182
|
+
userEvent.type(input, '{enter}');
|
|
183
|
+
|
|
184
|
+
expect(onSetPage).toHaveBeenCalled();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('should NOT call', () => {
|
|
188
|
+
render(<Pagination itemCount={40} />);
|
|
189
|
+
|
|
190
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
191
|
+
expect(onSetPage).not.toHaveBeenCalled();
|
|
192
|
+
});
|
|
267
193
|
});
|
|
268
194
|
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
.
|
|
275
|
-
|
|
195
|
+
describe('onFirst', () => {
|
|
196
|
+
const onFirst = jest.fn();
|
|
197
|
+
test('should call', () => {
|
|
198
|
+
render(<Pagination onFirstClick={onFirst} itemCount={40} page={2} />);
|
|
199
|
+
|
|
200
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to first page' }));
|
|
201
|
+
expect(onFirst).toHaveBeenCalled();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('should NOT call', () => {
|
|
205
|
+
render(<Pagination itemCount={40} page={2} />);
|
|
206
|
+
|
|
207
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to first page' }));
|
|
208
|
+
expect(onFirst).not.toHaveBeenCalled();
|
|
209
|
+
});
|
|
276
210
|
});
|
|
277
|
-
});
|
|
278
211
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
.
|
|
285
|
-
.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
212
|
+
describe('onLast', () => {
|
|
213
|
+
const onLast = jest.fn();
|
|
214
|
+
test('should call', () => {
|
|
215
|
+
render(<Pagination onLastClick={onLast} itemCount={40} />);
|
|
216
|
+
|
|
217
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
218
|
+
expect(onLast).toHaveBeenCalled();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('should NOT call', () => {
|
|
222
|
+
render(<Pagination itemCount={40} />);
|
|
223
|
+
|
|
224
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
225
|
+
expect(onLast).not.toHaveBeenCalled();
|
|
226
|
+
});
|
|
289
227
|
});
|
|
290
228
|
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
.
|
|
297
|
-
|
|
229
|
+
describe('onPrevious', () => {
|
|
230
|
+
const onPrevious = jest.fn();
|
|
231
|
+
test('should call', () => {
|
|
232
|
+
render(<Pagination onPreviousClick={onPrevious} itemCount={40} page={3} />);
|
|
233
|
+
|
|
234
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
235
|
+
expect(onPrevious).toHaveBeenCalled();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('should NOT call', () => {
|
|
239
|
+
render(<Pagination itemCount={40} />);
|
|
240
|
+
|
|
241
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
242
|
+
expect(onPrevious).not.toHaveBeenCalled();
|
|
243
|
+
});
|
|
298
244
|
});
|
|
299
|
-
});
|
|
300
245
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
.
|
|
307
|
-
.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
.
|
|
314
|
-
|
|
315
|
-
|
|
246
|
+
describe('onNext', () => {
|
|
247
|
+
const onNext = jest.fn();
|
|
248
|
+
test('should call', () => {
|
|
249
|
+
render(<Pagination onNextClick={onNext} itemCount={40} />);
|
|
250
|
+
|
|
251
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to next page' }));
|
|
252
|
+
expect(onNext).toHaveBeenCalled();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('should NOT call', () => {
|
|
256
|
+
render(<Pagination itemCount={40} />);
|
|
257
|
+
|
|
258
|
+
userEvent.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
259
|
+
expect(onNext).not.toHaveBeenCalled();
|
|
260
|
+
});
|
|
316
261
|
});
|
|
317
262
|
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
.
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
.
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
263
|
+
describe('onPerPage', () => {
|
|
264
|
+
const onPerPage = jest.fn();
|
|
265
|
+
test('should call', () => {
|
|
266
|
+
render(<Pagination onPerPageSelect={onPerPage} itemCount={40} />);
|
|
267
|
+
|
|
268
|
+
userEvent.click(screen.getByRole('button', { name: 'Items per page' }));
|
|
269
|
+
userEvent.click(screen.getByText('20 per page'));
|
|
270
|
+
|
|
271
|
+
expect(onPerPage).toHaveBeenCalled();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test('should NOT call', () => {
|
|
275
|
+
render(<Pagination itemCount={40} />);
|
|
276
|
+
|
|
277
|
+
userEvent.click(screen.getByRole('button', { name: 'Items per page' }));
|
|
278
|
+
userEvent.click(screen.getByText('20 per page'));
|
|
279
|
+
|
|
280
|
+
expect(onPerPage).not.toHaveBeenCalled();
|
|
281
|
+
});
|
|
330
282
|
});
|
|
331
283
|
});
|
|
332
284
|
});
|