@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,125 +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, { useReducer } from "react";
18
- import { WizardSteps, Props } from "./WizardSteps";
19
- import { getAllByRole, getByText, render } from "@testing-library/react";
20
- import { WizardStateContext, Props as ProviderProps } from "../WizardStateProvider";
21
- import { WizardStateType, reducer, changeCurrentStepNo } from "../wizardStateReducer";
22
- import userEvent from "@testing-library/user-event";
23
-
24
- const initWizardState: WizardStateType = {
25
- steps: [
26
- {
27
- label: "Step 1"
28
- },
29
- {
30
- label: "Step 2"
31
- },
32
- {
33
- label: "Step 3",
34
- disabled: true
35
- },
36
- {
37
- label: "Step 4"
38
- }
39
- ],
40
- currentStepNo: 1,
41
- mode: "add"
42
- };
43
-
44
- const initParams: Props = {
45
- onStepClick: jest.fn()
46
- };
47
-
48
- const renderWizardSteps = (initReducerState?: WizardStateType) => {
49
- const wizardState = initReducerState ? initReducerState : initWizardState;
50
- const dispatch = jest.fn();
51
-
52
- const Provider = ({ children }: ProviderProps) => {
53
- const [state] = useReducer(reducer, wizardState);
54
- return (
55
- <WizardStateContext.Provider value={{ state, dispatch }}>
56
- {children}
57
- </WizardStateContext.Provider>
58
- );
59
- };
60
-
61
- const renderObj = render(
62
- <Provider initialState={initWizardState}>
63
- <WizardSteps {...initParams} />
64
- </Provider>
65
- );
66
-
67
- return {
68
- ...renderObj,
69
- dispatch
70
- };
71
- };
72
-
73
- const getStepButtons = (container: HTMLElement) => getAllByRole(container, "button");
74
-
75
- describe("WizardSteps", () => {
76
- it("renders without crashing", async () => {
77
- const { container, dispatch } = renderWizardSteps();
78
- const buttons = getStepButtons(container);
79
- (
80
- initParams.onStepClick as jest.MockedFunction<typeof initParams.onStepClick>
81
- ).mockReturnValueOnce(true);
82
-
83
- expect(buttons).toHaveLength(4);
84
- await userEvent.click(buttons[0]);
85
- expect(initParams.onStepClick).toHaveBeenCalledWith(initWizardState.currentStepNo, 0);
86
- expect(dispatch).toBeCalledWith(changeCurrentStepNo(0));
87
- expect(buttons[0].querySelector(".checkmark")).toBeDefined();
88
- expect(getByText(buttons[1], "2")).toBeDefined();
89
- expect(getByText(buttons[2], "3")).toBeDefined();
90
- expect(getByText(buttons[3], "4")).toBeDefined();
91
-
92
- await userEvent.click(buttons[1]);
93
- await userEvent.click(buttons[2]);
94
- await userEvent.click(buttons[3]);
95
- expect(initParams.onStepClick).toHaveBeenCalledTimes(1);
96
- });
97
-
98
- it("should allow to click on future and prev steps but not on current and disabled steps when mode is set to `edit`", async () => {
99
- const { container, dispatch } = renderWizardSteps({ ...initWizardState, mode: "edit" });
100
- const buttons = getStepButtons(container);
101
- (
102
- initParams.onStepClick as jest.MockedFunction<typeof initParams.onStepClick>
103
- ).mockReturnValueOnce(true);
104
-
105
- await userEvent.click(buttons[3]);
106
- expect(initParams.onStepClick).toHaveBeenCalledWith(initWizardState.currentStepNo, 3);
107
- expect(dispatch).toBeCalledWith(changeCurrentStepNo(3));
108
-
109
- await userEvent.click(buttons[1]);
110
- await userEvent.click(buttons[2]);
111
- expect(initParams.onStepClick).toHaveBeenCalledTimes(1);
112
- });
113
-
114
- it("should do not change step when `onStepClick` callback returns false", async () => {
115
- const { container, dispatch } = renderWizardSteps({ ...initWizardState, mode: "edit" });
116
- const buttons = getStepButtons(container);
117
- (
118
- initParams.onStepClick as jest.MockedFunction<typeof initParams.onStepClick>
119
- ).mockReturnValueOnce(false);
120
-
121
- await userEvent.click(buttons[3]);
122
- expect(initParams.onStepClick).toHaveBeenCalledWith(initWizardState.currentStepNo, 3);
123
- expect(dispatch).not.toBeCalled();
124
- });
125
- });
@@ -1,55 +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, { Fragment } from "react";
18
- import { BaseStyling } from "./BaseStyling";
19
- import { Button } from "../Button/Button";
20
- import { render } from "@testing-library/react";
21
-
22
- describe("BaseStyling should render", () => {
23
- it("renders without crashing", async () => {
24
- const { container, findByTestId } = render(
25
- <Fragment>
26
- <BaseStyling>
27
- <Button data-testid="button">Test</Button>
28
- </BaseStyling>
29
- </Fragment>
30
- );
31
-
32
- const button = await findByTestId("button");
33
- expect(button).toHaveStyle({ backgroundColor: "rgb(158, 0, 107);" });
34
- expect(container.querySelector("#child")).toBeDefined();
35
- });
36
- });
37
-
38
- describe("Should override default color", () => {
39
- it("overrides primary color", async () => {
40
- const { findByTestId } = render(
41
- <Fragment>
42
- <BaseStyling
43
- properties={{
44
- colorPrimary: "rgb(255, 255, 255);"
45
- }}
46
- >
47
- <Button data-testid="button">Test</Button>
48
- </BaseStyling>
49
- </Fragment>
50
- );
51
-
52
- const button = await findByTestId("button");
53
- expect(button).toHaveStyle({ backgroundColor: "rgb(255, 255, 255);" });
54
- });
55
- });
@@ -1,65 +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, { Fragment } from "react";
18
- import { render, fireEvent } from "@testing-library/react";
19
- import userEvent from "@testing-library/user-event";
20
- import { useAnimation } from "./useAnimation";
21
- import { act } from "react-dom/test-utils";
22
-
23
- describe("useAnimation", () => {
24
- it("should execute", async () => {
25
- const callback = jest.fn();
26
-
27
- const Component = () => {
28
- const { ref, animationStarted, startAnimation } = useAnimation<HTMLDivElement>(callback);
29
-
30
- return (
31
- <Fragment>
32
- <button data-testid="button" onClick={() => startAnimation()}>
33
- start animation
34
- </button>
35
- <div
36
- data-testid="animated-div"
37
- ref={ref}
38
- className={animationStarted ? "animation-started" : ""}
39
- >
40
- animated div
41
- </div>
42
- </Fragment>
43
- );
44
- };
45
-
46
- const { getByTestId } = render(<Component />);
47
-
48
- const animatedDiv = getByTestId("animated-div");
49
- const startButton = getByTestId("button");
50
-
51
- expect(animatedDiv).not.toHaveClass("animation-started");
52
- expect(callback).not.toBeCalled();
53
- await userEvent.click(startButton);
54
-
55
- expect(animatedDiv).toHaveClass("animation-started");
56
- expect(callback).not.toBeCalled();
57
-
58
- act(() => {
59
- fireEvent.animationEnd(animatedDiv);
60
- });
61
-
62
- expect(animatedDiv).toHaveClass("animation-started");
63
- expect(callback).toBeCalled();
64
- });
65
- });
@@ -1,55 +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, { Fragment, useState } from "react";
18
- import { useBodyClick } from "./useBodyClick";
19
- import { render } from "@testing-library/react";
20
- import userEvent from "@testing-library/user-event";
21
-
22
- describe("function should be executed", () => {
23
- it("should execute", async () => {
24
- const clickHandler = jest.fn();
25
- const validateFunction = jest.fn(() => true);
26
-
27
- const Component = () => {
28
- const [variable, setVariable] = useState(true);
29
- const [variable2, setvariable2] = useState(true);
30
- useBodyClick(validateFunction, clickHandler, [variable, variable2]);
31
-
32
- return (
33
- <Fragment>
34
- <button data-testid="button1" onClick={() => setVariable(!variable)}>
35
- Test
36
- </button>
37
- <button data-testid="button2" onClick={() => setvariable2(!variable2)}>
38
- Test
39
- </button>
40
- </Fragment>
41
- );
42
- };
43
-
44
- const { getByTestId } = render(<Component></Component>);
45
-
46
- const button1 = getByTestId("button1");
47
- const button2 = getByTestId("button2");
48
-
49
- await userEvent.click(button1);
50
- await userEvent.click(button2);
51
-
52
- expect(clickHandler).toHaveBeenCalledTimes(2);
53
- expect(validateFunction).toHaveBeenCalledTimes(2);
54
- });
55
- });
@@ -1,150 +0,0 @@
1
- import { renderHook, act } from "@testing-library/react";
2
- import { useDebouncedCallback } from "./useDebouncedCallback";
3
-
4
- const BASE_DELAY = 300;
5
- const EXTRA_DELAY = 200;
6
-
7
- const sleep = (delay: number) => new Promise(resolve => setTimeout(resolve, delay));
8
-
9
- describe("Testing the useDebouncedCallback hook", () => {
10
- it("should run callback after specified delay", async () => {
11
- const delay = BASE_DELAY;
12
- const callback = jest.fn();
13
-
14
- const { result } = renderHook(() => useDebouncedCallback(callback, delay));
15
-
16
- expect(callback).toHaveBeenCalledTimes(0);
17
- act(result.current);
18
- await sleep(delay + EXTRA_DELAY);
19
-
20
- expect(callback).toHaveBeenCalledTimes(1);
21
-
22
- act(result.current);
23
- await sleep(delay + EXTRA_DELAY);
24
-
25
- expect(callback).toHaveBeenCalledTimes(2);
26
- });
27
-
28
- it("should pass args through to callback function", async () => {
29
- let mutableValue = "";
30
- const delay = BASE_DELAY;
31
- const callback = jest.fn(arg => (mutableValue = `got arg ${arg}`));
32
-
33
- const { result } = renderHook(() => useDebouncedCallback(callback, delay));
34
-
35
- act(() => result.current("passthrough"));
36
- await sleep(delay + EXTRA_DELAY);
37
-
38
- expect(callback).toHaveBeenCalledTimes(1);
39
- expect(mutableValue).toBe(`got arg passthrough`);
40
- });
41
-
42
- it("should cancel pending call if fn is called again", async () => {
43
- const delay = BASE_DELAY;
44
- const callback = jest.fn();
45
-
46
- const { result } = renderHook(() => useDebouncedCallback(callback, delay));
47
-
48
- expect(callback).toHaveBeenCalledTimes(0);
49
- act(result.current);
50
- await sleep(delay / 2);
51
-
52
- act(result.current);
53
- await sleep(delay + EXTRA_DELAY);
54
-
55
- expect(callback).toHaveBeenCalledTimes(1);
56
- });
57
-
58
- it("should cancel pending call if callback changes", async () => {
59
- const delay = BASE_DELAY;
60
- const callback1 = jest.fn();
61
- const callback2 = jest.fn();
62
-
63
- const { result, rerender } = renderHook(
64
- ({ callback, delay }: { callback: () => unknown; delay: number }) =>
65
- useDebouncedCallback(callback, delay),
66
- { initialProps: { callback: callback1, delay } }
67
- );
68
-
69
- act(result.current);
70
- await sleep(delay / 2);
71
-
72
- rerender({ callback: callback2, delay });
73
- act(result.current);
74
- await sleep(delay + EXTRA_DELAY);
75
-
76
- expect(callback1).toHaveBeenCalledTimes(0);
77
- expect(callback2).toHaveBeenCalledTimes(1);
78
- });
79
-
80
- it("should cancel pending call if delay changes", async () => {
81
- const delay1 = BASE_DELAY;
82
- const delay2 = BASE_DELAY * 2;
83
- const callback = jest.fn();
84
-
85
- const { result, rerender } = renderHook(
86
- ({ callback, delay }: { callback: () => unknown; delay: number }) =>
87
- useDebouncedCallback(callback, delay),
88
- { initialProps: { callback, delay: delay1 } }
89
- );
90
-
91
- act(result.current);
92
- await sleep(delay1 / 2);
93
-
94
- rerender({ callback, delay: delay2 });
95
- act(result.current);
96
- await sleep(delay2 + EXTRA_DELAY);
97
-
98
- expect(callback).toHaveBeenCalledTimes(1);
99
- });
100
-
101
- it("should cancel pending call if dependencies change", async () => {
102
- const delay = BASE_DELAY;
103
- const callback = jest.fn();
104
-
105
- const { result, rerender } = renderHook(
106
- ({
107
- callback,
108
- delay,
109
- dependencies
110
- }: {
111
- callback: () => unknown;
112
- delay: number;
113
- dependencies: any[];
114
- }) => useDebouncedCallback(callback, delay, dependencies),
115
- { initialProps: { callback, delay, dependencies: ["a"] } }
116
- );
117
-
118
- act(result.current);
119
- await sleep(delay / 2);
120
-
121
- rerender({ callback, delay, dependencies: ["b"] });
122
- act(result.current);
123
- await sleep(delay + EXTRA_DELAY);
124
-
125
- expect(callback).toHaveBeenCalledTimes(1);
126
- });
127
-
128
- it("should support async callbacks", async () => {
129
- const makeAsyncCall = jest.fn(
130
- () =>
131
- new Promise(async resolve => {
132
- await sleep(delay / 2);
133
- resolve(null);
134
- })
135
- );
136
-
137
- const delay = BASE_DELAY;
138
- const callback = jest.fn(async () => {
139
- await makeAsyncCall();
140
- });
141
-
142
- const { result } = renderHook(() => useDebouncedCallback(callback, delay));
143
-
144
- await act(async () => result.current());
145
- await sleep(delay + EXTRA_DELAY);
146
-
147
- expect(callback).toHaveBeenCalledTimes(1);
148
- expect(makeAsyncCall).toHaveBeenCalledTimes(1);
149
- });
150
- });
@@ -1,28 +0,0 @@
1
- import { renderHook } from "@testing-library/react";
2
- import { useDetermineStatusIcon } from "./useDetermineStatusIcon";
3
-
4
- describe("it should return the correct icon", () => {
5
- it("should return an icon of type success", () => {
6
- const { result } = renderHook(useDetermineStatusIcon, {
7
- initialProps: { success: true, error: false }
8
- });
9
-
10
- expect(result.current).toBeDefined();
11
- expect(result.current?.props?.["data-icon-status"]).toEqual("success");
12
- });
13
-
14
- it("should return an icon of type error", () => {
15
- const { result } = renderHook(useDetermineStatusIcon, {
16
- initialProps: { success: true, error: true }
17
- });
18
-
19
- expect(result.current).toBeDefined();
20
- expect(result.current?.props?.["data-icon-status"]).toEqual("error");
21
- });
22
-
23
- it("should return null", () => {
24
- const { result } = renderHook(useDetermineStatusIcon);
25
-
26
- expect(result.current).toBeNull();
27
- });
28
- });
@@ -1,56 +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 { useFormSelector } from "./useFormSelector";
18
- import { renderHook } from "@testing-library/react";
19
-
20
- describe("we should get the correct return values and describedBy is the same as identifier", () => {
21
- it("should return correct values", () => {
22
- const { result } = renderHook(() =>
23
- useFormSelector({
24
- name: "test",
25
- errorMessage: "errormessage",
26
- error: false,
27
- parentErrorId: "parenterrorid",
28
- helperText: "helpertext",
29
- parentHelperId: "parenthelperid"
30
- })
31
- );
32
-
33
- expect(result.current.describedBy).toHaveLength(15);
34
- expect(result.current.errorId).toHaveLength(15);
35
- expect(result.current.identifier).toHaveLength(15);
36
-
37
- expect(result.current.describedBy).toBe(result.current.identifier);
38
- });
39
- });
40
-
41
- describe("describedBy should be the parenterrorid", () => {
42
- it("should be linked correctly", () => {
43
- const { result } = renderHook(() =>
44
- useFormSelector({
45
- name: "test",
46
- errorMessage: "errormessage",
47
- error: true,
48
- parentErrorId: "parenterrorid",
49
- helperText: "helpertext",
50
- parentHelperId: "parenthelperid"
51
- })
52
- );
53
-
54
- expect(result.current.describedBy).toBe("parenterrorid");
55
- });
56
- });