@onewelcome/react-lib-components 0.1.7-alpha → 0.1.8-alpha

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 (69) hide show
  1. package/dist/DataGrid/DataGrid.d.ts +30 -0
  2. package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +14 -0
  3. package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +13 -0
  4. package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +16 -0
  5. package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +6 -0
  6. package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +7 -0
  7. package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +10 -0
  8. package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +10 -0
  9. package/dist/DataGrid/datagrid.interfaces.d.ts +13 -0
  10. package/dist/Form/Select/Option.d.ts +9 -4
  11. package/dist/Form/Select/Select.d.ts +8 -2
  12. package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +1 -1
  13. package/dist/Icon/Icon.d.ts +1 -0
  14. package/dist/_BaseStyling_/BaseStyling.d.ts +4 -0
  15. package/dist/hooks/useSpacing.d.ts +1 -1
  16. package/dist/hooks/useWrapper.d.ts +1 -1
  17. package/dist/index.d.ts +5 -0
  18. package/dist/react-lib-components.cjs.development.js +949 -272
  19. package/dist/react-lib-components.cjs.development.js.map +1 -1
  20. package/dist/react-lib-components.cjs.production.min.js +1 -1
  21. package/dist/react-lib-components.cjs.production.min.js.map +1 -1
  22. package/dist/react-lib-components.esm.js +947 -273
  23. package/dist/react-lib-components.esm.js.map +1 -1
  24. package/dist/util/helper.d.ts +1 -1
  25. package/package.json +11 -11
  26. package/src/ContextMenu/ContextMenu.tsx +16 -1
  27. package/src/DataGrid/DataGrid.module.scss +21 -0
  28. package/src/DataGrid/DataGrid.test.tsx +276 -0
  29. package/src/DataGrid/DataGrid.tsx +101 -0
  30. package/src/DataGrid/DataGridActions/DataGridActions.module.scss +35 -0
  31. package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +184 -0
  32. package/src/DataGrid/DataGridActions/DataGridActions.tsx +109 -0
  33. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +41 -0
  34. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +83 -0
  35. package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +88 -0
  36. package/src/DataGrid/DataGridBody/DataGridBody.module.scss +10 -0
  37. package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +123 -0
  38. package/src/DataGrid/DataGridBody/DataGridBody.tsx +64 -0
  39. package/src/DataGrid/DataGridBody/DataGridCell.module.scss +33 -0
  40. package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +74 -0
  41. package/src/DataGrid/DataGridBody/DataGridCell.tsx +25 -0
  42. package/src/DataGrid/DataGridBody/DataGridRow.module.scss +7 -0
  43. package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +101 -0
  44. package/src/DataGrid/DataGridBody/DataGridRow.tsx +27 -0
  45. package/src/DataGrid/DataGridBody/__snapshots__/DataGridBody.test.tsx.snap +258 -0
  46. package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +26 -0
  47. package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +255 -0
  48. package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +80 -0
  49. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +68 -0
  50. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +128 -0
  51. package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +72 -0
  52. package/src/DataGrid/datagrid.interfaces.ts +14 -0
  53. package/src/Form/Select/Option.tsx +39 -21
  54. package/src/Form/Select/Select.module.scss +1 -1
  55. package/src/Form/Select/Select.test.tsx +235 -56
  56. package/src/Form/Select/Select.tsx +194 -34
  57. package/src/Form/Toggle/Toggle.module.scss +1 -0
  58. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +44 -0
  59. package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +4 -2
  60. package/src/Icon/Icon.module.scss +4 -0
  61. package/src/Icon/Icon.tsx +1 -0
  62. package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
  63. package/src/Notifications/BaseModal/BaseModal.test.tsx +2 -1
  64. package/src/Notifications/Dialog/Dialog.module.scss +1 -1
  65. package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.module.scss +1 -1
  66. package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +1 -1
  67. package/src/Pagination/Pagination.module.scss +74 -74
  68. package/src/_BaseStyling_/BaseStyling.tsx +14 -6
  69. package/src/index.ts +6 -0
@@ -0,0 +1,101 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { DataGridRow, Props } from './DataGridRow';
3
+ import { render } from '@testing-library/react';
4
+ import { DataGridCell } from './DataGridCell';
5
+
6
+ const defaultParams: Props = {
7
+ children: [<DataGridCell>1</DataGridCell>, <DataGridCell>2</DataGridCell>],
8
+ headers: [
9
+ { name: 'firstName', headline: 'first name' },
10
+ { name: 'lastName', headline: 'last name' },
11
+ ],
12
+ };
13
+
14
+ const createDataGridRow = (params?: (defaultParams: Props) => Props) => {
15
+ let parameters: Props = defaultParams;
16
+ if (params) {
17
+ parameters = params(defaultParams);
18
+ }
19
+ const container = document.createElement('tbody');
20
+ const queries = render(<DataGridRow {...parameters} data-testid="dataGridRow" />, { container });
21
+ const dataGridRow = queries.getByTestId('dataGridRow');
22
+
23
+ return {
24
+ ...queries,
25
+ dataGridRow,
26
+ };
27
+ };
28
+
29
+ describe('DataGridRow should render', () => {
30
+ it('renders without crashing', () => {
31
+ const { dataGridRow, getAllByRole } = createDataGridRow();
32
+
33
+ expect(dataGridRow).toBeDefined();
34
+ expect(dataGridRow).toHaveClass('row', { exact: true });
35
+ const cells = getAllByRole('cell');
36
+ expect(cells).toHaveLength(2);
37
+ expect(cells[0]).toHaveTextContent('1');
38
+ expect(cells[1]).toHaveTextContent('2');
39
+ });
40
+
41
+ it('renders with additional class', () => {
42
+ const { dataGridRow } = createDataGridRow((params) => ({ ...params, className: 'test' }));
43
+
44
+ expect(dataGridRow).toHaveClass('row test', { exact: true });
45
+ });
46
+
47
+ it('renders loading state', () => {
48
+ const { dataGridRow } = createDataGridRow((params) => ({ ...params, isLoading: true }));
49
+
50
+ expect(dataGridRow).toHaveClass('row loading', { exact: true });
51
+ });
52
+
53
+ it('renders only visible columns', () => {
54
+ const { dataGridRow, getAllByRole } = createDataGridRow((params) => ({
55
+ ...params,
56
+ headers: [
57
+ { name: 'firstName', headline: 'first name', hidden: true },
58
+ { name: 'lastName', headline: 'last name', hidden: true },
59
+ { name: 'date', headline: 'date' },
60
+ { name: 'status', headline: 'status' },
61
+ ],
62
+ children: [
63
+ <DataGridCell>1</DataGridCell>,
64
+ <DataGridCell>2</DataGridCell>,
65
+ <DataGridCell>3</DataGridCell>,
66
+ <DataGridCell>4</DataGridCell>,
67
+ ],
68
+ }));
69
+
70
+ expect(dataGridRow).toBeDefined();
71
+ const cells = getAllByRole('cell');
72
+ expect(cells).toHaveLength(2);
73
+ expect(cells[0]).toHaveTextContent('3');
74
+ expect(cells[1]).toHaveTextContent('4');
75
+ });
76
+ });
77
+
78
+ describe('ref should work', () => {
79
+ it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
80
+ const ExampleComponent = ({
81
+ propagateRef,
82
+ }: {
83
+ propagateRef: (ref: React.RefObject<HTMLElement>) => void;
84
+ }) => {
85
+ const ref = useRef(null);
86
+
87
+ useEffect(() => {
88
+ propagateRef(ref);
89
+ }, [ref]);
90
+
91
+ return <DataGridRow {...defaultParams} data-ref="testing" ref={ref} />;
92
+ };
93
+
94
+ const refCheck = (ref: React.RefObject<HTMLElement>) => {
95
+ expect(ref.current).toHaveAttribute('data-ref', 'testing');
96
+ };
97
+
98
+ const container = document.createElement('tbody');
99
+ render(<ExampleComponent propagateRef={refCheck} />, { container });
100
+ });
101
+ });
@@ -0,0 +1,27 @@
1
+ import React, { ComponentPropsWithRef } from 'react';
2
+ import { HeaderCell } from '../datagrid.interfaces';
3
+ import classes from './DataGridRow.module.scss';
4
+
5
+ export interface Props extends ComponentPropsWithRef<'tr'> {
6
+ headers?: HeaderCell[];
7
+ isLoading?: boolean;
8
+ }
9
+
10
+ export const DataGridRow = React.forwardRef<HTMLTableRowElement, Props>(
11
+ ({ children, className, headers, isLoading, ...rest }: Props, ref) => {
12
+ const visibleCells = React.Children.map(children, (child, index) => {
13
+ const visible = headers?.length! > index ? !headers![index].hidden : true;
14
+ return visible && child;
15
+ });
16
+
17
+ const classNames = [classes['row']];
18
+ className && classNames.push(className);
19
+ isLoading && classNames.push(classes['loading']);
20
+
21
+ return (
22
+ <tr {...rest} ref={ref} className={classNames.join(' ')}>
23
+ {visibleCells}
24
+ </tr>
25
+ );
26
+ }
27
+ );
@@ -0,0 +1,258 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DataGridBody should render renders without crashing 1`] = `
4
+ Array [
5
+ <tr
6
+ class="row"
7
+ >
8
+ <td
9
+ class="cell "
10
+ >
11
+ <span
12
+ class="typography_style_body "
13
+ >
14
+ Paweł
15
+ </span>
16
+ </td>
17
+ <td
18
+ class="cell "
19
+ >
20
+ <span
21
+ class="typography_style_body "
22
+ >
23
+ Napieracz
24
+ </span>
25
+ </td>
26
+ <td
27
+ class="cell "
28
+ >
29
+ <span
30
+ class="typography_style_body "
31
+ >
32
+ 12.12.1990
33
+ </span>
34
+ </td>
35
+ <td
36
+ class="cell "
37
+ >
38
+ <span
39
+ class="typography_style_body "
40
+ >
41
+ <div
42
+ class="context-menu"
43
+ >
44
+ <button
45
+ aria-controls="consent_menu_Paweł-menu"
46
+ aria-expanded="false"
47
+ aria-haspopup="true"
48
+ class="button icon-button text default button-m"
49
+ id="consent_menu_Paweł"
50
+ tabindex="0"
51
+ type="button"
52
+ >
53
+ <span
54
+ aria-hidden="true"
55
+ class="icon icon-ellipsis-alt "
56
+ data-icon="true"
57
+ />
58
+ <span
59
+ class="sr-only"
60
+ >
61
+ Actions for Paweł
62
+ </span>
63
+ </button>
64
+ </div>
65
+ </span>
66
+ </td>
67
+ </tr>,
68
+ <tr
69
+ class="row"
70
+ >
71
+ <td
72
+ class="cell "
73
+ >
74
+ <span
75
+ class="typography_style_body "
76
+ >
77
+ Michał
78
+ </span>
79
+ </td>
80
+ <td
81
+ class="cell "
82
+ >
83
+ <span
84
+ class="typography_style_body "
85
+ >
86
+ Górski
87
+ </span>
88
+ </td>
89
+ <td
90
+ class="cell "
91
+ >
92
+ <span
93
+ class="typography_style_body "
94
+ >
95
+ 12.12.1994
96
+ </span>
97
+ </td>
98
+ <td
99
+ class="cell "
100
+ >
101
+ <span
102
+ class="typography_style_body "
103
+ >
104
+ <div
105
+ class="context-menu"
106
+ >
107
+ <button
108
+ aria-controls="consent_menu_Michał-menu"
109
+ aria-expanded="false"
110
+ aria-haspopup="true"
111
+ class="button icon-button text default button-m"
112
+ id="consent_menu_Michał"
113
+ tabindex="0"
114
+ type="button"
115
+ >
116
+ <span
117
+ aria-hidden="true"
118
+ class="icon icon-ellipsis-alt "
119
+ data-icon="true"
120
+ />
121
+ <span
122
+ class="sr-only"
123
+ >
124
+ Actions for Michał
125
+ </span>
126
+ </button>
127
+ </div>
128
+ </span>
129
+ </td>
130
+ </tr>,
131
+ <tr
132
+ class="row"
133
+ >
134
+ <td
135
+ class="cell "
136
+ >
137
+ <span
138
+ class="typography_style_body "
139
+ >
140
+ Daniel
141
+ </span>
142
+ </td>
143
+ <td
144
+ class="cell "
145
+ >
146
+ <span
147
+ class="typography_style_body "
148
+ >
149
+ Velden
150
+ </span>
151
+ </td>
152
+ <td
153
+ class="cell "
154
+ >
155
+ <span
156
+ class="typography_style_body "
157
+ >
158
+ 12.12.199x
159
+ </span>
160
+ </td>
161
+ <td
162
+ class="cell "
163
+ >
164
+ <span
165
+ class="typography_style_body "
166
+ >
167
+ <div
168
+ class="context-menu"
169
+ >
170
+ <button
171
+ aria-controls="consent_menu_Daniel-menu"
172
+ aria-expanded="false"
173
+ aria-haspopup="true"
174
+ class="button icon-button text default button-m"
175
+ id="consent_menu_Daniel"
176
+ tabindex="0"
177
+ type="button"
178
+ >
179
+ <span
180
+ aria-hidden="true"
181
+ class="icon icon-ellipsis-alt "
182
+ data-icon="true"
183
+ />
184
+ <span
185
+ class="sr-only"
186
+ >
187
+ Actions for Daniel
188
+ </span>
189
+ </button>
190
+ </div>
191
+ </span>
192
+ </td>
193
+ </tr>,
194
+ <tr
195
+ class="row"
196
+ >
197
+ <td
198
+ class="cell "
199
+ >
200
+ <span
201
+ class="typography_style_body "
202
+ >
203
+ Jasha
204
+ </span>
205
+ </td>
206
+ <td
207
+ class="cell "
208
+ >
209
+ <span
210
+ class="typography_style_body "
211
+ >
212
+ Joachimsthal
213
+ </span>
214
+ </td>
215
+ <td
216
+ class="cell "
217
+ >
218
+ <span
219
+ class="typography_style_body "
220
+ >
221
+ 12.12.198x
222
+ </span>
223
+ </td>
224
+ <td
225
+ class="cell "
226
+ >
227
+ <span
228
+ class="typography_style_body "
229
+ >
230
+ <div
231
+ class="context-menu"
232
+ >
233
+ <button
234
+ aria-controls="consent_menu_Jasha-menu"
235
+ aria-expanded="false"
236
+ aria-haspopup="true"
237
+ class="button icon-button text default button-m"
238
+ id="consent_menu_Jasha"
239
+ tabindex="0"
240
+ type="button"
241
+ >
242
+ <span
243
+ aria-hidden="true"
244
+ class="icon icon-ellipsis-alt "
245
+ data-icon="true"
246
+ />
247
+ <span
248
+ class="sr-only"
249
+ >
250
+ Actions for Jasha
251
+ </span>
252
+ </button>
253
+ </div>
254
+ </span>
255
+ </td>
256
+ </tr>,
257
+ ]
258
+ `;
@@ -0,0 +1,26 @@
1
+ .thead {
2
+ &::after {
3
+ content: '';
4
+ position: absolute;
5
+ top: 2.5rem;
6
+ width: calc(100% - 2rem);
7
+ left: 1rem;
8
+ border-bottom: 1px solid #c3c3c7;
9
+ }
10
+ }
11
+
12
+ .row {
13
+ height: 2.5rem;
14
+ }
15
+
16
+ .context-menu {
17
+ width: 4.125rem;
18
+ box-sizing: border-box;
19
+ }
20
+
21
+ @media only screen and (min-width: 50em) {
22
+ .thead::after {
23
+ width: calc(100% - 2.5rem);
24
+ left: 1.25rem;
25
+ }
26
+ }
@@ -0,0 +1,255 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { DataGridHeader, Props } from './DataGridHeader';
3
+ import { getByRole, render } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+
6
+ const defaultParams: Props = {
7
+ headers: [
8
+ { name: 'firstName', headline: 'First name' },
9
+ { name: 'lastName', headline: 'Last name' },
10
+ ],
11
+ };
12
+
13
+ const createDataGridHeader = (params?: (defaultParams: Props) => Props) => {
14
+ let parameters: Props = defaultParams;
15
+ if (params) {
16
+ parameters = params(defaultParams);
17
+ }
18
+ const container = document.createElement('table');
19
+ const queries = render(<DataGridHeader {...parameters} data-testid="dataGridHeader" />, {
20
+ container,
21
+ });
22
+ const dataGridHeader = queries.getByTestId('dataGridHeader');
23
+
24
+ return {
25
+ ...queries,
26
+ dataGridHeader,
27
+ };
28
+ };
29
+
30
+ describe('DataGridHeader should render', () => {
31
+ it('renders without crashing', () => {
32
+ const { dataGridHeader, getAllByRole, getByRole } = createDataGridHeader();
33
+
34
+ expect(dataGridHeader).toBeDefined();
35
+ expect(getAllByRole('columnheader')).toHaveLength(2);
36
+ expect(getByRole('cell')).toBeDefined(); //context-menu empty cell
37
+
38
+ expect(dataGridHeader.querySelectorAll('[data-icon]')).toHaveLength(0);
39
+ });
40
+
41
+ it('renders without hidden cell', () => {
42
+ const { dataGridHeader, getByRole } = createDataGridHeader((params) => ({
43
+ ...params,
44
+ headers: [...params.headers].map((header, idx) => ({ ...header, hidden: idx === 1 })),
45
+ }));
46
+
47
+ expect(dataGridHeader).toBeDefined();
48
+ expect(getByRole('columnheader')).toHaveTextContent(defaultParams.headers[0].headline);
49
+ expect(getByRole('cell')).toBeDefined(); //context-menu empty cell
50
+
51
+ expect(dataGridHeader.querySelectorAll('[data-icon]')).toHaveLength(0);
52
+ });
53
+
54
+ it('renders without contenxt-menu empty cell', () => {
55
+ const { dataGridHeader, getAllByRole, queryByRole } = createDataGridHeader((params) => ({
56
+ ...params,
57
+ disableContextMenuColumn: true,
58
+ }));
59
+
60
+ expect(dataGridHeader).toBeDefined();
61
+ expect(getAllByRole('columnheader')).toHaveLength(2);
62
+ expect(queryByRole('cell')).toBeNull(); //context-menu empty cell
63
+ });
64
+
65
+ it('renders headers cells without sorting indicators even when initialSort is provided', () => {
66
+ const { dataGridHeader } = createDataGridHeader((params) => ({
67
+ ...params,
68
+ initialSort: [{ name: params.headers[0].name, direction: 'ASC' }],
69
+ }));
70
+
71
+ expect(dataGridHeader.querySelectorAll('[data-icon]')).toHaveLength(0);
72
+ });
73
+
74
+ it('renders headers cells with sorting indicators', () => {
75
+ const onSort = jest.fn();
76
+ const { dataGridHeader } = createDataGridHeader((params) => ({
77
+ ...params,
78
+ onSort,
79
+ }));
80
+
81
+ const sortingIcons = dataGridHeader.querySelectorAll('[data-icon]');
82
+ expect(sortingIcons).toHaveLength(4);
83
+ sortingIcons.forEach((icon) => expect(icon).not.toHaveClass('hidden'));
84
+ });
85
+
86
+ it('renders headers cells with sorting indicators when initialSort provided with direction ASC', () => {
87
+ const onSort = jest.fn();
88
+ const { dataGridHeader, getAllByRole } = createDataGridHeader((params) => ({
89
+ ...params,
90
+ initialSort: [{ name: params.headers[0].name, direction: 'ASC' }],
91
+ onSort,
92
+ }));
93
+
94
+ expect(dataGridHeader.querySelectorAll('[data-icon]:not(.hidden)')).toHaveLength(3);
95
+ const [firstNameCell, lastNameCell] = getAllByRole('columnheader');
96
+ expect(firstNameCell).toHaveAttribute('aria-sort', 'ascending');
97
+ expect(lastNameCell).not.toHaveAttribute('aria-sort');
98
+ });
99
+
100
+ it('renders headers cells with sorting indicators when initialSort provided with direction DESC', () => {
101
+ const onSort = jest.fn();
102
+ const { dataGridHeader, getAllByRole } = createDataGridHeader((params) => ({
103
+ ...params,
104
+ initialSort: [{ name: params.headers[1].name, direction: 'DESC' }],
105
+ onSort,
106
+ }));
107
+
108
+ expect(dataGridHeader.querySelectorAll('[data-icon]:not(.hidden)')).toHaveLength(3);
109
+ const [firstNameCell, lastNameCell] = getAllByRole('columnheader');
110
+ expect(firstNameCell).not.toHaveAttribute('aria-sort');
111
+ expect(lastNameCell).toHaveAttribute('aria-sort', 'descending');
112
+ });
113
+ });
114
+
115
+ describe('DataGridHeader should be interactive', () => {
116
+ it('clicking on cell call onSort callback', () => {
117
+ const onSortHandler = jest.fn();
118
+ const { getAllByRole } = createDataGridHeader((params) => ({
119
+ ...params,
120
+ onSort: onSortHandler,
121
+ }));
122
+
123
+ const [firstNameCell, lastNameCell] = getAllByRole('columnheader');
124
+ userEvent.click(getByRole(firstNameCell, 'button'));
125
+
126
+ expect(onSortHandler).toBeCalledWith([
127
+ { name: defaultParams.headers[0].name, direction: 'ASC' },
128
+ ]);
129
+ expect(firstNameCell).toHaveAttribute('aria-sort', 'ascending');
130
+ expect(lastNameCell).not.toHaveAttribute('aria-sort');
131
+ });
132
+
133
+ it('clicking on multiple cells call onSort callback with one column selected when single-sorting is enabled', () => {
134
+ const onSortHandler = jest.fn();
135
+ const { getAllByRole } = createDataGridHeader((params) => ({
136
+ ...params,
137
+ onSort: onSortHandler,
138
+ }));
139
+
140
+ const [firstNameCell, lastNameCell] = getAllByRole('columnheader');
141
+
142
+ userEvent.click(getByRole(firstNameCell, 'button'));
143
+ userEvent.click(getByRole(lastNameCell, 'button'));
144
+ expect(onSortHandler).toBeCalledWith([
145
+ { name: defaultParams.headers[0].name, direction: 'ASC' },
146
+ ]);
147
+ expect(onSortHandler).toBeCalledWith([
148
+ { name: defaultParams.headers[1].name, direction: 'ASC' },
149
+ ]);
150
+ expect(firstNameCell).not.toHaveAttribute('aria-sort');
151
+ expect(lastNameCell).toHaveAttribute('aria-sort', 'ascending');
152
+
153
+ userEvent.click(getByRole(lastNameCell, 'button'));
154
+ expect(onSortHandler).toBeCalledWith([
155
+ { name: defaultParams.headers[1].name, direction: 'DESC' },
156
+ ]);
157
+ expect(firstNameCell).not.toHaveAttribute('aria-sort');
158
+ expect(lastNameCell).toHaveAttribute('aria-sort', 'descending');
159
+
160
+ userEvent.click(getByRole(firstNameCell, 'button'));
161
+ expect(onSortHandler).toBeCalledWith([
162
+ { name: defaultParams.headers[0].name, direction: 'ASC' },
163
+ ]);
164
+ expect(firstNameCell).toHaveAttribute('aria-sort', 'ascending');
165
+ expect(lastNameCell).not.toHaveAttribute('aria-sort');
166
+
167
+ userEvent.click(getByRole(firstNameCell, 'button'));
168
+ expect(onSortHandler).toBeCalledWith([
169
+ { name: defaultParams.headers[1].name, direction: 'DESC' },
170
+ ]);
171
+ expect(firstNameCell).toHaveAttribute('aria-sort', 'descending');
172
+ expect(lastNameCell).not.toHaveAttribute('aria-sort');
173
+
174
+ userEvent.click(getByRole(firstNameCell, 'button'));
175
+ expect(onSortHandler).toBeCalledWith([]);
176
+ expect(firstNameCell).not.toHaveAttribute('aria-sort');
177
+ expect(lastNameCell).not.toHaveAttribute('aria-sort');
178
+ });
179
+
180
+ it('clicking on multiple cells call onSort callback with multiple columns selected when multi-sorting is enabled', () => {
181
+ const onSortHandler = jest.fn();
182
+ const { getAllByRole } = createDataGridHeader((params) => ({
183
+ ...params,
184
+ enableMultiSorting: true,
185
+ onSort: onSortHandler,
186
+ }));
187
+
188
+ const [firstNameCell, lastNameCell] = getAllByRole('columnheader');
189
+
190
+ userEvent.click(getByRole(firstNameCell, 'button'));
191
+ userEvent.click(getByRole(lastNameCell, 'button'));
192
+ expect(onSortHandler).toBeCalledWith([
193
+ { name: defaultParams.headers[0].name, direction: 'ASC' },
194
+ ]);
195
+ expect(onSortHandler).toBeCalledWith([
196
+ { name: defaultParams.headers[1].name, direction: 'ASC' },
197
+ { name: defaultParams.headers[0].name, direction: 'ASC' },
198
+ ]);
199
+ expect(firstNameCell).toHaveAttribute('aria-sort', 'ascending');
200
+ expect(lastNameCell).toHaveAttribute('aria-sort', 'ascending');
201
+
202
+ userEvent.click(getByRole(lastNameCell, 'button'));
203
+ expect(onSortHandler).toBeCalledWith([
204
+ { name: defaultParams.headers[1].name, direction: 'DESC' },
205
+ { name: defaultParams.headers[0].name, direction: 'ASC' },
206
+ ]);
207
+ expect(firstNameCell).toHaveAttribute('aria-sort', 'ascending');
208
+ expect(lastNameCell).toHaveAttribute('aria-sort', 'descending');
209
+
210
+ userEvent.click(getByRole(firstNameCell, 'button'));
211
+ expect(onSortHandler).toBeCalledWith([
212
+ { name: defaultParams.headers[0].name, direction: 'DESC' },
213
+ { name: defaultParams.headers[1].name, direction: 'DESC' },
214
+ ]);
215
+ expect(firstNameCell).toHaveAttribute('aria-sort', 'descending');
216
+ expect(lastNameCell).toHaveAttribute('aria-sort', 'descending');
217
+
218
+ userEvent.click(getByRole(firstNameCell, 'button'));
219
+ expect(onSortHandler).toBeCalledWith([
220
+ { name: defaultParams.headers[1].name, direction: 'DESC' },
221
+ ]);
222
+ expect(firstNameCell).not.toHaveAttribute('aria-sort');
223
+ expect(lastNameCell).toHaveAttribute('aria-sort', 'descending');
224
+
225
+ userEvent.click(getByRole(lastNameCell, 'button'));
226
+ expect(onSortHandler).toBeCalledWith([]);
227
+ expect(firstNameCell).not.toHaveAttribute('aria-sort');
228
+ expect(lastNameCell).not.toHaveAttribute('aria-sort');
229
+ });
230
+ });
231
+
232
+ describe('ref should work', () => {
233
+ it('should give back the proper data prop, this also checks if the component propagates ...rest properly', () => {
234
+ const ExampleComponent = ({
235
+ propagateRef,
236
+ }: {
237
+ propagateRef: (ref: React.RefObject<HTMLElement>) => void;
238
+ }) => {
239
+ const ref = useRef(null);
240
+
241
+ useEffect(() => {
242
+ propagateRef(ref);
243
+ }, [ref]);
244
+
245
+ return <DataGridHeader {...defaultParams} data-ref="testing" ref={ref} />;
246
+ };
247
+
248
+ const refCheck = (ref: React.RefObject<HTMLElement>) => {
249
+ expect(ref.current).toHaveAttribute('data-ref', 'testing');
250
+ };
251
+
252
+ const container = document.createElement('table');
253
+ render(<ExampleComponent propagateRef={refCheck} />, { container });
254
+ });
255
+ });