@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,84 +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 { FormHelperText, Props } from "./FormHelperText";
19
- import { render } from "@testing-library/react";
20
-
21
- const defaultParams: Props = {
22
- error: false,
23
- children: "This is a field description"
24
- };
25
-
26
- const createFormHelperText = (params?: (defaultParams: Props) => Props) => {
27
- let parameters: Props = defaultParams;
28
- if (params) {
29
- parameters = params(defaultParams);
30
- }
31
- const queries = render(<FormHelperText {...parameters} data-testid="formhelpertext" />);
32
- const formhelpertext = queries.getByTestId("formhelpertext");
33
-
34
- return {
35
- ...queries,
36
- formhelpertext
37
- };
38
- };
39
-
40
- describe("FormHelperText should render", () => {
41
- it("renders without crashing", () => {
42
- const { formhelpertext } = createFormHelperText();
43
-
44
- expect(formhelpertext).toBeTruthy();
45
- });
46
- });
47
-
48
- describe("ref should work", () => {
49
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
50
- const ExampleComponent = ({
51
- propagateRef
52
- }: {
53
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
54
- }) => {
55
- const ref = useRef(null);
56
-
57
- useEffect(() => {
58
- if (ref.current) {
59
- propagateRef && propagateRef(ref);
60
- }
61
- }, [ref]);
62
-
63
- return <FormHelperText {...defaultParams} data-ref="testing" ref={ref} />;
64
- };
65
-
66
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
67
- expect(ref.current).toHaveAttribute("data-ref", "testing");
68
- };
69
-
70
- render(<ExampleComponent propagateRef={refCheck} />);
71
- });
72
- });
73
-
74
- describe("Attributes", () => {
75
- it("contains the error class", () => {
76
- const { formhelpertext } = createFormHelperText(defaultParams => ({
77
- ...defaultParams,
78
- error: true
79
- }));
80
-
81
- expect(formhelpertext).toHaveClass("error");
82
- expect(formhelpertext).toHaveStyle({ color: "rgb(226, 42, 29);" });
83
- });
84
- });
@@ -1,94 +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, { useRef, useEffect } from "react";
18
- import { FormSelectorWrapper, Props } from "./FormSelectorWrapper";
19
- import { render } from "@testing-library/react";
20
-
21
- const defaultParams: Props = {};
22
-
23
- const createFormSelectorWrapper = (params?: (defaultParams: Props) => Props) => {
24
- let parameters: Props = defaultParams;
25
- if (params) {
26
- parameters = params(defaultParams);
27
- }
28
- const queries = render(
29
- <FormSelectorWrapper {...parameters} data-testid="formSelectorWrapper">
30
- formSelectorWrapper content
31
- </FormSelectorWrapper>
32
- );
33
- const formSelectorWrapper = queries.getByTestId("formSelectorWrapper");
34
-
35
- return {
36
- ...queries,
37
- formSelectorWrapper
38
- };
39
- };
40
-
41
- describe("FormSelectorWrapper should render", () => {
42
- it("renders without crashing", () => {
43
- const { formSelectorWrapper } = createFormSelectorWrapper();
44
-
45
- expect(formSelectorWrapper).toBeDefined();
46
- });
47
- });
48
-
49
- describe("ref should work", () => {
50
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
51
- const ExampleComponent = ({
52
- propagateRef
53
- }: {
54
- propagateRef?: (
55
- ref: React.RefObject<HTMLElement>,
56
- ref2: React.RefObject<HTMLElement>,
57
- ref3: React.RefObject<HTMLElement>
58
- ) => void;
59
- }) => {
60
- const ref = useRef(null);
61
- const helperRef = useRef(null);
62
- const containerRef = useRef(null);
63
-
64
- useEffect(() => {
65
- if (ref.current) {
66
- propagateRef && propagateRef(ref, helperRef, containerRef);
67
- }
68
- }, [ref]);
69
-
70
- return (
71
- <FormSelectorWrapper
72
- {...defaultParams}
73
- containerProps={{ "data-ref": "testing", ref: containerRef }}
74
- helperText="helpertext"
75
- helperProps={{ "data-ref": "testing", ref: helperRef }}
76
- data-ref="testing"
77
- ref={ref}
78
- />
79
- );
80
- };
81
-
82
- const refCheck = (
83
- ref: React.RefObject<HTMLElement>,
84
- ref2: React.RefObject<HTMLElement>,
85
- ref3: React.RefObject<HTMLElement>
86
- ) => {
87
- expect(ref.current).toHaveAttribute("data-ref", "testing");
88
- expect(ref2.current).toHaveAttribute("data-ref", "testing");
89
- expect(ref3.current).toHaveAttribute("data-ref", "testing");
90
- };
91
-
92
- render(<ExampleComponent propagateRef={refCheck} />);
93
- });
94
- });
@@ -1,267 +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, useState, Fragment } from "react";
18
- import { Input, Props, Type } from "./Input";
19
- import { act, fireEvent, render } from "@testing-library/react";
20
- import userEvent from "@testing-library/user-event";
21
- import { Label } from "../Label/Label";
22
-
23
- const defaultParams: Props = {
24
- name: "input",
25
- type: "text"
26
- };
27
-
28
- const createInput = (params?: (defaultParams: Props) => Props) => {
29
- let parameters: Props = defaultParams;
30
- if (params) {
31
- parameters = params(defaultParams);
32
- }
33
- const queries = render(<Input {...parameters} data-testid="input" />);
34
- const input = queries.getByTestId("input");
35
-
36
- return {
37
- ...queries,
38
- input
39
- };
40
- };
41
-
42
- const CreateInputComponent = ({
43
- onValueChange,
44
- type
45
- }: {
46
- onValueChange: (value: string) => void;
47
- type: Type;
48
- }) => {
49
- const [inputValue, setInputValue] = useState("");
50
-
51
- useEffect(() => {
52
- if (inputValue !== "") {
53
- onValueChange(inputValue);
54
- }
55
- }, [inputValue]);
56
-
57
- return (
58
- <Fragment>
59
- <Label htmlFor="sample-input">Test</Label>
60
- <Input
61
- name="sample_input"
62
- type={type}
63
- id="sample-input"
64
- value={inputValue}
65
- onChange={e => setInputValue(e.target.value)}
66
- />
67
- </Fragment>
68
- );
69
- };
70
-
71
- describe("Input should render", () => {
72
- it("renders without crashing and has a name and type", () => {
73
- const { input } = createInput();
74
- expect(input).toBeTruthy();
75
- });
76
- });
77
-
78
- describe("ref should work", () => {
79
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
80
- const ExampleComponent = ({
81
- propagateRef
82
- }: {
83
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
84
- }) => {
85
- const ref = useRef(null);
86
-
87
- useEffect(() => {
88
- if (ref.current) {
89
- propagateRef && propagateRef(ref);
90
- }
91
- }, [ref]);
92
-
93
- return <Input {...defaultParams} data-ref="testing" ref={ref} />;
94
- };
95
-
96
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
97
- expect(ref.current).toHaveAttribute("data-ref", "testing");
98
- };
99
-
100
- render(<ExampleComponent propagateRef={refCheck} />);
101
- });
102
- });
103
-
104
- describe("Should have the appropriate attributes", () => {
105
- it("is disabled and has a class", () => {
106
- const { input } = createInput(defaultParams => ({
107
- ...defaultParams,
108
- disabled: true,
109
- className: "classname"
110
- }));
111
-
112
- expect(input).toHaveAttribute("disabled");
113
- expect(input).toHaveClass("classname");
114
- });
115
-
116
- it("should render an input with spellcheck enabled", () => {
117
- const { input } = createInput(defaultParams => ({ ...defaultParams, spellCheck: true }));
118
-
119
- expect(input).toHaveAttribute("spellcheck", "true");
120
- });
121
-
122
- it("should render an input with spellcheck disabled by default", () => {
123
- const { input } = createInput(defaultParams => ({ ...defaultParams }));
124
-
125
- expect(input).toHaveAttribute("spellcheck", "false");
126
- });
127
- });
128
-
129
- describe("Should render all different types of inputs", () => {
130
- it.each([
131
- ["text", "testing", "testing"],
132
- ["email", "testing@testing.com", "testing@testing.com"],
133
- ["tel", "06123456789", "06123456789"],
134
- ["number", "1234567890", "1234567890"],
135
- ["search", "example", "example"],
136
- ["time", "1234", "12:34"],
137
- ["url", "https://www.onewelcome.com", "https://www.onewelcome.com"]
138
- ])(
139
- "renders a %p input with %p as a value",
140
- async (type: string, value: string, result: string) => {
141
- let changedValue = "";
142
-
143
- const { findByLabelText } = render(
144
- <CreateInputComponent type={type as Type} onValueChange={value => (changedValue = value)} />
145
- );
146
-
147
- const input = await findByLabelText(/Test/);
148
-
149
- await act(() => {
150
- input.focus();
151
- });
152
-
153
- await userEvent.keyboard(value);
154
-
155
- expect(changedValue).toBe(result);
156
- }
157
- );
158
-
159
- it("should render a password input", () => {
160
- const { input } = createInput(defaultParams => ({ ...defaultParams, type: "password" }));
161
-
162
- expect(input).toHaveAttribute("type", "password");
163
- });
164
-
165
- it("should render a datetime input", async () => {
166
- let changedValue = "";
167
-
168
- const { findByLabelText } = render(
169
- <CreateInputComponent type="datetime-local" onValueChange={value => (changedValue = value)} />
170
- );
171
-
172
- const input = await findByLabelText(/Test/);
173
-
174
- const testValue = "2019-03-29T12:34";
175
- fireEvent.change(input, { target: { value: testValue } });
176
-
177
- expect(changedValue).toBe(testValue);
178
- });
179
-
180
- it("should be hidden", () => {
181
- const { input } = createInput(defaultParams => ({ ...defaultParams, type: "hidden" }));
182
-
183
- expect(input.parentElement).toHaveClass("hidden");
184
- expect(input).toHaveAttribute("type", "hidden");
185
- });
186
- });
187
-
188
- describe("It should execute the listeners", () => {
189
- it("fires event handlers", async () => {
190
- const onChangeHandler = jest.fn();
191
- const onKeyUpHandler = jest.fn();
192
- const onKeyDownHandler = jest.fn();
193
-
194
- const { input } = createInput(defaultParams => ({
195
- ...defaultParams,
196
- type: "text",
197
- onKeyUp: onKeyUpHandler,
198
- onKeyDown: onKeyDownHandler,
199
- onChange: onChangeHandler
200
- }));
201
-
202
- await act(() => {
203
- input.focus();
204
- });
205
-
206
- expect(input).toHaveFocus();
207
-
208
- await userEvent.keyboard("test");
209
-
210
- expect(onKeyUpHandler).toHaveBeenCalled();
211
- expect(onKeyDownHandler).toHaveBeenCalled();
212
- expect(onChangeHandler).toHaveBeenCalled();
213
- });
214
- });
215
-
216
- describe("It should render prefix and suffix ", () => {
217
- it("renders prefix and suffix", () => {
218
- const prefix = "http://";
219
- const suffix = ".com";
220
- const { getByText } = createInput(defaultParams => ({
221
- ...defaultParams,
222
- prefix,
223
- suffix
224
- }));
225
-
226
- expect(getByText(prefix)).toBeDefined();
227
- expect(getByText(suffix)).toBeDefined();
228
- });
229
-
230
- it("renders prefix and suffix when they are elements", () => {
231
- const prefix = <span data-testid="prefix">http://</span>;
232
- const suffix = <span data-testid="suffix">.com</span>;
233
- const { getByTestId } = createInput(defaultParams => ({
234
- ...defaultParams,
235
- prefix,
236
- suffix
237
- }));
238
-
239
- const prefixElement = getByTestId("prefix");
240
- const suffixElement = getByTestId("suffix");
241
-
242
- expect(prefixElement).toBeInTheDocument();
243
- expect(suffixElement).toBeInTheDocument();
244
- });
245
-
246
- it("error icon should be visible with suffix", () => {
247
- const suffix = ".com";
248
- const { input, getByText } = createInput(defaultParams => ({
249
- ...defaultParams,
250
- error: true,
251
- suffix
252
- }));
253
-
254
- expect(input.querySelector("icon-warning")).toBeDefined();
255
- expect(getByText(suffix)).toBeDefined();
256
- });
257
-
258
- it("success icon should be visible", () => {
259
- const { input } = createInput(defaultParams => ({
260
- ...defaultParams,
261
- success: true
262
- }));
263
- const icon = input.querySelector(".icon-checkmark-circle-alt");
264
- expect(input.querySelector(".success")).toBeDefined();
265
- expect(icon).toBeDefined();
266
- });
267
- });
@@ -1,68 +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 { Label } from "./Label";
19
- import { render } from "@testing-library/react";
20
-
21
- describe("Label should render", () => {
22
- it("renders without crashing", () => {
23
- const { getByTestId } = render(
24
- <Label htmlFor="input-name" data-testid="component">
25
- Label
26
- </Label>
27
- );
28
- const component = getByTestId("component");
29
- expect(component).toBeDefined();
30
- });
31
-
32
- it("adds htmlFor attribute", () => {
33
- const { getByTestId } = render(
34
- <Label htmlFor="input-name" data-testid="component">
35
- Label
36
- </Label>
37
- );
38
-
39
- const component = getByTestId("component");
40
- expect(component.getAttribute("for")).toBe("input-name");
41
- });
42
- });
43
-
44
- describe("ref should work", () => {
45
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
46
- const ExampleComponent = ({
47
- propagateRef
48
- }: {
49
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
50
- }) => {
51
- const ref = useRef(null);
52
-
53
- useEffect(() => {
54
- if (ref.current) {
55
- propagateRef && propagateRef(ref);
56
- }
57
- }, [ref]);
58
-
59
- return <Label data-ref="testing" ref={ref} />;
60
- };
61
-
62
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
63
- expect(ref.current).toHaveAttribute("data-ref", "testing");
64
- };
65
-
66
- render(<ExampleComponent propagateRef={refCheck} />);
67
- });
68
- });
@@ -1,130 +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 { Radio, Props } from "./Radio";
19
- import { render } from "@testing-library/react";
20
- import userEvent from "@testing-library/user-event";
21
-
22
- const onChangeHandeler = jest.fn();
23
-
24
- const defaultParams: Props = {
25
- value: "test",
26
- children: "Label",
27
- checked: false,
28
- error: false,
29
- errorMessage: "errormessage",
30
- disabled: false,
31
- formSelectorWrapperProps: { "data-testid": "radiowrapper" },
32
- helperText: "helpertext",
33
- onChange: onChangeHandeler
34
- };
35
-
36
- const createRadio = (params?: (defaultParams: Props) => Props) => {
37
- let parameters: Props = defaultParams;
38
- if (params) {
39
- parameters = params(defaultParams);
40
- }
41
- const queries = render(<Radio {...parameters} data-testid="radio" />);
42
- const radio = queries.getByTestId("radio");
43
- const radiowrapper = queries.getByTestId("radiowrapper");
44
-
45
- return {
46
- ...queries,
47
- radio,
48
- radiowrapper
49
- };
50
- };
51
-
52
- describe("Radio should render", () => {
53
- it("renders without crashing and has proper attributes/values", () => {
54
- const { radio } = createRadio();
55
-
56
- expect((radio as HTMLInputElement).value).toBe("test");
57
- expect((radio as HTMLInputElement).checked).toBe(false);
58
- expect(radio).toBeTruthy();
59
- });
60
-
61
- it("it is checked", () => {
62
- const { radio } = createRadio(defaultParams => ({ ...defaultParams, checked: true }));
63
-
64
- expect((radio as HTMLInputElement).checked).toBe(true);
65
- });
66
-
67
- it("it is disabled", () => {
68
- const { radio, radiowrapper } = createRadio(defaultParams => ({
69
- ...defaultParams,
70
- disabled: true
71
- }));
72
-
73
- expect((radio as HTMLInputElement).disabled).toBe(true);
74
- expect(radiowrapper).toHaveClass("disabled");
75
- });
76
-
77
- it("has the correct describedby value when theres no error", async () => {
78
- const { radio, findByText } = createRadio(defaultParams => ({
79
- ...defaultParams,
80
- error: true
81
- }));
82
-
83
- const error = await findByText("errormessage");
84
-
85
- expect(radio).toHaveAttribute("aria-describedby", error.id);
86
- });
87
- });
88
-
89
- describe("ref should work", () => {
90
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
91
- const ExampleComponent = ({
92
- propagateRef
93
- }: {
94
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
95
- }) => {
96
- const ref = useRef(null);
97
-
98
- useEffect(() => {
99
- if (ref.current) {
100
- propagateRef && propagateRef(ref);
101
- }
102
- }, [ref]);
103
-
104
- return <Radio {...defaultParams} data-ref="testing" ref={ref} />;
105
- };
106
-
107
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
108
- expect(ref.current).toHaveAttribute("data-ref", "testing");
109
- };
110
-
111
- render(<ExampleComponent propagateRef={refCheck} />);
112
- });
113
- });
114
-
115
- describe("Radio should be interactive", () => {
116
- it("should call onChange when clicked", async () => {
117
- const { radio } = createRadio();
118
-
119
- expect(onChangeHandeler).not.toBeCalled();
120
- await userEvent.click(radio);
121
- expect(onChangeHandeler).toBeCalledTimes(1);
122
- });
123
-
124
- it("should not call onChange when disabled", async () => {
125
- const { radio } = createRadio(defaultParams => ({ ...defaultParams, disabled: true }));
126
-
127
- await userEvent.click(radio);
128
- expect(onChangeHandeler).not.toBeCalled();
129
- });
130
- });
@@ -1,57 +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 { Option } from "./Option";
19
- import { render } from "@testing-library/react";
20
-
21
- describe("Option should render", () => {
22
- it("renders without crashing", () => {
23
- const { getByTestId } = render(
24
- <Option value="option" data-testid="component">
25
- Option
26
- </Option>
27
- );
28
- const component = getByTestId("component");
29
- expect(component).toBeDefined();
30
- });
31
- });
32
-
33
- describe("ref should work", () => {
34
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
35
- const ExampleComponent = ({
36
- propagateRef
37
- }: {
38
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
39
- }) => {
40
- const ref = useRef(null);
41
-
42
- useEffect(() => {
43
- if (ref.current) {
44
- propagateRef && propagateRef(ref);
45
- }
46
- }, [ref]);
47
-
48
- return <Option value="test" children="Test" data-ref="testing" ref={ref} />;
49
- };
50
-
51
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
52
- expect(ref.current).toHaveAttribute("data-ref", "testing");
53
- };
54
-
55
- render(<ExampleComponent propagateRef={refCheck} />);
56
- });
57
- });