@onewelcome/react-lib-components 0.2.0 → 0.2.3
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/Breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/Button/BaseButton.d.ts +4 -4
- package/dist/Button/Button.d.ts +3 -3
- package/dist/Button/IconButton.d.ts +4 -4
- package/dist/ContextMenu/ContextMenu.d.ts +5 -5
- package/dist/ContextMenu/ContextMenuItem.d.ts +2 -2
- package/dist/DataGrid/DataGrid.d.ts +6 -6
- package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +4 -4
- package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +2 -2
- package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +3 -3
- package/dist/DataGrid/datagrid.interfaces.d.ts +1 -1
- package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
- package/dist/Form/Fieldset/Fieldset.d.ts +3 -3
- package/dist/Form/Form.d.ts +1 -1
- package/dist/Form/FormControl/FormControl.d.ts +3 -3
- package/dist/Form/FormGroup/FormGroup.d.ts +5 -5
- package/dist/Form/FormHelperText/FormHelperText.d.ts +3 -3
- package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +6 -6
- package/dist/Form/Input/Input.d.ts +5 -5
- package/dist/Form/Label/Label.d.ts +2 -2
- package/dist/Form/Radio/Radio.d.ts +5 -5
- package/dist/Form/Select/Option.d.ts +2 -2
- package/dist/Form/Select/Select.d.ts +5 -5
- package/dist/Form/Textarea/Textarea.d.ts +6 -6
- package/dist/Form/Toggle/Toggle.d.ts +3 -3
- package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +6 -6
- package/dist/Form/form.interfaces.d.ts +1 -1
- package/dist/Icon/Icon.d.ts +3 -3
- package/dist/Link/Link.d.ts +7 -7
- package/dist/Notifications/BaseModal/BaseModal.d.ts +4 -4
- package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +2 -2
- package/dist/Notifications/Dialog/Dialog.d.ts +5 -5
- package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +3 -3
- package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +2 -2
- package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +3 -3
- package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +7 -7
- package/dist/Notifications/Modal/Modal.d.ts +1 -1
- package/dist/Notifications/Modal/ModalActions/ModalActions.d.ts +1 -1
- package/dist/Notifications/Modal/ModalContent/ModalContent.d.ts +1 -1
- package/dist/Notifications/Modal/ModalHeader/ModalHeader.d.ts +1 -1
- package/dist/Notifications/SlideInModal/SlideInModal.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarItem/SnackbarItem.d.ts +2 -2
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +2 -2
- package/dist/Notifications/Snackbar/interfaces.d.ts +2 -2
- package/dist/Pagination/Pagination.d.ts +3 -3
- package/dist/Popover/Popover.d.ts +3 -3
- package/dist/Skeleton/Skeleton.d.ts +3 -3
- package/dist/StatusIndicator/StatusIndicator.d.ts +5 -5
- package/dist/Tabs/Tab.d.ts +1 -1
- package/dist/Tabs/TabButton.d.ts +2 -2
- package/dist/Tabs/TabPanel.d.ts +2 -2
- package/dist/Tabs/Tabs.d.ts +4 -4
- package/dist/TextEllipsis/TextEllipsis.d.ts +2 -2
- package/dist/Tiles/Tile.d.ts +5 -5
- package/dist/Tiles/Tiles.d.ts +2 -2
- package/dist/Tooltip/Tooltip.d.ts +3 -3
- package/dist/Typography/Typography.d.ts +3 -3
- package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +2 -2
- package/dist/Wizard/Wizard.d.ts +3 -3
- package/dist/Wizard/WizardActions/WizardActions.d.ts +2 -2
- package/dist/Wizard/WizardStateProvider.d.ts +2 -2
- package/dist/Wizard/WizardSteps/WizardSteps.d.ts +2 -2
- package/dist/Wizard/wizardStateReducer.d.ts +5 -5
- package/dist/_BaseStyling_/BaseStyling.d.ts +1 -1
- package/dist/hooks/usePosition.d.ts +4 -4
- package/dist/hooks/useRepeater.d.ts +1 -1
- package/dist/hooks/useScroll.d.ts +1 -1
- package/dist/hooks/useSpacing.d.ts +1 -1
- package/dist/hooks/useWrapper.d.ts +1 -1
- package/dist/index.d.ts +55 -55
- package/dist/react-lib-components.cjs.development.js +676 -578
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +676 -578
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +27 -16
- package/src/Breadcrumbs/Breadcrumbs.test.tsx +15 -15
- package/src/Breadcrumbs/Breadcrumbs.tsx +11 -11
- package/src/Button/BaseButton.module.scss +1 -1
- package/src/Button/BaseButton.test.tsx +27 -27
- package/src/Button/BaseButton.tsx +8 -8
- package/src/Button/Button.module.scss +5 -5
- package/src/Button/Button.test.tsx +39 -39
- package/src/Button/Button.tsx +10 -10
- package/src/Button/IconButton.module.scss +5 -5
- package/src/Button/IconButton.test.tsx +29 -29
- package/src/Button/IconButton.tsx +11 -11
- package/src/ContextMenu/ContextMenu.test.tsx +97 -76
- package/src/ContextMenu/ContextMenu.tsx +48 -42
- package/src/ContextMenu/ContextMenuItem.module.scss +1 -1
- package/src/ContextMenu/ContextMenuItem.tsx +7 -5
- package/src/DataGrid/DataGrid.test.tsx +193 -193
- package/src/DataGrid/DataGrid.tsx +26 -26
- package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +63 -63
- package/src/DataGrid/DataGridActions/DataGridActions.tsx +15 -15
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +1 -1
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +21 -21
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +20 -20
- package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +40 -40
- package/src/DataGrid/DataGridBody/DataGridBody.tsx +10 -10
- package/src/DataGrid/DataGridBody/DataGridCell.module.scss +1 -1
- package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +25 -25
- package/src/DataGrid/DataGridBody/DataGridCell.tsx +6 -6
- package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +38 -38
- package/src/DataGrid/DataGridBody/DataGridRow.tsx +8 -8
- package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +1 -2
- package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +119 -119
- package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +13 -13
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +2 -0
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +51 -51
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +14 -14
- package/src/DataGrid/datagrid.interfaces.ts +1 -1
- package/src/Form/Checkbox/Checkbox.test.tsx +74 -74
- package/src/Form/Checkbox/Checkbox.tsx +27 -27
- package/src/Form/Fieldset/Fieldset.module.scss +1 -1
- package/src/Form/Fieldset/Fieldset.test.tsx +35 -35
- package/src/Form/Fieldset/Fieldset.tsx +27 -27
- package/src/Form/Form.test.tsx +18 -18
- package/src/Form/Form.tsx +3 -3
- package/src/Form/FormControl/FormControl.test.tsx +22 -22
- package/src/Form/FormControl/FormControl.tsx +10 -10
- package/src/Form/FormGroup/FormGroup.test.tsx +37 -37
- package/src/Form/FormGroup/FormGroup.tsx +16 -16
- package/src/Form/FormHelperText/FormHelperText.test.tsx +18 -18
- package/src/Form/FormHelperText/FormHelperText.tsx +7 -7
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +15 -15
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +14 -14
- package/src/Form/Input/Input.module.scss +20 -44
- package/src/Form/Input/Input.test.tsx +121 -73
- package/src/Form/Input/Input.tsx +96 -35
- package/src/Form/Label/Label.test.tsx +13 -13
- package/src/Form/Label/Label.tsx +6 -6
- package/src/Form/Radio/Radio.test.tsx +35 -35
- package/src/Form/Radio/Radio.tsx +17 -17
- package/src/Form/Select/Option.test.tsx +10 -10
- package/src/Form/Select/Option.tsx +8 -8
- package/src/Form/Select/Select.module.scss +7 -9
- package/src/Form/Select/Select.test.tsx +144 -141
- package/src/Form/Select/Select.tsx +79 -78
- package/src/Form/Textarea/Textarea.module.scss +8 -18
- package/src/Form/Textarea/Textarea.test.tsx +27 -27
- package/src/Form/Textarea/Textarea.tsx +33 -13
- package/src/Form/Toggle/Toggle.module.scss +1 -1
- package/src/Form/Toggle/Toggle.test.tsx +22 -22
- package/src/Form/Toggle/Toggle.tsx +10 -10
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +39 -39
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +12 -12
- package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +2 -8
- package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +30 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +35 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +12 -12
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +12 -12
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +2 -11
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +50 -50
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +22 -22
- package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +2 -2
- package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +11 -11
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +17 -17
- package/src/Form/form.interfaces.ts +1 -1
- package/src/Icon/Icon.module.scss +71 -71
- package/src/Icon/Icon.test.tsx +18 -18
- package/src/Icon/Icon.tsx +70 -70
- package/src/Link/Link.module.scss +5 -5
- package/src/Link/Link.test.tsx +76 -76
- package/src/Link/Link.tsx +27 -27
- package/src/Link/types.d.ts +1 -1
- package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
- package/src/Notifications/BaseModal/BaseModal.test.tsx +53 -53
- package/src/Notifications/BaseModal/BaseModal.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +13 -13
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +19 -19
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +10 -10
- package/src/Notifications/Dialog/Dialog.test.tsx +35 -35
- package/src/Notifications/Dialog/Dialog.tsx +19 -19
- package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +14 -14
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +6 -6
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +12 -12
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +6 -6
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +20 -20
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +7 -7
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +36 -36
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +8 -8
- package/src/Notifications/Modal/Modal.test.tsx +6 -6
- package/src/Notifications/Modal/Modal.tsx +1 -1
- package/src/Notifications/Modal/ModalActions/ModalActions.tsx +2 -2
- package/src/Notifications/Modal/ModalContent/ModalContent.tsx +2 -2
- package/src/Notifications/Modal/ModalHeader/ModalHeader.tsx +2 -2
- package/src/Notifications/SlideInModal/SlideInModal.test.tsx +16 -16
- package/src/Notifications/SlideInModal/SlideInModal.tsx +16 -11
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +16 -16
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.tsx +6 -6
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +2 -2
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +17 -17
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +23 -23
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +32 -32
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +18 -18
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +3 -3
- package/src/Notifications/Snackbar/interfaces.ts +2 -2
- package/src/Notifications/Snackbar/useSnackbar.ts +2 -2
- package/src/Pagination/Pagination.module.scss +2 -0
- package/src/Pagination/Pagination.test.tsx +47 -47
- package/src/Pagination/Pagination.tsx +35 -35
- package/src/Popover/Popover.test.tsx +19 -19
- package/src/Popover/Popover.tsx +7 -7
- package/src/Skeleton/Skeleton.module.scss +2 -2
- package/src/Skeleton/Skeleton.test.tsx +29 -29
- package/src/Skeleton/Skeleton.tsx +10 -10
- package/src/StatusIndicator/StatusIndicator.test.tsx +38 -38
- package/src/StatusIndicator/StatusIndicator.tsx +9 -9
- package/src/Tabs/Tab.test.tsx +13 -13
- package/src/Tabs/Tab.tsx +1 -1
- package/src/Tabs/TabButton.test.tsx +28 -28
- package/src/Tabs/TabButton.tsx +7 -7
- package/src/Tabs/TabPanel.test.tsx +30 -30
- package/src/Tabs/TabPanel.tsx +4 -4
- package/src/Tabs/Tabs.test.tsx +93 -93
- package/src/Tabs/Tabs.tsx +25 -25
- package/src/TextEllipsis/TextEllipsis.test.tsx +22 -22
- package/src/TextEllipsis/TextEllipsis.tsx +6 -6
- package/src/Tiles/Tile.module.scss +1 -1
- package/src/Tiles/Tile.test.tsx +42 -42
- package/src/Tiles/Tile.tsx +22 -22
- package/src/Tiles/Tiles.test.tsx +30 -30
- package/src/Tiles/Tiles.tsx +9 -9
- package/src/Tooltip/Tooltip.test.tsx +35 -35
- package/src/Tooltip/Tooltip.tsx +21 -21
- package/src/Typography/Typography.module.scss +1 -1
- package/src/Typography/Typography.test.tsx +49 -49
- package/src/Typography/Typography.tsx +42 -42
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.module.scss +1 -1
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +26 -26
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +24 -24
- package/src/Wizard/Wizard.test.tsx +56 -56
- package/src/Wizard/Wizard.tsx +6 -6
- package/src/Wizard/WizardActions/WizardActions.test.tsx +34 -34
- package/src/Wizard/WizardActions/WizardActions.tsx +14 -14
- package/src/Wizard/WizardStateProvider.tsx +3 -3
- package/src/Wizard/WizardSteps/WizardSteps.test.tsx +27 -27
- package/src/Wizard/WizardSteps/WizardSteps.tsx +7 -7
- package/src/Wizard/wizardStateReducer.ts +9 -9
- package/src/_BaseStyling_/BaseStyling.test.tsx +14 -14
- package/src/_BaseStyling_/BaseStyling.tsx +50 -50
- package/src/hooks/useAnimation.test.tsx +12 -12
- package/src/hooks/useAnimation.ts +4 -4
- package/src/hooks/useBodyClick.test.tsx +8 -8
- package/src/hooks/useBodyClick.ts +3 -3
- package/src/hooks/useFormSelector.test.ts +17 -17
- package/src/hooks/useFormSelector.ts +4 -4
- package/src/hooks/usePosition.test.tsx +215 -215
- package/src/hooks/usePosition.ts +68 -68
- package/src/hooks/useRepeater.test.tsx +26 -26
- package/src/hooks/useRepeater.ts +5 -5
- package/src/hooks/useScroll.test.tsx +5 -5
- package/src/hooks/useScroll.ts +3 -3
- package/src/hooks/useSpacing.test.ts +40 -40
- package/src/hooks/useSpacing.ts +3 -3
- package/src/hooks/useWrapper.test.ts +12 -12
- package/src/hooks/useWrapper.ts +14 -7
- package/src/index.ts +67 -67
- package/src/mixins.module.scss +76 -27
- package/src/types.d.ts +1 -1
- package/src/util/helper.test.tsx +25 -25
- package/src/util/helper.tsx +64 -64
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { DataGridHeader, Props } from
|
|
3
|
-
import { getByRole, render } from
|
|
4
|
-
import userEvent from
|
|
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
5
|
|
|
6
6
|
const defaultParams: Props = {
|
|
7
7
|
headers: [
|
|
8
|
-
{ name:
|
|
9
|
-
{ name:
|
|
10
|
-
]
|
|
8
|
+
{ name: "firstName", headline: "First name" },
|
|
9
|
+
{ name: "lastName", headline: "Last name" }
|
|
10
|
+
]
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const createDataGridHeader = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -15,224 +15,224 @@ const createDataGridHeader = (params?: (defaultParams: Props) => Props) => {
|
|
|
15
15
|
if (params) {
|
|
16
16
|
parameters = params(defaultParams);
|
|
17
17
|
}
|
|
18
|
-
const container = document.createElement(
|
|
18
|
+
const container = document.createElement("table");
|
|
19
19
|
const queries = render(<DataGridHeader {...parameters} data-testid="dataGridHeader" />, {
|
|
20
|
-
container
|
|
20
|
+
container
|
|
21
21
|
});
|
|
22
|
-
const dataGridHeader = queries.getByTestId(
|
|
22
|
+
const dataGridHeader = queries.getByTestId("dataGridHeader");
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
...queries,
|
|
26
|
-
dataGridHeader
|
|
26
|
+
dataGridHeader
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
describe(
|
|
31
|
-
it(
|
|
30
|
+
describe("DataGridHeader should render", () => {
|
|
31
|
+
it("renders without crashing", () => {
|
|
32
32
|
const { dataGridHeader, getAllByRole, getByRole } = createDataGridHeader();
|
|
33
33
|
|
|
34
34
|
expect(dataGridHeader).toBeDefined();
|
|
35
|
-
expect(getAllByRole(
|
|
36
|
-
expect(getByRole(
|
|
35
|
+
expect(getAllByRole("columnheader")).toHaveLength(2);
|
|
36
|
+
expect(getByRole("cell")).toBeDefined(); //context-menu empty cell
|
|
37
37
|
|
|
38
|
-
expect(dataGridHeader.querySelectorAll(
|
|
38
|
+
expect(dataGridHeader.querySelectorAll("[data-icon]")).toHaveLength(0);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
it(
|
|
42
|
-
const { dataGridHeader, getByRole } = createDataGridHeader(
|
|
41
|
+
it("renders without hidden cell", () => {
|
|
42
|
+
const { dataGridHeader, getByRole } = createDataGridHeader(params => ({
|
|
43
43
|
...params,
|
|
44
|
-
headers: [...params.headers].map((header, idx) => ({ ...header, hidden: idx === 1 }))
|
|
44
|
+
headers: [...params.headers].map((header, idx) => ({ ...header, hidden: idx === 1 }))
|
|
45
45
|
}));
|
|
46
46
|
|
|
47
47
|
expect(dataGridHeader).toBeDefined();
|
|
48
|
-
expect(getByRole(
|
|
49
|
-
expect(getByRole(
|
|
48
|
+
expect(getByRole("columnheader")).toHaveTextContent(defaultParams.headers[0].headline);
|
|
49
|
+
expect(getByRole("cell")).toBeDefined(); //context-menu empty cell
|
|
50
50
|
|
|
51
|
-
expect(dataGridHeader.querySelectorAll(
|
|
51
|
+
expect(dataGridHeader.querySelectorAll("[data-icon]")).toHaveLength(0);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it(
|
|
55
|
-
const { dataGridHeader, getAllByRole, queryByRole } = createDataGridHeader(
|
|
54
|
+
it("renders without contenxt-menu empty cell", () => {
|
|
55
|
+
const { dataGridHeader, getAllByRole, queryByRole } = createDataGridHeader(params => ({
|
|
56
56
|
...params,
|
|
57
|
-
disableContextMenuColumn: true
|
|
57
|
+
disableContextMenuColumn: true
|
|
58
58
|
}));
|
|
59
59
|
|
|
60
60
|
expect(dataGridHeader).toBeDefined();
|
|
61
|
-
expect(getAllByRole(
|
|
62
|
-
expect(queryByRole(
|
|
61
|
+
expect(getAllByRole("columnheader")).toHaveLength(2);
|
|
62
|
+
expect(queryByRole("cell")).toBeNull(); //context-menu empty cell
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
it(
|
|
66
|
-
const { dataGridHeader } = createDataGridHeader(
|
|
65
|
+
it("renders headers cells without sorting indicators even when initialSort is provided", () => {
|
|
66
|
+
const { dataGridHeader } = createDataGridHeader(params => ({
|
|
67
67
|
...params,
|
|
68
|
-
initialSort: [{ name: params.headers[0].name, direction:
|
|
68
|
+
initialSort: [{ name: params.headers[0].name, direction: "ASC" }]
|
|
69
69
|
}));
|
|
70
70
|
|
|
71
|
-
expect(dataGridHeader.querySelectorAll(
|
|
71
|
+
expect(dataGridHeader.querySelectorAll("[data-icon]")).toHaveLength(0);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
it(
|
|
74
|
+
it("renders headers cells with sorting indicators", () => {
|
|
75
75
|
const onSort = jest.fn();
|
|
76
|
-
const { dataGridHeader } = createDataGridHeader(
|
|
76
|
+
const { dataGridHeader } = createDataGridHeader(params => ({
|
|
77
77
|
...params,
|
|
78
|
-
onSort
|
|
78
|
+
onSort
|
|
79
79
|
}));
|
|
80
80
|
|
|
81
|
-
const sortingIcons = dataGridHeader.querySelectorAll(
|
|
81
|
+
const sortingIcons = dataGridHeader.querySelectorAll("[data-icon]");
|
|
82
82
|
expect(sortingIcons).toHaveLength(4);
|
|
83
|
-
sortingIcons.forEach(
|
|
83
|
+
sortingIcons.forEach(icon => expect(icon).not.toHaveClass("hidden"));
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
it(
|
|
86
|
+
it("renders headers cells with sorting indicators when initialSort provided with direction ASC", () => {
|
|
87
87
|
const onSort = jest.fn();
|
|
88
|
-
const { dataGridHeader, getAllByRole } = createDataGridHeader(
|
|
88
|
+
const { dataGridHeader, getAllByRole } = createDataGridHeader(params => ({
|
|
89
89
|
...params,
|
|
90
|
-
initialSort: [{ name: params.headers[0].name, direction:
|
|
91
|
-
onSort
|
|
90
|
+
initialSort: [{ name: params.headers[0].name, direction: "ASC" }],
|
|
91
|
+
onSort
|
|
92
92
|
}));
|
|
93
93
|
|
|
94
|
-
expect(dataGridHeader.querySelectorAll(
|
|
95
|
-
const [firstNameCell, lastNameCell] = getAllByRole(
|
|
96
|
-
expect(firstNameCell).toHaveAttribute(
|
|
97
|
-
expect(lastNameCell).not.toHaveAttribute(
|
|
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
98
|
});
|
|
99
99
|
|
|
100
|
-
it(
|
|
100
|
+
it("renders headers cells with sorting indicators when initialSort provided with direction DESC", () => {
|
|
101
101
|
const onSort = jest.fn();
|
|
102
|
-
const { dataGridHeader, getAllByRole } = createDataGridHeader(
|
|
102
|
+
const { dataGridHeader, getAllByRole } = createDataGridHeader(params => ({
|
|
103
103
|
...params,
|
|
104
|
-
initialSort: [{ name: params.headers[1].name, direction:
|
|
105
|
-
onSort
|
|
104
|
+
initialSort: [{ name: params.headers[1].name, direction: "DESC" }],
|
|
105
|
+
onSort
|
|
106
106
|
}));
|
|
107
107
|
|
|
108
|
-
expect(dataGridHeader.querySelectorAll(
|
|
109
|
-
const [firstNameCell, lastNameCell] = getAllByRole(
|
|
110
|
-
expect(firstNameCell).not.toHaveAttribute(
|
|
111
|
-
expect(lastNameCell).toHaveAttribute(
|
|
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
112
|
});
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
describe(
|
|
116
|
-
it(
|
|
115
|
+
describe("DataGridHeader should be interactive", () => {
|
|
116
|
+
it("clicking on cell call onSort callback", () => {
|
|
117
117
|
const onSortHandler = jest.fn();
|
|
118
|
-
const { getAllByRole } = createDataGridHeader(
|
|
118
|
+
const { getAllByRole } = createDataGridHeader(params => ({
|
|
119
119
|
...params,
|
|
120
|
-
onSort: onSortHandler
|
|
120
|
+
onSort: onSortHandler
|
|
121
121
|
}));
|
|
122
122
|
|
|
123
|
-
const [firstNameCell, lastNameCell] = getAllByRole(
|
|
124
|
-
userEvent.click(getByRole(firstNameCell,
|
|
123
|
+
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
124
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
125
125
|
|
|
126
126
|
expect(onSortHandler).toBeCalledWith([
|
|
127
|
-
{ name: defaultParams.headers[0].name, direction:
|
|
127
|
+
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
128
128
|
]);
|
|
129
|
-
expect(firstNameCell).toHaveAttribute(
|
|
130
|
-
expect(lastNameCell).not.toHaveAttribute(
|
|
129
|
+
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
130
|
+
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
it(
|
|
133
|
+
it("clicking on multiple cells call onSort callback with one column selected when single-sorting is enabled", () => {
|
|
134
134
|
const onSortHandler = jest.fn();
|
|
135
|
-
const { getAllByRole } = createDataGridHeader(
|
|
135
|
+
const { getAllByRole } = createDataGridHeader(params => ({
|
|
136
136
|
...params,
|
|
137
|
-
onSort: onSortHandler
|
|
137
|
+
onSort: onSortHandler
|
|
138
138
|
}));
|
|
139
139
|
|
|
140
|
-
const [firstNameCell, lastNameCell] = getAllByRole(
|
|
140
|
+
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
141
141
|
|
|
142
|
-
userEvent.click(getByRole(firstNameCell,
|
|
143
|
-
userEvent.click(getByRole(lastNameCell,
|
|
142
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
143
|
+
userEvent.click(getByRole(lastNameCell, "button"));
|
|
144
144
|
expect(onSortHandler).toBeCalledWith([
|
|
145
|
-
{ name: defaultParams.headers[0].name, direction:
|
|
145
|
+
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
146
146
|
]);
|
|
147
147
|
expect(onSortHandler).toBeCalledWith([
|
|
148
|
-
{ name: defaultParams.headers[1].name, direction:
|
|
148
|
+
{ name: defaultParams.headers[1].name, direction: "ASC" }
|
|
149
149
|
]);
|
|
150
|
-
expect(firstNameCell).not.toHaveAttribute(
|
|
151
|
-
expect(lastNameCell).toHaveAttribute(
|
|
150
|
+
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
151
|
+
expect(lastNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
152
152
|
|
|
153
|
-
userEvent.click(getByRole(lastNameCell,
|
|
153
|
+
userEvent.click(getByRole(lastNameCell, "button"));
|
|
154
154
|
expect(onSortHandler).toBeCalledWith([
|
|
155
|
-
{ name: defaultParams.headers[1].name, direction:
|
|
155
|
+
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
156
156
|
]);
|
|
157
|
-
expect(firstNameCell).not.toHaveAttribute(
|
|
158
|
-
expect(lastNameCell).toHaveAttribute(
|
|
157
|
+
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
158
|
+
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
159
159
|
|
|
160
|
-
userEvent.click(getByRole(firstNameCell,
|
|
160
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
161
161
|
expect(onSortHandler).toBeCalledWith([
|
|
162
|
-
{ name: defaultParams.headers[0].name, direction:
|
|
162
|
+
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
163
163
|
]);
|
|
164
|
-
expect(firstNameCell).toHaveAttribute(
|
|
165
|
-
expect(lastNameCell).not.toHaveAttribute(
|
|
164
|
+
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
165
|
+
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
166
166
|
|
|
167
|
-
userEvent.click(getByRole(firstNameCell,
|
|
167
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
168
168
|
expect(onSortHandler).toBeCalledWith([
|
|
169
|
-
{ name: defaultParams.headers[1].name, direction:
|
|
169
|
+
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
170
170
|
]);
|
|
171
|
-
expect(firstNameCell).toHaveAttribute(
|
|
172
|
-
expect(lastNameCell).not.toHaveAttribute(
|
|
171
|
+
expect(firstNameCell).toHaveAttribute("aria-sort", "descending");
|
|
172
|
+
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
173
173
|
|
|
174
|
-
userEvent.click(getByRole(firstNameCell,
|
|
174
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
175
175
|
expect(onSortHandler).toBeCalledWith([]);
|
|
176
|
-
expect(firstNameCell).not.toHaveAttribute(
|
|
177
|
-
expect(lastNameCell).not.toHaveAttribute(
|
|
176
|
+
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
177
|
+
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
-
it(
|
|
180
|
+
it("clicking on multiple cells call onSort callback with multiple columns selected when multi-sorting is enabled", () => {
|
|
181
181
|
const onSortHandler = jest.fn();
|
|
182
|
-
const { getAllByRole } = createDataGridHeader(
|
|
182
|
+
const { getAllByRole } = createDataGridHeader(params => ({
|
|
183
183
|
...params,
|
|
184
184
|
enableMultiSorting: true,
|
|
185
|
-
onSort: onSortHandler
|
|
185
|
+
onSort: onSortHandler
|
|
186
186
|
}));
|
|
187
187
|
|
|
188
|
-
const [firstNameCell, lastNameCell] = getAllByRole(
|
|
188
|
+
const [firstNameCell, lastNameCell] = getAllByRole("columnheader");
|
|
189
189
|
|
|
190
|
-
userEvent.click(getByRole(firstNameCell,
|
|
191
|
-
userEvent.click(getByRole(lastNameCell,
|
|
190
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
191
|
+
userEvent.click(getByRole(lastNameCell, "button"));
|
|
192
192
|
expect(onSortHandler).toBeCalledWith([
|
|
193
|
-
{ name: defaultParams.headers[0].name, direction:
|
|
193
|
+
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
194
194
|
]);
|
|
195
195
|
expect(onSortHandler).toBeCalledWith([
|
|
196
|
-
{ name: defaultParams.headers[1].name, direction:
|
|
197
|
-
{ name: defaultParams.headers[0].name, direction:
|
|
196
|
+
{ name: defaultParams.headers[1].name, direction: "ASC" },
|
|
197
|
+
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
198
198
|
]);
|
|
199
|
-
expect(firstNameCell).toHaveAttribute(
|
|
200
|
-
expect(lastNameCell).toHaveAttribute(
|
|
199
|
+
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
200
|
+
expect(lastNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
201
201
|
|
|
202
|
-
userEvent.click(getByRole(lastNameCell,
|
|
202
|
+
userEvent.click(getByRole(lastNameCell, "button"));
|
|
203
203
|
expect(onSortHandler).toBeCalledWith([
|
|
204
|
-
{ name: defaultParams.headers[1].name, direction:
|
|
205
|
-
{ name: defaultParams.headers[0].name, direction:
|
|
204
|
+
{ name: defaultParams.headers[1].name, direction: "DESC" },
|
|
205
|
+
{ name: defaultParams.headers[0].name, direction: "ASC" }
|
|
206
206
|
]);
|
|
207
|
-
expect(firstNameCell).toHaveAttribute(
|
|
208
|
-
expect(lastNameCell).toHaveAttribute(
|
|
207
|
+
expect(firstNameCell).toHaveAttribute("aria-sort", "ascending");
|
|
208
|
+
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
209
209
|
|
|
210
|
-
userEvent.click(getByRole(firstNameCell,
|
|
210
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
211
211
|
expect(onSortHandler).toBeCalledWith([
|
|
212
|
-
{ name: defaultParams.headers[0].name, direction:
|
|
213
|
-
{ name: defaultParams.headers[1].name, direction:
|
|
212
|
+
{ name: defaultParams.headers[0].name, direction: "DESC" },
|
|
213
|
+
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
214
214
|
]);
|
|
215
|
-
expect(firstNameCell).toHaveAttribute(
|
|
216
|
-
expect(lastNameCell).toHaveAttribute(
|
|
215
|
+
expect(firstNameCell).toHaveAttribute("aria-sort", "descending");
|
|
216
|
+
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
217
217
|
|
|
218
|
-
userEvent.click(getByRole(firstNameCell,
|
|
218
|
+
userEvent.click(getByRole(firstNameCell, "button"));
|
|
219
219
|
expect(onSortHandler).toBeCalledWith([
|
|
220
|
-
{ name: defaultParams.headers[1].name, direction:
|
|
220
|
+
{ name: defaultParams.headers[1].name, direction: "DESC" }
|
|
221
221
|
]);
|
|
222
|
-
expect(firstNameCell).not.toHaveAttribute(
|
|
223
|
-
expect(lastNameCell).toHaveAttribute(
|
|
222
|
+
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
223
|
+
expect(lastNameCell).toHaveAttribute("aria-sort", "descending");
|
|
224
224
|
|
|
225
|
-
userEvent.click(getByRole(lastNameCell,
|
|
225
|
+
userEvent.click(getByRole(lastNameCell, "button"));
|
|
226
226
|
expect(onSortHandler).toBeCalledWith([]);
|
|
227
|
-
expect(firstNameCell).not.toHaveAttribute(
|
|
228
|
-
expect(lastNameCell).not.toHaveAttribute(
|
|
227
|
+
expect(firstNameCell).not.toHaveAttribute("aria-sort");
|
|
228
|
+
expect(lastNameCell).not.toHaveAttribute("aria-sort");
|
|
229
229
|
});
|
|
230
230
|
});
|
|
231
231
|
|
|
232
|
-
describe(
|
|
233
|
-
it(
|
|
232
|
+
describe("ref should work", () => {
|
|
233
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
234
234
|
const ExampleComponent = ({
|
|
235
|
-
propagateRef
|
|
235
|
+
propagateRef
|
|
236
236
|
}: {
|
|
237
237
|
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
238
238
|
}) => {
|
|
@@ -246,10 +246,10 @@ describe('ref should work', () => {
|
|
|
246
246
|
};
|
|
247
247
|
|
|
248
248
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
249
|
-
expect(ref.current).toHaveAttribute(
|
|
249
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
-
const container = document.createElement(
|
|
252
|
+
const container = document.createElement("table");
|
|
253
253
|
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
254
254
|
});
|
|
255
255
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, useEffect, useState } from
|
|
2
|
-
import { ColumnName, Direction, HeaderCell, OnSortFunction, Sort } from
|
|
3
|
-
import { DataGridHeaderCell } from
|
|
4
|
-
import classes from
|
|
1
|
+
import React, { ComponentPropsWithRef, useEffect, useState } from "react";
|
|
2
|
+
import { ColumnName, Direction, HeaderCell, OnSortFunction, Sort } from "../datagrid.interfaces";
|
|
3
|
+
import { DataGridHeaderCell } from "./DataGridHeaderCell";
|
|
4
|
+
import classes from "./DataGridHeader.module.scss";
|
|
5
5
|
|
|
6
|
-
export interface Props extends ComponentPropsWithRef<
|
|
6
|
+
export interface Props extends ComponentPropsWithRef<"thead"> {
|
|
7
7
|
headers: HeaderCell[];
|
|
8
8
|
initialSort?: Sort;
|
|
9
9
|
onSort?: OnSortFunction;
|
|
@@ -12,7 +12,7 @@ export interface Props extends ComponentPropsWithRef<'thead'> {
|
|
|
12
12
|
spacing?: React.CSSProperties;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const sortingStates = [undefined,
|
|
15
|
+
const sortingStates = [undefined, "ASC", "DESC"] as (Direction | undefined)[];
|
|
16
16
|
|
|
17
17
|
export const DataGridHeader = React.forwardRef<HTMLTableSectionElement, Props>(
|
|
18
18
|
(
|
|
@@ -34,7 +34,7 @@ export const DataGridHeader = React.forwardRef<HTMLTableSectionElement, Props>(
|
|
|
34
34
|
}, [initialSort]);
|
|
35
35
|
|
|
36
36
|
const calculateNextSortState = (direction?: Direction) => {
|
|
37
|
-
const currentDirectionIdx = sortingStates.findIndex(
|
|
37
|
+
const currentDirectionIdx = sortingStates.findIndex(item => item === direction);
|
|
38
38
|
return sortingStates[currentDirectionIdx + (1 % sortingStates.length)];
|
|
39
39
|
};
|
|
40
40
|
|
|
@@ -43,8 +43,8 @@ export const DataGridHeader = React.forwardRef<HTMLTableSectionElement, Props>(
|
|
|
43
43
|
* Last modified sorting column has the highest priority.
|
|
44
44
|
*/
|
|
45
45
|
const updateSortList = (name: ColumnName): Sort => {
|
|
46
|
-
const current = sortList.find(
|
|
47
|
-
const restSortList = enableMultiSorting ? sortList.filter(
|
|
46
|
+
const current = sortList.find(item => item.name === name);
|
|
47
|
+
const restSortList = enableMultiSorting ? sortList.filter(item => item.name !== name) : [];
|
|
48
48
|
const newSortDirection = calculateNextSortState(current?.direction);
|
|
49
49
|
return newSortDirection
|
|
50
50
|
? [{ name, direction: newSortDirection }, ...restSortList]
|
|
@@ -71,7 +71,7 @@ export const DataGridHeader = React.forwardRef<HTMLTableSectionElement, Props>(
|
|
|
71
71
|
headerStyle.paddingRight = spacing?.paddingRight;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const sort = sortList.find(
|
|
74
|
+
const sort = sortList.find(item => item.name === header.name);
|
|
75
75
|
return (
|
|
76
76
|
<DataGridHeaderCell
|
|
77
77
|
key={header.name}
|
|
@@ -86,14 +86,14 @@ export const DataGridHeader = React.forwardRef<HTMLTableSectionElement, Props>(
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
return (
|
|
89
|
-
<thead {...rest} ref={ref} className={classes[
|
|
90
|
-
<tr className={classes[
|
|
89
|
+
<thead {...rest} ref={ref} className={classes["thead"]}>
|
|
90
|
+
<tr className={classes["row"]}>
|
|
91
91
|
{headerCells}
|
|
92
92
|
{!disableContextMenuColumn && (
|
|
93
93
|
<td
|
|
94
94
|
style={{ paddingRight: spacing?.paddingRight }}
|
|
95
95
|
aria-label="context menu"
|
|
96
|
-
className={classes[
|
|
96
|
+
className={classes["context-menu"]}
|
|
97
97
|
></td>
|
|
98
98
|
)}
|
|
99
99
|
</tr>
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { DataGridHeaderCell, Props } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import userEvent from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { DataGridHeaderCell, Props } from "./DataGridHeaderCell";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
5
|
|
|
6
|
-
const defaultParams: Props = { name:
|
|
6
|
+
const defaultParams: Props = { name: "name-123", headline: "Test" };
|
|
7
7
|
|
|
8
8
|
const createDataGridHeaderCell = (params?: (defaultParams: Props) => Props) => {
|
|
9
9
|
let parameters: Props = defaultParams;
|
|
10
10
|
if (params) {
|
|
11
11
|
parameters = params(defaultParams);
|
|
12
12
|
}
|
|
13
|
-
const container = document.createElement(
|
|
13
|
+
const container = document.createElement("tr");
|
|
14
14
|
const queries = render(<DataGridHeaderCell {...parameters} data-testid="dataGridHeaderCell" />, {
|
|
15
|
-
container
|
|
15
|
+
container
|
|
16
16
|
});
|
|
17
|
-
const dataGridHeaderCell = queries.getByTestId(
|
|
17
|
+
const dataGridHeaderCell = queries.getByTestId("dataGridHeaderCell");
|
|
18
18
|
|
|
19
19
|
return {
|
|
20
20
|
...queries,
|
|
21
|
-
dataGridHeaderCell
|
|
21
|
+
dataGridHeaderCell
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
describe(
|
|
26
|
-
it(
|
|
25
|
+
describe("DataGridHeaderCell should render", () => {
|
|
26
|
+
it("renders without crashing", () => {
|
|
27
27
|
const { dataGridHeaderCell, queryByRole } = createDataGridHeaderCell();
|
|
28
28
|
|
|
29
29
|
expect(dataGridHeaderCell).toBeDefined();
|
|
30
30
|
expect(dataGridHeaderCell).toHaveTextContent(defaultParams.headline);
|
|
31
|
-
expect(queryByRole(
|
|
32
|
-
expect(dataGridHeaderCell.querySelectorAll(
|
|
31
|
+
expect(queryByRole("button")).toBeDefined();
|
|
32
|
+
expect(dataGridHeaderCell.querySelectorAll("[data-icon]")).toHaveLength(2);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it(
|
|
36
|
-
const { dataGridHeaderCell } = createDataGridHeaderCell(
|
|
35
|
+
it("renders without sorting indicators (icons)", () => {
|
|
36
|
+
const { dataGridHeaderCell } = createDataGridHeaderCell(params => ({
|
|
37
37
|
...params,
|
|
38
|
-
disableSorting: true
|
|
38
|
+
disableSorting: true
|
|
39
39
|
}));
|
|
40
40
|
|
|
41
|
-
expect(dataGridHeaderCell.querySelector(
|
|
41
|
+
expect(dataGridHeaderCell.querySelector("[data-icon]")).toBeNull();
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
it(
|
|
44
|
+
it("renders DESC and ASC sorting indicators (icons) when sorting is enabled and current sorting is not defined", () => {
|
|
45
45
|
const { dataGridHeaderCell } = createDataGridHeaderCell();
|
|
46
46
|
|
|
47
47
|
expect(dataGridHeaderCell).toBeDefined();
|
|
48
|
-
const sortingIcons = dataGridHeaderCell.querySelectorAll(
|
|
48
|
+
const sortingIcons = dataGridHeaderCell.querySelectorAll("[data-icon]");
|
|
49
49
|
expect(sortingIcons).toHaveLength(2);
|
|
50
|
-
sortingIcons.forEach(
|
|
51
|
-
expect(icon).toHaveClass(
|
|
52
|
-
expect(icon).not.toHaveClass(
|
|
53
|
-
expect(icon).not.toHaveClass(
|
|
50
|
+
sortingIcons.forEach(icon => {
|
|
51
|
+
expect(icon).toHaveClass("indicator");
|
|
52
|
+
expect(icon).not.toHaveClass("active");
|
|
53
|
+
expect(icon).not.toHaveClass("hidden");
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
it(
|
|
58
|
-
const { dataGridHeaderCell } = createDataGridHeaderCell(
|
|
57
|
+
it("renders ASC sorting indicator (icon) when sorting is enabled and current sorting is ASC", () => {
|
|
58
|
+
const { dataGridHeaderCell } = createDataGridHeaderCell(params => ({
|
|
59
59
|
...params,
|
|
60
|
-
activeSortDirection:
|
|
60
|
+
activeSortDirection: "ASC"
|
|
61
61
|
}));
|
|
62
62
|
|
|
63
63
|
expect(dataGridHeaderCell).toBeDefined();
|
|
64
|
-
const sortingIcons = dataGridHeaderCell.querySelectorAll(
|
|
64
|
+
const sortingIcons = dataGridHeaderCell.querySelectorAll("[data-icon]");
|
|
65
65
|
expect(sortingIcons).toHaveLength(2);
|
|
66
|
-
sortingIcons.forEach(
|
|
67
|
-
expect(sortingIcons[0]).toHaveClass(
|
|
68
|
-
expect(sortingIcons[0]).not.toHaveClass(
|
|
69
|
-
expect(sortingIcons[1]).toHaveClass(
|
|
70
|
-
expect(sortingIcons[1]).not.toHaveClass(
|
|
66
|
+
sortingIcons.forEach(icon => expect(icon).toHaveClass("indicator"));
|
|
67
|
+
expect(sortingIcons[0]).toHaveClass("indicator", "active", "icon-triangle-up");
|
|
68
|
+
expect(sortingIcons[0]).not.toHaveClass("hidden");
|
|
69
|
+
expect(sortingIcons[1]).toHaveClass("indicator", "hidden", "icon-triangle-down");
|
|
70
|
+
expect(sortingIcons[1]).not.toHaveClass("active");
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
it(
|
|
75
|
-
const { dataGridHeaderCell } = createDataGridHeaderCell(
|
|
74
|
+
it("renders DESC sorting indicator (icon) when sorting is enabled and current sorting is DESC", () => {
|
|
75
|
+
const { dataGridHeaderCell } = createDataGridHeaderCell(params => ({
|
|
76
76
|
...params,
|
|
77
|
-
activeSortDirection:
|
|
77
|
+
activeSortDirection: "DESC"
|
|
78
78
|
}));
|
|
79
79
|
|
|
80
80
|
expect(dataGridHeaderCell).toBeDefined();
|
|
81
|
-
const sortingIcons = dataGridHeaderCell.querySelectorAll(
|
|
81
|
+
const sortingIcons = dataGridHeaderCell.querySelectorAll("[data-icon]");
|
|
82
82
|
expect(sortingIcons).toHaveLength(2);
|
|
83
|
-
sortingIcons.forEach(
|
|
84
|
-
expect(sortingIcons[0]).toHaveClass(
|
|
85
|
-
expect(sortingIcons[0]).not.toHaveClass(
|
|
86
|
-
expect(sortingIcons[1]).toHaveClass(
|
|
87
|
-
expect(sortingIcons[1]).not.toHaveClass(
|
|
83
|
+
sortingIcons.forEach(icon => expect(icon).toHaveClass("indicator"));
|
|
84
|
+
expect(sortingIcons[0]).toHaveClass("indicator", "hidden", "icon-triangle-up");
|
|
85
|
+
expect(sortingIcons[0]).not.toHaveClass("active");
|
|
86
|
+
expect(sortingIcons[1]).toHaveClass("indicator", "active", "icon-triangle-down");
|
|
87
|
+
expect(sortingIcons[1]).not.toHaveClass("hidden");
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
describe(
|
|
91
|
-
it(
|
|
90
|
+
describe("DataGridHeaderCell should be interactive", () => {
|
|
91
|
+
it("clicking on cell calls onSort callback", () => {
|
|
92
92
|
const onSortHandler = jest.fn();
|
|
93
|
-
const { getByRole } = createDataGridHeaderCell(
|
|
93
|
+
const { getByRole } = createDataGridHeaderCell(params => ({
|
|
94
94
|
...params,
|
|
95
95
|
disableSorting: false,
|
|
96
|
-
onSort: onSortHandler
|
|
96
|
+
onSort: onSortHandler
|
|
97
97
|
}));
|
|
98
98
|
|
|
99
|
-
userEvent.click(getByRole(
|
|
99
|
+
userEvent.click(getByRole("button"));
|
|
100
100
|
|
|
101
101
|
expect(onSortHandler).toBeCalledWith(defaultParams.name);
|
|
102
102
|
});
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
describe(
|
|
106
|
-
it(
|
|
105
|
+
describe("ref should work", () => {
|
|
106
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
107
107
|
const ExampleComponent = ({
|
|
108
|
-
propagateRef
|
|
108
|
+
propagateRef
|
|
109
109
|
}: {
|
|
110
110
|
propagateRef: (ref: React.RefObject<HTMLElement>) => void;
|
|
111
111
|
}) => {
|
|
@@ -119,10 +119,10 @@ describe('ref should work', () => {
|
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
122
|
-
expect(ref.current).toHaveAttribute(
|
|
122
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
-
const container = document.createElement(
|
|
125
|
+
const container = document.createElement("tr");
|
|
126
126
|
render(<ExampleComponent propagateRef={refCheck} />, { container });
|
|
127
127
|
});
|
|
128
128
|
});
|