@coveord/plasma-mantine 48.2.0 → 48.3.0

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.
Files changed (37) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test.log +8 -8
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/cjs/components/table/Table.js +2 -1
  5. package/dist/cjs/components/table/Table.js.map +1 -1
  6. package/dist/cjs/components/table/TableContext.js.map +1 -1
  7. package/dist/cjs/components/table/TablePagination.js +4 -1
  8. package/dist/cjs/components/table/TablePagination.js.map +1 -1
  9. package/dist/definitions/components/table/Table.d.ts.map +1 -1
  10. package/dist/definitions/components/table/TableContext.d.ts +5 -1
  11. package/dist/definitions/components/table/TableContext.d.ts.map +1 -1
  12. package/dist/definitions/components/table/TablePagination.d.ts.map +1 -1
  13. package/dist/definitions/components/table/useTable.d.ts +1 -0
  14. package/dist/definitions/components/table/useTable.d.ts.map +1 -1
  15. package/dist/esm/components/table/Table.js +2 -1
  16. package/dist/esm/components/table/Table.js.map +1 -1
  17. package/dist/esm/components/table/TableContext.js.map +1 -1
  18. package/dist/esm/components/table/TablePagination.js +4 -1
  19. package/dist/esm/components/table/TablePagination.js.map +1 -1
  20. package/package.json +2 -2
  21. package/src/components/collection/__tests__/Collection.spec.tsx +14 -8
  22. package/src/components/date-range-picker/__tests__/DateRangePickerInlineCalendar.spec.tsx +23 -18
  23. package/src/components/date-range-picker/__tests__/DateRangePickerPopoverCalendar.spec.tsx +15 -12
  24. package/src/components/date-range-picker/__tests__/DateRangePickerPresetSelect.spec.tsx +4 -3
  25. package/src/components/date-range-picker/__tests__/EditableDateRangePicker.spec.tsx +6 -5
  26. package/src/components/inline-confirm/__tests__/InlineConfirm.spec.tsx +17 -13
  27. package/src/components/modal-wizard/__tests__/ModalWizard.spec.tsx +20 -14
  28. package/src/components/table/Table.tsx +1 -0
  29. package/src/components/table/TableContext.tsx +5 -1
  30. package/src/components/table/TablePagination.tsx +2 -1
  31. package/src/components/table/__tests__/Table.spec.tsx +6 -4
  32. package/src/components/table/__tests__/TableActions.spec.tsx +4 -3
  33. package/src/components/table/__tests__/TableDateRangePicker.spec.tsx +5 -4
  34. package/src/components/table/__tests__/TableFilter.spec.tsx +3 -2
  35. package/src/components/table/__tests__/TablePagination.spec.tsx +8 -0
  36. package/src/components/table/__tests__/TablePerPage.spec.tsx +3 -2
  37. package/src/components/table/__tests__/TablePredicate.spec.tsx +3 -2
@@ -4,21 +4,23 @@ import dayjs from 'dayjs';
4
4
  import {DateRangePickerInlineCalendar} from '../DateRangePickerInlineCalendar';
5
5
 
6
6
  describe('DateRangePickerInlineCalendar', () => {
7
- it('calls onApply when the user clicks on the apply button', () => {
7
+ it('calls onApply when the user clicks on the apply button', async () => {
8
+ const user = userEvent.setup({delay: null});
8
9
  const onApply = jest.fn();
9
10
  render(<DateRangePickerInlineCalendar initialRange={[null, null]} onApply={onApply} onCancel={jest.fn()} />);
10
11
 
11
- userEvent.click(screen.getByRole('button', {name: 'Apply'}));
12
+ await user.click(screen.getByRole('button', {name: 'Apply'}));
12
13
 
13
14
  expect(onApply).toHaveBeenCalledTimes(1);
14
15
  expect(onApply).toHaveBeenCalledWith([null, null]);
15
16
  });
16
17
 
17
- it('calls onCancel when the user clicks on the cancel button', () => {
18
+ it('calls onCancel when the user clicks on the cancel button', async () => {
19
+ const user = userEvent.setup({delay: null});
18
20
  const onCancel = jest.fn();
19
21
  render(<DateRangePickerInlineCalendar initialRange={[null, null]} onApply={jest.fn()} onCancel={onCancel} />);
20
22
 
21
- userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
23
+ await user.click(screen.getByRole('button', {name: 'Cancel'}));
22
24
 
23
25
  expect(onCancel).toHaveBeenCalledTimes(1);
24
26
  });
@@ -29,7 +31,8 @@ describe('DateRangePickerInlineCalendar', () => {
29
31
  expect(screen.queryByRole('searchbox')).not.toBeInTheDocument();
30
32
  });
31
33
 
32
- it('calls onApply with the selected dates when choosing a preset', () => {
34
+ it('calls onApply with the selected dates when choosing a preset', async () => {
35
+ const user = userEvent.setup({delay: null});
33
36
  const onApply = jest.fn();
34
37
  render(
35
38
  <DateRangePickerInlineCalendar
@@ -42,50 +45,52 @@ describe('DateRangePickerInlineCalendar', () => {
42
45
  />
43
46
  );
44
47
 
45
- userEvent.click(
48
+ await user.click(
46
49
  screen.getByRole('searchbox', {
47
50
  name: 'Date range',
48
51
  })
49
52
  );
50
- userEvent.click(screen.getByRole('option', {name: 'select me'}));
51
- userEvent.click(screen.getByRole('button', {name: 'Apply'}));
53
+ await user.click(screen.getByRole('option', {name: 'select me'}));
54
+ await user.click(screen.getByRole('button', {name: 'Apply'}));
52
55
 
53
56
  expect(onApply).toHaveBeenCalledWith([new Date(1999, 11, 31), new Date(2000, 0, 1)]);
54
57
  });
55
58
 
56
- it('calls onApply with the selected dates when clicking in the calendar', () => {
59
+ it('calls onApply with the selected dates when clicking in the calendar', async () => {
60
+ const user = userEvent.setup({delay: null});
57
61
  jest.useFakeTimers().setSystemTime(new Date(2022, 0, 31));
58
62
  const onApply = jest.fn();
59
63
  render(<DateRangePickerInlineCalendar initialRange={[null, null]} onApply={onApply} onCancel={jest.fn()} />);
60
64
 
61
65
  // click once for the start, once for the end
62
- userEvent.click(screen.getAllByRole('button', {name: '8'})[0]);
63
- userEvent.click(screen.getAllByRole('button', {name: '14'})[0]);
66
+ await user.click(screen.getAllByRole('button', {name: '8'})[0]);
67
+ await user.click(screen.getAllByRole('button', {name: '14'})[0]);
64
68
 
65
- userEvent.click(screen.getByRole('button', {name: 'Apply'}));
69
+ await user.click(screen.getByRole('button', {name: 'Apply'}));
66
70
 
67
71
  expect(onApply).toHaveBeenCalledWith([new Date(2022, 0, 8), new Date(2022, 0, 14)]);
68
72
 
69
73
  jest.useRealTimers();
70
74
  });
71
75
 
72
- it('calls onApply with the selected dates when typing in the inputs', () => {
76
+ it('calls onApply with the selected dates when typing in the inputs', async () => {
77
+ const user = userEvent.setup({delay: null});
73
78
  const onApply = jest.fn();
74
79
  render(<DateRangePickerInlineCalendar initialRange={[null, null]} onApply={onApply} onCancel={jest.fn()} />);
75
80
 
76
81
  const startInput = screen.getByRole('textbox', {
77
82
  name: /start/i,
78
83
  });
79
- userEvent.clear(startInput);
80
- userEvent.type(startInput, 'Jan 8, 2022');
84
+ await user.clear(startInput);
85
+ await user.type(startInput, 'Jan 8, 2022');
81
86
 
82
87
  const endInput = screen.getByRole('textbox', {
83
88
  name: /end/i,
84
89
  });
85
- userEvent.clear(endInput);
86
- userEvent.type(endInput, 'Jan 14, 2022');
90
+ await user.clear(endInput);
91
+ await user.type(endInput, 'Jan 14, 2022');
87
92
 
88
- userEvent.click(screen.getByRole('button', {name: 'Apply'}));
93
+ await user.click(screen.getByRole('button', {name: 'Apply'}));
89
94
 
90
95
  expect(onApply).toHaveBeenCalledWith([
91
96
  dayjs(new Date(2022, 0, 8)).startOf('day').toDate(),
@@ -19,7 +19,8 @@ describe('DateRangePickerPopoverCalendar', () => {
19
19
  expect(screen.queryByRole('searchbox')).not.toBeInTheDocument();
20
20
  });
21
21
 
22
- it('updates with the selected dates when choosing a preset', () => {
22
+ it('updates with the selected dates when choosing a preset', async () => {
23
+ const user = userEvent.setup({delay: null});
23
24
  const Fixture = () => {
24
25
  const form = useForm<{dates: DateRangePickerValue}>({initialValues: {dates: [null, null]}});
25
26
  return (
@@ -36,17 +37,18 @@ describe('DateRangePickerPopoverCalendar', () => {
36
37
  };
37
38
  render(<Fixture />);
38
39
 
39
- userEvent.click(
40
+ await user.click(
40
41
  screen.getByRole('searchbox', {
41
42
  name: 'Date range',
42
43
  })
43
44
  );
44
- userEvent.click(screen.getByRole('option', {name: 'select me'}));
45
+ await user.click(screen.getByRole('option', {name: 'select me'}));
45
46
 
46
47
  expect(screen.getByTestId('json')).toHaveTextContent('["1999-12-31T00:00:00.000Z","2000-01-01T00:00:00.000Z"]');
47
48
  });
48
49
 
49
- it('calls onApply with the selected dates when clicking in the calendar', () => {
50
+ it('calls onApply with the selected dates when clicking in the calendar', async () => {
51
+ const user = userEvent.setup({delay: null});
50
52
  jest.useFakeTimers().setSystemTime(new Date(2022, 0, 31));
51
53
  const Fixture = () => {
52
54
  const form = useForm<{dates: DateRangePickerValue}>({initialValues: {dates: [null, null]}});
@@ -59,10 +61,10 @@ describe('DateRangePickerPopoverCalendar', () => {
59
61
  };
60
62
  render(<Fixture />);
61
63
 
62
- userEvent.click(screen.getByRole('textbox', {name: 'Start'}));
64
+ await user.click(screen.getByRole('textbox', {name: 'Start'}));
63
65
  // click once for the start, once for the end
64
- userEvent.click(screen.getAllByRole('button', {name: '8'})[0]);
65
- userEvent.click(screen.getAllByRole('button', {name: '14'})[0]);
66
+ await user.click(screen.getAllByRole('button', {name: '8'})[0]);
67
+ await user.click(screen.getAllByRole('button', {name: '14'})[0]);
66
68
 
67
69
  // hides the calendar when the second date is clicked
68
70
  expect(screen.queryByRole('button', {name: '8'})).not.toBeInTheDocument();
@@ -72,7 +74,8 @@ describe('DateRangePickerPopoverCalendar', () => {
72
74
  jest.useRealTimers();
73
75
  });
74
76
 
75
- it('calls onApply with the selected dates when typing in the inputs', () => {
77
+ it('calls onApply with the selected dates when typing in the inputs', async () => {
78
+ const user = userEvent.setup({delay: null});
76
79
  const Fixture = () => {
77
80
  const form = useForm<{dates: DateRangePickerValue}>({initialValues: {dates: [null, null]}});
78
81
  return (
@@ -87,14 +90,14 @@ describe('DateRangePickerPopoverCalendar', () => {
87
90
  const startInput = screen.getByRole('textbox', {
88
91
  name: /start/i,
89
92
  });
90
- userEvent.clear(startInput);
91
- userEvent.type(startInput, 'Jan 8, 2022');
93
+ await user.clear(startInput);
94
+ await user.type(startInput, 'Jan 8, 2022');
92
95
 
93
96
  const endInput = screen.getByRole('textbox', {
94
97
  name: /end/i,
95
98
  });
96
- userEvent.clear(endInput);
97
- userEvent.type(endInput, 'Jan 14, 2022');
99
+ await user.clear(endInput);
100
+ await user.type(endInput, 'Jan 14, 2022');
98
101
 
99
102
  expect(screen.getByTestId('json')).toHaveTextContent('["2022-01-08T00:00:00.000Z","2022-01-14T23:59:59.999Z"]');
100
103
  });
@@ -3,7 +3,8 @@ import {render, screen, userEvent} from '@test-utils';
3
3
  import {DateRangePickerPresetSelect} from '../DateRangePickerPresetSelect';
4
4
 
5
5
  describe('DateRangePickerPresetSelect', () => {
6
- it('calls onChange when selecting a preset', () => {
6
+ it('calls onChange when selecting a preset', async () => {
7
+ const user = userEvent.setup({delay: null});
7
8
  const onChange = jest.fn();
8
9
  render(
9
10
  <DateRangePickerPresetSelect
@@ -15,12 +16,12 @@ describe('DateRangePickerPresetSelect', () => {
15
16
  />
16
17
  );
17
18
 
18
- userEvent.click(
19
+ await user.click(
19
20
  screen.getByRole('searchbox', {
20
21
  name: 'Date range',
21
22
  })
22
23
  );
23
- userEvent.click(screen.getByRole('option', {name: 'select me'}));
24
+ await user.click(screen.getByRole('option', {name: 'select me'}));
24
25
 
25
26
  expect(onChange).toHaveBeenCalledWith([new Date(1999, 11, 31), new Date(2000, 0, 1)]);
26
27
  });
@@ -18,7 +18,8 @@ describe('EditableDateRangePicker', () => {
18
18
  expect(screen.getByText('SEPARATOR')).toBeVisible();
19
19
  });
20
20
 
21
- it('updates when editing values', () => {
21
+ it('updates when editing values', async () => {
22
+ const user = userEvent.setup({delay: null});
22
23
  const Fixture = () => {
23
24
  const [value, setValue] = useState<DateRangePickerValue>([null, null]);
24
25
  return (
@@ -33,14 +34,14 @@ describe('EditableDateRangePicker', () => {
33
34
  const startInput = screen.getByRole('textbox', {
34
35
  name: /start/i,
35
36
  });
36
- userEvent.clear(startInput);
37
- userEvent.type(startInput, 'Jan 8, 2022');
37
+ await user.clear(startInput);
38
+ await user.type(startInput, 'Jan 8, 2022');
38
39
 
39
40
  const endInput = screen.getByRole('textbox', {
40
41
  name: /end/i,
41
42
  });
42
- userEvent.clear(endInput);
43
- userEvent.type(endInput, 'Jan 14, 2022');
43
+ await user.clear(endInput);
44
+ await user.type(endInput, 'Jan 14, 2022');
44
45
 
45
46
  expect(screen.getByTestId('json')).toHaveTextContent('["2022-01-08T00:00:00.000Z","2022-01-14T23:59:59.999Z"]');
46
47
  });
@@ -9,7 +9,8 @@ describe('InlineConfirm', () => {
9
9
  expect(screen.getByText('Hello World')).toBeVisible();
10
10
  });
11
11
 
12
- it('calls the onClick prop when clicking on a button', () => {
12
+ it('calls the onClick prop when clicking on a button', async () => {
13
+ const user = userEvent.setup({delay: null});
13
14
  const onClickSpy = jest.fn();
14
15
  render(
15
16
  <InlineConfirm>
@@ -19,12 +20,13 @@ describe('InlineConfirm', () => {
19
20
  </InlineConfirm>
20
21
  );
21
22
 
22
- userEvent.click(screen.getByRole('button', {name: 'Delete'}));
23
+ await user.click(screen.getByRole('button', {name: 'Delete'}));
23
24
 
24
25
  expect(onClickSpy).toHaveBeenCalledTimes(1);
25
26
  });
26
27
 
27
- it('replace the children with a prompt when clicking on a button which requires confirmation', () => {
28
+ it('replace the children with a prompt when clicking on a button which requires confirmation', async () => {
29
+ const user = userEvent.setup({delay: null});
28
30
  render(
29
31
  <InlineConfirm>
30
32
  <InlineConfirm.Button id="my-button-id">Remove</InlineConfirm.Button>
@@ -34,13 +36,14 @@ describe('InlineConfirm', () => {
34
36
  expect(screen.queryByText('Are you sure?')).not.toBeInTheDocument();
35
37
  expect(screen.getByRole('button', {name: 'Remove'})).toBeVisible();
36
38
 
37
- userEvent.click(screen.getByRole('button', {name: 'Remove'}));
39
+ await user.click(screen.getByRole('button', {name: 'Remove'}));
38
40
 
39
41
  expect(screen.getByText('Are you sure?')).toBeVisible();
40
42
  expect(screen.queryByRole('button', {name: 'Remove'})).not.toBeInTheDocument();
41
43
  });
42
44
 
43
- it('hides the prompt when the user cancel and call onConfirm when the user confirms', () => {
45
+ it('hides the prompt when the user cancel and call onConfirm when the user confirms', async () => {
46
+ const user = userEvent.setup({delay: null});
44
47
  const confirmSpy = jest.fn();
45
48
  render(
46
49
  <InlineConfirm>
@@ -55,22 +58,23 @@ describe('InlineConfirm', () => {
55
58
  </InlineConfirm>
56
59
  );
57
60
 
58
- userEvent.click(screen.getByRole('button', {name: 'Remove'}));
61
+ await user.click(screen.getByRole('button', {name: 'Remove'}));
59
62
  expect(screen.getByText('Are you sure?')).toBeVisible();
60
63
 
61
- userEvent.click(screen.getByRole('button', {name: 'I changed my mind'}));
64
+ await user.click(screen.getByRole('button', {name: 'I changed my mind'}));
62
65
  expect(screen.queryByText('Are you sure?')).not.toBeInTheDocument();
63
66
  expect(confirmSpy).not.toHaveBeenCalled();
64
67
 
65
- userEvent.click(screen.getByRole('button', {name: 'Remove'}));
68
+ await user.click(screen.getByRole('button', {name: 'Remove'}));
66
69
  expect(screen.getByText('Are you sure?')).toBeVisible();
67
70
 
68
- userEvent.click(screen.getByRole('button', {name: 'I confirm'}));
71
+ await user.click(screen.getByRole('button', {name: 'I confirm'}));
69
72
  expect(screen.queryByText('Are you sure?')).not.toBeInTheDocument();
70
73
  expect(confirmSpy).toHaveBeenCalledTimes(1);
71
74
  });
72
75
 
73
- it('shows the prompt related to the clicked button', () => {
76
+ it('shows the prompt related to the clicked button', async () => {
77
+ const user = userEvent.setup({delay: null});
74
78
  render(
75
79
  <InlineConfirm>
76
80
  <InlineConfirm.Button id="remove">Remove</InlineConfirm.Button>
@@ -81,13 +85,13 @@ describe('InlineConfirm', () => {
81
85
  </InlineConfirm>
82
86
  );
83
87
 
84
- userEvent.click(screen.getByRole('button', {name: 'Remove'}));
88
+ await user.click(screen.getByRole('button', {name: 'Remove'}));
85
89
  expect(screen.getByText('Delete X?')).toBeVisible();
86
90
  expect(screen.queryByText('Print?')).not.toBeInTheDocument();
87
91
 
88
- userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
92
+ await user.click(screen.getByRole('button', {name: 'Cancel'}));
89
93
 
90
- userEvent.click(screen.getByRole('button', {name: 'Print'}));
94
+ await user.click(screen.getByRole('button', {name: 'Print'}));
91
95
  expect(screen.queryByText('Delete X?')).not.toBeInTheDocument();
92
96
  expect(screen.getByText('Print?')).toBeVisible();
93
97
  });
@@ -2,7 +2,8 @@ import {render, screen, userEvent} from '@test-utils';
2
2
  import {ModalWizard} from '../ModalWizard';
3
3
 
4
4
  describe('ModalWizard', () => {
5
- it('navigate slides using footer buttons', () => {
5
+ it('navigate slides using footer buttons', async () => {
6
+ const user = userEvent.setup({delay: null});
6
7
  const modelSteps = [
7
8
  {
8
9
  docLink: 'https://google.com',
@@ -69,7 +70,7 @@ describe('ModalWizard', () => {
69
70
  });
70
71
  expect(nextButton).toBeInTheDocument();
71
72
 
72
- userEvent.click(nextButton);
73
+ await user.click(nextButton);
73
74
 
74
75
  expect(
75
76
  screen.getByRole('heading', {
@@ -96,7 +97,7 @@ describe('ModalWizard', () => {
96
97
  });
97
98
  expect(nextButton).toBeInTheDocument();
98
99
 
99
- userEvent.click(nextButton);
100
+ await user.click(nextButton);
100
101
 
101
102
  expect(
102
103
  screen.getByRole('heading', {
@@ -125,7 +126,7 @@ describe('ModalWizard', () => {
125
126
  expect(nextButton).toBeInTheDocument();
126
127
  expect(nextButton).toBeDisabled();
127
128
 
128
- userEvent.click(
129
+ await user.click(
129
130
  screen.getByRole('button', {
130
131
  name: /previous/i,
131
132
  })
@@ -152,7 +153,8 @@ describe('ModalWizard', () => {
152
153
  ).toBeInTheDocument();
153
154
  });
154
155
 
155
- it('modal wizard onClose', () => {
156
+ it('modal wizard onClose', async () => {
157
+ const user = userEvent.setup({delay: null});
156
158
  const modelSteps = [
157
159
  {
158
160
  docLink: 'https://google.com',
@@ -182,12 +184,13 @@ describe('ModalWizard', () => {
182
184
  const closeButton = screen.getByRole('button', {
183
185
  name: /closebuttonlabel/i,
184
186
  });
185
- userEvent.click(closeButton);
187
+ await user.click(closeButton);
186
188
 
187
189
  expect(onClose).toHaveBeenCalledTimes(1);
188
190
  });
189
191
 
190
- it('modal wizard onCancel', () => {
192
+ it('modal wizard onCancel', async () => {
193
+ const user = userEvent.setup({delay: null});
191
194
  const modelSteps = [
192
195
  {
193
196
  docLink: 'https://google.com',
@@ -217,12 +220,13 @@ describe('ModalWizard', () => {
217
220
  const cancelButton = screen.getByRole('button', {
218
221
  name: /cancel/i,
219
222
  });
220
- userEvent.click(cancelButton);
223
+ await user.click(cancelButton);
221
224
 
222
225
  expect(onClose).toHaveBeenCalledTimes(1);
223
226
  });
224
227
 
225
- it('modal wizard onFinish', () => {
228
+ it('modal wizard onFinish', async () => {
229
+ const user = userEvent.setup({delay: null});
226
230
  const modelSteps = [
227
231
  {
228
232
  docLink: 'https://google.com',
@@ -254,11 +258,12 @@ describe('ModalWizard', () => {
254
258
  name: /finish/i,
255
259
  });
256
260
 
257
- userEvent.click(finishButton);
261
+ await user.click(finishButton);
258
262
  expect(onFinish).toHaveBeenCalledTimes(1);
259
263
  });
260
264
 
261
- it('handle dirty state if user confirms close', () => {
265
+ it('handle dirty state if user confirms close', async () => {
266
+ const user = userEvent.setup({delay: null});
262
267
  const modelSteps = [
263
268
  {
264
269
  docLink: 'https://google.com',
@@ -295,13 +300,14 @@ describe('ModalWizard', () => {
295
300
  });
296
301
 
297
302
  handleDirtyState.mockReturnValueOnce(true);
298
- userEvent.click(closeButton);
303
+ await user.click(closeButton);
299
304
 
300
305
  expect(handleDirtyState).toHaveBeenCalledTimes(1);
301
306
  expect(onClose).toHaveBeenCalledTimes(1);
302
307
  });
303
308
 
304
- it('handle dirty state if user confirms cancel', () => {
309
+ it('handle dirty state if user confirms cancel', async () => {
310
+ const user = userEvent.setup({delay: null});
305
311
  const modelSteps = [
306
312
  {
307
313
  docLink: 'https://google.com',
@@ -338,7 +344,7 @@ describe('ModalWizard', () => {
338
344
  });
339
345
 
340
346
  handleDirtyState.mockReturnValueOnce(false);
341
- userEvent.click(closeButton);
347
+ await user.click(closeButton);
342
348
  expect(handleDirtyState).toHaveBeenCalledTimes(1);
343
349
  expect(onClose).toHaveBeenCalledTimes(0);
344
350
  });
@@ -265,6 +265,7 @@ export const Table: TableType = <T,>({
265
265
  getSelectedRow,
266
266
  clearSelection,
267
267
  form,
268
+ containerRef: outsideClickRef,
268
269
  }}
269
270
  >
270
271
  {header}
@@ -1,7 +1,7 @@
1
1
  import {DateRangePickerValue} from '@mantine/dates';
2
2
  import {UseFormReturnType} from '@mantine/form';
3
3
  import {TableState} from '@tanstack/react-table';
4
- import {createContext, Dispatch} from 'react';
4
+ import {createContext, Dispatch, RefObject} from 'react';
5
5
 
6
6
  export type onTableChangeEvent = (params: TableState & TableFormType) => void;
7
7
 
@@ -51,6 +51,10 @@ type TableContextType = {
51
51
  * Form used to handle predicates and dateRange
52
52
  */
53
53
  form: UseFormReturnType<TableFormType>;
54
+ /**
55
+ * Table container ref
56
+ */
57
+ containerRef: RefObject<HTMLDivElement>;
54
58
  };
55
59
 
56
60
  export const TableContext = createContext<TableContextType | null>(null);
@@ -11,12 +11,13 @@ interface TablePaginationProps {
11
11
  }
12
12
 
13
13
  export const TablePagination: FunctionComponent<TablePaginationProps> = ({totalPages}) => {
14
- const {state, setState} = useTable();
14
+ const {state, setState, containerRef} = useTable();
15
15
  const updatePage = (newPage: number) => {
16
16
  setState((prevState: TableState) => ({
17
17
  ...prevState,
18
18
  pagination: {...prevState.pagination, pageIndex: newPage - 1},
19
19
  }));
20
+ containerRef.current.scrollIntoView({behavior: 'smooth'});
20
21
  };
21
22
 
22
23
  return (
@@ -69,6 +69,7 @@ describe('Table', () => {
69
69
  });
70
70
 
71
71
  it('opens the collapsible rows when the user click on the toggle', async () => {
72
+ const user = userEvent.setup({delay: null});
72
73
  const Fixture: FunctionComponent<{row: RowData}> = ({row}) => <div>Collapsible content: {row.lastName}</div>;
73
74
  const customColumns: Array<ColumnDef<RowData>> = [
74
75
  columnHelper.accessor('firstName', {
@@ -89,7 +90,7 @@ describe('Table', () => {
89
90
 
90
91
  expect(screen.queryByText('Collapsible content: last')).not.toBeVisible();
91
92
 
92
- userEvent.click(screen.getByRole('button', {name: 'arrowHeadDown'}));
93
+ await user.click(screen.getByRole('button', {name: 'arrowHeadDown'}));
93
94
  await waitFor(() => {
94
95
  expect(screen.queryByText('Collapsible content: last')).toBeVisible();
95
96
  });
@@ -126,7 +127,8 @@ describe('Table', () => {
126
127
  expect(allRows).toHaveLength(2);
127
128
  });
128
129
 
129
- it('reset row selection when user click outside the table', () => {
130
+ it('reset row selection when user click outside the table', async () => {
131
+ const user = userEvent.setup({delay: null});
130
132
  render(
131
133
  <div>
132
134
  <div>I'm a header</div>
@@ -144,11 +146,11 @@ describe('Table', () => {
144
146
 
145
147
  expect(row).not.toHaveClass('__mantine-ref-rowSelected');
146
148
 
147
- userEvent.click(row);
149
+ await user.click(row);
148
150
 
149
151
  expect(row).toHaveClass('__mantine-ref-rowSelected');
150
152
 
151
- userEvent.click(screen.getByText(/i'm a header/i));
153
+ await user.click(screen.getByText(/i'm a header/i));
152
154
 
153
155
  expect(row).not.toHaveClass('__mantine-ref-rowSelected');
154
156
  });
@@ -10,7 +10,8 @@ const columnHelper = createColumnHelper<RowData>();
10
10
  const columns: Array<ColumnDef<RowData>> = [columnHelper.accessor('name', {enableSorting: false})];
11
11
 
12
12
  describe('Table.Actions', () => {
13
- it('displays the actions when the row is selected', () => {
13
+ it('displays the actions when the row is selected', async () => {
14
+ const user = userEvent.setup({delay: null});
14
15
  render(
15
16
  <Table<RowData> data={[{name: 'fruit'}, {name: 'vegetable'}]} columns={columns}>
16
17
  <Table.Header>
@@ -24,12 +25,12 @@ describe('Table.Actions', () => {
24
25
  expect(screen.queryByRole('button', {name: 'Eat vegetable'})).not.toBeInTheDocument();
25
26
 
26
27
  // select the fruit row
27
- userEvent.click(screen.getByRole('cell', {name: 'fruit'}));
28
+ await user.click(screen.getByRole('cell', {name: 'fruit'}));
28
29
  expect(screen.getByRole('button', {name: 'Eat fruit'})).toBeVisible();
29
30
  expect(screen.queryByRole('button', {name: 'Eat vegetable'})).not.toBeInTheDocument();
30
31
 
31
32
  // select the vegetable row
32
- userEvent.click(screen.getByRole('cell', {name: 'vegetable'}));
33
+ await user.click(screen.getByRole('cell', {name: 'vegetable'}));
33
34
  expect(screen.queryByRole('button', {name: 'Eat fruit'})).not.toBeInTheDocument();
34
35
  expect(screen.getByRole('button', {name: 'Eat vegetable'})).toBeVisible();
35
36
  });
@@ -46,6 +46,7 @@ describe('Table.DateRangePicker', () => {
46
46
  });
47
47
 
48
48
  it('displays the selected date range in the table', async () => {
49
+ const user = userEvent.setup({delay: null});
49
50
  const onChange = jest.fn();
50
51
  render(
51
52
  <Table
@@ -65,19 +66,19 @@ describe('Table.DateRangePicker', () => {
65
66
  await screen.findByText('Jan 01, 2022 - Jan 07, 2022');
66
67
  await screen.findByRole('button', {name: 'calendar'});
67
68
 
68
- userEvent.click(screen.getByRole('button', {name: 'calendar'}));
69
+ await user.click(screen.getByRole('button', {name: 'calendar'}));
69
70
 
70
71
  await screen.findByRole('dialog');
71
72
 
72
73
  // select a preset
73
- userEvent.click(
74
+ await user.click(
74
75
  screen.getByRole('searchbox', {
75
76
  name: 'Date range',
76
77
  })
77
78
  );
78
- userEvent.click(screen.getByRole('option', {name: 'Preset'}));
79
+ await user.click(screen.getByRole('option', {name: 'Preset'}));
79
80
 
80
- userEvent.click(screen.getByRole('button', {name: 'Apply'}));
81
+ await user.click(screen.getByRole('button', {name: 'Apply'}));
81
82
 
82
83
  await waitFor(() => expect(screen.queryByText('Jan 08, 2022 - Jan 14, 2022')).toBeVisible());
83
84
  expect(onChange).toHaveBeenCalledWith(
@@ -22,7 +22,8 @@ describe('Table.Filter', () => {
22
22
  expect(screen.getByPlaceholderText('hello fruits')).toBeVisible();
23
23
  });
24
24
 
25
- it('calls onChange when typing something in the filter', () => {
25
+ it('calls onChange when typing something in the filter', async () => {
26
+ const user = userEvent.setup({delay: null});
26
27
  const onChange = jest.fn();
27
28
  render(
28
29
  <Table data={[{name: 'fruit'}, {name: 'vegetable'}]} columns={columns} onChange={onChange}>
@@ -32,7 +33,7 @@ describe('Table.Filter', () => {
32
33
  </Table>
33
34
  );
34
35
 
35
- userEvent.type(screen.getByRole('textbox'), 'vegetable');
36
+ await user.type(screen.getByRole('textbox'), 'vegetable');
36
37
 
37
38
  expect(onChange).toHaveBeenCalledWith(expect.objectContaining({globalFilter: 'vegetable'}));
38
39
  });
@@ -9,6 +9,14 @@ const columnHelper = createColumnHelper<RowData>();
9
9
  const columns: Array<ColumnDef<RowData>> = [columnHelper.accessor('name', {enableSorting: false})];
10
10
 
11
11
  describe('Table.Pagination', () => {
12
+ beforeEach(() => {
13
+ if (!HTMLElement.prototype.scrollIntoView) {
14
+ HTMLElement.prototype.scrollIntoView = () => {
15
+ jest.fn();
16
+ };
17
+ }
18
+ });
19
+
12
20
  it('displays the number of pages', () => {
13
21
  render(
14
22
  <Table data={[{name: 'fruit'}, {name: 'vegetable'}]} columns={columns}>
@@ -62,7 +62,8 @@ describe('Table.PerPage', () => {
62
62
  );
63
63
  });
64
64
 
65
- it('calls onChange when changing the number of items per page', () => {
65
+ it('calls onChange when changing the number of items per page', async () => {
66
+ const user = userEvent.setup({delay: null});
66
67
  const onChange = jest.fn();
67
68
  render(
68
69
  <Table data={[{name: 'fruit'}, {name: 'vegetable'}]} columns={columns} onChange={onChange}>
@@ -72,7 +73,7 @@ describe('Table.PerPage', () => {
72
73
  </Table>
73
74
  );
74
75
 
75
- userEvent.click(screen.queryByRole('radio', {name: '100'}));
76
+ await user.click(screen.queryByRole('radio', {name: '100'}));
76
77
 
77
78
  expect(onChange).toHaveBeenCalledWith(
78
79
  expect.objectContaining({pagination: expect.objectContaining({pageSize: 100})})