@onewelcome/react-lib-components 6.0.0 → 6.1.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.
- package/dist/cjs/Button/Button.module.cjs.js +1 -1
- package/dist/cjs/Button/IconButton.module.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenu.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenu.cjs.js.map +1 -1
- package/dist/cjs/ContextMenu/ContextMenuItem.module.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenuService.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenuService.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridActions/DataGridColumnsToggle.module.cjs.js +1 -1
- package/dist/cjs/Form/Input/Input.module.cjs.js +1 -1
- package/dist/cjs/Form/Select/Option.cjs.js +1 -1
- package/dist/cjs/Form/Select/Option.cjs.js.map +1 -1
- package/dist/cjs/Form/Select/Select.cjs.js +1 -1
- package/dist/cjs/Form/Select/Select.cjs.js.map +1 -1
- package/dist/cjs/Form/Select/Select.module.cjs.js +1 -1
- package/dist/cjs/Form/Select/SelectService.cjs.js +1 -1
- package/dist/cjs/Form/Select/SelectService.cjs.js.map +1 -1
- package/dist/cjs/Form/Textarea/Textarea.module.cjs.js +1 -1
- package/dist/cjs/Link/Link.module.cjs.js +1 -1
- package/dist/cjs/Notifications/BaseModal/BaseModal.module.cjs.js +1 -1
- package/dist/cjs/Notifications/SlideInModal/SlideInModal.module.cjs.js +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.cjs.js +1 -1
- package/dist/cjs/Popover/Popover.cjs.js +1 -1
- package/dist/cjs/Popover/Popover.cjs.js.map +1 -1
- package/dist/cjs/Popover/Popover.module.cjs.js +1 -1
- package/dist/cjs/Stepper/Step.cjs.js +1 -1
- package/dist/cjs/Stepper/Step.cjs.js.map +1 -1
- package/dist/cjs/Stepper/Step.module.cjs.js +1 -1
- package/dist/cjs/Stepper/Stepper.cjs.js +1 -1
- package/dist/cjs/Stepper/Stepper.cjs.js.map +1 -1
- package/dist/cjs/Tabs/TabButton.module.cjs.js +1 -1
- package/dist/cjs/TextEllipsis/TextEllipsis.module.cjs.js +1 -1
- package/dist/cjs/Tiles/Tile.module.cjs.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.module.cjs.js +1 -1
- package/dist/cjs/Wizard/BaseWizardSteps/BaseWizardSteps.module.cjs.js +1 -1
- package/dist/cjs/src/.scope.d.ts +2 -0
- package/dist/cjs/src/components/ContextMenu/ContextMenu.d.ts +1 -1
- package/dist/cjs/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
- package/dist/cjs/src/components/Form/Select/Option.d.ts +1 -0
- package/dist/cjs/src/components/Form/Select/Select.d.ts +20 -0
- package/dist/cjs/src/components/Form/Select/Select.interfaces.d.ts +3 -1
- package/dist/cjs/src/components/Form/Select/Select.test.d.ts +63 -1
- package/dist/cjs/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
- package/dist/cjs/src/components/Form/Select/SelectService.d.ts +3 -2
- package/dist/cjs/src/components/Stepper/Stepper.d.ts +0 -1
- package/dist/cjs/src/hooks/usePosition.cjs.js.map +1 -1
- package/dist/cjs/src/hooks/usePosition.d.ts +1 -1
- package/dist/esm/Button/Button.module.esm.js +1 -1
- package/dist/esm/Button/IconButton.module.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenu.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenu.esm.js.map +1 -1
- package/dist/esm/ContextMenu/ContextMenuItem.module.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenuService.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenuService.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridActions/DataGridColumnsToggle.module.esm.js +1 -1
- package/dist/esm/Form/Input/Input.module.esm.js +1 -1
- package/dist/esm/Form/Select/Option.esm.js +1 -1
- package/dist/esm/Form/Select/Option.esm.js.map +1 -1
- package/dist/esm/Form/Select/Select.esm.js +1 -1
- package/dist/esm/Form/Select/Select.esm.js.map +1 -1
- package/dist/esm/Form/Select/Select.module.esm.js +1 -1
- package/dist/esm/Form/Select/SelectService.esm.js +1 -1
- package/dist/esm/Form/Select/SelectService.esm.js.map +1 -1
- package/dist/esm/Form/Textarea/Textarea.module.esm.js +1 -1
- package/dist/esm/Link/Link.module.esm.js +1 -1
- package/dist/esm/Notifications/BaseModal/BaseModal.module.esm.js +1 -1
- package/dist/esm/Notifications/SlideInModal/SlideInModal.module.esm.js +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.esm.js +1 -1
- package/dist/esm/Popover/Popover.esm.js +1 -1
- package/dist/esm/Popover/Popover.esm.js.map +1 -1
- package/dist/esm/Popover/Popover.module.esm.js +1 -1
- package/dist/esm/Stepper/Step.esm.js +1 -1
- package/dist/esm/Stepper/Step.esm.js.map +1 -1
- package/dist/esm/Stepper/Step.module.esm.js +1 -1
- package/dist/esm/Stepper/Stepper.esm.js +1 -1
- package/dist/esm/Stepper/Stepper.esm.js.map +1 -1
- package/dist/esm/Tabs/TabButton.module.esm.js +1 -1
- package/dist/esm/TextEllipsis/TextEllipsis.module.esm.js +1 -1
- package/dist/esm/Tiles/Tile.module.esm.js +1 -1
- package/dist/esm/Tooltip/Tooltip.module.esm.js +1 -1
- package/dist/esm/Wizard/BaseWizardSteps/BaseWizardSteps.module.esm.js +1 -1
- package/dist/esm/src/.scope.d.ts +2 -0
- package/dist/esm/src/components/ContextMenu/ContextMenu.d.ts +1 -1
- package/dist/esm/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
- package/dist/esm/src/components/Form/Select/Option.d.ts +1 -0
- package/dist/esm/src/components/Form/Select/Select.d.ts +20 -0
- package/dist/esm/src/components/Form/Select/Select.interfaces.d.ts +3 -1
- package/dist/esm/src/components/Form/Select/Select.test.d.ts +63 -1
- package/dist/esm/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
- package/dist/esm/src/components/Form/Select/SelectService.d.ts +3 -2
- package/dist/esm/src/components/Stepper/Stepper.d.ts +0 -1
- package/dist/esm/src/hooks/usePosition.d.ts +1 -1
- package/dist/esm/src/hooks/usePosition.esm.js.map +1 -1
- package/package.json +48 -45
- package/src/{hooks/useWrapper.test.ts → .scope.ts} +1 -12
- package/src/components/ContextMenu/ContextMenu.tsx +13 -23
- package/src/components/ContextMenu/ContextMenuService.ts +47 -1
- package/src/components/Form/Select/Option.tsx +3 -1
- package/src/components/Form/Select/Select.interfaces.ts +3 -1
- package/src/components/Form/Select/Select.module.scss +55 -34
- package/src/components/Form/Select/Select.tsx +74 -23
- package/src/components/Form/Select/SelectService.ts +26 -10
- package/src/components/Link/Link.module.scss +16 -0
- package/src/components/Popover/Popover.tsx +19 -2
- package/src/components/Stepper/Step.tsx +2 -1
- package/src/components/Stepper/Stepper.tsx +0 -2
- package/src/components/Tooltip/Tooltip.module.scss +1 -0
- package/src/hooks/usePosition.ts +1 -1
- package/src/interfaces.ts +2 -2
- package/src/mixins.module.scss +2 -4
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -64
- package/src/components/Button/BaseButton.test.tsx +0 -133
- package/src/components/Button/Button.test.tsx +0 -150
- package/src/components/Button/IconButton.test.tsx +0 -106
- package/src/components/ContextMenu/ContextMenu.test.tsx +0 -358
- package/src/components/DataGrid/DataGrid.test.tsx +0 -437
- package/src/components/DataGrid/DataGridActions/DataGridActions.test.tsx +0 -204
- package/src/components/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +0 -99
- package/src/components/DataGrid/DataGridBody/DataGridBody.test.tsx +0 -140
- package/src/components/DataGrid/DataGridBody/DataGridCell.test.tsx +0 -90
- package/src/components/DataGrid/DataGridBody/DataGridRow.test.tsx +0 -117
- package/src/components/DataGrid/DataGridHeader/DataGridHeader.test.tsx +0 -276
- package/src/components/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +0 -144
- package/src/components/Form/Checkbox/Checkbox.test.tsx +0 -308
- package/src/components/Form/Fieldset/Fieldset.test.tsx +0 -127
- package/src/components/Form/FileUpload/FileItem/FileItem.test.tsx +0 -103
- package/src/components/Form/FileUpload/FileUpload.test.tsx +0 -374
- package/src/components/Form/Form.test.tsx +0 -63
- package/src/components/Form/FormControl/FormControl.test.tsx +0 -98
- package/src/components/Form/FormGroup/FormGroup.test.tsx +0 -127
- package/src/components/Form/FormHelperText/FormHelperText.test.tsx +0 -84
- package/src/components/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +0 -94
- package/src/components/Form/Input/Input.test.tsx +0 -267
- package/src/components/Form/Label/Label.test.tsx +0 -68
- package/src/components/Form/Radio/Radio.test.tsx +0 -130
- package/src/components/Form/Select/Option.test.tsx +0 -57
- package/src/components/Form/Select/Select.test.tsx +0 -564
- package/src/components/Form/Textarea/Textarea.test.tsx +0 -124
- package/src/components/Form/Toggle/Toggle.test.tsx +0 -200
- package/src/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +0 -141
- package/src/components/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +0 -211
- package/src/components/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +0 -117
- package/src/components/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +0 -186
- package/src/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +0 -173
- package/src/components/Form/Wrapper/Wrapper/Wrapper.test.tsx +0 -59
- package/src/components/Icon/Icon.test.tsx +0 -83
- package/src/components/Link/Link.test.tsx +0 -203
- package/src/components/Notifications/Banner/Banner.test.tsx +0 -84
- package/src/components/Notifications/BaseModal/BaseModal.test.tsx +0 -194
- package/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +0 -74
- package/src/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +0 -71
- package/src/components/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +0 -74
- package/src/components/Notifications/Dialog/Dialog.test.tsx +0 -118
- package/src/components/Notifications/Dialog/DialogActions/DialogActions.test.tsx +0 -61
- package/src/components/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +0 -87
- package/src/components/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +0 -111
- package/src/components/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +0 -175
- package/src/components/Notifications/Modal/Modal.test.tsx +0 -18
- package/src/components/Notifications/NotificationProvider/NotificationContext.test.tsx +0 -449
- package/src/components/Notifications/SlideInModal/SlideInModal.test.tsx +0 -90
- package/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +0 -53
- package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +0 -77
- package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +0 -219
- package/src/components/Notifications/Snackbar/useSnackbar.test.tsx +0 -136
- package/src/components/Pagination/Pagination.test.tsx +0 -183
- package/src/components/Popover/Popover.test.tsx +0 -103
- package/src/components/ProgressBar/ProgressBar.test.tsx +0 -91
- package/src/components/Skeleton/Skeleton.test.tsx +0 -112
- package/src/components/StatusIndicator/StatusIndicator.test.tsx +0 -143
- package/src/components/Stepper/Stepper.test.tsx +0 -83
- package/src/components/Tabs/Tab.test.tsx +0 -49
- package/src/components/Tabs/TabButton.test.tsx +0 -65
- package/src/components/Tabs/Tabs.test.tsx +0 -291
- package/src/components/Tag/Tag.test.tsx +0 -89
- package/src/components/TextEllipsis/TextEllipsis.test.tsx +0 -96
- package/src/components/Tiles/Tile.test.tsx +0 -183
- package/src/components/Tiles/Tiles.test.tsx +0 -162
- package/src/components/Tooltip/Tooltip.test.tsx +0 -390
- package/src/components/Typography/Typography.test.tsx +0 -177
- package/src/components/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +0 -90
- package/src/components/Wizard/Wizard.test.tsx +0 -218
- package/src/components/Wizard/WizardActions/WizardActions.test.tsx +0 -187
- package/src/components/Wizard/WizardSteps/WizardSteps.test.tsx +0 -125
- package/src/components/_BaseStyling_/BaseStyling.test.tsx +0 -55
- package/src/hooks/useAnimation.test.tsx +0 -65
- package/src/hooks/useBodyClick.test.tsx +0 -55
- package/src/hooks/useDebouncedCallback.test.ts +0 -150
- package/src/hooks/useDetermineStatusIcon.test.ts +0 -28
- package/src/hooks/useFormSelector.test.ts +0 -56
- package/src/hooks/usePosition.test.tsx +0 -510
- package/src/hooks/useRepeater.test.tsx +0 -156
- package/src/hooks/useScroll.test.tsx +0 -36
- package/src/hooks/useSpacing.test.ts +0 -86
- package/src/hooks/useUploadFile.test.ts +0 -211
- package/src/util/helper.test.tsx +0 -403
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2022 OneWelcome B.V.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import React, { useEffect, useRef } from "react";
|
|
18
|
-
import { DataGridHeader, Props } from "./DataGridHeader";
|
|
19
|
-
import { getByRole, render } from "@testing-library/react";
|
|
20
|
-
import userEvent from "@testing-library/user-event";
|
|
21
|
-
|
|
22
|
-
const defaultParams: Props = {
|
|
23
|
-
headers: [
|
|
24
|
-
{ name: "firstName", headline: "First name", align: "center" },
|
|
25
|
-
{ name: "lastName", headline: "Last name", align: "right" }
|
|
26
|
-
]
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const createDataGridHeader = (params?: (defaultParams: Props) => Props) => {
|
|
30
|
-
let parameters: Props = defaultParams;
|
|
31
|
-
if (params) {
|
|
32
|
-
parameters = params(defaultParams);
|
|
33
|
-
}
|
|
34
|
-
const container = document.createElement("table");
|
|
35
|
-
const queries = render(<DataGridHeader {...parameters} data-testid="dataGridHeader" />, {
|
|
36
|
-
container
|
|
37
|
-
});
|
|
38
|
-
const dataGridHeader = queries.getByTestId("dataGridHeader");
|
|
39
|
-
return {
|
|
40
|
-
...queries,
|
|
41
|
-
dataGridHeader
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
describe("DataGridHeader should render", () => {
|
|
46
|
-
it("renders without crashing", () => {
|
|
47
|
-
const { dataGridHeader, getAllByRole, getByRole } = createDataGridHeader();
|
|
48
|
-
|
|
49
|
-
expect(dataGridHeader).toBeDefined();
|
|
50
|
-
expect(getAllByRole("columnheader")).toHaveLength(2);
|
|
51
|
-
expect(getByRole("cell")).toBeDefined(); //context-menu empty cell
|
|
52
|
-
|
|
53
|
-
const headerCells = dataGridHeader.querySelectorAll("th");
|
|
54
|
-
|
|
55
|
-
expect(headerCells).toHaveLength(2);
|
|
56
|
-
expect(headerCells[0]).toHaveStyle({ textAlign: "center" });
|
|
57
|
-
expect(headerCells[1]).toHaveStyle({ textAlign: "right" });
|
|
58
|
-
|
|
59
|
-
expect(dataGridHeader.querySelectorAll("[data-icon]")).toHaveLength(0);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("renders without hidden cell", () => {
|
|
63
|
-
const { dataGridHeader, getByRole } = createDataGridHeader(params => ({
|
|
64
|
-
...params,
|
|
65
|
-
headers: [...params.headers].map((header, idx) => ({ ...header, hidden: idx === 1 }))
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
expect(dataGridHeader).toBeDefined();
|
|
69
|
-
expect(getByRole("columnheader")).toHaveTextContent(defaultParams.headers[0].headline);
|
|
70
|
-
expect(getByRole("cell")).toBeDefined(); //context-menu empty cell
|
|
71
|
-
|
|
72
|
-
expect(dataGridHeader.querySelectorAll("[data-icon]")).toHaveLength(0);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("renders without contenxt-menu empty cell", () => {
|
|
76
|
-
const { dataGridHeader, getAllByRole, queryByRole } = createDataGridHeader(params => ({
|
|
77
|
-
...params,
|
|
78
|
-
disableContextMenuColumn: true
|
|
79
|
-
}));
|
|
80
|
-
|
|
81
|
-
expect(dataGridHeader).toBeDefined();
|
|
82
|
-
expect(getAllByRole("columnheader")).toHaveLength(2);
|
|
83
|
-
expect(queryByRole("cell")).toBeNull(); //context-menu empty cell
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("renders headers cells without sorting indicators even when initialSort is provided", () => {
|
|
87
|
-
const { dataGridHeader } = createDataGridHeader(params => ({
|
|
88
|
-
...params,
|
|
89
|
-
initialSort: [{ name: params.headers[0].name, direction: "ASC" }]
|
|
90
|
-
}));
|
|
91
|
-
|
|
92
|
-
expect(dataGridHeader.querySelectorAll("[data-icon]")).toHaveLength(0);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("renders headers cells with sorting indicators", () => {
|
|
96
|
-
const onSort = jest.fn();
|
|
97
|
-
const { dataGridHeader } = createDataGridHeader(params => ({
|
|
98
|
-
...params,
|
|
99
|
-
onSort
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
const sortingIcons = dataGridHeader.querySelectorAll("[data-icon]");
|
|
103
|
-
expect(sortingIcons).toHaveLength(4);
|
|
104
|
-
sortingIcons.forEach(icon => expect(icon).not.toHaveClass("hidden"));
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("renders headers cells with sorting indicators when initialSort provided with direction ASC", () => {
|
|
108
|
-
const onSort = jest.fn();
|
|
109
|
-
const { dataGridHeader, getAllByRole } = createDataGridHeader(params => ({
|
|
110
|
-
...params,
|
|
111
|
-
initialSort: [{ name: params.headers[0].name, direction: "ASC" }],
|
|
112
|
-
onSort
|
|
113
|
-
}));
|
|
114
|
-
|
|
115
|
-
expect(dataGridHeader.querySelectorAll("[data-icon]:not(.hidden)")).toHaveLength(3);
|
|
116
|
-
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
117
|
-
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
118
|
-
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("renders headers cells with sorting indicators when initialSort provided with direction DESC", () => {
|
|
122
|
-
const onSort = jest.fn();
|
|
123
|
-
const { dataGridHeader, getAllByRole } = createDataGridHeader(params => ({
|
|
124
|
-
...params,
|
|
125
|
-
initialSort: [{ name: params.headers[1].name, direction: "DESC" }],
|
|
126
|
-
onSort
|
|
127
|
-
}));
|
|
128
|
-
|
|
129
|
-
expect(dataGridHeader.querySelectorAll("[data-icon]:not(.hidden)")).toHaveLength(3);
|
|
130
|
-
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
131
|
-
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
132
|
-
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe("DataGridHeader should be interactive", () => {
|
|
137
|
-
it("clicking on cell call onSort callback", async () => {
|
|
138
|
-
const onSortHandler = jest.fn();
|
|
139
|
-
const { getAllByRole } = createDataGridHeader(params => ({
|
|
140
|
-
...params,
|
|
141
|
-
onSort: onSortHandler
|
|
142
|
-
}));
|
|
143
|
-
|
|
144
|
-
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
145
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
146
|
-
|
|
147
|
-
expect(onSortHandler).toBeCalledWith([
|
|
148
|
-
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
149
|
-
]);
|
|
150
|
-
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
151
|
-
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("clicking on multiple cells call onSort callback with one column selected when single-sorting is enabled", async () => {
|
|
155
|
-
const onSortHandler = jest.fn();
|
|
156
|
-
const { getAllByRole } = createDataGridHeader(params => ({
|
|
157
|
-
...params,
|
|
158
|
-
onSort: onSortHandler
|
|
159
|
-
}));
|
|
160
|
-
|
|
161
|
-
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
162
|
-
|
|
163
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
164
|
-
await userEvent.click(getByRole(lastNameCell, "button"));
|
|
165
|
-
expect(onSortHandler).toBeCalledWith([
|
|
166
|
-
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
167
|
-
]);
|
|
168
|
-
expect(onSortHandler).toBeCalledWith([
|
|
169
|
-
{ name: defaultParams.headers[1].name, direction: "ASC" }
|
|
170
|
-
]);
|
|
171
|
-
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
172
|
-
expect(lastNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
173
|
-
|
|
174
|
-
await userEvent.click(getByRole(lastNameCell, "button"));
|
|
175
|
-
expect(onSortHandler).toBeCalledWith([
|
|
176
|
-
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
177
|
-
]);
|
|
178
|
-
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
179
|
-
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
180
|
-
|
|
181
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
182
|
-
expect(onSortHandler).toBeCalledWith([
|
|
183
|
-
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
184
|
-
]);
|
|
185
|
-
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
186
|
-
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
187
|
-
|
|
188
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
189
|
-
expect(onSortHandler).toBeCalledWith([
|
|
190
|
-
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
191
|
-
]);
|
|
192
|
-
expect(firstNameCell).toHaveAttribute("aria-sort", "descending");
|
|
193
|
-
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
194
|
-
|
|
195
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
196
|
-
expect(onSortHandler).toBeCalledWith([]);
|
|
197
|
-
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
198
|
-
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("clicking on multiple cells call onSort callback with multiple columns selected when multi-sorting is enabled", async () => {
|
|
202
|
-
const onSortHandler = jest.fn();
|
|
203
|
-
const { getAllByRole } = createDataGridHeader(params => ({
|
|
204
|
-
...params,
|
|
205
|
-
enableMultiSorting: true,
|
|
206
|
-
onSort: onSortHandler
|
|
207
|
-
}));
|
|
208
|
-
|
|
209
|
-
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
210
|
-
|
|
211
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
212
|
-
await userEvent.click(getByRole(lastNameCell, "button"));
|
|
213
|
-
expect(onSortHandler).toBeCalledWith([
|
|
214
|
-
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
215
|
-
]);
|
|
216
|
-
expect(onSortHandler).toBeCalledWith([
|
|
217
|
-
{ name: defaultParams.headers[1].name, direction: "ASC" },
|
|
218
|
-
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
219
|
-
]);
|
|
220
|
-
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
221
|
-
expect(lastNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
222
|
-
|
|
223
|
-
await userEvent.click(getByRole(lastNameCell, "button"));
|
|
224
|
-
expect(onSortHandler).toBeCalledWith([
|
|
225
|
-
{ name: defaultParams.headers[1].name, direction: "DESC" },
|
|
226
|
-
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
227
|
-
]);
|
|
228
|
-
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
229
|
-
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
230
|
-
|
|
231
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
232
|
-
expect(onSortHandler).toBeCalledWith([
|
|
233
|
-
{ name: defaultParams.headers[0].name, direction: "DESC" },
|
|
234
|
-
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
235
|
-
]);
|
|
236
|
-
expect(firstNameCell).toHaveAttribute("aria-sort", "descending");
|
|
237
|
-
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
238
|
-
|
|
239
|
-
await userEvent.click(getByRole(firstNameCell, "button"));
|
|
240
|
-
expect(onSortHandler).toBeCalledWith([
|
|
241
|
-
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
242
|
-
]);
|
|
243
|
-
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
244
|
-
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
245
|
-
|
|
246
|
-
await userEvent.click(getByRole(lastNameCell, "button"));
|
|
247
|
-
expect(onSortHandler).toBeCalledWith([]);
|
|
248
|
-
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
249
|
-
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe("ref should work", () => {
|
|
254
|
-
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
255
|
-
const ExampleComponent = ({
|
|
256
|
-
propagateRef
|
|
257
|
-
}: {
|
|
258
|
-
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
259
|
-
}) => {
|
|
260
|
-
const ref = useRef(null);
|
|
261
|
-
|
|
262
|
-
useEffect(() => {
|
|
263
|
-
propagateRef(ref);
|
|
264
|
-
}, [ref]);
|
|
265
|
-
|
|
266
|
-
return <DataGridHeader {...defaultParams} data-ref="testing" ref={ref} />;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
270
|
-
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const container = document.createElement("table");
|
|
274
|
-
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
275
|
-
});
|
|
276
|
-
});
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2022 OneWelcome B.V.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import React, { useEffect, useRef } from "react";
|
|
18
|
-
import { DataGridHeaderCell, Props } from "./DataGridHeaderCell";
|
|
19
|
-
import { render } from "@testing-library/react";
|
|
20
|
-
import userEvent from "@testing-library/user-event";
|
|
21
|
-
|
|
22
|
-
const defaultParams: Props = { name: "name-123", headline: "Test" };
|
|
23
|
-
|
|
24
|
-
const createDataGridHeaderCell = (params?: (defaultParams: Props) => Props) => {
|
|
25
|
-
let parameters: Props = defaultParams;
|
|
26
|
-
if (params) {
|
|
27
|
-
parameters = params(defaultParams);
|
|
28
|
-
}
|
|
29
|
-
const container = document.createElement("tr");
|
|
30
|
-
const queries = render(<DataGridHeaderCell {...parameters} data-testid="dataGridHeaderCell" />, {
|
|
31
|
-
container
|
|
32
|
-
});
|
|
33
|
-
const dataGridHeaderCell = queries.getByTestId("dataGridHeaderCell");
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
...queries,
|
|
37
|
-
dataGridHeaderCell
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
describe("DataGridHeaderCell should render", () => {
|
|
42
|
-
it("renders without crashing", () => {
|
|
43
|
-
const { dataGridHeaderCell, queryByRole } = createDataGridHeaderCell();
|
|
44
|
-
|
|
45
|
-
expect(dataGridHeaderCell).toBeDefined();
|
|
46
|
-
expect(dataGridHeaderCell).toHaveTextContent(defaultParams.headline);
|
|
47
|
-
expect(queryByRole("button")).toBeDefined();
|
|
48
|
-
expect(dataGridHeaderCell.querySelectorAll("[data-icon]")).toHaveLength(2);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("renders without sorting indicators (icons)", () => {
|
|
52
|
-
const { dataGridHeaderCell } = createDataGridHeaderCell(params => ({
|
|
53
|
-
...params,
|
|
54
|
-
disableSorting: true
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
expect(dataGridHeaderCell.querySelector("[data-icon]")).toBeNull();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("renders DESC and ASC sorting indicators (icons) when sorting is enabled and current sorting is not defined", () => {
|
|
61
|
-
const { dataGridHeaderCell } = createDataGridHeaderCell();
|
|
62
|
-
|
|
63
|
-
expect(dataGridHeaderCell).toBeDefined();
|
|
64
|
-
const sortingIcons = dataGridHeaderCell.querySelectorAll("[data-icon]");
|
|
65
|
-
expect(sortingIcons).toHaveLength(2);
|
|
66
|
-
sortingIcons.forEach(icon => {
|
|
67
|
-
expect(icon).toHaveClass("indicator");
|
|
68
|
-
expect(icon).not.toHaveClass("active");
|
|
69
|
-
expect(icon).not.toHaveClass("hidden");
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("renders ASC sorting indicator (icon) when sorting is enabled and current sorting is ASC", () => {
|
|
74
|
-
const { dataGridHeaderCell } = createDataGridHeaderCell(params => ({
|
|
75
|
-
...params,
|
|
76
|
-
activeSortDirection: "ASC"
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
expect(dataGridHeaderCell).toBeDefined();
|
|
80
|
-
const sortingIcons = dataGridHeaderCell.querySelectorAll("[data-icon]");
|
|
81
|
-
expect(sortingIcons).toHaveLength(2);
|
|
82
|
-
sortingIcons.forEach(icon => expect(icon).toHaveClass("indicator"));
|
|
83
|
-
expect(sortingIcons[0]).toHaveClass("indicator", "active", "icon-triangle-up");
|
|
84
|
-
expect(sortingIcons[0]).not.toHaveClass("hidden");
|
|
85
|
-
expect(sortingIcons[1]).toHaveClass("indicator", "hidden", "icon-triangle-down");
|
|
86
|
-
expect(sortingIcons[1]).not.toHaveClass("active");
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("renders DESC sorting indicator (icon) when sorting is enabled and current sorting is DESC", () => {
|
|
91
|
-
const { dataGridHeaderCell } = createDataGridHeaderCell(params => ({
|
|
92
|
-
...params,
|
|
93
|
-
activeSortDirection: "DESC"
|
|
94
|
-
}));
|
|
95
|
-
|
|
96
|
-
expect(dataGridHeaderCell).toBeDefined();
|
|
97
|
-
const sortingIcons = dataGridHeaderCell.querySelectorAll("[data-icon]");
|
|
98
|
-
expect(sortingIcons).toHaveLength(2);
|
|
99
|
-
sortingIcons.forEach(icon => expect(icon).toHaveClass("indicator"));
|
|
100
|
-
expect(sortingIcons[0]).toHaveClass("indicator", "hidden", "icon-triangle-up");
|
|
101
|
-
expect(sortingIcons[0]).not.toHaveClass("active");
|
|
102
|
-
expect(sortingIcons[1]).toHaveClass("indicator", "active", "icon-triangle-down");
|
|
103
|
-
expect(sortingIcons[1]).not.toHaveClass("hidden");
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe("DataGridHeaderCell should be interactive", () => {
|
|
107
|
-
it("clicking on cell calls onSort callback", async () => {
|
|
108
|
-
const onSortHandler = jest.fn();
|
|
109
|
-
const { getByRole } = createDataGridHeaderCell(params => ({
|
|
110
|
-
...params,
|
|
111
|
-
disableSorting: false,
|
|
112
|
-
onSort: onSortHandler
|
|
113
|
-
}));
|
|
114
|
-
|
|
115
|
-
await userEvent.click(getByRole("button"));
|
|
116
|
-
|
|
117
|
-
expect(onSortHandler).toBeCalledWith(defaultParams.name);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe("ref should work", () => {
|
|
122
|
-
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
123
|
-
const ExampleComponent = ({
|
|
124
|
-
propagateRef
|
|
125
|
-
}: {
|
|
126
|
-
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
127
|
-
}) => {
|
|
128
|
-
const ref = useRef(null);
|
|
129
|
-
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
propagateRef(ref);
|
|
132
|
-
}, [ref]);
|
|
133
|
-
|
|
134
|
-
return <DataGridHeaderCell {...defaultParams} data-ref="testing" ref={ref} />;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
138
|
-
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const container = document.createElement("tr");
|
|
142
|
-
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
143
|
-
});
|
|
144
|
-
});
|