@onewelcome/react-lib-components 5.2.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 (255) hide show
  1. package/dist/cjs/Button/BaseButton.cjs.js.map +1 -1
  2. package/dist/cjs/Button/BaseButton.module.cjs.js +1 -1
  3. package/dist/cjs/Button/Button.module.cjs.js +1 -1
  4. package/dist/cjs/Button/IconButton.module.cjs.js +1 -1
  5. package/dist/cjs/ContextMenu/ContextMenu.cjs.js +1 -1
  6. package/dist/cjs/ContextMenu/ContextMenu.cjs.js.map +1 -1
  7. package/dist/cjs/ContextMenu/ContextMenuItem.module.cjs.js +1 -1
  8. package/dist/cjs/ContextMenu/ContextMenuService.cjs.js +1 -1
  9. package/dist/cjs/ContextMenu/ContextMenuService.cjs.js.map +1 -1
  10. package/dist/cjs/DataGrid/DataGridActions/DataGridColumnsToggle.module.cjs.js +1 -1
  11. package/dist/cjs/Form/Input/Input.module.cjs.js +1 -1
  12. package/dist/cjs/Form/Select/Option.cjs.js +1 -1
  13. package/dist/cjs/Form/Select/Option.cjs.js.map +1 -1
  14. package/dist/cjs/Form/Select/Select.cjs.js +1 -1
  15. package/dist/cjs/Form/Select/Select.cjs.js.map +1 -1
  16. package/dist/cjs/Form/Select/Select.module.cjs.js +1 -1
  17. package/dist/cjs/Form/Select/SelectService.cjs.js +1 -1
  18. package/dist/cjs/Form/Select/SelectService.cjs.js.map +1 -1
  19. package/dist/cjs/Form/Textarea/Textarea.module.cjs.js +1 -1
  20. package/dist/cjs/Icon/Icon.cjs.js +1 -1
  21. package/dist/cjs/Icon/Icon.cjs.js.map +1 -1
  22. package/dist/cjs/Icon/Icon.module.cjs.js +1 -1
  23. package/dist/cjs/Link/Link.cjs.js.map +1 -1
  24. package/dist/cjs/Link/Link.module.cjs.js +1 -1
  25. package/dist/cjs/Notifications/BaseModal/BaseModal.module.cjs.js +1 -1
  26. package/dist/cjs/Notifications/SlideInModal/SlideInModal.module.cjs.js +1 -1
  27. package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.cjs.js +1 -1
  28. package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.cjs.js.map +1 -1
  29. package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.cjs.js +1 -1
  30. package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.cjs.js +1 -1
  31. package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.cjs.js.map +1 -1
  32. package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.cjs.js.map +1 -1
  33. package/dist/cjs/Notifications/Snackbar/interfaces.cjs.js +2 -0
  34. package/dist/cjs/Notifications/Snackbar/interfaces.cjs.js.map +1 -0
  35. package/dist/cjs/Popover/Popover.cjs.js +1 -1
  36. package/dist/cjs/Popover/Popover.cjs.js.map +1 -1
  37. package/dist/cjs/Popover/Popover.module.cjs.js +1 -1
  38. package/dist/cjs/Stepper/Step.cjs.js +1 -1
  39. package/dist/cjs/Stepper/Step.cjs.js.map +1 -1
  40. package/dist/cjs/Stepper/Step.module.cjs.js +1 -1
  41. package/dist/cjs/Stepper/Stepper.cjs.js +1 -1
  42. package/dist/cjs/Stepper/Stepper.cjs.js.map +1 -1
  43. package/dist/cjs/Tabs/TabButton.module.cjs.js +1 -1
  44. package/dist/cjs/TextEllipsis/TextEllipsis.module.cjs.js +1 -1
  45. package/dist/cjs/Tiles/Tile.module.cjs.js +1 -1
  46. package/dist/cjs/Tooltip/Tooltip.module.cjs.js +1 -1
  47. package/dist/cjs/Wizard/BaseWizardSteps/BaseWizardSteps.module.cjs.js +1 -1
  48. package/dist/cjs/_BaseStyling_/BaseStyling.cjs.js +1 -1
  49. package/dist/cjs/_BaseStyling_/BaseStyling.cjs.js.map +1 -1
  50. package/dist/cjs/src/.scope.d.ts +2 -0
  51. package/dist/cjs/src/components/Button/BaseButton.d.ts +1 -1
  52. package/dist/cjs/src/components/ContextMenu/ContextMenu.d.ts +1 -1
  53. package/dist/cjs/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
  54. package/dist/cjs/src/components/Form/Select/Option.d.ts +1 -0
  55. package/dist/cjs/src/components/Form/Select/Select.d.ts +20 -0
  56. package/dist/cjs/src/components/Form/Select/Select.interfaces.d.ts +3 -1
  57. package/dist/cjs/src/components/Form/Select/Select.test.d.ts +63 -1
  58. package/dist/cjs/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
  59. package/dist/cjs/src/components/Form/Select/SelectService.d.ts +3 -2
  60. package/dist/cjs/src/components/Icon/Icon.d.ts +4 -1
  61. package/dist/cjs/src/components/Link/Link.d.ts +1 -1
  62. package/dist/cjs/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +5 -5
  63. package/dist/cjs/src/components/Notifications/Snackbar/interfaces.d.ts +6 -0
  64. package/dist/cjs/src/components/Notifications/Snackbar/useSnackbar.d.ts +4 -4
  65. package/dist/cjs/src/components/Notifications/Snackbar/useSnackbar.test.d.ts +1 -0
  66. package/dist/cjs/src/components/Stepper/Stepper.d.ts +0 -1
  67. package/dist/cjs/src/components/_BaseStyling_/BaseStyling.d.ts +11 -10
  68. package/dist/cjs/src/hooks/usePosition.cjs.js.map +1 -1
  69. package/dist/cjs/src/hooks/usePosition.d.ts +1 -1
  70. package/dist/esm/Button/BaseButton.esm.js.map +1 -1
  71. package/dist/esm/Button/BaseButton.module.esm.js +1 -1
  72. package/dist/esm/Button/Button.module.esm.js +1 -1
  73. package/dist/esm/Button/IconButton.module.esm.js +1 -1
  74. package/dist/esm/ContextMenu/ContextMenu.esm.js +1 -1
  75. package/dist/esm/ContextMenu/ContextMenu.esm.js.map +1 -1
  76. package/dist/esm/ContextMenu/ContextMenuItem.module.esm.js +1 -1
  77. package/dist/esm/ContextMenu/ContextMenuService.esm.js +1 -1
  78. package/dist/esm/ContextMenu/ContextMenuService.esm.js.map +1 -1
  79. package/dist/esm/DataGrid/DataGridActions/DataGridColumnsToggle.module.esm.js +1 -1
  80. package/dist/esm/Form/Input/Input.module.esm.js +1 -1
  81. package/dist/esm/Form/Select/Option.esm.js +1 -1
  82. package/dist/esm/Form/Select/Option.esm.js.map +1 -1
  83. package/dist/esm/Form/Select/Select.esm.js +1 -1
  84. package/dist/esm/Form/Select/Select.esm.js.map +1 -1
  85. package/dist/esm/Form/Select/Select.module.esm.js +1 -1
  86. package/dist/esm/Form/Select/SelectService.esm.js +1 -1
  87. package/dist/esm/Form/Select/SelectService.esm.js.map +1 -1
  88. package/dist/esm/Form/Textarea/Textarea.module.esm.js +1 -1
  89. package/dist/esm/Icon/Icon.esm.js +1 -1
  90. package/dist/esm/Icon/Icon.esm.js.map +1 -1
  91. package/dist/esm/Icon/Icon.module.esm.js +1 -1
  92. package/dist/esm/Link/Link.esm.js.map +1 -1
  93. package/dist/esm/Link/Link.module.esm.js +1 -1
  94. package/dist/esm/Notifications/BaseModal/BaseModal.module.esm.js +1 -1
  95. package/dist/esm/Notifications/SlideInModal/SlideInModal.module.esm.js +1 -1
  96. package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.esm.js +1 -1
  97. package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.esm.js.map +1 -1
  98. package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.esm.js +1 -1
  99. package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.esm.js +1 -1
  100. package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.esm.js.map +1 -1
  101. package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.esm.js.map +1 -1
  102. package/dist/esm/Notifications/Snackbar/interfaces.esm.js +2 -0
  103. package/dist/esm/Notifications/Snackbar/interfaces.esm.js.map +1 -0
  104. package/dist/esm/Popover/Popover.esm.js +1 -1
  105. package/dist/esm/Popover/Popover.esm.js.map +1 -1
  106. package/dist/esm/Popover/Popover.module.esm.js +1 -1
  107. package/dist/esm/Stepper/Step.esm.js +1 -1
  108. package/dist/esm/Stepper/Step.esm.js.map +1 -1
  109. package/dist/esm/Stepper/Step.module.esm.js +1 -1
  110. package/dist/esm/Stepper/Stepper.esm.js +1 -1
  111. package/dist/esm/Stepper/Stepper.esm.js.map +1 -1
  112. package/dist/esm/Tabs/TabButton.module.esm.js +1 -1
  113. package/dist/esm/TextEllipsis/TextEllipsis.module.esm.js +1 -1
  114. package/dist/esm/Tiles/Tile.module.esm.js +1 -1
  115. package/dist/esm/Tooltip/Tooltip.module.esm.js +1 -1
  116. package/dist/esm/Wizard/BaseWizardSteps/BaseWizardSteps.module.esm.js +1 -1
  117. package/dist/esm/_BaseStyling_/BaseStyling.esm.js +1 -1
  118. package/dist/esm/_BaseStyling_/BaseStyling.esm.js.map +1 -1
  119. package/dist/esm/src/.scope.d.ts +2 -0
  120. package/dist/esm/src/components/Button/BaseButton.d.ts +1 -1
  121. package/dist/esm/src/components/ContextMenu/ContextMenu.d.ts +1 -1
  122. package/dist/esm/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
  123. package/dist/esm/src/components/Form/Select/Option.d.ts +1 -0
  124. package/dist/esm/src/components/Form/Select/Select.d.ts +20 -0
  125. package/dist/esm/src/components/Form/Select/Select.interfaces.d.ts +3 -1
  126. package/dist/esm/src/components/Form/Select/Select.test.d.ts +63 -1
  127. package/dist/esm/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
  128. package/dist/esm/src/components/Form/Select/SelectService.d.ts +3 -2
  129. package/dist/esm/src/components/Icon/Icon.d.ts +4 -1
  130. package/dist/esm/src/components/Link/Link.d.ts +1 -1
  131. package/dist/esm/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +5 -5
  132. package/dist/esm/src/components/Notifications/Snackbar/interfaces.d.ts +6 -0
  133. package/dist/esm/src/components/Notifications/Snackbar/useSnackbar.d.ts +4 -4
  134. package/dist/esm/src/components/Notifications/Snackbar/useSnackbar.test.d.ts +1 -0
  135. package/dist/esm/src/components/Stepper/Stepper.d.ts +0 -1
  136. package/dist/esm/src/components/_BaseStyling_/BaseStyling.d.ts +11 -10
  137. package/dist/esm/src/hooks/usePosition.d.ts +1 -1
  138. package/dist/esm/src/hooks/usePosition.esm.js.map +1 -1
  139. package/package.json +48 -45
  140. package/src/{hooks/useWrapper.test.ts → .scope.ts} +1 -12
  141. package/src/components/Button/BaseButton.tsx +1 -1
  142. package/src/components/Button/Button.module.scss +2 -10
  143. package/src/components/ContextMenu/ContextMenu.tsx +13 -23
  144. package/src/components/ContextMenu/ContextMenuService.ts +47 -1
  145. package/src/components/Form/Select/Option.tsx +3 -1
  146. package/src/components/Form/Select/Select.interfaces.ts +3 -1
  147. package/src/components/Form/Select/Select.module.scss +55 -34
  148. package/src/components/Form/Select/Select.tsx +74 -23
  149. package/src/components/Form/Select/SelectService.ts +26 -10
  150. package/src/components/Icon/Icon.module.scss +12 -0
  151. package/src/components/Icon/Icon.tsx +4 -1
  152. package/src/components/Link/Link.module.scss +28 -4
  153. package/src/components/Link/Link.tsx +1 -1
  154. package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +14 -21
  155. package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +17 -13
  156. package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +43 -17
  157. package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +5 -13
  158. package/src/components/Notifications/Snackbar/interfaces.ts +15 -0
  159. package/src/components/Popover/Popover.tsx +19 -2
  160. package/src/components/Stepper/Step.tsx +2 -1
  161. package/src/components/Stepper/Stepper.tsx +0 -2
  162. package/src/components/Tooltip/Tooltip.module.scss +1 -0
  163. package/src/components/_BaseStyling_/BaseStyling.tsx +24 -22
  164. package/src/font/icomoon.eot +0 -0
  165. package/src/font/icomoon.svg +5 -2
  166. package/src/font/icomoon.ttf +0 -0
  167. package/src/font/icomoon.woff +0 -0
  168. package/src/font/selection.json +1 -1
  169. package/src/hooks/usePosition.ts +1 -1
  170. package/src/interfaces.ts +2 -2
  171. package/src/mixins.module.scss +60 -61
  172. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -64
  173. package/src/components/Button/BaseButton.test.tsx +0 -133
  174. package/src/components/Button/Button.test.tsx +0 -138
  175. package/src/components/Button/IconButton.test.tsx +0 -122
  176. package/src/components/ContextMenu/ContextMenu.test.tsx +0 -358
  177. package/src/components/DataGrid/DataGrid.test.tsx +0 -437
  178. package/src/components/DataGrid/DataGridActions/DataGridActions.test.tsx +0 -204
  179. package/src/components/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +0 -99
  180. package/src/components/DataGrid/DataGridBody/DataGridBody.test.tsx +0 -140
  181. package/src/components/DataGrid/DataGridBody/DataGridCell.test.tsx +0 -90
  182. package/src/components/DataGrid/DataGridBody/DataGridRow.test.tsx +0 -117
  183. package/src/components/DataGrid/DataGridHeader/DataGridHeader.test.tsx +0 -276
  184. package/src/components/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +0 -144
  185. package/src/components/Form/Checkbox/Checkbox.test.tsx +0 -308
  186. package/src/components/Form/Fieldset/Fieldset.test.tsx +0 -127
  187. package/src/components/Form/FileUpload/FileItem/FileItem.test.tsx +0 -103
  188. package/src/components/Form/FileUpload/FileUpload.test.tsx +0 -374
  189. package/src/components/Form/Form.test.tsx +0 -63
  190. package/src/components/Form/FormControl/FormControl.test.tsx +0 -98
  191. package/src/components/Form/FormGroup/FormGroup.test.tsx +0 -127
  192. package/src/components/Form/FormHelperText/FormHelperText.test.tsx +0 -84
  193. package/src/components/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +0 -94
  194. package/src/components/Form/Input/Input.test.tsx +0 -267
  195. package/src/components/Form/Label/Label.test.tsx +0 -68
  196. package/src/components/Form/Radio/Radio.test.tsx +0 -130
  197. package/src/components/Form/Select/Option.test.tsx +0 -57
  198. package/src/components/Form/Select/Select.test.tsx +0 -564
  199. package/src/components/Form/Textarea/Textarea.test.tsx +0 -124
  200. package/src/components/Form/Toggle/Toggle.test.tsx +0 -200
  201. package/src/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +0 -141
  202. package/src/components/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +0 -211
  203. package/src/components/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +0 -117
  204. package/src/components/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +0 -186
  205. package/src/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +0 -173
  206. package/src/components/Form/Wrapper/Wrapper/Wrapper.test.tsx +0 -59
  207. package/src/components/Icon/Icon.test.tsx +0 -83
  208. package/src/components/Link/Link.test.tsx +0 -197
  209. package/src/components/Notifications/Banner/Banner.test.tsx +0 -84
  210. package/src/components/Notifications/BaseModal/BaseModal.test.tsx +0 -194
  211. package/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +0 -74
  212. package/src/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +0 -71
  213. package/src/components/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +0 -74
  214. package/src/components/Notifications/Dialog/Dialog.test.tsx +0 -118
  215. package/src/components/Notifications/Dialog/DialogActions/DialogActions.test.tsx +0 -61
  216. package/src/components/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +0 -87
  217. package/src/components/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +0 -111
  218. package/src/components/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +0 -175
  219. package/src/components/Notifications/Modal/Modal.test.tsx +0 -18
  220. package/src/components/Notifications/NotificationProvider/NotificationContext.test.tsx +0 -449
  221. package/src/components/Notifications/SlideInModal/SlideInModal.test.tsx +0 -90
  222. package/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +0 -53
  223. package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +0 -63
  224. package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +0 -215
  225. package/src/components/Pagination/Pagination.test.tsx +0 -183
  226. package/src/components/Popover/Popover.test.tsx +0 -103
  227. package/src/components/ProgressBar/ProgressBar.test.tsx +0 -91
  228. package/src/components/Skeleton/Skeleton.test.tsx +0 -112
  229. package/src/components/StatusIndicator/StatusIndicator.test.tsx +0 -143
  230. package/src/components/Stepper/Stepper.test.tsx +0 -83
  231. package/src/components/Tabs/Tab.test.tsx +0 -49
  232. package/src/components/Tabs/TabButton.test.tsx +0 -65
  233. package/src/components/Tabs/Tabs.test.tsx +0 -291
  234. package/src/components/Tag/Tag.test.tsx +0 -89
  235. package/src/components/TextEllipsis/TextEllipsis.test.tsx +0 -96
  236. package/src/components/Tiles/Tile.test.tsx +0 -183
  237. package/src/components/Tiles/Tiles.test.tsx +0 -162
  238. package/src/components/Tooltip/Tooltip.test.tsx +0 -390
  239. package/src/components/Typography/Typography.test.tsx +0 -177
  240. package/src/components/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +0 -90
  241. package/src/components/Wizard/Wizard.test.tsx +0 -218
  242. package/src/components/Wizard/WizardActions/WizardActions.test.tsx +0 -187
  243. package/src/components/Wizard/WizardSteps/WizardSteps.test.tsx +0 -125
  244. package/src/components/_BaseStyling_/BaseStyling.test.tsx +0 -55
  245. package/src/hooks/useAnimation.test.tsx +0 -65
  246. package/src/hooks/useBodyClick.test.tsx +0 -55
  247. package/src/hooks/useDebouncedCallback.test.ts +0 -150
  248. package/src/hooks/useDetermineStatusIcon.test.ts +0 -28
  249. package/src/hooks/useFormSelector.test.ts +0 -56
  250. package/src/hooks/usePosition.test.tsx +0 -510
  251. package/src/hooks/useRepeater.test.tsx +0 -156
  252. package/src/hooks/useScroll.test.tsx +0 -36
  253. package/src/hooks/useSpacing.test.ts +0 -86
  254. package/src/hooks/useUploadFile.test.ts +0 -211
  255. package/src/util/helper.test.tsx +0 -403
@@ -1,403 +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, { useCallback, useEffect, useState } from "react";
18
- import { fireEvent, waitFor } from "@testing-library/dom";
19
- import {
20
- debounce,
21
- filterProps,
22
- generateID,
23
- remToPx,
24
- throttle,
25
- areArraysDifferent,
26
- getValueByPath,
27
- isEqual,
28
- isJsonString,
29
- deepMerge
30
- } from "./helper";
31
- import { render } from "@testing-library/react";
32
- import { act } from "react-dom/test-utils";
33
-
34
- /* Generate an ID of 20 characters with a string woven in */
35
-
36
- describe("generateID should correctly generate IDs in the correct way", () => {
37
- it("generates an ID of length 20 with a string woven in", () => {
38
- const ID1 = generateID(20, "thistestingstring");
39
- expect(ID1.length).toBe(20);
40
- });
41
-
42
- it("genereates an ID without a string woven in", () => {
43
- const ID2 = generateID(20);
44
- expect(ID2.length).toBe(20);
45
- });
46
- });
47
-
48
- describe("filterprops should return the correct object", () => {
49
- it("gives back the props we told it to filter", () => {
50
- const propsObject = {
51
- "data-filter": true,
52
- "data-test": false,
53
- "aria-hidden": false,
54
- "aria-expanded": true,
55
- title: "test",
56
- className: "example-classname"
57
- };
58
-
59
- const returnedPropsObject = filterProps(propsObject, /^data-/);
60
-
61
- expect(returnedPropsObject).toStrictEqual({ "data-filter": true, "data-test": false });
62
- });
63
-
64
- it("gives back the propsObject without the props we told it to filter", () => {
65
- const propsObject = {
66
- "data-filter": true,
67
- "data-test": false,
68
- "aria-hidden": false,
69
- "aria-expanded": true,
70
- title: "test",
71
- className: "example-classname"
72
- };
73
-
74
- const returnedPropsObject = filterProps(propsObject, /^data-/, false);
75
-
76
- expect(returnedPropsObject).toStrictEqual({
77
- "aria-hidden": false,
78
- "aria-expanded": true,
79
- title: "test",
80
- className: "example-classname"
81
- });
82
- });
83
- });
84
-
85
- describe("debounce function", () => {
86
- it("debounced the resizing of the window, it will only execute 1 time", async () => {
87
- const debouncedFunction = jest.fn();
88
-
89
- window.addEventListener("resize", debounce(debouncedFunction, 200));
90
-
91
- act(() => {
92
- fireEvent.resize(window);
93
- fireEvent.resize(window);
94
- fireEvent.resize(window);
95
- fireEvent.resize(window);
96
- fireEvent.resize(window);
97
- });
98
-
99
- await waitFor(() => expect(debouncedFunction).toHaveBeenCalledTimes(1));
100
- });
101
-
102
- it("Works in a react component as well, it should only fire the exampleFunction once.", async () => {
103
- const ExampleComponent = ({
104
- debouncedFunction
105
- }: {
106
- debouncedFunction: (...args: unknown[]) => unknown;
107
- }) => {
108
- const [variable, setVariable] = useState(0);
109
-
110
- useEffect(() => {
111
- debouncedFunction(variable);
112
- }, [variable]);
113
-
114
- const incrementVariable = () => {
115
- act(() => {
116
- setVariable(Math.random());
117
- });
118
- };
119
-
120
- useEffect(() => {
121
- window.addEventListener("resize", debounce(incrementVariable, 200));
122
- }, []);
123
-
124
- return null;
125
- };
126
-
127
- const exampleFunction = jest.fn();
128
-
129
- render(<ExampleComponent debouncedFunction={exampleFunction} />);
130
-
131
- act(() => {
132
- fireEvent.resize(window);
133
- fireEvent.resize(window);
134
- fireEvent.resize(window);
135
- fireEvent.resize(window);
136
- fireEvent.resize(window);
137
- });
138
-
139
- expect(exampleFunction).toHaveBeenCalledTimes(1);
140
- });
141
- });
142
-
143
- describe("throttling works", () => {
144
- it("Works in a react component as well, it should only fire the exampleFunction once.", async () => {
145
- const ExampleComponent = ({
146
- throttledFunction
147
- }: {
148
- throttledFunction: (...args: unknown[]) => unknown;
149
- }) => {
150
- const [variable, setVariable] = useState(0);
151
-
152
- useEffect(() => {
153
- throttledFunction(variable);
154
- }, [variable]);
155
-
156
- const incrementVariable = useCallback(() => {
157
- act(() => {
158
- setVariable(Math.random());
159
- });
160
- }, []);
161
-
162
- useEffect(() => {
163
- window.addEventListener("resize", throttle(incrementVariable, 1));
164
- }, []);
165
-
166
- return null;
167
- };
168
-
169
- const exampleFunction = jest.fn();
170
-
171
- render(<ExampleComponent throttledFunction={exampleFunction} />);
172
-
173
- act(() => {
174
- fireEvent.resize(window);
175
- fireEvent.resize(window);
176
- fireEvent.resize(window);
177
- fireEvent.resize(window);
178
- fireEvent.resize(window);
179
- fireEvent.resize(window);
180
- fireEvent.resize(window);
181
- fireEvent.resize(window);
182
- fireEvent.resize(window);
183
- fireEvent.resize(window);
184
- });
185
-
186
- expect(exampleFunction).not.toHaveBeenCalledTimes(1);
187
- expect(exampleFunction).not.toHaveBeenCalledTimes(10);
188
- });
189
- });
190
-
191
- describe("areArraysDifferent works as expected", () => {
192
- it("should return true for different arrays", () => {
193
- const arr1 = [
194
- {
195
- name: "test1"
196
- },
197
- {
198
- name: "test2"
199
- }
200
- ];
201
-
202
- const arr2 = [
203
- {
204
- name: "test1"
205
- },
206
- {
207
- name: "test3"
208
- }
209
- ];
210
-
211
- const result = areArraysDifferent(arr1, arr2, "name");
212
- expect(result).toBe(true);
213
- });
214
-
215
- it("should return false for arrays with same values", () => {
216
- const arr1 = [
217
- {
218
- name: "test1"
219
- }
220
- ];
221
-
222
- const arr2 = [
223
- {
224
- name: "test1"
225
- }
226
- ];
227
-
228
- const result = areArraysDifferent(arr1, arr2, "name");
229
- expect(result).toBe(false);
230
- });
231
-
232
- it("should return false for falsy values", () => {
233
- const arr1 = [
234
- {
235
- name: "test1"
236
- }
237
- ];
238
-
239
- const arr2 = [
240
- {
241
- label: "test1"
242
- }
243
- ];
244
-
245
- const result = areArraysDifferent(arr1, arr2, "name");
246
- expect(result).toBe(true);
247
- });
248
- });
249
-
250
- describe("return correct values from getValueByPath", () => {
251
- it("should return the correct value form a multi layered object", () => {
252
- const val = "test";
253
- const obj = {
254
- firstNode: {
255
- secondNode: {
256
- thirdNode: {
257
- val
258
- }
259
- }
260
- }
261
- };
262
-
263
- const result = getValueByPath(obj, "firstNode.secondNode.thirdNode.val");
264
- expect(result).toBe(val);
265
- });
266
- });
267
-
268
- describe("verifies if isEqual returns the correct value", () => {
269
- it("should return true for equal values objects", () => {
270
- const obj1 = {
271
- name1: "test1",
272
- name2: {
273
- val: "test2"
274
- }
275
- };
276
-
277
- const obj2 = {
278
- name1: "test1",
279
- name2: {
280
- val: "test2"
281
- }
282
- };
283
-
284
- const res = isEqual(obj1, obj2);
285
- expect(res).toBe(true);
286
- });
287
-
288
- it("should return false for unequal values objects", () => {
289
- const obj1 = {
290
- name1: "test1",
291
- name2: {
292
- val: "test2"
293
- }
294
- };
295
-
296
- const obj2 = {
297
- name1: "test1"
298
- };
299
-
300
- const res = isEqual(obj1, obj2);
301
- expect(res).toBe(false);
302
- });
303
-
304
- it("should return false for falsy values", () => {
305
- const obj1 = {
306
- name1: "test1",
307
- name2: {
308
- val: "test2"
309
- }
310
- };
311
- const obj2 = null;
312
-
313
- const res = isEqual(obj1, obj2);
314
- expect(res).toBe(false);
315
- });
316
-
317
- it("should return false for different types", () => {
318
- const obj1 = [
319
- {
320
- name1: "test1",
321
- name2: {
322
- val: "test2"
323
- }
324
- }
325
- ];
326
- const obj2 = {
327
- name1: "test1",
328
- name2: {
329
- val: "test2"
330
- }
331
- };
332
-
333
- const res = isEqual(obj1, obj2);
334
- expect(res).toBe(false);
335
- });
336
- });
337
-
338
- describe("pixel to rem function works", () => {
339
- document.documentElement.style.setProperty("font-size", "16px");
340
-
341
- it.each([
342
- [1, 16],
343
- [1.25, 20],
344
- [1.5, 24],
345
- [1.75, 28],
346
- [2, 32]
347
- ])("%p rem equals %p px when font-size is 16px", async (rem: number, px: number) => {
348
- const result = remToPx(rem);
349
-
350
- expect(result).toBe(px);
351
- });
352
- });
353
-
354
- describe("isJsonString should work", () => {
355
- it("should return true when parameter is a valid JSON string", () => {
356
- const param = JSON.stringify({ test: 1 });
357
-
358
- expect(isJsonString(param)).toEqual(true);
359
- });
360
-
361
- it("should return false when parameter is a valid JSON string", () => {
362
- const param = { test: 2 };
363
-
364
- expect(isJsonString(param)).toEqual(false);
365
- });
366
- });
367
-
368
- describe("deepMerge function", () => {
369
- it("should return the first object if the second one is falsy", () => {
370
- const obj1 = { a: 1 };
371
- const obj2 = false;
372
-
373
- expect(deepMerge(obj1, obj2)).toEqual({ a: 1 });
374
- });
375
-
376
- it("should return a merged object with no nested object", () => {
377
- const obj1 = { a: 1, b: 2 };
378
- const obj2 = { b: 3, c: 4 };
379
-
380
- expect(deepMerge(obj1, obj2)).toEqual({ a: 1, b: 3, c: 4 });
381
- });
382
-
383
- it("should return a merged object with nested object", () => {
384
- const obj1 = { a: 1, b: { x: 1, y: 2 } };
385
- const obj2 = { b: { y: 3, z: 4 }, c: 4 };
386
-
387
- expect(deepMerge(obj1, obj2)).toEqual({ a: 1, b: { x: 1, y: 3, z: 4 }, c: 4 });
388
- });
389
-
390
- it("should replace non-object values in the first object with values in the second object", () => {
391
- const obj1 = { a: 1, b: 2 };
392
- const obj2 = { b: { y: 3, z: 4 }, c: 4 };
393
-
394
- expect(deepMerge(obj1, obj2)).toEqual({ a: 1, b: { y: 3, z: 4 }, c: 4 });
395
- });
396
-
397
- it("should not merge array values but replace them", () => {
398
- const obj1 = { a: 1, b: [1, 2] };
399
- const obj2 = { b: [3, 4], c: 4 };
400
-
401
- expect(deepMerge(obj1, obj2)).toEqual({ a: 1, b: [3, 4], c: 4 });
402
- });
403
- });