@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,437 +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 { DataGrid, Props } from "./DataGrid";
|
|
19
|
-
import { getAllByRole, render, queryAllByRole, getByRole } from "@testing-library/react";
|
|
20
|
-
import { DataGridRow } from "./DataGridBody/DataGridRow";
|
|
21
|
-
import { DataGridCell } from "./DataGridBody/DataGridCell";
|
|
22
|
-
import { ContextMenu } from "../ContextMenu/ContextMenu";
|
|
23
|
-
import { IconButton } from "../Button/IconButton";
|
|
24
|
-
import { Icon, Icons } from "../Icon/Icon";
|
|
25
|
-
import { ContextMenuItem } from "../ContextMenu/ContextMenuItem";
|
|
26
|
-
import userEvent from "@testing-library/user-event";
|
|
27
|
-
|
|
28
|
-
type DataType = { firstName: string; lastName: string; date: string };
|
|
29
|
-
|
|
30
|
-
const defaultParams: Props<DataType> = {
|
|
31
|
-
children: ({ item }) => (
|
|
32
|
-
<DataGridRow key={item.firstName}>
|
|
33
|
-
<DataGridCell>{item.firstName}</DataGridCell>
|
|
34
|
-
<DataGridCell>{item.lastName}</DataGridCell>
|
|
35
|
-
<DataGridCell>{item.date}</DataGridCell>
|
|
36
|
-
<DataGridCell>
|
|
37
|
-
<ContextMenu
|
|
38
|
-
id={`consent_menu_${item.firstName}`}
|
|
39
|
-
trigger={
|
|
40
|
-
<IconButton title={`Actions for ${item.firstName}`} color="default">
|
|
41
|
-
<Icon icon={Icons.EllipsisAlt} />
|
|
42
|
-
</IconButton>
|
|
43
|
-
}
|
|
44
|
-
>
|
|
45
|
-
<ContextMenuItem>Item 1</ContextMenuItem>
|
|
46
|
-
</ContextMenu>
|
|
47
|
-
</DataGridCell>
|
|
48
|
-
</DataGridRow>
|
|
49
|
-
),
|
|
50
|
-
headers: [
|
|
51
|
-
{ name: "firstName", headline: "First name" },
|
|
52
|
-
{ name: "lastName", headline: "Last name" },
|
|
53
|
-
{ name: "date", headline: "Date" }
|
|
54
|
-
],
|
|
55
|
-
enableMultiSorting: true,
|
|
56
|
-
data: [
|
|
57
|
-
{ firstName: "Paweł", lastName: "Napieracz", date: "12.12.1990" },
|
|
58
|
-
{ firstName: "Michał", lastName: "Górski", date: "12.12.1994" },
|
|
59
|
-
{ firstName: "Daniel", lastName: "Velden", date: "12.12.199x" },
|
|
60
|
-
{ firstName: "Jasha", lastName: "Joachimsthal", date: "12.12.198x" }
|
|
61
|
-
]
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const createDataGrid = (params?: (defaultParams: Props<DataType>) => Props<DataType>) => {
|
|
65
|
-
let parameters = defaultParams;
|
|
66
|
-
if (params) {
|
|
67
|
-
parameters = params(defaultParams);
|
|
68
|
-
}
|
|
69
|
-
const queries = render(<DataGrid {...parameters} data-testid="dataGrid" />);
|
|
70
|
-
const dataGrid = queries.getByTestId("dataGrid");
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
...queries,
|
|
74
|
-
dataGrid
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
describe("DataGrid should render", () => {
|
|
79
|
-
it("renders without crashing", () => {
|
|
80
|
-
const rowsCount = defaultParams.data?.length!;
|
|
81
|
-
const colsCount = defaultParams.headers?.length!;
|
|
82
|
-
const contextMenuCellCount = 1;
|
|
83
|
-
const { dataGrid, ...queries } = createDataGrid();
|
|
84
|
-
|
|
85
|
-
expect(dataGrid).toBeDefined();
|
|
86
|
-
|
|
87
|
-
expect(dataGrid.querySelector(".actions")).toBeNull();
|
|
88
|
-
|
|
89
|
-
const [thead, tbody] = queries.getAllByRole("rowgroup");
|
|
90
|
-
|
|
91
|
-
expect(queryAllByRole(thead, "columnheader")).toHaveLength(3);
|
|
92
|
-
expect(queryAllByRole(thead, "cell")).toHaveLength(contextMenuCellCount);
|
|
93
|
-
expect(queryAllByRole(thead, "button")).toHaveLength(0); //sorting should be disabled by default
|
|
94
|
-
|
|
95
|
-
expect(queryAllByRole(tbody, "cell")).toHaveLength(
|
|
96
|
-
rowsCount * (colsCount + contextMenuCellCount)
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("renders actions buttons", () => {
|
|
101
|
-
const { dataGrid } = createDataGrid(params => ({
|
|
102
|
-
...params,
|
|
103
|
-
actions: {
|
|
104
|
-
enableAddBtn: true,
|
|
105
|
-
enableColumnsBtn: true,
|
|
106
|
-
enableSearchBtn: true
|
|
107
|
-
}
|
|
108
|
-
}));
|
|
109
|
-
const [addBtn, desktopColumnsBtn, mobileColumnsBtn, desktopSearchBtn, mobileSearchBtn] =
|
|
110
|
-
getAllByRole(dataGrid.querySelector(".actions")!, "button");
|
|
111
|
-
expect(addBtn).toHaveTextContent("Add item");
|
|
112
|
-
expect(desktopColumnsBtn).toHaveTextContent("Columns");
|
|
113
|
-
expect(mobileColumnsBtn).toHaveTextContent("Show/hide columns");
|
|
114
|
-
expect(desktopSearchBtn).toHaveTextContent("Search");
|
|
115
|
-
expect(mobileSearchBtn).toHaveTextContent("Search");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("renders table with initialized sorting indicators", () => {
|
|
119
|
-
const { getAllByRole } = createDataGrid(params => ({
|
|
120
|
-
...params,
|
|
121
|
-
onSort: jest.fn(),
|
|
122
|
-
initialSort: [
|
|
123
|
-
{ name: defaultParams.headers[0].name, direction: "DESC" },
|
|
124
|
-
{ name: defaultParams.headers[2].name, direction: "ASC" }
|
|
125
|
-
]
|
|
126
|
-
}));
|
|
127
|
-
|
|
128
|
-
const [firstNameHeader, lastNameHeader, dateHeader] = getAllByRole("columnheader");
|
|
129
|
-
expect(firstNameHeader).toHaveAttribute("aria-sort", "descending");
|
|
130
|
-
expect(lastNameHeader).not.toHaveAttribute("aria-sort");
|
|
131
|
-
expect(dateHeader).toHaveAttribute("aria-sort", "ascending");
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("renders table without context menu", () => {
|
|
135
|
-
const rowsCount = defaultParams.data?.length!;
|
|
136
|
-
const colsCount = defaultParams.headers?.length!;
|
|
137
|
-
const { getAllByRole } = createDataGrid(params => ({
|
|
138
|
-
...params,
|
|
139
|
-
disableContextMenuColumn: true,
|
|
140
|
-
children: ({ item }) => (
|
|
141
|
-
<DataGridRow key={item.firstName}>
|
|
142
|
-
<DataGridCell>{item.firstName}</DataGridCell>
|
|
143
|
-
<DataGridCell>{item.lastName}</DataGridCell>
|
|
144
|
-
<DataGridCell>{item.date}</DataGridCell>
|
|
145
|
-
</DataGridRow>
|
|
146
|
-
)
|
|
147
|
-
}));
|
|
148
|
-
|
|
149
|
-
expect(getAllByRole("columnheader")).toHaveLength(3);
|
|
150
|
-
expect(getAllByRole("cell")).toHaveLength(rowsCount * colsCount);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("renders loading state with skeleton loading animation on data cells and empty row on content menu cells", () => {
|
|
154
|
-
const { ...queries } = createDataGrid(params => ({ ...params, isLoading: true }));
|
|
155
|
-
|
|
156
|
-
const [_thead, tbody] = queries.getAllByRole("rowgroup");
|
|
157
|
-
expect(
|
|
158
|
-
getAllByRole(tbody, "cell").find((cell, index) => {
|
|
159
|
-
const contextMenuCell = index % 4 === 3;
|
|
160
|
-
return (
|
|
161
|
-
!contextMenuCell && (cell.firstChild as HTMLElement).getAttribute("class") !== "loading"
|
|
162
|
-
);
|
|
163
|
-
})
|
|
164
|
-
).toBeUndefined();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("renders empty state", () => {
|
|
168
|
-
const emptyLabel = "emptyLabel";
|
|
169
|
-
const { ...queries } = createDataGrid(params => ({ ...params, emptyLabel, data: [] }));
|
|
170
|
-
|
|
171
|
-
const [_thead, tbody] = queries.getAllByRole("rowgroup");
|
|
172
|
-
const rows = getAllByRole(tbody, "row");
|
|
173
|
-
const firstRowCells = getAllByRole(rows[0], "cell");
|
|
174
|
-
expect(firstRowCells).toHaveLength(1);
|
|
175
|
-
expect(firstRowCells[0]).toHaveAttribute("colspan", `${defaultParams.headers.length + 1}`);
|
|
176
|
-
expect(firstRowCells[0]).toHaveTextContent(emptyLabel);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("renders pagination", () => {
|
|
180
|
-
const { getByRole } = createDataGrid(params => ({
|
|
181
|
-
...params,
|
|
182
|
-
paginationProps: {
|
|
183
|
-
totalElements: 105,
|
|
184
|
-
pageSize: 10,
|
|
185
|
-
currentPage: 2,
|
|
186
|
-
onPageChange: jest.fn(),
|
|
187
|
-
onPageSizeChange: jest.fn()
|
|
188
|
-
}
|
|
189
|
-
}));
|
|
190
|
-
|
|
191
|
-
expect(getByRole("button", { name: "previous" })).toBeDefined();
|
|
192
|
-
expect(getByRole("button", { name: "next" })).toBeDefined();
|
|
193
|
-
expect(getByRole("button", { name: "last" })).toBeDefined();
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
describe("DataGrid should have interactive table header", () => {
|
|
198
|
-
it("clicking table headers should call sort callback", async () => {
|
|
199
|
-
const onSort = jest.fn();
|
|
200
|
-
const { getAllByRole } = createDataGrid(params => ({
|
|
201
|
-
...params,
|
|
202
|
-
onSort
|
|
203
|
-
}));
|
|
204
|
-
|
|
205
|
-
const [firstNameHeader, lastNameHeader, dateHeader] = getAllByRole("columnheader");
|
|
206
|
-
|
|
207
|
-
await userEvent.click(getByRole(firstNameHeader, "button"));
|
|
208
|
-
expect(onSort).toBeCalledWith([{ name: defaultParams.headers[0].name, direction: "ASC" }]);
|
|
209
|
-
|
|
210
|
-
await userEvent.click(getByRole(lastNameHeader, "button"));
|
|
211
|
-
await userEvent.click(getByRole(dateHeader, "button"));
|
|
212
|
-
expect(onSort).toBeCalledWith([
|
|
213
|
-
{ name: defaultParams.headers[2].name, direction: "ASC" },
|
|
214
|
-
{ name: defaultParams.headers[1].name, direction: "ASC" },
|
|
215
|
-
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
216
|
-
]);
|
|
217
|
-
|
|
218
|
-
await userEvent.click(getByRole(firstNameHeader, "button"));
|
|
219
|
-
expect(onSort).toBeCalledWith([
|
|
220
|
-
{ name: defaultParams.headers[0].name, direction: "DESC" },
|
|
221
|
-
{ name: defaultParams.headers[2].name, direction: "ASC" },
|
|
222
|
-
{ name: defaultParams.headers[1].name, direction: "ASC" }
|
|
223
|
-
]);
|
|
224
|
-
|
|
225
|
-
await userEvent.click(getByRole(dateHeader, "button"));
|
|
226
|
-
expect(onSort).toBeCalledWith([
|
|
227
|
-
{ name: defaultParams.headers[2].name, direction: "DESC" },
|
|
228
|
-
{ name: defaultParams.headers[0].name, direction: "DESC" },
|
|
229
|
-
{ name: defaultParams.headers[1].name, direction: "ASC" }
|
|
230
|
-
]);
|
|
231
|
-
|
|
232
|
-
await userEvent.click(getByRole(dateHeader, "button"));
|
|
233
|
-
await userEvent.click(getByRole(firstNameHeader, "button"));
|
|
234
|
-
await userEvent.click(getByRole(lastNameHeader, "button"));
|
|
235
|
-
expect(onSort).toBeCalledWith([{ name: defaultParams.headers[1].name, direction: "DESC" }]);
|
|
236
|
-
expect(onSort).toBeCalledTimes(8);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("clicking on show/hide columns popover should show/hide columns", async () => {
|
|
240
|
-
const { getByRole, findByLabelText, ...queries } = createDataGrid(params => ({
|
|
241
|
-
...params,
|
|
242
|
-
actions: { enableColumnsBtn: true }
|
|
243
|
-
}));
|
|
244
|
-
expect(queries.getAllByRole("columnheader")).toHaveLength(3);
|
|
245
|
-
|
|
246
|
-
await userEvent.click(getByRole("button", { name: "Columns" }));
|
|
247
|
-
|
|
248
|
-
const nameToggle = await findByLabelText(defaultParams.headers[1].headline);
|
|
249
|
-
expect(nameToggle).toBeChecked();
|
|
250
|
-
await userEvent.click(nameToggle);
|
|
251
|
-
expect(nameToggle).not.toBeChecked();
|
|
252
|
-
expect(getByRole("button", { name: "Close show columns dialog" })).toBeDefined();
|
|
253
|
-
|
|
254
|
-
const columns = queries.getAllByRole("columnheader");
|
|
255
|
-
expect(columns).toHaveLength(2);
|
|
256
|
-
expect(columns[0]).toHaveTextContent(defaultParams.headers[0].headline);
|
|
257
|
-
expect(columns[1]).toHaveTextContent(defaultParams.headers[2].headline);
|
|
258
|
-
|
|
259
|
-
const rowsCount = defaultParams.data?.length!;
|
|
260
|
-
const colsCount = defaultParams.headers.length;
|
|
261
|
-
const hiddenColsCount = defaultParams.headers.length;
|
|
262
|
-
const contextMenuColsCount = defaultParams.headers.length;
|
|
263
|
-
const [_thead, tbody] = queries.getAllByRole("rowgroup");
|
|
264
|
-
expect(getAllByRole(tbody, "cell")).toHaveLength(
|
|
265
|
-
rowsCount * (colsCount - hiddenColsCount + contextMenuColsCount)
|
|
266
|
-
);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
describe("ref should work", () => {
|
|
271
|
-
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
272
|
-
const ExampleComponent = ({
|
|
273
|
-
propagateRef
|
|
274
|
-
}: {
|
|
275
|
-
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
276
|
-
}) => {
|
|
277
|
-
const ref = useRef(null);
|
|
278
|
-
|
|
279
|
-
useEffect(() => {
|
|
280
|
-
propagateRef(ref);
|
|
281
|
-
}, [ref]);
|
|
282
|
-
|
|
283
|
-
return <DataGrid {...defaultParams} data-ref="testing" ref={ref} />;
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
287
|
-
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
render(<ExampleComponent propagateRef={refCheck} />);
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
describe("spacing should work correctly", () => {
|
|
295
|
-
it("gives the proper paddings to the right elements", () => {
|
|
296
|
-
const { dataGrid } = createDataGrid(defaultParams => ({
|
|
297
|
-
...defaultParams,
|
|
298
|
-
spacing: { padding: 4 },
|
|
299
|
-
paginationProps: {
|
|
300
|
-
totalElements: 105,
|
|
301
|
-
pageSize: 10,
|
|
302
|
-
currentPage: 2,
|
|
303
|
-
onPageChange: jest.fn(),
|
|
304
|
-
onPageSizeChange: jest.fn()
|
|
305
|
-
}
|
|
306
|
-
}));
|
|
307
|
-
|
|
308
|
-
const firstHeaderCell = dataGrid.querySelector(".table .thead .row .header-cell");
|
|
309
|
-
const lastHeaderCell = dataGrid.querySelector(".table .thead .row td");
|
|
310
|
-
const firstBodyCell = dataGrid.querySelector(".table tbody .row .cell");
|
|
311
|
-
const lastBodyCell = dataGrid.querySelector(".table tbody .row td:last-of-type");
|
|
312
|
-
const pagination = dataGrid.querySelector(".pagination-wrapper");
|
|
313
|
-
|
|
314
|
-
expect(dataGrid).toHaveStyle({ "padding-top": "1rem", "padding-bottom": "1rem" });
|
|
315
|
-
expect(firstHeaderCell).toHaveStyle({ "padding-left": "1rem" });
|
|
316
|
-
expect(lastHeaderCell).toHaveStyle({ "padding-right": "1rem" });
|
|
317
|
-
expect(firstBodyCell).toHaveStyle({ "padding-left": "1rem" });
|
|
318
|
-
expect(lastBodyCell).toHaveStyle({ "padding-right": "1rem" });
|
|
319
|
-
expect(pagination).toHaveStyle({ "padding-left": "1rem", "padding-right": "1rem" });
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("gives the proper paddings to the right elements", () => {
|
|
323
|
-
const { dataGrid } = createDataGrid(defaultParams => ({
|
|
324
|
-
...defaultParams,
|
|
325
|
-
spacing: { padding: "4 5" },
|
|
326
|
-
paginationProps: {
|
|
327
|
-
totalElements: 105,
|
|
328
|
-
pageSize: 10,
|
|
329
|
-
currentPage: 2,
|
|
330
|
-
onPageChange: jest.fn(),
|
|
331
|
-
onPageSizeChange: jest.fn()
|
|
332
|
-
}
|
|
333
|
-
}));
|
|
334
|
-
|
|
335
|
-
const firstHeaderCell = dataGrid.querySelector(".table .thead .row .header-cell");
|
|
336
|
-
const lastHeaderCell = dataGrid.querySelector(".table .thead .row td");
|
|
337
|
-
const firstBodyCell = dataGrid.querySelector(".table tbody .row .cell");
|
|
338
|
-
const lastBodyCell = dataGrid.querySelector(".table tbody .row td:last-of-type");
|
|
339
|
-
const pagination = dataGrid.querySelector(".pagination-wrapper");
|
|
340
|
-
|
|
341
|
-
expect(dataGrid).toHaveStyle({ "padding-top": "1rem", "padding-bottom": "1rem" });
|
|
342
|
-
expect(firstHeaderCell).toHaveStyle({ "padding-left": "1.25rem" });
|
|
343
|
-
expect(lastHeaderCell).toHaveStyle({ "padding-right": "1.25rem" });
|
|
344
|
-
expect(firstBodyCell).toHaveStyle({ "padding-left": "1.25rem" });
|
|
345
|
-
expect(lastBodyCell).toHaveStyle({ "padding-right": "1.25rem" });
|
|
346
|
-
expect(pagination).toHaveStyle({ "padding-left": "1.25rem", "padding-right": "1.25rem" });
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it("gives the proper paddings to the right elements", () => {
|
|
350
|
-
const { dataGrid } = createDataGrid(defaultParams => ({
|
|
351
|
-
...defaultParams,
|
|
352
|
-
spacing: { padding: "4 5 8" },
|
|
353
|
-
paginationProps: {
|
|
354
|
-
totalElements: 105,
|
|
355
|
-
pageSize: 10,
|
|
356
|
-
currentPage: 2,
|
|
357
|
-
onPageChange: jest.fn(),
|
|
358
|
-
onPageSizeChange: jest.fn()
|
|
359
|
-
}
|
|
360
|
-
}));
|
|
361
|
-
|
|
362
|
-
const firstHeaderCell = dataGrid.querySelector(".table .thead .row .header-cell");
|
|
363
|
-
const lastHeaderCell = dataGrid.querySelector(".table .thead .row td");
|
|
364
|
-
const firstBodyCell = dataGrid.querySelector(".table tbody .row .cell");
|
|
365
|
-
const lastBodyCell = dataGrid.querySelector(".table tbody .row td:last-of-type");
|
|
366
|
-
const pagination = dataGrid.querySelector(".pagination-wrapper");
|
|
367
|
-
|
|
368
|
-
expect(dataGrid).toHaveStyle({ "padding-top": "1rem", "padding-bottom": "2rem" });
|
|
369
|
-
expect(firstHeaderCell).toHaveStyle({ "padding-left": "1.25rem" });
|
|
370
|
-
expect(lastHeaderCell).toHaveStyle({ "padding-right": "1.25rem" });
|
|
371
|
-
expect(firstBodyCell).toHaveStyle({ "padding-left": "1.25rem" });
|
|
372
|
-
expect(lastBodyCell).toHaveStyle({ "padding-right": "1.25rem" });
|
|
373
|
-
expect(pagination).toHaveStyle({ "padding-left": "1.25rem", "padding-right": "1.25rem" });
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it("gives the proper paddings to the right elements", () => {
|
|
377
|
-
const { dataGrid } = createDataGrid(defaultParams => ({
|
|
378
|
-
...defaultParams,
|
|
379
|
-
spacing: { padding: "6 4 8 8" },
|
|
380
|
-
paginationProps: {
|
|
381
|
-
totalElements: 105,
|
|
382
|
-
pageSize: 10,
|
|
383
|
-
currentPage: 2,
|
|
384
|
-
onPageChange: jest.fn(),
|
|
385
|
-
onPageSizeChange: jest.fn()
|
|
386
|
-
}
|
|
387
|
-
}));
|
|
388
|
-
|
|
389
|
-
const firstHeaderCell = dataGrid.querySelector(".table .thead .row .header-cell");
|
|
390
|
-
const lastHeaderCell = dataGrid.querySelector(".table .thead .row td");
|
|
391
|
-
const firstBodyCell = dataGrid.querySelector(".table tbody .row .cell");
|
|
392
|
-
const lastBodyCell = dataGrid.querySelector(".table tbody .row td:last-of-type");
|
|
393
|
-
const pagination = dataGrid.querySelector(".pagination-wrapper");
|
|
394
|
-
|
|
395
|
-
expect(dataGrid).toHaveStyle({ "padding-top": "1.5rem", "padding-bottom": "2rem" });
|
|
396
|
-
expect(firstHeaderCell).toHaveStyle({ "padding-left": "2rem" });
|
|
397
|
-
expect(lastHeaderCell).toHaveStyle({ "padding-right": "1rem" });
|
|
398
|
-
expect(firstBodyCell).toHaveStyle({ "padding-left": "2rem" });
|
|
399
|
-
expect(lastBodyCell).toHaveStyle({ "padding-right": "1rem" });
|
|
400
|
-
expect(pagination).toHaveStyle({ "padding-left": "2rem", "padding-right": "1rem" });
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it("gives the proper paddings to the right elements, also with contextmenu disabled", () => {
|
|
404
|
-
const { dataGrid } = createDataGrid(defaultParams => ({
|
|
405
|
-
...defaultParams,
|
|
406
|
-
spacing: { padding: "6 4 8 8" },
|
|
407
|
-
disableContextMenuColumn: true,
|
|
408
|
-
paginationProps: {
|
|
409
|
-
totalElements: 105,
|
|
410
|
-
pageSize: 10,
|
|
411
|
-
currentPage: 2,
|
|
412
|
-
onPageChange: jest.fn(),
|
|
413
|
-
onPageSizeChange: jest.fn()
|
|
414
|
-
},
|
|
415
|
-
children: ({ item }) => (
|
|
416
|
-
<DataGridRow key={item.firstName}>
|
|
417
|
-
<DataGridCell>{item.firstName}</DataGridCell>
|
|
418
|
-
<DataGridCell>{item.lastName}</DataGridCell>
|
|
419
|
-
<DataGridCell>{item.date}</DataGridCell>
|
|
420
|
-
</DataGridRow>
|
|
421
|
-
)
|
|
422
|
-
}));
|
|
423
|
-
|
|
424
|
-
const firstHeaderCell = dataGrid.querySelector(".table .thead .row .header-cell");
|
|
425
|
-
const lastHeaderCell = dataGrid.querySelector(".table .thead .row th:last-of-type");
|
|
426
|
-
const firstBodyCell = dataGrid.querySelector(".table tbody .row .cell");
|
|
427
|
-
const lastBodyCell = dataGrid.querySelector(".table tbody .row td:last-of-type");
|
|
428
|
-
const pagination = dataGrid.querySelector(".pagination-wrapper");
|
|
429
|
-
|
|
430
|
-
expect(dataGrid).toHaveStyle({ "padding-top": "1.5rem", "padding-bottom": "2rem" });
|
|
431
|
-
expect(firstHeaderCell).toHaveStyle({ "padding-left": "2rem" });
|
|
432
|
-
expect(lastHeaderCell).toHaveStyle({ "padding-right": "1rem" });
|
|
433
|
-
expect(firstBodyCell).toHaveStyle({ "padding-left": "2rem" });
|
|
434
|
-
expect(lastBodyCell).toHaveStyle({ "padding-right": "1rem" });
|
|
435
|
-
expect(pagination).toHaveStyle({ "padding-left": "2rem", "padding-right": "1rem" });
|
|
436
|
-
});
|
|
437
|
-
});
|
|
@@ -1,204 +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 { DataGridActions, Props } from "./DataGridActions";
|
|
19
|
-
import { render } from "@testing-library/react";
|
|
20
|
-
import userEvent from "@testing-library/user-event";
|
|
21
|
-
|
|
22
|
-
const defaultParams: Props = {
|
|
23
|
-
headers: [],
|
|
24
|
-
onColumnToggled: jest.fn()
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const createDataGridActions = (params?: (defaultParams: Props) => Props) => {
|
|
28
|
-
let parameters: Props = defaultParams;
|
|
29
|
-
if (params) {
|
|
30
|
-
parameters = params(defaultParams);
|
|
31
|
-
}
|
|
32
|
-
const queries = render(<DataGridActions {...parameters} data-testid="dataGridActions" />);
|
|
33
|
-
const dataGridActions = queries.getByTestId("dataGridActions");
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
...queries,
|
|
37
|
-
dataGridActions
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
describe("DataGridActions should render", () => {
|
|
42
|
-
it("renders without crashing", () => {
|
|
43
|
-
const { container } = render(<DataGridActions {...defaultParams} />);
|
|
44
|
-
|
|
45
|
-
expect(container).toBeEmptyDOMElement();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("renders all buttons", () => {
|
|
49
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
50
|
-
...params,
|
|
51
|
-
enableAddBtn: true,
|
|
52
|
-
enableColumnsBtn: true,
|
|
53
|
-
enableSearchBtn: true
|
|
54
|
-
}));
|
|
55
|
-
|
|
56
|
-
expect(dataGridActions).toBeDefined();
|
|
57
|
-
const buttons = getAllByRole("button");
|
|
58
|
-
expect(buttons).toHaveLength(5);
|
|
59
|
-
expect(buttons[0]).toHaveTextContent("Add item");
|
|
60
|
-
expect(buttons[1]).toHaveTextContent("Columns");
|
|
61
|
-
expect(buttons[2]).toHaveTextContent("Show/hide columns");
|
|
62
|
-
expect(buttons[3]).toHaveTextContent("Search");
|
|
63
|
-
expect(buttons[4]).toHaveTextContent("Search");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("renders only add button", () => {
|
|
67
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
68
|
-
...params,
|
|
69
|
-
enableAddBtn: true
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
expect(dataGridActions).toBeDefined();
|
|
73
|
-
const buttons = getAllByRole("button");
|
|
74
|
-
expect(buttons).toHaveLength(1);
|
|
75
|
-
expect(buttons[0]).toHaveTextContent("Add item");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("renders only columns button", () => {
|
|
79
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
80
|
-
...params,
|
|
81
|
-
enableColumnsBtn: true
|
|
82
|
-
}));
|
|
83
|
-
|
|
84
|
-
expect(dataGridActions).toBeDefined();
|
|
85
|
-
const buttons = getAllByRole("button");
|
|
86
|
-
expect(buttons).toHaveLength(2);
|
|
87
|
-
expect(buttons[0]).toHaveTextContent("Columns");
|
|
88
|
-
expect(buttons[1]).toHaveTextContent("Show/hide columns");
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("renders only search button", () => {
|
|
92
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
93
|
-
...params,
|
|
94
|
-
enableAddBtn: false,
|
|
95
|
-
enableColumnsBtn: false,
|
|
96
|
-
enableSearchBtn: true
|
|
97
|
-
}));
|
|
98
|
-
|
|
99
|
-
expect(dataGridActions).toBeDefined();
|
|
100
|
-
const buttons = getAllByRole("button");
|
|
101
|
-
expect(buttons).toHaveLength(2);
|
|
102
|
-
expect(buttons[0]).toHaveTextContent("Search");
|
|
103
|
-
expect(buttons[1]).toHaveTextContent("Search");
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("renders buttons with overwritten props", () => {
|
|
107
|
-
const addBtnProps = { children: "button1", title: "title1" };
|
|
108
|
-
const columnsBtnProps = { children: "button2", title: "title2" };
|
|
109
|
-
const searchBtnProps = { children: "button3", title: "title3" };
|
|
110
|
-
const searchIconBtnProps = { title: "title4" };
|
|
111
|
-
const { dataGridActions, getAllByRole } = createDataGridActions(params => ({
|
|
112
|
-
...params,
|
|
113
|
-
enableAddBtn: true,
|
|
114
|
-
enableColumnsBtn: true,
|
|
115
|
-
enableSearchBtn: true,
|
|
116
|
-
addBtnProps,
|
|
117
|
-
columnsBtnProps,
|
|
118
|
-
searchBtnProps,
|
|
119
|
-
searchIconBtnProps
|
|
120
|
-
}));
|
|
121
|
-
|
|
122
|
-
expect(dataGridActions).toBeDefined();
|
|
123
|
-
const [addBtn, desktopColumnsBtn, mobileColumnsBtn, desktopSearchBtn, mobileSearchBtn] =
|
|
124
|
-
getAllByRole("button");
|
|
125
|
-
expect(addBtn).toHaveTextContent(addBtnProps.children);
|
|
126
|
-
expect(addBtn).toHaveAttribute("title", addBtnProps.title);
|
|
127
|
-
expect(desktopColumnsBtn).toHaveTextContent(columnsBtnProps.children);
|
|
128
|
-
expect(desktopColumnsBtn).toHaveAttribute("title", columnsBtnProps.title);
|
|
129
|
-
expect(mobileColumnsBtn).toHaveTextContent(columnsBtnProps.title);
|
|
130
|
-
expect(desktopSearchBtn).toHaveTextContent(searchBtnProps.children);
|
|
131
|
-
expect(desktopSearchBtn).toHaveAttribute("title", searchBtnProps.title);
|
|
132
|
-
expect(mobileSearchBtn).toHaveTextContent(searchIconBtnProps.title);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe("DataGridActions should be interactive", () => {
|
|
137
|
-
it("clicking on columns button opens show/hide columns popover", async () => {
|
|
138
|
-
const toggleHeader = { name: "test", headline: "Label" };
|
|
139
|
-
const { getAllByRole, findByLabelText } = createDataGridActions(params => ({
|
|
140
|
-
...params,
|
|
141
|
-
enableColumnsBtn: true,
|
|
142
|
-
headers: [toggleHeader]
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
await userEvent.click(getAllByRole("button")[0]);
|
|
146
|
-
|
|
147
|
-
const toggle = await findByLabelText(toggleHeader.headline);
|
|
148
|
-
expect(toggle).toBeDefined();
|
|
149
|
-
expect(toggle).toBeChecked();
|
|
150
|
-
|
|
151
|
-
await userEvent.click(toggle);
|
|
152
|
-
expect(defaultParams.onColumnToggled).toBeCalledWith(toggleHeader.name);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("clicking on add button runs callback", async () => {
|
|
156
|
-
const onClick = jest.fn();
|
|
157
|
-
const { getAllByRole } = createDataGridActions(params => ({
|
|
158
|
-
...params,
|
|
159
|
-
enableAddBtn: true,
|
|
160
|
-
addBtnProps: { onClick }
|
|
161
|
-
}));
|
|
162
|
-
|
|
163
|
-
await userEvent.click(getAllByRole("button")[0]);
|
|
164
|
-
|
|
165
|
-
expect(onClick).toBeCalledTimes(1);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("clicking on search button runs callback", async () => {
|
|
169
|
-
const onClick = jest.fn();
|
|
170
|
-
const { getAllByRole } = createDataGridActions(params => ({
|
|
171
|
-
...params,
|
|
172
|
-
enableSearchBtn: true,
|
|
173
|
-
searchBtnProps: { onClick }
|
|
174
|
-
}));
|
|
175
|
-
|
|
176
|
-
await userEvent.click(getAllByRole("button")[0]);
|
|
177
|
-
|
|
178
|
-
expect(onClick).toBeCalledTimes(1);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe("ref should work", () => {
|
|
183
|
-
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
184
|
-
const ExampleComponent = ({
|
|
185
|
-
propagateRef
|
|
186
|
-
}: {
|
|
187
|
-
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
188
|
-
}) => {
|
|
189
|
-
const ref = useRef(null);
|
|
190
|
-
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
propagateRef(ref);
|
|
193
|
-
}, [ref]);
|
|
194
|
-
|
|
195
|
-
return <DataGridActions {...defaultParams} data-ref="testing" enableAddBtn ref={ref} />;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
199
|
-
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
render(<ExampleComponent propagateRef={refCheck} />);
|
|
203
|
-
});
|
|
204
|
-
});
|