@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.
Files changed (194) hide show
  1. package/dist/cjs/Button/Button.module.cjs.js +1 -1
  2. package/dist/cjs/Button/IconButton.module.cjs.js +1 -1
  3. package/dist/cjs/ContextMenu/ContextMenu.cjs.js +1 -1
  4. package/dist/cjs/ContextMenu/ContextMenu.cjs.js.map +1 -1
  5. package/dist/cjs/ContextMenu/ContextMenuItem.module.cjs.js +1 -1
  6. package/dist/cjs/ContextMenu/ContextMenuService.cjs.js +1 -1
  7. package/dist/cjs/ContextMenu/ContextMenuService.cjs.js.map +1 -1
  8. package/dist/cjs/DataGrid/DataGridActions/DataGridColumnsToggle.module.cjs.js +1 -1
  9. package/dist/cjs/Form/Input/Input.module.cjs.js +1 -1
  10. package/dist/cjs/Form/Select/Option.cjs.js +1 -1
  11. package/dist/cjs/Form/Select/Option.cjs.js.map +1 -1
  12. package/dist/cjs/Form/Select/Select.cjs.js +1 -1
  13. package/dist/cjs/Form/Select/Select.cjs.js.map +1 -1
  14. package/dist/cjs/Form/Select/Select.module.cjs.js +1 -1
  15. package/dist/cjs/Form/Select/SelectService.cjs.js +1 -1
  16. package/dist/cjs/Form/Select/SelectService.cjs.js.map +1 -1
  17. package/dist/cjs/Form/Textarea/Textarea.module.cjs.js +1 -1
  18. package/dist/cjs/Link/Link.module.cjs.js +1 -1
  19. package/dist/cjs/Notifications/BaseModal/BaseModal.module.cjs.js +1 -1
  20. package/dist/cjs/Notifications/SlideInModal/SlideInModal.module.cjs.js +1 -1
  21. package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.cjs.js +1 -1
  22. package/dist/cjs/Popover/Popover.cjs.js +1 -1
  23. package/dist/cjs/Popover/Popover.cjs.js.map +1 -1
  24. package/dist/cjs/Popover/Popover.module.cjs.js +1 -1
  25. package/dist/cjs/Stepper/Step.cjs.js +1 -1
  26. package/dist/cjs/Stepper/Step.cjs.js.map +1 -1
  27. package/dist/cjs/Stepper/Step.module.cjs.js +1 -1
  28. package/dist/cjs/Stepper/Stepper.cjs.js +1 -1
  29. package/dist/cjs/Stepper/Stepper.cjs.js.map +1 -1
  30. package/dist/cjs/Tabs/TabButton.module.cjs.js +1 -1
  31. package/dist/cjs/TextEllipsis/TextEllipsis.module.cjs.js +1 -1
  32. package/dist/cjs/Tiles/Tile.module.cjs.js +1 -1
  33. package/dist/cjs/Tooltip/Tooltip.module.cjs.js +1 -1
  34. package/dist/cjs/Wizard/BaseWizardSteps/BaseWizardSteps.module.cjs.js +1 -1
  35. package/dist/cjs/src/.scope.d.ts +2 -0
  36. package/dist/cjs/src/components/ContextMenu/ContextMenu.d.ts +1 -1
  37. package/dist/cjs/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
  38. package/dist/cjs/src/components/Form/Select/Option.d.ts +1 -0
  39. package/dist/cjs/src/components/Form/Select/Select.d.ts +20 -0
  40. package/dist/cjs/src/components/Form/Select/Select.interfaces.d.ts +3 -1
  41. package/dist/cjs/src/components/Form/Select/Select.test.d.ts +63 -1
  42. package/dist/cjs/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
  43. package/dist/cjs/src/components/Form/Select/SelectService.d.ts +3 -2
  44. package/dist/cjs/src/components/Stepper/Stepper.d.ts +0 -1
  45. package/dist/cjs/src/hooks/usePosition.cjs.js.map +1 -1
  46. package/dist/cjs/src/hooks/usePosition.d.ts +1 -1
  47. package/dist/esm/Button/Button.module.esm.js +1 -1
  48. package/dist/esm/Button/IconButton.module.esm.js +1 -1
  49. package/dist/esm/ContextMenu/ContextMenu.esm.js +1 -1
  50. package/dist/esm/ContextMenu/ContextMenu.esm.js.map +1 -1
  51. package/dist/esm/ContextMenu/ContextMenuItem.module.esm.js +1 -1
  52. package/dist/esm/ContextMenu/ContextMenuService.esm.js +1 -1
  53. package/dist/esm/ContextMenu/ContextMenuService.esm.js.map +1 -1
  54. package/dist/esm/DataGrid/DataGridActions/DataGridColumnsToggle.module.esm.js +1 -1
  55. package/dist/esm/Form/Input/Input.module.esm.js +1 -1
  56. package/dist/esm/Form/Select/Option.esm.js +1 -1
  57. package/dist/esm/Form/Select/Option.esm.js.map +1 -1
  58. package/dist/esm/Form/Select/Select.esm.js +1 -1
  59. package/dist/esm/Form/Select/Select.esm.js.map +1 -1
  60. package/dist/esm/Form/Select/Select.module.esm.js +1 -1
  61. package/dist/esm/Form/Select/SelectService.esm.js +1 -1
  62. package/dist/esm/Form/Select/SelectService.esm.js.map +1 -1
  63. package/dist/esm/Form/Textarea/Textarea.module.esm.js +1 -1
  64. package/dist/esm/Link/Link.module.esm.js +1 -1
  65. package/dist/esm/Notifications/BaseModal/BaseModal.module.esm.js +1 -1
  66. package/dist/esm/Notifications/SlideInModal/SlideInModal.module.esm.js +1 -1
  67. package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.esm.js +1 -1
  68. package/dist/esm/Popover/Popover.esm.js +1 -1
  69. package/dist/esm/Popover/Popover.esm.js.map +1 -1
  70. package/dist/esm/Popover/Popover.module.esm.js +1 -1
  71. package/dist/esm/Stepper/Step.esm.js +1 -1
  72. package/dist/esm/Stepper/Step.esm.js.map +1 -1
  73. package/dist/esm/Stepper/Step.module.esm.js +1 -1
  74. package/dist/esm/Stepper/Stepper.esm.js +1 -1
  75. package/dist/esm/Stepper/Stepper.esm.js.map +1 -1
  76. package/dist/esm/Tabs/TabButton.module.esm.js +1 -1
  77. package/dist/esm/TextEllipsis/TextEllipsis.module.esm.js +1 -1
  78. package/dist/esm/Tiles/Tile.module.esm.js +1 -1
  79. package/dist/esm/Tooltip/Tooltip.module.esm.js +1 -1
  80. package/dist/esm/Wizard/BaseWizardSteps/BaseWizardSteps.module.esm.js +1 -1
  81. package/dist/esm/src/.scope.d.ts +2 -0
  82. package/dist/esm/src/components/ContextMenu/ContextMenu.d.ts +1 -1
  83. package/dist/esm/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
  84. package/dist/esm/src/components/Form/Select/Option.d.ts +1 -0
  85. package/dist/esm/src/components/Form/Select/Select.d.ts +20 -0
  86. package/dist/esm/src/components/Form/Select/Select.interfaces.d.ts +3 -1
  87. package/dist/esm/src/components/Form/Select/Select.test.d.ts +63 -1
  88. package/dist/esm/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
  89. package/dist/esm/src/components/Form/Select/SelectService.d.ts +3 -2
  90. package/dist/esm/src/components/Stepper/Stepper.d.ts +0 -1
  91. package/dist/esm/src/hooks/usePosition.d.ts +1 -1
  92. package/dist/esm/src/hooks/usePosition.esm.js.map +1 -1
  93. package/package.json +48 -45
  94. package/src/{hooks/useWrapper.test.ts → .scope.ts} +1 -12
  95. package/src/components/ContextMenu/ContextMenu.tsx +13 -23
  96. package/src/components/ContextMenu/ContextMenuService.ts +47 -1
  97. package/src/components/Form/Select/Option.tsx +3 -1
  98. package/src/components/Form/Select/Select.interfaces.ts +3 -1
  99. package/src/components/Form/Select/Select.module.scss +55 -34
  100. package/src/components/Form/Select/Select.tsx +74 -23
  101. package/src/components/Form/Select/SelectService.ts +26 -10
  102. package/src/components/Link/Link.module.scss +16 -0
  103. package/src/components/Popover/Popover.tsx +19 -2
  104. package/src/components/Stepper/Step.tsx +2 -1
  105. package/src/components/Stepper/Stepper.tsx +0 -2
  106. package/src/components/Tooltip/Tooltip.module.scss +1 -0
  107. package/src/hooks/usePosition.ts +1 -1
  108. package/src/interfaces.ts +2 -2
  109. package/src/mixins.module.scss +2 -4
  110. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -64
  111. package/src/components/Button/BaseButton.test.tsx +0 -133
  112. package/src/components/Button/Button.test.tsx +0 -150
  113. package/src/components/Button/IconButton.test.tsx +0 -106
  114. package/src/components/ContextMenu/ContextMenu.test.tsx +0 -358
  115. package/src/components/DataGrid/DataGrid.test.tsx +0 -437
  116. package/src/components/DataGrid/DataGridActions/DataGridActions.test.tsx +0 -204
  117. package/src/components/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +0 -99
  118. package/src/components/DataGrid/DataGridBody/DataGridBody.test.tsx +0 -140
  119. package/src/components/DataGrid/DataGridBody/DataGridCell.test.tsx +0 -90
  120. package/src/components/DataGrid/DataGridBody/DataGridRow.test.tsx +0 -117
  121. package/src/components/DataGrid/DataGridHeader/DataGridHeader.test.tsx +0 -276
  122. package/src/components/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +0 -144
  123. package/src/components/Form/Checkbox/Checkbox.test.tsx +0 -308
  124. package/src/components/Form/Fieldset/Fieldset.test.tsx +0 -127
  125. package/src/components/Form/FileUpload/FileItem/FileItem.test.tsx +0 -103
  126. package/src/components/Form/FileUpload/FileUpload.test.tsx +0 -374
  127. package/src/components/Form/Form.test.tsx +0 -63
  128. package/src/components/Form/FormControl/FormControl.test.tsx +0 -98
  129. package/src/components/Form/FormGroup/FormGroup.test.tsx +0 -127
  130. package/src/components/Form/FormHelperText/FormHelperText.test.tsx +0 -84
  131. package/src/components/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +0 -94
  132. package/src/components/Form/Input/Input.test.tsx +0 -267
  133. package/src/components/Form/Label/Label.test.tsx +0 -68
  134. package/src/components/Form/Radio/Radio.test.tsx +0 -130
  135. package/src/components/Form/Select/Option.test.tsx +0 -57
  136. package/src/components/Form/Select/Select.test.tsx +0 -564
  137. package/src/components/Form/Textarea/Textarea.test.tsx +0 -124
  138. package/src/components/Form/Toggle/Toggle.test.tsx +0 -200
  139. package/src/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +0 -141
  140. package/src/components/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +0 -211
  141. package/src/components/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +0 -117
  142. package/src/components/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +0 -186
  143. package/src/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +0 -173
  144. package/src/components/Form/Wrapper/Wrapper/Wrapper.test.tsx +0 -59
  145. package/src/components/Icon/Icon.test.tsx +0 -83
  146. package/src/components/Link/Link.test.tsx +0 -203
  147. package/src/components/Notifications/Banner/Banner.test.tsx +0 -84
  148. package/src/components/Notifications/BaseModal/BaseModal.test.tsx +0 -194
  149. package/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +0 -74
  150. package/src/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +0 -71
  151. package/src/components/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +0 -74
  152. package/src/components/Notifications/Dialog/Dialog.test.tsx +0 -118
  153. package/src/components/Notifications/Dialog/DialogActions/DialogActions.test.tsx +0 -61
  154. package/src/components/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +0 -87
  155. package/src/components/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +0 -111
  156. package/src/components/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +0 -175
  157. package/src/components/Notifications/Modal/Modal.test.tsx +0 -18
  158. package/src/components/Notifications/NotificationProvider/NotificationContext.test.tsx +0 -449
  159. package/src/components/Notifications/SlideInModal/SlideInModal.test.tsx +0 -90
  160. package/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +0 -53
  161. package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +0 -77
  162. package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +0 -219
  163. package/src/components/Notifications/Snackbar/useSnackbar.test.tsx +0 -136
  164. package/src/components/Pagination/Pagination.test.tsx +0 -183
  165. package/src/components/Popover/Popover.test.tsx +0 -103
  166. package/src/components/ProgressBar/ProgressBar.test.tsx +0 -91
  167. package/src/components/Skeleton/Skeleton.test.tsx +0 -112
  168. package/src/components/StatusIndicator/StatusIndicator.test.tsx +0 -143
  169. package/src/components/Stepper/Stepper.test.tsx +0 -83
  170. package/src/components/Tabs/Tab.test.tsx +0 -49
  171. package/src/components/Tabs/TabButton.test.tsx +0 -65
  172. package/src/components/Tabs/Tabs.test.tsx +0 -291
  173. package/src/components/Tag/Tag.test.tsx +0 -89
  174. package/src/components/TextEllipsis/TextEllipsis.test.tsx +0 -96
  175. package/src/components/Tiles/Tile.test.tsx +0 -183
  176. package/src/components/Tiles/Tiles.test.tsx +0 -162
  177. package/src/components/Tooltip/Tooltip.test.tsx +0 -390
  178. package/src/components/Typography/Typography.test.tsx +0 -177
  179. package/src/components/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +0 -90
  180. package/src/components/Wizard/Wizard.test.tsx +0 -218
  181. package/src/components/Wizard/WizardActions/WizardActions.test.tsx +0 -187
  182. package/src/components/Wizard/WizardSteps/WizardSteps.test.tsx +0 -125
  183. package/src/components/_BaseStyling_/BaseStyling.test.tsx +0 -55
  184. package/src/hooks/useAnimation.test.tsx +0 -65
  185. package/src/hooks/useBodyClick.test.tsx +0 -55
  186. package/src/hooks/useDebouncedCallback.test.ts +0 -150
  187. package/src/hooks/useDetermineStatusIcon.test.ts +0 -28
  188. package/src/hooks/useFormSelector.test.ts +0 -56
  189. package/src/hooks/usePosition.test.tsx +0 -510
  190. package/src/hooks/useRepeater.test.tsx +0 -156
  191. package/src/hooks/useScroll.test.tsx +0 -36
  192. package/src/hooks/useSpacing.test.ts +0 -86
  193. package/src/hooks/useUploadFile.test.ts +0 -211
  194. package/src/util/helper.test.tsx +0 -403
@@ -1,99 +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 { DataGridColumnsToggle, Props } from "./DataGridColumnsToggle";
19
- import { render } from "@testing-library/react";
20
- import userEvent from "@testing-library/user-event";
21
-
22
- const defaultParams: Props = {
23
- open: true,
24
- headers: [
25
- { headline: "Name", name: "name" },
26
- { headline: "Date", name: "date", hidden: true }
27
- ],
28
- onClose: jest.fn(),
29
- onToggleClicked: jest.fn()
30
- };
31
-
32
- const createDataGridColumnsToggle = (params?: (defaultParams: Props) => Props) => {
33
- let parameters: Props = defaultParams;
34
- if (params) {
35
- parameters = params(defaultParams);
36
- }
37
- const queries = render(
38
- <DataGridColumnsToggle {...parameters} data-testid="dataGridColumnsToggle" />
39
- );
40
- const dataGridColumnsToggle = queries.getByTestId("dataGridColumnsToggle");
41
-
42
- return {
43
- ...queries,
44
- dataGridColumnsToggle
45
- };
46
- };
47
-
48
- describe("DataGridColumnsToggle should render", () => {
49
- it("renders without crashing", () => {
50
- const { dataGridColumnsToggle, getByLabelText, getByText } = createDataGridColumnsToggle();
51
-
52
- expect(dataGridColumnsToggle).toBeDefined();
53
- expect(getByText("Show columns")).toBeDefined();
54
- expect(getByLabelText(defaultParams.headers[0].headline)).toBeChecked();
55
- expect(getByLabelText(defaultParams.headers[1].headline)).not.toBeChecked();
56
- });
57
- });
58
-
59
- describe("DataGridColumnsToggle should be interactive", () => {
60
- it("clicking on close calls onClose callback", async () => {
61
- const { getByRole } = createDataGridColumnsToggle();
62
-
63
- await userEvent.click(getByRole("button"));
64
-
65
- expect(defaultParams.onClose).toBeCalledTimes(1);
66
- });
67
-
68
- it("clicking outside of container (on backdrop layer) calls onClose callback", async () => {
69
- createDataGridColumnsToggle();
70
-
71
- await userEvent.click(document.querySelector(".backdrop")!);
72
-
73
- expect(defaultParams.onClose).toBeCalledTimes(1);
74
- });
75
- });
76
-
77
- describe("ref should work", () => {
78
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
79
- const ExampleComponent = ({
80
- propagateRef
81
- }: {
82
- propagateRef: (ref: React.RefObject<HTMLElement>) => void;
83
- }) => {
84
- const ref = useRef(null);
85
-
86
- useEffect(() => {
87
- propagateRef(ref);
88
- }, [ref]);
89
-
90
- return <DataGridColumnsToggle {...defaultParams} data-ref="testing" ref={ref} />;
91
- };
92
-
93
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
94
- expect(ref.current).toHaveAttribute("data-ref", "testing");
95
- };
96
-
97
- render(<ExampleComponent propagateRef={refCheck} />);
98
- });
99
- });
@@ -1,140 +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 { DataGridBody, Props } from "./DataGridBody";
19
- import { render, getAllByRole } from "@testing-library/react";
20
- import { DataGridRow } from "./DataGridRow";
21
- import { DataGridCell } from "./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
-
27
- type DataType = { firstName: string; lastName: string; date: string };
28
-
29
- const defaultParams: Props<DataType> = {
30
- children: ({ item }) => (
31
- <DataGridRow key={item.firstName}>
32
- <DataGridCell>{item.firstName}</DataGridCell>
33
- <DataGridCell>{item.lastName}</DataGridCell>
34
- <DataGridCell>{item.date}</DataGridCell>
35
- <DataGridCell>
36
- <ContextMenu
37
- id={`consent_menu_${item.firstName}`}
38
- trigger={
39
- <IconButton title={`Actions for ${item.firstName}`} color="default">
40
- <Icon icon={Icons.EllipsisAlt} />
41
- </IconButton>
42
- }
43
- >
44
- <ContextMenuItem>Item 1</ContextMenuItem>
45
- </ContextMenu>
46
- </DataGridCell>
47
- </DataGridRow>
48
- ),
49
- headers: [
50
- { name: "firstName", headline: "First name" },
51
- { name: "lastName", headline: "Last name" },
52
- { name: "date", headline: "Date" }
53
- ],
54
- data: [
55
- { firstName: "Paweł", lastName: "Napieracz", date: "12.12.1990" },
56
- { firstName: "Michał", lastName: "Górski", date: "12.12.1994" },
57
- { firstName: "Daniel", lastName: "Velden", date: "12.12.199x" },
58
- { firstName: "Jasha", lastName: "Joachimsthal", date: "12.12.198x" }
59
- ]
60
- };
61
-
62
- const createDataGridBody = (params?: (defaultParams: Props<DataType>) => Props<DataType>) => {
63
- let parameters = defaultParams;
64
- if (params) {
65
- parameters = params(defaultParams);
66
- }
67
- const container = document.createElement("table");
68
- const queries = render(<DataGridBody {...parameters} data-testid="dataGridBody" />, {
69
- container
70
- });
71
- const dataGridBody = queries.getByTestId("dataGridBody");
72
-
73
- return {
74
- ...queries,
75
- dataGridBody
76
- };
77
- };
78
-
79
- describe("DataGridBody should render", () => {
80
- it("renders without crashing", () => {
81
- const { dataGridBody } = createDataGridBody();
82
-
83
- expect(dataGridBody).toBeDefined();
84
- const rows = getAllByRole(dataGridBody, "row");
85
-
86
- expect(rows).toMatchSnapshot();
87
- });
88
-
89
- it("renders loading state with only visible columns", () => {
90
- const headers = [...defaultParams.headers];
91
- headers[0] = { ...headers[0], hidden: true };
92
- const { dataGridBody } = createDataGridBody(params => ({ ...params, headers }));
93
-
94
- expect(dataGridBody).toBeDefined();
95
- const rows = getAllByRole(dataGridBody, "row");
96
- const firstRowCells = getAllByRole(rows[0], "cell");
97
- expect(firstRowCells).toHaveLength(3);
98
- expect(firstRowCells[0]).toHaveTextContent(defaultParams.data?.[0].lastName!);
99
- });
100
-
101
- it("renders empty state", () => {
102
- const emptyLabel = "emptyLabel";
103
- const { dataGridBody } = createDataGridBody(params => ({
104
- ...params,
105
- emptyLabel,
106
- data: undefined
107
- }));
108
-
109
- const rows = getAllByRole(dataGridBody, "row");
110
- const firstRowCells = getAllByRole(rows[0], "cell");
111
- expect(firstRowCells).toHaveLength(1);
112
- expect(firstRowCells[0]).toHaveAttribute("colspan", `${defaultParams.headers.length + 1}`);
113
- expect(firstRowCells[0]).toHaveTextContent(emptyLabel);
114
- });
115
- });
116
-
117
- describe("ref should work", () => {
118
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
119
- const ExampleComponent = ({
120
- propagateRef
121
- }: {
122
- propagateRef: (ref: React.RefObject<HTMLElement>) => void;
123
- }) => {
124
- const ref = useRef(null);
125
-
126
- useEffect(() => {
127
- propagateRef(ref);
128
- }, [ref]);
129
-
130
- return <DataGridBody {...defaultParams} data-ref="testing" ref={ref} />;
131
- };
132
-
133
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
134
- expect(ref.current).toHaveAttribute("data-ref", "testing");
135
- };
136
-
137
- const container = document.createElement("table");
138
- render(<ExampleComponent propagateRef={refCheck} />, { container });
139
- });
140
- });
@@ -1,90 +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 { DataGridCell, Props } from "./DataGridCell";
19
- import { render } from "@testing-library/react";
20
-
21
- const defaultParams: Props = {
22
- children: "cell"
23
- };
24
-
25
- const createDataGridCell = (params?: (defaultParams: Props) => Props) => {
26
- let parameters: Props = defaultParams;
27
- if (params) {
28
- parameters = params(defaultParams);
29
- }
30
- const container = document.createElement("tr");
31
- const queries = render(<DataGridCell {...parameters} data-testid="dataGridCell" />, {
32
- container
33
- });
34
- const dataGridCell = queries.getByTestId("dataGridCell");
35
-
36
- return {
37
- ...queries,
38
- dataGridCell
39
- };
40
- };
41
-
42
- describe("DataGridCell should render", () => {
43
- it("renders without crashing", () => {
44
- const { dataGridCell } = createDataGridCell();
45
-
46
- expect(dataGridCell).toBeDefined();
47
- expect(dataGridCell).toHaveClass("cell");
48
- expect(dataGridCell).toHaveTextContent(defaultParams.children as string);
49
- });
50
-
51
- it("renders with additional class", () => {
52
- const { dataGridCell } = createDataGridCell(params => ({ ...params, className: "test" }));
53
-
54
- expect(dataGridCell).toHaveClass("cell", "test");
55
- });
56
-
57
- it("renders loading state", () => {
58
- const { dataGridCell } = createDataGridCell(params => ({ ...params, isLoading: true }));
59
-
60
- const skeletonLoadingEl = dataGridCell.querySelector("div");
61
- expect(skeletonLoadingEl).toHaveClass("loading");
62
- expect(skeletonLoadingEl).toHaveAttribute("aria-busy", "true");
63
- expect(skeletonLoadingEl).toHaveAttribute("aria-live", "polite");
64
- });
65
- });
66
-
67
- describe("ref should work", () => {
68
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
69
- const ExampleComponent = ({
70
- propagateRef
71
- }: {
72
- propagateRef: (ref: React.RefObject<HTMLElement>) => void;
73
- }) => {
74
- const ref = useRef(null);
75
-
76
- useEffect(() => {
77
- propagateRef(ref);
78
- }, [ref]);
79
-
80
- return <DataGridCell {...defaultParams} data-ref="testing" ref={ref} />;
81
- };
82
-
83
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
84
- expect(ref.current).toHaveAttribute("data-ref", "testing");
85
- };
86
-
87
- const container = document.createElement("tr");
88
- render(<ExampleComponent propagateRef={refCheck} />, { container });
89
- });
90
- });
@@ -1,117 +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 { DataGridRow, Props } from "./DataGridRow";
19
- import { render } from "@testing-library/react";
20
- import { DataGridCell } from "./DataGridCell";
21
-
22
- const defaultParams: Props = {
23
- children: [<DataGridCell>1</DataGridCell>, <DataGridCell>2</DataGridCell>],
24
- headers: [
25
- { name: "firstName", headline: "first name" },
26
- { name: "lastName", headline: "last name" }
27
- ]
28
- };
29
-
30
- const createDataGridRow = (params?: (defaultParams: Props) => Props) => {
31
- let parameters: Props = defaultParams;
32
- if (params) {
33
- parameters = params(defaultParams);
34
- }
35
- const container = document.createElement("tbody");
36
- const queries = render(<DataGridRow {...parameters} data-testid="dataGridRow" />, { container });
37
- const dataGridRow = queries.getByTestId("dataGridRow");
38
-
39
- return {
40
- ...queries,
41
- dataGridRow
42
- };
43
- };
44
-
45
- describe("DataGridRow should render", () => {
46
- it("renders without crashing", () => {
47
- const { dataGridRow, getAllByRole } = createDataGridRow();
48
-
49
- expect(dataGridRow).toBeDefined();
50
- expect(dataGridRow).toHaveClass("row", { exact: true });
51
- const cells = getAllByRole("cell");
52
- expect(cells).toHaveLength(2);
53
- expect(cells[0]).toHaveTextContent("1");
54
- expect(cells[1]).toHaveTextContent("2");
55
- });
56
-
57
- it("renders with additional class", () => {
58
- const { dataGridRow } = createDataGridRow(params => ({ ...params, className: "test" }));
59
-
60
- expect(dataGridRow).toHaveClass("row test", { exact: true });
61
- });
62
-
63
- it("renders loading state", () => {
64
- const { dataGridRow } = createDataGridRow(params => ({ ...params, isLoading: true }));
65
-
66
- expect(dataGridRow).toHaveClass("row loading", { exact: true });
67
- });
68
-
69
- it("renders only visible columns", () => {
70
- const { dataGridRow, getAllByRole } = createDataGridRow(params => ({
71
- ...params,
72
- headers: [
73
- { name: "firstName", headline: "first name", hidden: true },
74
- { name: "lastName", headline: "last name", hidden: true },
75
- { name: "date", headline: "date" },
76
- { name: "status", headline: "status" }
77
- ],
78
- children: [
79
- <DataGridCell>1</DataGridCell>,
80
- <DataGridCell>2</DataGridCell>,
81
- <DataGridCell>3</DataGridCell>,
82
- <DataGridCell>4</DataGridCell>
83
- ]
84
- }));
85
-
86
- expect(dataGridRow).toBeDefined();
87
- const cells = getAllByRole("cell");
88
- expect(cells).toHaveLength(2);
89
- expect(cells[0]).toHaveTextContent("3");
90
- expect(cells[1]).toHaveTextContent("4");
91
- });
92
- });
93
-
94
- describe("ref should work", () => {
95
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
96
- const ExampleComponent = ({
97
- propagateRef
98
- }: {
99
- propagateRef: (ref: React.RefObject<HTMLElement>) => void;
100
- }) => {
101
- const ref = useRef(null);
102
-
103
- useEffect(() => {
104
- propagateRef(ref);
105
- }, [ref]);
106
-
107
- return <DataGridRow {...defaultParams} data-ref="testing" ref={ref} />;
108
- };
109
-
110
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
111
- expect(ref.current).toHaveAttribute("data-ref", "testing");
112
- };
113
-
114
- const container = document.createElement("tbody");
115
- render(<ExampleComponent propagateRef={refCheck} />, { container });
116
- });
117
- });