@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,308 +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 { Checkbox, Props } from "./Checkbox";
19
- import { render } from "@testing-library/react";
20
- import userEvent from "@testing-library/user-event";
21
- import { Toggle } from "../Toggle/Toggle";
22
-
23
- const onChangeHandler = jest.fn();
24
-
25
- const defaultParams: Props = {
26
- name: "Testing",
27
- children: "checkbox content",
28
- helperText: "example helper",
29
- onChange: onChangeHandler
30
- };
31
-
32
- const createCheckbox = (params?: (defaultParams: Props) => Props) => {
33
- let parameters: Props = defaultParams;
34
- if (params) {
35
- parameters = params(defaultParams);
36
- }
37
- const queries = render(<Checkbox {...parameters} data-testid="checkbox" />);
38
- const checkbox = queries.getByTestId("checkbox");
39
-
40
- return {
41
- ...queries,
42
- checkbox
43
- };
44
- };
45
-
46
- describe("Checkbox should render", () => {
47
- it("renders without crashing", () => {
48
- const { checkbox } = createCheckbox();
49
- expect(checkbox).toBeTruthy();
50
- });
51
- });
52
-
53
- describe("ref should work", () => {
54
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
55
- const ExampleComponent = ({
56
- propagateRef
57
- }: {
58
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
59
- }) => {
60
- const ref = useRef(null);
61
-
62
- useEffect(() => {
63
- if (ref.current) {
64
- propagateRef && propagateRef(ref);
65
- }
66
- }, [ref]);
67
-
68
- return <Checkbox {...defaultParams} data-ref="testing" ref={ref} />;
69
- };
70
-
71
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
72
- expect(ref.current).toHaveAttribute("data-ref", "testing");
73
- };
74
-
75
- render(<ExampleComponent propagateRef={refCheck} />);
76
- });
77
- });
78
-
79
- describe("Checkbox should have proper attributes", () => {
80
- it("should be unchecked", () => {
81
- const { checkbox } = createCheckbox();
82
-
83
- expect(checkbox).toHaveAttribute("aria-checked", "false");
84
- });
85
-
86
- it("should be checked", () => {
87
- const { checkbox } = createCheckbox(defaultParams => ({ ...defaultParams, checked: true }));
88
-
89
- expect(checkbox).toHaveAttribute("aria-checked", "true");
90
- });
91
-
92
- it("should call the onChange function", async () => {
93
- const onChangeHandler = jest.fn();
94
- const { checkbox } = createCheckbox(defaultParams => ({
95
- ...defaultParams,
96
- onChange: onChangeHandler
97
- }));
98
- await userEvent.click(checkbox);
99
- expect(onChangeHandler).toHaveBeenCalled();
100
- });
101
-
102
- it("should be disabled", async () => {
103
- const onChangeHandler = jest.fn();
104
- const { checkbox } = createCheckbox(defaultParams => ({
105
- ...defaultParams,
106
- onChange: onChangeHandler,
107
- disabled: true
108
- }));
109
-
110
- expect(checkbox).toBeDisabled();
111
-
112
- await userEvent.click(checkbox);
113
-
114
- expect(onChangeHandler).not.toHaveBeenCalled();
115
- });
116
-
117
- it("nested checkbox should be disabled", () => {
118
- const { getByTestId } = createCheckbox(defaultParams => ({
119
- ...defaultParams,
120
- indeterminate: false,
121
- label: "test",
122
- children: (
123
- <Checkbox data-testid="nested-checkbox" name="test" disabled={true}>
124
- test
125
- </Checkbox>
126
- )
127
- }));
128
-
129
- const nestedCheckbox = getByTestId("nested-checkbox");
130
-
131
- expect(nestedCheckbox).toBeDisabled();
132
- });
133
-
134
- it("should have helpertext rendered", () => {
135
- const { getByText } = createCheckbox();
136
-
137
- const helperText = getByText("example helper");
138
-
139
- expect(helperText).toBeTruthy();
140
- });
141
-
142
- it("should have the error state enabled", () => {
143
- const { checkbox, container, getByTestId } = createCheckbox(defaultParams => ({
144
- ...defaultParams,
145
- error: true,
146
- errorMessage: "This is an error",
147
- formSelectorWrapperProps: { "data-testid": "checkbox-wrapper" }
148
- }));
149
-
150
- expect(checkbox).toHaveAttribute(
151
- "aria-describedby",
152
- container.querySelector(".error-message")!.id
153
- );
154
-
155
- expect(checkbox).toHaveAttribute("aria-invalid", "true");
156
- expect(getByTestId("checkbox-wrapper")).toHaveClass("error");
157
- });
158
-
159
- it("should have a correctly linked label element", () => {
160
- const { checkbox, container } = createCheckbox(defaultParams => ({
161
- ...defaultParams,
162
- label: "Label"
163
- }));
164
-
165
- const id = checkbox.getAttribute("id");
166
- const label = container.querySelector(`label[for=${id}]`);
167
-
168
- expect(label).toBeTruthy();
169
- expect(label).toHaveTextContent("Label");
170
- });
171
-
172
- it("should have a react element as label", () => {
173
- const { checkbox, container } = createCheckbox(defaultParams => ({
174
- ...defaultParams,
175
- label: <span>Label element</span>
176
- }));
177
-
178
- const id = checkbox.getAttribute("id");
179
- const label = container.querySelector(`label[for=${id}]`);
180
-
181
- expect(label).toBeTruthy();
182
- expect(label).toHaveTextContent("Label element");
183
- });
184
- });
185
-
186
- describe("Checkbox should be interactive", () => {
187
- it("should call onChange when clicked", async () => {
188
- const { checkbox } = createCheckbox();
189
-
190
- expect(onChangeHandler).not.toBeCalled();
191
- await userEvent.click(checkbox);
192
- expect(onChangeHandler).toBeCalledTimes(1);
193
- });
194
-
195
- it("should not call onChange when disabled", async () => {
196
- const { checkbox } = createCheckbox(defaultParams => ({ ...defaultParams, disabled: true }));
197
-
198
- await userEvent.click(checkbox);
199
- expect(onChangeHandler).not.toBeCalled();
200
- });
201
- });
202
-
203
- describe("toggle version", () => {
204
- it("should turn into a toggle", () => {
205
- const { container } = render(<Toggle name="toggle">Test</Toggle>);
206
-
207
- expect(container.querySelector("[data-toggle]")).toBeInTheDocument();
208
- });
209
- });
210
-
211
- describe("missing attributes gets us errors", () => {
212
- it("throws an error for missing label prop", () => {
213
- // Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
214
- const err = console.error;
215
- console.error = jest.fn();
216
-
217
- let actual;
218
-
219
- try {
220
- // @ts-ignore: mandatory props (test for non-typescript react projects)
221
- createCheckbox(defaultParams => ({
222
- ...defaultParams,
223
- children: <Checkbox name="test">Test</Checkbox>
224
- }));
225
- } catch (e: any) {
226
- actual = e.message;
227
- }
228
-
229
- const expected =
230
- "If you have nested checkboxes you have to manage the indeterminate state by passing a boolean to the `indeterminate` prop.";
231
-
232
- expect(actual).toEqual(expected);
233
-
234
- console.error = err;
235
- });
236
-
237
- it("throws an error for indeterminate prop", () => {
238
- // Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
239
- const err = console.error;
240
- console.error = jest.fn();
241
-
242
- let actual;
243
-
244
- try {
245
- // @ts-ignore: mandatory props (test for non-typescript react projects)
246
- createCheckbox(defaultParams => ({
247
- ...defaultParams,
248
- label: "testing",
249
- children: <Checkbox name="test">Test</Checkbox>
250
- }));
251
- } catch (e: any) {
252
- actual = e.message;
253
- }
254
-
255
- const expected =
256
- "If you have nested checkboxes you have to manage the indeterminate state by passing a boolean to the `indeterminate` prop.";
257
-
258
- expect(actual).toEqual(expected);
259
-
260
- console.error = err;
261
- });
262
-
263
- it("throws an error for incorrect children prop", () => {
264
- // Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
265
- const err = console.error;
266
- console.error = jest.fn();
267
-
268
- let actual;
269
-
270
- try {
271
- // @ts-ignore: mandatory props (test for non-typescript react projects)
272
- createCheckbox(defaultParams => ({
273
- name: undefined
274
- }));
275
- } catch (e: any) {
276
- actual = e.message;
277
- }
278
-
279
- const expected = "Please pass a 'name' prop to your <Checkbox> component.";
280
-
281
- expect(actual).toEqual(expected);
282
-
283
- console.error = err;
284
- });
285
-
286
- it("throws an error for missing name prop", () => {
287
- // Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
288
- const err = console.error;
289
- console.error = jest.fn();
290
-
291
- let actual;
292
-
293
- try {
294
- // @ts-ignore: mandatory props (test for non-typescript react projects)
295
- createCheckbox(defaultParams => ({
296
- children: "test"
297
- }));
298
- } catch (e: any) {
299
- actual = e.message;
300
- }
301
-
302
- const expected = "Please pass a 'name' prop to your <Checkbox> component.";
303
-
304
- expect(actual).toEqual(expected);
305
-
306
- console.error = err;
307
- });
308
- });
@@ -1,127 +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 { Fieldset, Props } from "./Fieldset";
19
- import { render } from "@testing-library/react";
20
- import { FormControl } from "../FormControl/FormControl";
21
- import { Input } from "../Input/Input";
22
- import { Select } from "../Select/Select";
23
- import { Option } from "../Select/Option";
24
-
25
- const defaultParams: Props = {
26
- legend: "Example",
27
- legendStyle: "h2",
28
- children: [
29
- <FormControl data-testid="form-control">
30
- <Input placeholder="This is a placeholder" name="example" type="text" />
31
- </FormControl>,
32
- <FormControl data-testid="form-control">
33
- <Select name="Example select" value="placeholder" onChange={jest.fn}>
34
- <Option value="option1">Option1</Option>
35
- <Option value="option2">Option2</Option>
36
- <Option value="option3">Option3</Option>
37
- </Select>
38
- </FormControl>
39
- ]
40
- };
41
-
42
- const createFieldset = (params?: (defaultParams: Props) => Props) => {
43
- let parameters: Props = defaultParams;
44
- if (params) {
45
- parameters = params(defaultParams);
46
- }
47
- const queries = render(<Fieldset {...parameters} data-testid="fieldset" />);
48
- const fieldset = queries.getByTestId("fieldset");
49
-
50
- return {
51
- ...queries,
52
- fieldset
53
- };
54
- };
55
-
56
- describe("Fieldset should render", () => {
57
- it("renders without crashing", () => {
58
- const { fieldset } = createFieldset();
59
-
60
- expect(fieldset).toBeTruthy();
61
- });
62
- });
63
-
64
- describe("ref should work", () => {
65
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
66
- const ExampleComponent = ({
67
- propagateRef
68
- }: {
69
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
70
- }) => {
71
- const ref = useRef(null);
72
-
73
- useEffect(() => {
74
- if (ref.current) {
75
- propagateRef && propagateRef(ref);
76
- }
77
- }, [ref]);
78
-
79
- return <Fieldset {...defaultParams} data-ref="testing" ref={ref} />;
80
- };
81
-
82
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
83
- expect(ref.current).toHaveAttribute("data-ref", "testing");
84
- };
85
-
86
- render(<ExampleComponent propagateRef={refCheck} />);
87
- });
88
- });
89
-
90
- describe("Fieldset should get proper attributes and classes", () => {
91
- it("has no padding class", () => {
92
- const { fieldset } = createFieldset(defaultParams => ({ ...defaultParams, noPadding: true }));
93
-
94
- expect(fieldset).toHaveClass("no-padding");
95
- });
96
-
97
- it("has no background styling", () => {
98
- const { fieldset } = createFieldset(defaultParams => ({
99
- ...defaultParams,
100
- noBackground: true
101
- }));
102
-
103
- expect(fieldset.style.backgroundColor).toBe("");
104
- });
105
-
106
- it("has a correct legend and title <span> element", () => {
107
- const { getByText } = createFieldset();
108
-
109
- const legend = getByText(/example/i, { selector: "legend" });
110
- const title = getByText(/example/i, { selector: "span" });
111
-
112
- expect(legend).toHaveTextContent("Example");
113
- expect(legend).toBeTruthy();
114
- expect(title).toHaveClass("typography_style_h2");
115
- expect(title).toBeTruthy();
116
- expect(title).toHaveTextContent("Example");
117
- });
118
-
119
- it("renders its children correctly", () => {
120
- const { getAllByTestId } = createFieldset();
121
-
122
- const formcontrols = getAllByTestId("form-control");
123
-
124
- expect(formcontrols).toBeTruthy();
125
- expect(formcontrols).toHaveLength(2);
126
- });
127
- });
@@ -1,103 +0,0 @@
1
- import React from "react";
2
- import { FILE_ACTION, FileItem, Props } from "./FileItem";
3
- import { render } from "@testing-library/react";
4
- import user from "@testing-library/user-event";
5
-
6
- const defaultParams: Props = {
7
- name: "Test.txt"
8
- };
9
-
10
- const createFileItem = (params?: (defaultParams: Props) => Props) => {
11
- let parameters: Props = defaultParams;
12
- if (params) {
13
- parameters = params(defaultParams);
14
- }
15
- const queries = render(<FileItem {...parameters} />);
16
- const component = queries.getByLabelText(`${parameters.name}-wrapper`);
17
- const title = component.querySelector(".file-name");
18
- const fileIcon = component.querySelector(".file-icon");
19
- const actionIcon = component.querySelector(".action-icon");
20
- const errorSubtitle = component.querySelector(".file-subtitle");
21
- const progressBar = component.querySelector(".progress-bar");
22
-
23
- return {
24
- ...queries,
25
- component,
26
- title,
27
- fileIcon,
28
- actionIcon,
29
- errorSubtitle,
30
- progressBar
31
- };
32
- };
33
-
34
- describe("component should render", () => {
35
- it("renders without crashing", () => {
36
- const { component } = createFileItem();
37
-
38
- expect(component).toBeDefined();
39
- });
40
- });
41
-
42
- describe("component should change display the correct style and elements according to the status", () => {
43
- it("should show the correct details for completed", () => {
44
- const { actionIcon, title } = createFileItem(defaultParams => ({
45
- ...defaultParams,
46
- status: "completed"
47
- }));
48
- expect(title).toHaveClass("completed");
49
- expect(actionIcon).toHaveAttribute("title", FILE_ACTION.DELETE);
50
- });
51
-
52
- it("should show the correct details for uploading", () => {
53
- const { actionIcon, title, progressBar } = createFileItem(defaultParams => ({
54
- ...defaultParams,
55
- status: "uploading"
56
- }));
57
- expect(title).toHaveClass("uploading");
58
- expect(actionIcon).toHaveAttribute("title", FILE_ACTION.ABORT);
59
- expect(progressBar).toBeDefined();
60
- });
61
-
62
- it("should show the correct details for readonly", () => {
63
- const { actionIcon, title } = createFileItem(defaultParams => ({
64
- ...defaultParams,
65
- status: "readonly"
66
- }));
67
- expect(title).toHaveClass("readonly");
68
- expect(actionIcon).toBeNull();
69
- });
70
-
71
- it("should show the correct details for error", () => {
72
- const { actionIcon, title, errorSubtitle } = createFileItem(defaultParams => ({
73
- ...defaultParams,
74
- status: "error"
75
- }));
76
- expect(title).toHaveClass("error");
77
- expect(actionIcon).toHaveAttribute("title", FILE_ACTION.REMOVE);
78
- expect(errorSubtitle).toBeDefined();
79
- });
80
-
81
- it("should show the correct details for retry", () => {
82
- const { actionIcon, title } = createFileItem(defaultParams => ({
83
- ...defaultParams,
84
- status: "retry"
85
- }));
86
- expect(title).toHaveClass("retry");
87
- expect(actionIcon).toHaveAttribute("title", FILE_ACTION.RETRY);
88
- });
89
- });
90
-
91
- describe("component should transmit the correct message upwards when a file action icon is clicked", () => {
92
- it("should call retry action", async () => {
93
- const onRequestedFileAction = jest.fn();
94
- const { actionIcon } = createFileItem(defaultParams => ({
95
- ...defaultParams,
96
- status: "retry",
97
- onRequestedFileAction
98
- }));
99
-
100
- await user.click(actionIcon as Element);
101
- expect(onRequestedFileAction).toHaveBeenNthCalledWith(1, FILE_ACTION.RETRY, defaultParams.name);
102
- });
103
- });