@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.
- 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/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.module.cjs.js +1 -1
- 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/src/.scope.d.ts +2 -0
- 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/Stepper/Stepper.d.ts +0 -1
- 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/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/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.module.esm.js +1 -1
- 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/src/.scope.d.ts +2 -0
- 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/Stepper/Stepper.d.ts +0 -1
- 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/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/Link/Link.module.scss +16 -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/hooks/usePosition.ts +1 -1
- package/src/interfaces.ts +2 -2
- package/src/mixins.module.scss +2 -4
- 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 -150
- package/src/components/Button/IconButton.test.tsx +0 -106
- 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 -203
- 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 -77
- package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +0 -219
- package/src/components/Notifications/Snackbar/useSnackbar.test.tsx +0 -136
- 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,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
|
-
});
|