@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.
- package/dist/cjs/Button/BaseButton.cjs.js.map +1 -1
- package/dist/cjs/Button/BaseButton.module.cjs.js +1 -1
- package/dist/cjs/Button/Button.module.cjs.js +1 -1
- package/dist/cjs/Button/IconButton.module.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenu.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenu.cjs.js.map +1 -1
- package/dist/cjs/ContextMenu/ContextMenuItem.module.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenuService.cjs.js +1 -1
- package/dist/cjs/ContextMenu/ContextMenuService.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridActions/DataGridColumnsToggle.module.cjs.js +1 -1
- package/dist/cjs/Form/Input/Input.module.cjs.js +1 -1
- package/dist/cjs/Form/Select/Option.cjs.js +1 -1
- package/dist/cjs/Form/Select/Option.cjs.js.map +1 -1
- package/dist/cjs/Form/Select/Select.cjs.js +1 -1
- package/dist/cjs/Form/Select/Select.cjs.js.map +1 -1
- package/dist/cjs/Form/Select/Select.module.cjs.js +1 -1
- package/dist/cjs/Form/Select/SelectService.cjs.js +1 -1
- package/dist/cjs/Form/Select/SelectService.cjs.js.map +1 -1
- package/dist/cjs/Form/Textarea/Textarea.module.cjs.js +1 -1
- package/dist/cjs/Icon/Icon.cjs.js +1 -1
- package/dist/cjs/Icon/Icon.cjs.js.map +1 -1
- package/dist/cjs/Icon/Icon.module.cjs.js +1 -1
- package/dist/cjs/Link/Link.cjs.js.map +1 -1
- package/dist/cjs/Link/Link.module.cjs.js +1 -1
- package/dist/cjs/Notifications/BaseModal/BaseModal.module.cjs.js +1 -1
- package/dist/cjs/Notifications/SlideInModal/SlideInModal.module.cjs.js +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.cjs.js +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.cjs.js +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.cjs.js +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.cjs.js.map +1 -1
- package/dist/cjs/Notifications/Snackbar/interfaces.cjs.js +2 -0
- package/dist/cjs/Notifications/Snackbar/interfaces.cjs.js.map +1 -0
- package/dist/cjs/Popover/Popover.cjs.js +1 -1
- package/dist/cjs/Popover/Popover.cjs.js.map +1 -1
- package/dist/cjs/Popover/Popover.module.cjs.js +1 -1
- package/dist/cjs/Stepper/Step.cjs.js +1 -1
- package/dist/cjs/Stepper/Step.cjs.js.map +1 -1
- package/dist/cjs/Stepper/Step.module.cjs.js +1 -1
- package/dist/cjs/Stepper/Stepper.cjs.js +1 -1
- package/dist/cjs/Stepper/Stepper.cjs.js.map +1 -1
- package/dist/cjs/Tabs/TabButton.module.cjs.js +1 -1
- package/dist/cjs/TextEllipsis/TextEllipsis.module.cjs.js +1 -1
- package/dist/cjs/Tiles/Tile.module.cjs.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.module.cjs.js +1 -1
- package/dist/cjs/Wizard/BaseWizardSteps/BaseWizardSteps.module.cjs.js +1 -1
- package/dist/cjs/_BaseStyling_/BaseStyling.cjs.js +1 -1
- package/dist/cjs/_BaseStyling_/BaseStyling.cjs.js.map +1 -1
- package/dist/cjs/src/.scope.d.ts +2 -0
- package/dist/cjs/src/components/Button/BaseButton.d.ts +1 -1
- package/dist/cjs/src/components/ContextMenu/ContextMenu.d.ts +1 -1
- package/dist/cjs/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
- package/dist/cjs/src/components/Form/Select/Option.d.ts +1 -0
- package/dist/cjs/src/components/Form/Select/Select.d.ts +20 -0
- package/dist/cjs/src/components/Form/Select/Select.interfaces.d.ts +3 -1
- package/dist/cjs/src/components/Form/Select/Select.test.d.ts +63 -1
- package/dist/cjs/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
- package/dist/cjs/src/components/Form/Select/SelectService.d.ts +3 -2
- package/dist/cjs/src/components/Icon/Icon.d.ts +4 -1
- package/dist/cjs/src/components/Link/Link.d.ts +1 -1
- package/dist/cjs/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +5 -5
- package/dist/cjs/src/components/Notifications/Snackbar/interfaces.d.ts +6 -0
- package/dist/cjs/src/components/Notifications/Snackbar/useSnackbar.d.ts +4 -4
- package/dist/cjs/src/components/Notifications/Snackbar/useSnackbar.test.d.ts +1 -0
- package/dist/cjs/src/components/Stepper/Stepper.d.ts +0 -1
- package/dist/cjs/src/components/_BaseStyling_/BaseStyling.d.ts +11 -10
- package/dist/cjs/src/hooks/usePosition.cjs.js.map +1 -1
- package/dist/cjs/src/hooks/usePosition.d.ts +1 -1
- package/dist/esm/Button/BaseButton.esm.js.map +1 -1
- package/dist/esm/Button/BaseButton.module.esm.js +1 -1
- package/dist/esm/Button/Button.module.esm.js +1 -1
- package/dist/esm/Button/IconButton.module.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenu.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenu.esm.js.map +1 -1
- package/dist/esm/ContextMenu/ContextMenuItem.module.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenuService.esm.js +1 -1
- package/dist/esm/ContextMenu/ContextMenuService.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridActions/DataGridColumnsToggle.module.esm.js +1 -1
- package/dist/esm/Form/Input/Input.module.esm.js +1 -1
- package/dist/esm/Form/Select/Option.esm.js +1 -1
- package/dist/esm/Form/Select/Option.esm.js.map +1 -1
- package/dist/esm/Form/Select/Select.esm.js +1 -1
- package/dist/esm/Form/Select/Select.esm.js.map +1 -1
- package/dist/esm/Form/Select/Select.module.esm.js +1 -1
- package/dist/esm/Form/Select/SelectService.esm.js +1 -1
- package/dist/esm/Form/Select/SelectService.esm.js.map +1 -1
- package/dist/esm/Form/Textarea/Textarea.module.esm.js +1 -1
- package/dist/esm/Icon/Icon.esm.js +1 -1
- package/dist/esm/Icon/Icon.esm.js.map +1 -1
- package/dist/esm/Icon/Icon.module.esm.js +1 -1
- package/dist/esm/Link/Link.esm.js.map +1 -1
- package/dist/esm/Link/Link.module.esm.js +1 -1
- package/dist/esm/Notifications/BaseModal/BaseModal.module.esm.js +1 -1
- package/dist/esm/Notifications/SlideInModal/SlideInModal.module.esm.js +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.esm.js +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.esm.js +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.esm.js +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.esm.js.map +1 -1
- package/dist/esm/Notifications/Snackbar/interfaces.esm.js +2 -0
- package/dist/esm/Notifications/Snackbar/interfaces.esm.js.map +1 -0
- package/dist/esm/Popover/Popover.esm.js +1 -1
- package/dist/esm/Popover/Popover.esm.js.map +1 -1
- package/dist/esm/Popover/Popover.module.esm.js +1 -1
- package/dist/esm/Stepper/Step.esm.js +1 -1
- package/dist/esm/Stepper/Step.esm.js.map +1 -1
- package/dist/esm/Stepper/Step.module.esm.js +1 -1
- package/dist/esm/Stepper/Stepper.esm.js +1 -1
- package/dist/esm/Stepper/Stepper.esm.js.map +1 -1
- package/dist/esm/Tabs/TabButton.module.esm.js +1 -1
- package/dist/esm/TextEllipsis/TextEllipsis.module.esm.js +1 -1
- package/dist/esm/Tiles/Tile.module.esm.js +1 -1
- package/dist/esm/Tooltip/Tooltip.module.esm.js +1 -1
- package/dist/esm/Wizard/BaseWizardSteps/BaseWizardSteps.module.esm.js +1 -1
- package/dist/esm/_BaseStyling_/BaseStyling.esm.js +1 -1
- package/dist/esm/_BaseStyling_/BaseStyling.esm.js.map +1 -1
- package/dist/esm/src/.scope.d.ts +2 -0
- package/dist/esm/src/components/Button/BaseButton.d.ts +1 -1
- package/dist/esm/src/components/ContextMenu/ContextMenu.d.ts +1 -1
- package/dist/esm/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
- package/dist/esm/src/components/Form/Select/Option.d.ts +1 -0
- package/dist/esm/src/components/Form/Select/Select.d.ts +20 -0
- package/dist/esm/src/components/Form/Select/Select.interfaces.d.ts +3 -1
- package/dist/esm/src/components/Form/Select/Select.test.d.ts +63 -1
- package/dist/esm/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
- package/dist/esm/src/components/Form/Select/SelectService.d.ts +3 -2
- package/dist/esm/src/components/Icon/Icon.d.ts +4 -1
- package/dist/esm/src/components/Link/Link.d.ts +1 -1
- package/dist/esm/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +5 -5
- package/dist/esm/src/components/Notifications/Snackbar/interfaces.d.ts +6 -0
- package/dist/esm/src/components/Notifications/Snackbar/useSnackbar.d.ts +4 -4
- package/dist/esm/src/components/Notifications/Snackbar/useSnackbar.test.d.ts +1 -0
- package/dist/esm/src/components/Stepper/Stepper.d.ts +0 -1
- package/dist/esm/src/components/_BaseStyling_/BaseStyling.d.ts +11 -10
- package/dist/esm/src/hooks/usePosition.d.ts +1 -1
- package/dist/esm/src/hooks/usePosition.esm.js.map +1 -1
- package/package.json +48 -45
- package/src/{hooks/useWrapper.test.ts → .scope.ts} +1 -12
- package/src/components/Button/BaseButton.tsx +1 -1
- package/src/components/Button/Button.module.scss +2 -10
- package/src/components/ContextMenu/ContextMenu.tsx +13 -23
- package/src/components/ContextMenu/ContextMenuService.ts +47 -1
- package/src/components/Form/Select/Option.tsx +3 -1
- package/src/components/Form/Select/Select.interfaces.ts +3 -1
- package/src/components/Form/Select/Select.module.scss +55 -34
- package/src/components/Form/Select/Select.tsx +74 -23
- package/src/components/Form/Select/SelectService.ts +26 -10
- package/src/components/Icon/Icon.module.scss +12 -0
- package/src/components/Icon/Icon.tsx +4 -1
- package/src/components/Link/Link.module.scss +28 -4
- package/src/components/Link/Link.tsx +1 -1
- package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +14 -21
- package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +17 -13
- package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +43 -17
- package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +5 -13
- package/src/components/Notifications/Snackbar/interfaces.ts +15 -0
- package/src/components/Popover/Popover.tsx +19 -2
- package/src/components/Stepper/Step.tsx +2 -1
- package/src/components/Stepper/Stepper.tsx +0 -2
- package/src/components/Tooltip/Tooltip.module.scss +1 -0
- package/src/components/_BaseStyling_/BaseStyling.tsx +24 -22
- package/src/font/icomoon.eot +0 -0
- package/src/font/icomoon.svg +5 -2
- package/src/font/icomoon.ttf +0 -0
- package/src/font/icomoon.woff +0 -0
- package/src/font/selection.json +1 -1
- package/src/hooks/usePosition.ts +1 -1
- package/src/interfaces.ts +2 -2
- package/src/mixins.module.scss +60 -61
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -64
- package/src/components/Button/BaseButton.test.tsx +0 -133
- package/src/components/Button/Button.test.tsx +0 -138
- package/src/components/Button/IconButton.test.tsx +0 -122
- package/src/components/ContextMenu/ContextMenu.test.tsx +0 -358
- package/src/components/DataGrid/DataGrid.test.tsx +0 -437
- package/src/components/DataGrid/DataGridActions/DataGridActions.test.tsx +0 -204
- package/src/components/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +0 -99
- package/src/components/DataGrid/DataGridBody/DataGridBody.test.tsx +0 -140
- package/src/components/DataGrid/DataGridBody/DataGridCell.test.tsx +0 -90
- package/src/components/DataGrid/DataGridBody/DataGridRow.test.tsx +0 -117
- package/src/components/DataGrid/DataGridHeader/DataGridHeader.test.tsx +0 -276
- package/src/components/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +0 -144
- package/src/components/Form/Checkbox/Checkbox.test.tsx +0 -308
- package/src/components/Form/Fieldset/Fieldset.test.tsx +0 -127
- package/src/components/Form/FileUpload/FileItem/FileItem.test.tsx +0 -103
- package/src/components/Form/FileUpload/FileUpload.test.tsx +0 -374
- package/src/components/Form/Form.test.tsx +0 -63
- package/src/components/Form/FormControl/FormControl.test.tsx +0 -98
- package/src/components/Form/FormGroup/FormGroup.test.tsx +0 -127
- package/src/components/Form/FormHelperText/FormHelperText.test.tsx +0 -84
- package/src/components/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +0 -94
- package/src/components/Form/Input/Input.test.tsx +0 -267
- package/src/components/Form/Label/Label.test.tsx +0 -68
- package/src/components/Form/Radio/Radio.test.tsx +0 -130
- package/src/components/Form/Select/Option.test.tsx +0 -57
- package/src/components/Form/Select/Select.test.tsx +0 -564
- package/src/components/Form/Textarea/Textarea.test.tsx +0 -124
- package/src/components/Form/Toggle/Toggle.test.tsx +0 -200
- package/src/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +0 -141
- package/src/components/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +0 -211
- package/src/components/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +0 -117
- package/src/components/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +0 -186
- package/src/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +0 -173
- package/src/components/Form/Wrapper/Wrapper/Wrapper.test.tsx +0 -59
- package/src/components/Icon/Icon.test.tsx +0 -83
- package/src/components/Link/Link.test.tsx +0 -197
- package/src/components/Notifications/Banner/Banner.test.tsx +0 -84
- package/src/components/Notifications/BaseModal/BaseModal.test.tsx +0 -194
- package/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +0 -74
- package/src/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +0 -71
- package/src/components/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +0 -74
- package/src/components/Notifications/Dialog/Dialog.test.tsx +0 -118
- package/src/components/Notifications/Dialog/DialogActions/DialogActions.test.tsx +0 -61
- package/src/components/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +0 -87
- package/src/components/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +0 -111
- package/src/components/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +0 -175
- package/src/components/Notifications/Modal/Modal.test.tsx +0 -18
- package/src/components/Notifications/NotificationProvider/NotificationContext.test.tsx +0 -449
- package/src/components/Notifications/SlideInModal/SlideInModal.test.tsx +0 -90
- package/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +0 -53
- package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +0 -63
- package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +0 -215
- package/src/components/Pagination/Pagination.test.tsx +0 -183
- package/src/components/Popover/Popover.test.tsx +0 -103
- package/src/components/ProgressBar/ProgressBar.test.tsx +0 -91
- package/src/components/Skeleton/Skeleton.test.tsx +0 -112
- package/src/components/StatusIndicator/StatusIndicator.test.tsx +0 -143
- package/src/components/Stepper/Stepper.test.tsx +0 -83
- package/src/components/Tabs/Tab.test.tsx +0 -49
- package/src/components/Tabs/TabButton.test.tsx +0 -65
- package/src/components/Tabs/Tabs.test.tsx +0 -291
- package/src/components/Tag/Tag.test.tsx +0 -89
- package/src/components/TextEllipsis/TextEllipsis.test.tsx +0 -96
- package/src/components/Tiles/Tile.test.tsx +0 -183
- package/src/components/Tiles/Tiles.test.tsx +0 -162
- package/src/components/Tooltip/Tooltip.test.tsx +0 -390
- package/src/components/Typography/Typography.test.tsx +0 -177
- package/src/components/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +0 -90
- package/src/components/Wizard/Wizard.test.tsx +0 -218
- package/src/components/Wizard/WizardActions/WizardActions.test.tsx +0 -187
- package/src/components/Wizard/WizardSteps/WizardSteps.test.tsx +0 -125
- package/src/components/_BaseStyling_/BaseStyling.test.tsx +0 -55
- package/src/hooks/useAnimation.test.tsx +0 -65
- package/src/hooks/useBodyClick.test.tsx +0 -55
- package/src/hooks/useDebouncedCallback.test.ts +0 -150
- package/src/hooks/useDetermineStatusIcon.test.ts +0 -28
- package/src/hooks/useFormSelector.test.ts +0 -56
- package/src/hooks/usePosition.test.tsx +0 -510
- package/src/hooks/useRepeater.test.tsx +0 -156
- package/src/hooks/useScroll.test.tsx +0 -36
- package/src/hooks/useSpacing.test.ts +0 -86
- package/src/hooks/useUploadFile.test.ts +0 -211
- package/src/util/helper.test.tsx +0 -403
|
@@ -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
|
-
});
|