@onewelcome/react-lib-components 0.2.0 → 0.2.3
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/Breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/Button/BaseButton.d.ts +4 -4
- package/dist/Button/Button.d.ts +3 -3
- package/dist/Button/IconButton.d.ts +4 -4
- package/dist/ContextMenu/ContextMenu.d.ts +5 -5
- package/dist/ContextMenu/ContextMenuItem.d.ts +2 -2
- package/dist/DataGrid/DataGrid.d.ts +6 -6
- package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +4 -4
- package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +2 -2
- package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +3 -3
- package/dist/DataGrid/datagrid.interfaces.d.ts +1 -1
- package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
- package/dist/Form/Fieldset/Fieldset.d.ts +3 -3
- package/dist/Form/Form.d.ts +1 -1
- package/dist/Form/FormControl/FormControl.d.ts +3 -3
- package/dist/Form/FormGroup/FormGroup.d.ts +5 -5
- package/dist/Form/FormHelperText/FormHelperText.d.ts +3 -3
- package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +6 -6
- package/dist/Form/Input/Input.d.ts +5 -5
- package/dist/Form/Label/Label.d.ts +2 -2
- package/dist/Form/Radio/Radio.d.ts +5 -5
- package/dist/Form/Select/Option.d.ts +2 -2
- package/dist/Form/Select/Select.d.ts +5 -5
- package/dist/Form/Textarea/Textarea.d.ts +6 -6
- package/dist/Form/Toggle/Toggle.d.ts +3 -3
- package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +6 -6
- package/dist/Form/form.interfaces.d.ts +1 -1
- package/dist/Icon/Icon.d.ts +3 -3
- package/dist/Link/Link.d.ts +7 -7
- package/dist/Notifications/BaseModal/BaseModal.d.ts +4 -4
- package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +2 -2
- package/dist/Notifications/Dialog/Dialog.d.ts +5 -5
- package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +3 -3
- package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +2 -2
- package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +3 -3
- package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +7 -7
- package/dist/Notifications/Modal/Modal.d.ts +1 -1
- package/dist/Notifications/Modal/ModalActions/ModalActions.d.ts +1 -1
- package/dist/Notifications/Modal/ModalContent/ModalContent.d.ts +1 -1
- package/dist/Notifications/Modal/ModalHeader/ModalHeader.d.ts +1 -1
- package/dist/Notifications/SlideInModal/SlideInModal.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarItem/SnackbarItem.d.ts +2 -2
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +2 -2
- package/dist/Notifications/Snackbar/interfaces.d.ts +2 -2
- package/dist/Pagination/Pagination.d.ts +3 -3
- package/dist/Popover/Popover.d.ts +3 -3
- package/dist/Skeleton/Skeleton.d.ts +3 -3
- package/dist/StatusIndicator/StatusIndicator.d.ts +5 -5
- package/dist/Tabs/Tab.d.ts +1 -1
- package/dist/Tabs/TabButton.d.ts +2 -2
- package/dist/Tabs/TabPanel.d.ts +2 -2
- package/dist/Tabs/Tabs.d.ts +4 -4
- package/dist/TextEllipsis/TextEllipsis.d.ts +2 -2
- package/dist/Tiles/Tile.d.ts +5 -5
- package/dist/Tiles/Tiles.d.ts +2 -2
- package/dist/Tooltip/Tooltip.d.ts +3 -3
- package/dist/Typography/Typography.d.ts +3 -3
- package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +2 -2
- package/dist/Wizard/Wizard.d.ts +3 -3
- package/dist/Wizard/WizardActions/WizardActions.d.ts +2 -2
- package/dist/Wizard/WizardStateProvider.d.ts +2 -2
- package/dist/Wizard/WizardSteps/WizardSteps.d.ts +2 -2
- package/dist/Wizard/wizardStateReducer.d.ts +5 -5
- package/dist/_BaseStyling_/BaseStyling.d.ts +1 -1
- package/dist/hooks/usePosition.d.ts +4 -4
- package/dist/hooks/useRepeater.d.ts +1 -1
- package/dist/hooks/useScroll.d.ts +1 -1
- package/dist/hooks/useSpacing.d.ts +1 -1
- package/dist/hooks/useWrapper.d.ts +1 -1
- package/dist/index.d.ts +55 -55
- package/dist/react-lib-components.cjs.development.js +676 -578
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +676 -578
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +27 -16
- package/src/Breadcrumbs/Breadcrumbs.test.tsx +15 -15
- package/src/Breadcrumbs/Breadcrumbs.tsx +11 -11
- package/src/Button/BaseButton.module.scss +1 -1
- package/src/Button/BaseButton.test.tsx +27 -27
- package/src/Button/BaseButton.tsx +8 -8
- package/src/Button/Button.module.scss +5 -5
- package/src/Button/Button.test.tsx +39 -39
- package/src/Button/Button.tsx +10 -10
- package/src/Button/IconButton.module.scss +5 -5
- package/src/Button/IconButton.test.tsx +29 -29
- package/src/Button/IconButton.tsx +11 -11
- package/src/ContextMenu/ContextMenu.test.tsx +97 -76
- package/src/ContextMenu/ContextMenu.tsx +48 -42
- package/src/ContextMenu/ContextMenuItem.module.scss +1 -1
- package/src/ContextMenu/ContextMenuItem.tsx +7 -5
- package/src/DataGrid/DataGrid.test.tsx +193 -193
- package/src/DataGrid/DataGrid.tsx +26 -26
- package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +63 -63
- package/src/DataGrid/DataGridActions/DataGridActions.tsx +15 -15
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +1 -1
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +21 -21
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +20 -20
- package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +40 -40
- package/src/DataGrid/DataGridBody/DataGridBody.tsx +10 -10
- package/src/DataGrid/DataGridBody/DataGridCell.module.scss +1 -1
- package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +25 -25
- package/src/DataGrid/DataGridBody/DataGridCell.tsx +6 -6
- package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +38 -38
- package/src/DataGrid/DataGridBody/DataGridRow.tsx +8 -8
- package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +1 -2
- package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +119 -119
- package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +13 -13
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +2 -0
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +51 -51
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +14 -14
- package/src/DataGrid/datagrid.interfaces.ts +1 -1
- package/src/Form/Checkbox/Checkbox.test.tsx +74 -74
- package/src/Form/Checkbox/Checkbox.tsx +27 -27
- package/src/Form/Fieldset/Fieldset.module.scss +1 -1
- package/src/Form/Fieldset/Fieldset.test.tsx +35 -35
- package/src/Form/Fieldset/Fieldset.tsx +27 -27
- package/src/Form/Form.test.tsx +18 -18
- package/src/Form/Form.tsx +3 -3
- package/src/Form/FormControl/FormControl.test.tsx +22 -22
- package/src/Form/FormControl/FormControl.tsx +10 -10
- package/src/Form/FormGroup/FormGroup.test.tsx +37 -37
- package/src/Form/FormGroup/FormGroup.tsx +16 -16
- package/src/Form/FormHelperText/FormHelperText.test.tsx +18 -18
- package/src/Form/FormHelperText/FormHelperText.tsx +7 -7
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +15 -15
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +14 -14
- package/src/Form/Input/Input.module.scss +20 -44
- package/src/Form/Input/Input.test.tsx +121 -73
- package/src/Form/Input/Input.tsx +96 -35
- package/src/Form/Label/Label.test.tsx +13 -13
- package/src/Form/Label/Label.tsx +6 -6
- package/src/Form/Radio/Radio.test.tsx +35 -35
- package/src/Form/Radio/Radio.tsx +17 -17
- package/src/Form/Select/Option.test.tsx +10 -10
- package/src/Form/Select/Option.tsx +8 -8
- package/src/Form/Select/Select.module.scss +7 -9
- package/src/Form/Select/Select.test.tsx +144 -141
- package/src/Form/Select/Select.tsx +79 -78
- package/src/Form/Textarea/Textarea.module.scss +8 -18
- package/src/Form/Textarea/Textarea.test.tsx +27 -27
- package/src/Form/Textarea/Textarea.tsx +33 -13
- package/src/Form/Toggle/Toggle.module.scss +1 -1
- package/src/Form/Toggle/Toggle.test.tsx +22 -22
- package/src/Form/Toggle/Toggle.tsx +10 -10
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +39 -39
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +12 -12
- package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +2 -8
- package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +30 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +35 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +12 -12
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +12 -12
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +2 -11
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +50 -50
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +22 -22
- package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +2 -2
- package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +11 -11
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +17 -17
- package/src/Form/form.interfaces.ts +1 -1
- package/src/Icon/Icon.module.scss +71 -71
- package/src/Icon/Icon.test.tsx +18 -18
- package/src/Icon/Icon.tsx +70 -70
- package/src/Link/Link.module.scss +5 -5
- package/src/Link/Link.test.tsx +76 -76
- package/src/Link/Link.tsx +27 -27
- package/src/Link/types.d.ts +1 -1
- package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
- package/src/Notifications/BaseModal/BaseModal.test.tsx +53 -53
- package/src/Notifications/BaseModal/BaseModal.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +13 -13
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +19 -19
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +10 -10
- package/src/Notifications/Dialog/Dialog.test.tsx +35 -35
- package/src/Notifications/Dialog/Dialog.tsx +19 -19
- package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +14 -14
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +6 -6
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +12 -12
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +6 -6
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +20 -20
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +7 -7
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +36 -36
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +8 -8
- package/src/Notifications/Modal/Modal.test.tsx +6 -6
- package/src/Notifications/Modal/Modal.tsx +1 -1
- package/src/Notifications/Modal/ModalActions/ModalActions.tsx +2 -2
- package/src/Notifications/Modal/ModalContent/ModalContent.tsx +2 -2
- package/src/Notifications/Modal/ModalHeader/ModalHeader.tsx +2 -2
- package/src/Notifications/SlideInModal/SlideInModal.test.tsx +16 -16
- package/src/Notifications/SlideInModal/SlideInModal.tsx +16 -11
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +16 -16
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.tsx +6 -6
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +2 -2
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +17 -17
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +23 -23
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +32 -32
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +18 -18
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +3 -3
- package/src/Notifications/Snackbar/interfaces.ts +2 -2
- package/src/Notifications/Snackbar/useSnackbar.ts +2 -2
- package/src/Pagination/Pagination.module.scss +2 -0
- package/src/Pagination/Pagination.test.tsx +47 -47
- package/src/Pagination/Pagination.tsx +35 -35
- package/src/Popover/Popover.test.tsx +19 -19
- package/src/Popover/Popover.tsx +7 -7
- package/src/Skeleton/Skeleton.module.scss +2 -2
- package/src/Skeleton/Skeleton.test.tsx +29 -29
- package/src/Skeleton/Skeleton.tsx +10 -10
- package/src/StatusIndicator/StatusIndicator.test.tsx +38 -38
- package/src/StatusIndicator/StatusIndicator.tsx +9 -9
- package/src/Tabs/Tab.test.tsx +13 -13
- package/src/Tabs/Tab.tsx +1 -1
- package/src/Tabs/TabButton.test.tsx +28 -28
- package/src/Tabs/TabButton.tsx +7 -7
- package/src/Tabs/TabPanel.test.tsx +30 -30
- package/src/Tabs/TabPanel.tsx +4 -4
- package/src/Tabs/Tabs.test.tsx +93 -93
- package/src/Tabs/Tabs.tsx +25 -25
- package/src/TextEllipsis/TextEllipsis.test.tsx +22 -22
- package/src/TextEllipsis/TextEllipsis.tsx +6 -6
- package/src/Tiles/Tile.module.scss +1 -1
- package/src/Tiles/Tile.test.tsx +42 -42
- package/src/Tiles/Tile.tsx +22 -22
- package/src/Tiles/Tiles.test.tsx +30 -30
- package/src/Tiles/Tiles.tsx +9 -9
- package/src/Tooltip/Tooltip.test.tsx +35 -35
- package/src/Tooltip/Tooltip.tsx +21 -21
- package/src/Typography/Typography.module.scss +1 -1
- package/src/Typography/Typography.test.tsx +49 -49
- package/src/Typography/Typography.tsx +42 -42
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.module.scss +1 -1
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +26 -26
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +24 -24
- package/src/Wizard/Wizard.test.tsx +56 -56
- package/src/Wizard/Wizard.tsx +6 -6
- package/src/Wizard/WizardActions/WizardActions.test.tsx +34 -34
- package/src/Wizard/WizardActions/WizardActions.tsx +14 -14
- package/src/Wizard/WizardStateProvider.tsx +3 -3
- package/src/Wizard/WizardSteps/WizardSteps.test.tsx +27 -27
- package/src/Wizard/WizardSteps/WizardSteps.tsx +7 -7
- package/src/Wizard/wizardStateReducer.ts +9 -9
- package/src/_BaseStyling_/BaseStyling.test.tsx +14 -14
- package/src/_BaseStyling_/BaseStyling.tsx +50 -50
- package/src/hooks/useAnimation.test.tsx +12 -12
- package/src/hooks/useAnimation.ts +4 -4
- package/src/hooks/useBodyClick.test.tsx +8 -8
- package/src/hooks/useBodyClick.ts +3 -3
- package/src/hooks/useFormSelector.test.ts +17 -17
- package/src/hooks/useFormSelector.ts +4 -4
- package/src/hooks/usePosition.test.tsx +215 -215
- package/src/hooks/usePosition.ts +68 -68
- package/src/hooks/useRepeater.test.tsx +26 -26
- package/src/hooks/useRepeater.ts +5 -5
- package/src/hooks/useScroll.test.tsx +5 -5
- package/src/hooks/useScroll.ts +3 -3
- package/src/hooks/useSpacing.test.ts +40 -40
- package/src/hooks/useSpacing.ts +3 -3
- package/src/hooks/useWrapper.test.ts +12 -12
- package/src/hooks/useWrapper.ts +14 -7
- package/src/index.ts +67 -67
- package/src/mixins.module.scss +76 -27
- package/src/types.d.ts +1 -1
- package/src/util/helper.test.tsx +25 -25
- package/src/util/helper.tsx +64 -64
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import React, { useState } from
|
|
2
|
-
import { Wizard, Props } from
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Wizard, Props } from "./Wizard";
|
|
3
3
|
import {
|
|
4
4
|
getAllByRole,
|
|
5
5
|
getByText,
|
|
6
6
|
render,
|
|
7
7
|
getByTestId,
|
|
8
8
|
queryByRole,
|
|
9
|
-
findByText
|
|
10
|
-
} from
|
|
11
|
-
import { WizardActions } from
|
|
12
|
-
import { WizardSteps } from
|
|
13
|
-
import userEvent from
|
|
9
|
+
findByText
|
|
10
|
+
} from "@testing-library/react";
|
|
11
|
+
import { WizardActions } from "./WizardActions/WizardActions";
|
|
12
|
+
import { WizardSteps } from "./WizardSteps/WizardSteps";
|
|
13
|
+
import userEvent from "@testing-library/user-event";
|
|
14
14
|
|
|
15
|
-
type initWizardPropsType = Omit<Omit<Props,
|
|
15
|
+
type initWizardPropsType = Omit<Omit<Props, "onStepChange">, "children">;
|
|
16
16
|
|
|
17
17
|
const initWizardParams: initWizardPropsType = {
|
|
18
18
|
steps: [
|
|
19
19
|
{
|
|
20
|
-
label:
|
|
20
|
+
label: "Step 1"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
label:
|
|
23
|
+
label: "Step 2"
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
|
-
label:
|
|
27
|
-
disabled: true
|
|
26
|
+
label: "Step 3",
|
|
27
|
+
disabled: true
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
label:
|
|
31
|
-
}
|
|
30
|
+
label: "Step 4"
|
|
31
|
+
}
|
|
32
32
|
],
|
|
33
33
|
initialStepNo: 0,
|
|
34
|
-
stepScreenReaderLabel:
|
|
35
|
-
mode:
|
|
34
|
+
stepScreenReaderLabel: "Step",
|
|
35
|
+
mode: "add"
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
const initWizardStepsProps = {
|
|
39
|
-
onStepClick: jest.fn()
|
|
39
|
+
onStepClick: jest.fn()
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const initWizardActionsProps = {
|
|
43
43
|
onNext: jest.fn(),
|
|
44
44
|
onCancel: jest.fn(),
|
|
45
45
|
onSaveAndClose: jest.fn(),
|
|
46
|
-
cancelButtonLabel:
|
|
47
|
-
previousButtonLabel:
|
|
48
|
-
nextButtonLabel:
|
|
49
|
-
saveAndCloseButtonLabel:
|
|
46
|
+
cancelButtonLabel: "Cancel",
|
|
47
|
+
previousButtonLabel: "Previous",
|
|
48
|
+
nextButtonLabel: "Next",
|
|
49
|
+
saveAndCloseButtonLabel: "Save & close"
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
const renderWizard = (wizardProps?: initWizardPropsType) => {
|
|
@@ -69,48 +69,48 @@ const renderWizard = (wizardProps?: initWizardPropsType) => {
|
|
|
69
69
|
return render(<Content />);
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
const getWizardContent = (container: HTMLElement) => getByTestId(container,
|
|
72
|
+
const getWizardContent = (container: HTMLElement) => getByTestId(container, "wizard-content");
|
|
73
73
|
|
|
74
74
|
const getStepButtons = (container: HTMLElement) =>
|
|
75
|
-
getAllByRole(getByTestId(container,
|
|
75
|
+
getAllByRole(getByTestId(container, "wizard-steps"), "button");
|
|
76
76
|
|
|
77
77
|
const getActionsButtons = (container: HTMLElement) => {
|
|
78
|
-
const actionsContainer = getByTestId(container,
|
|
79
|
-
const cancel = queryByRole(actionsContainer,
|
|
80
|
-
name: initWizardActionsProps.cancelButtonLabel
|
|
78
|
+
const actionsContainer = getByTestId(container, "wizard-actions");
|
|
79
|
+
const cancel = queryByRole(actionsContainer, "button", {
|
|
80
|
+
name: initWizardActionsProps.cancelButtonLabel
|
|
81
81
|
});
|
|
82
|
-
const next = queryByRole(actionsContainer,
|
|
83
|
-
name: initWizardActionsProps.nextButtonLabel
|
|
82
|
+
const next = queryByRole(actionsContainer, "button", {
|
|
83
|
+
name: initWizardActionsProps.nextButtonLabel
|
|
84
84
|
});
|
|
85
|
-
const prev = queryByRole(actionsContainer,
|
|
86
|
-
name: initWizardActionsProps.previousButtonLabel
|
|
85
|
+
const prev = queryByRole(actionsContainer, "button", {
|
|
86
|
+
name: initWizardActionsProps.previousButtonLabel
|
|
87
87
|
});
|
|
88
|
-
const save = queryByRole(actionsContainer,
|
|
89
|
-
name: initWizardActionsProps.saveAndCloseButtonLabel
|
|
88
|
+
const save = queryByRole(actionsContainer, "button", {
|
|
89
|
+
name: initWizardActionsProps.saveAndCloseButtonLabel
|
|
90
90
|
});
|
|
91
91
|
return { cancel, next, prev, save };
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
-
describe(
|
|
95
|
-
it(
|
|
94
|
+
describe("Wizard", () => {
|
|
95
|
+
it("renders without crashing", () => {
|
|
96
96
|
const { container } = renderWizard();
|
|
97
97
|
const { cancel, prev, next, save } = getActionsButtons(container);
|
|
98
98
|
const stepButtons = getStepButtons(container);
|
|
99
99
|
const wizardContent = getWizardContent(container);
|
|
100
100
|
|
|
101
101
|
expect(stepButtons).toHaveLength(4);
|
|
102
|
-
expect(getByText(stepButtons[0],
|
|
103
|
-
expect(getByText(stepButtons[1],
|
|
104
|
-
expect(getByText(stepButtons[2],
|
|
105
|
-
expect(getByText(stepButtons[3],
|
|
106
|
-
expect(wizardContent).toHaveTextContent(
|
|
102
|
+
expect(getByText(stepButtons[0], "1")).toBeDefined();
|
|
103
|
+
expect(getByText(stepButtons[1], "2")).toBeDefined();
|
|
104
|
+
expect(getByText(stepButtons[2], "3")).toBeDefined();
|
|
105
|
+
expect(getByText(stepButtons[3], "4")).toBeDefined();
|
|
106
|
+
expect(wizardContent).toHaveTextContent("Step 1");
|
|
107
107
|
expect(cancel).toBeDefined();
|
|
108
108
|
expect(next).toBeDefined();
|
|
109
109
|
expect(prev).toBeNull();
|
|
110
110
|
expect(save).toBeNull();
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
it(
|
|
113
|
+
it("should be able to click over whole wizard via action buttons", async () => {
|
|
114
114
|
const { container } = renderWizard();
|
|
115
115
|
const { next } = getActionsButtons(container);
|
|
116
116
|
const wizardContent = getWizardContent(container);
|
|
@@ -118,23 +118,23 @@ describe('Wizard', () => {
|
|
|
118
118
|
initWizardActionsProps.onNext as jest.MockedFunction<typeof initWizardActionsProps.onNext>
|
|
119
119
|
).mockReturnValue(true);
|
|
120
120
|
|
|
121
|
-
await findByText(wizardContent,
|
|
121
|
+
await findByText(wizardContent, "Step 1");
|
|
122
122
|
next && userEvent.click(next);
|
|
123
|
-
await findByText(wizardContent,
|
|
123
|
+
await findByText(wizardContent, "Step 2");
|
|
124
124
|
next && userEvent.click(next);
|
|
125
|
-
await findByText(wizardContent,
|
|
125
|
+
await findByText(wizardContent, "Step 4");
|
|
126
126
|
const { save, prev, cancel } = getActionsButtons(container);
|
|
127
127
|
save && userEvent.click(save);
|
|
128
128
|
expect(initWizardActionsProps.onSaveAndClose).toBeCalledWith(3);
|
|
129
129
|
prev && userEvent.click(prev);
|
|
130
|
-
await findByText(wizardContent,
|
|
130
|
+
await findByText(wizardContent, "Step 2");
|
|
131
131
|
prev && userEvent.click(prev);
|
|
132
|
-
await findByText(wizardContent,
|
|
132
|
+
await findByText(wizardContent, "Step 1");
|
|
133
133
|
cancel && userEvent.click(cancel);
|
|
134
134
|
expect(initWizardActionsProps.onCancel).toBeCalledTimes(1);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
it(
|
|
137
|
+
it("should not be able to click over whole wizard via steps buttons in add mode", async () => {
|
|
138
138
|
const { container } = renderWizard();
|
|
139
139
|
const { next } = getActionsButtons(container);
|
|
140
140
|
const stepsButtons = getStepButtons(container);
|
|
@@ -152,23 +152,23 @@ describe('Wizard', () => {
|
|
|
152
152
|
userEvent.click(stepsButtons[2]);
|
|
153
153
|
userEvent.click(stepsButtons[3]);
|
|
154
154
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(0);
|
|
155
|
-
await findByText(wizardContent,
|
|
155
|
+
await findByText(wizardContent, "Step 1");
|
|
156
156
|
|
|
157
157
|
next && userEvent.click(next);
|
|
158
158
|
next && userEvent.click(next);
|
|
159
|
-
await findByText(wizardContent,
|
|
159
|
+
await findByText(wizardContent, "Step 4");
|
|
160
160
|
userEvent.click(stepsButtons[2]);
|
|
161
161
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(0);
|
|
162
162
|
userEvent.click(stepsButtons[1]);
|
|
163
163
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(1);
|
|
164
|
-
await findByText(wizardContent,
|
|
164
|
+
await findByText(wizardContent, "Step 2");
|
|
165
165
|
userEvent.click(stepsButtons[0]);
|
|
166
166
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(2);
|
|
167
|
-
await findByText(wizardContent,
|
|
167
|
+
await findByText(wizardContent, "Step 1");
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
-
it(
|
|
171
|
-
const { container } = renderWizard({ ...initWizardParams, mode:
|
|
170
|
+
it("should be able to click over whole wizard via steps buttons in edit mode", async () => {
|
|
171
|
+
const { container } = renderWizard({ ...initWizardParams, mode: "edit" });
|
|
172
172
|
const stepsButtons = getStepButtons(container);
|
|
173
173
|
const wizardContent = getWizardContent(container);
|
|
174
174
|
(
|
|
@@ -179,20 +179,20 @@ describe('Wizard', () => {
|
|
|
179
179
|
|
|
180
180
|
userEvent.click(stepsButtons[1]);
|
|
181
181
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(1);
|
|
182
|
-
await findByText(wizardContent,
|
|
182
|
+
await findByText(wizardContent, "Step 2");
|
|
183
183
|
userEvent.click(stepsButtons[2]);
|
|
184
184
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(1);
|
|
185
185
|
userEvent.click(stepsButtons[3]);
|
|
186
186
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(2);
|
|
187
|
-
await findByText(wizardContent,
|
|
187
|
+
await findByText(wizardContent, "Step 4");
|
|
188
188
|
|
|
189
189
|
userEvent.click(stepsButtons[2]);
|
|
190
190
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(2);
|
|
191
191
|
userEvent.click(stepsButtons[1]);
|
|
192
192
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(3);
|
|
193
|
-
await findByText(wizardContent,
|
|
193
|
+
await findByText(wizardContent, "Step 2");
|
|
194
194
|
userEvent.click(stepsButtons[0]);
|
|
195
195
|
expect(initWizardStepsProps.onStepClick).toBeCalledTimes(4);
|
|
196
|
-
await findByText(wizardContent,
|
|
196
|
+
await findByText(wizardContent, "Step 1");
|
|
197
197
|
});
|
|
198
198
|
});
|
package/src/Wizard/Wizard.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { Fragment, useContext, useEffect } from
|
|
2
|
-
import { Step } from
|
|
3
|
-
import { WizardStateContext, WizardStateProvider } from
|
|
4
|
-
import { setWizardState } from
|
|
1
|
+
import React, { Fragment, useContext, useEffect } from "react";
|
|
2
|
+
import { Step } from "./BaseWizardSteps/BaseWizardSteps";
|
|
3
|
+
import { WizardStateContext, WizardStateProvider } from "./WizardStateProvider";
|
|
4
|
+
import { setWizardState } from "./wizardStateReducer";
|
|
5
5
|
|
|
6
|
-
export type WizardMode =
|
|
6
|
+
export type WizardMode = "add" | "edit";
|
|
7
7
|
|
|
8
8
|
export interface Props {
|
|
9
9
|
steps: Step[];
|
|
@@ -24,7 +24,7 @@ const useSetWizardState = (steps: Step[], mode: WizardMode, stepScreenReaderLabe
|
|
|
24
24
|
|
|
25
25
|
const useStepChanging = (onStepChange: (stepNo: number) => void) => {
|
|
26
26
|
const {
|
|
27
|
-
state: { currentStepNo }
|
|
27
|
+
state: { currentStepNo }
|
|
28
28
|
} = useContext(WizardStateContext);
|
|
29
29
|
|
|
30
30
|
useEffect(() => {
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import React, { useReducer } from
|
|
2
|
-
import { WizardActions, Props } from
|
|
3
|
-
import { queryByRole, render } from
|
|
4
|
-
import { WizardStateContext, Props as ProviderProps } from
|
|
5
|
-
import { WizardStateType, reducer, changeCurrentStepNo } from
|
|
6
|
-
import userEvent from
|
|
1
|
+
import React, { useReducer } from "react";
|
|
2
|
+
import { WizardActions, Props } from "./WizardActions";
|
|
3
|
+
import { queryByRole, render } from "@testing-library/react";
|
|
4
|
+
import { WizardStateContext, Props as ProviderProps } from "../WizardStateProvider";
|
|
5
|
+
import { WizardStateType, reducer, changeCurrentStepNo } from "../wizardStateReducer";
|
|
6
|
+
import userEvent from "@testing-library/user-event";
|
|
7
7
|
|
|
8
8
|
const initWizardState: WizardStateType = {
|
|
9
9
|
steps: [
|
|
10
10
|
{
|
|
11
|
-
label:
|
|
11
|
+
label: "Step 1"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
label:
|
|
14
|
+
label: "Step 2"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
label:
|
|
18
|
-
disabled: true
|
|
17
|
+
label: "Step 3",
|
|
18
|
+
disabled: true
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
label:
|
|
22
|
-
}
|
|
21
|
+
label: "Step 4"
|
|
22
|
+
}
|
|
23
23
|
],
|
|
24
24
|
currentStepNo: 0,
|
|
25
|
-
stepScreenReaderLabel:
|
|
26
|
-
mode:
|
|
25
|
+
stepScreenReaderLabel: "Step",
|
|
26
|
+
mode: "add"
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const initParams: Props = {
|
|
30
|
-
cancelButtonLabel:
|
|
31
|
-
previousButtonLabel:
|
|
32
|
-
nextButtonLabel:
|
|
33
|
-
saveAndCloseButtonLabel:
|
|
30
|
+
cancelButtonLabel: "Cancel",
|
|
31
|
+
previousButtonLabel: "Previous",
|
|
32
|
+
nextButtonLabel: "Next",
|
|
33
|
+
saveAndCloseButtonLabel: "Save & Close",
|
|
34
34
|
onCancel: jest.fn(),
|
|
35
35
|
onNext: jest.fn(),
|
|
36
36
|
onPrevious: jest.fn(),
|
|
37
|
-
onSaveAndClose: jest.fn()
|
|
37
|
+
onSaveAndClose: jest.fn()
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const renderWizardActions = (initReducerState?: WizardStateType, props?: Props) => {
|
|
@@ -59,20 +59,20 @@ const renderWizardActions = (initReducerState?: WizardStateType, props?: Props)
|
|
|
59
59
|
|
|
60
60
|
return {
|
|
61
61
|
...renderObj,
|
|
62
|
-
dispatch
|
|
62
|
+
dispatch
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
const getActionsButtons = (container: HTMLElement) => {
|
|
67
|
-
const cancel = queryByRole(container,
|
|
68
|
-
const next = queryByRole(container,
|
|
69
|
-
const prev = queryByRole(container,
|
|
70
|
-
const save = queryByRole(container,
|
|
67
|
+
const cancel = queryByRole(container, "button", { name: initParams.cancelButtonLabel });
|
|
68
|
+
const next = queryByRole(container, "button", { name: initParams.nextButtonLabel });
|
|
69
|
+
const prev = queryByRole(container, "button", { name: initParams.previousButtonLabel });
|
|
70
|
+
const save = queryByRole(container, "button", { name: initParams.saveAndCloseButtonLabel });
|
|
71
71
|
return { cancel, next, prev, save };
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
describe(
|
|
75
|
-
it(
|
|
74
|
+
describe("WizardActions", () => {
|
|
75
|
+
it("renders without crashing", () => {
|
|
76
76
|
const { container, dispatch } = renderWizardActions();
|
|
77
77
|
const { cancel, prev, next, save } = getActionsButtons(container);
|
|
78
78
|
(initParams.onNext as jest.MockedFunction<typeof initParams.onNext>).mockReturnValueOnce(true);
|
|
@@ -89,7 +89,7 @@ describe('WizardActions', () => {
|
|
|
89
89
|
expect(dispatch).toBeCalledWith(changeCurrentStepNo(1));
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
it(
|
|
92
|
+
it("should allow going prev and forward when there are prev step and next step (next step is disabled but next one can be used)", () => {
|
|
93
93
|
const { container, dispatch } = renderWizardActions({ ...initWizardState, currentStepNo: 1 });
|
|
94
94
|
const { cancel, prev, next, save } = getActionsButtons(container);
|
|
95
95
|
(initParams.onNext as jest.MockedFunction<typeof initParams.onNext>).mockReturnValueOnce(true);
|
|
@@ -108,7 +108,7 @@ describe('WizardActions', () => {
|
|
|
108
108
|
expect(save).toBeNull();
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
it(
|
|
111
|
+
it("should render save button but not next button when current step is the last step", () => {
|
|
112
112
|
const { container } = renderWizardActions({ ...initWizardState, currentStepNo: 3 });
|
|
113
113
|
const { cancel, prev, next, save } = getActionsButtons(container);
|
|
114
114
|
|
|
@@ -121,16 +121,16 @@ describe('WizardActions', () => {
|
|
|
121
121
|
expect(initParams.onSaveAndClose).toHaveBeenCalledWith(3);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
it(
|
|
124
|
+
it("should show save and close when next steps are disabled", () => {
|
|
125
125
|
const steps = [
|
|
126
126
|
initWizardState.steps[0],
|
|
127
127
|
{ ...initWizardState.steps[1], disabled: true },
|
|
128
|
-
{ ...initWizardState.steps[2], disabled: true }
|
|
128
|
+
{ ...initWizardState.steps[2], disabled: true }
|
|
129
129
|
];
|
|
130
130
|
const { container } = renderWizardActions({
|
|
131
131
|
...initWizardState,
|
|
132
132
|
steps: steps,
|
|
133
|
-
currentStepNo: 0
|
|
133
|
+
currentStepNo: 0
|
|
134
134
|
});
|
|
135
135
|
const { cancel, prev, next, save } = getActionsButtons(container);
|
|
136
136
|
|
|
@@ -143,8 +143,8 @@ describe('WizardActions', () => {
|
|
|
143
143
|
expect(initParams.onSaveAndClose).toHaveBeenCalledWith(0);
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
-
it(
|
|
147
|
-
const { container } = renderWizardActions({ ...initWizardState, mode:
|
|
146
|
+
it("should show save button on middle step when mode is `edit`", () => {
|
|
147
|
+
const { container } = renderWizardActions({ ...initWizardState, mode: "edit" });
|
|
148
148
|
const { cancel, prev, next, save } = getActionsButtons(container);
|
|
149
149
|
|
|
150
150
|
expect(cancel).toBeDefined();
|
|
@@ -156,7 +156,7 @@ describe('WizardActions', () => {
|
|
|
156
156
|
expect(initParams.onSaveAndClose).toHaveBeenCalledWith(0);
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
it(
|
|
159
|
+
it("should not allow going forward when dev returns false on onNext callback", () => {
|
|
160
160
|
const { container, dispatch } = renderWizardActions();
|
|
161
161
|
const { next } = getActionsButtons(container);
|
|
162
162
|
(initParams.onNext as jest.MockedFunction<typeof initParams.onNext>).mockReturnValueOnce(false);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { Fragment, useContext, useMemo } from
|
|
2
|
-
import { Button } from
|
|
3
|
-
import { Step } from
|
|
4
|
-
import { WizardMode } from
|
|
5
|
-
import { WizardStateContext } from
|
|
6
|
-
import { changeCurrentStepNo } from
|
|
1
|
+
import React, { Fragment, useContext, useMemo } from "react";
|
|
2
|
+
import { Button } from "../../Button/Button";
|
|
3
|
+
import { Step } from "../BaseWizardSteps/BaseWizardSteps";
|
|
4
|
+
import { WizardMode } from "../Wizard";
|
|
5
|
+
import { WizardStateContext } from "../WizardStateProvider";
|
|
6
|
+
import { changeCurrentStepNo } from "../wizardStateReducer";
|
|
7
7
|
|
|
8
8
|
export interface Props extends React.HTMLProps<HTMLDivElement> {
|
|
9
9
|
cancelButtonLabel: string;
|
|
@@ -44,20 +44,20 @@ export const WizardActions = ({
|
|
|
44
44
|
cancelButtonLabel,
|
|
45
45
|
previousButtonLabel,
|
|
46
46
|
nextButtonLabel,
|
|
47
|
-
saveAndCloseButtonLabel
|
|
47
|
+
saveAndCloseButtonLabel
|
|
48
48
|
}: Props) => {
|
|
49
49
|
const {
|
|
50
50
|
state: { mode, steps, currentStepNo },
|
|
51
|
-
dispatch
|
|
51
|
+
dispatch
|
|
52
52
|
} = useContext(WizardStateContext);
|
|
53
53
|
const nextStepNo = useNextStepNo(mode, currentStepNo, steps);
|
|
54
54
|
const hasNextStep = nextStepNo !== -1;
|
|
55
55
|
const previousStepNo = usePreviousStepNo(mode, currentStepNo, steps);
|
|
56
56
|
const hasPreviousStep = previousStepNo !== -1;
|
|
57
|
-
const isLastStepOrEditMode = !hasNextStep || mode ===
|
|
57
|
+
const isLastStepOrEditMode = !hasNextStep || mode === "edit";
|
|
58
58
|
|
|
59
|
-
const changeStepNo = (direction:
|
|
60
|
-
if (direction ===
|
|
59
|
+
const changeStepNo = (direction: "forward" | "backward") => {
|
|
60
|
+
if (direction === "forward") {
|
|
61
61
|
hasNextStep && dispatch(changeCurrentStepNo(nextStepNo));
|
|
62
62
|
} else {
|
|
63
63
|
hasPreviousStep && dispatch(changeCurrentStepNo(previousStepNo));
|
|
@@ -65,12 +65,12 @@ export const WizardActions = ({
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
const onNextWrapper = () => {
|
|
68
|
-
onNext(currentStepNo) && changeStepNo(
|
|
68
|
+
onNext(currentStepNo) && changeStepNo("forward");
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
const onPreviousWrapper = () => {
|
|
72
72
|
onPrevious && onPrevious();
|
|
73
|
-
changeStepNo(
|
|
73
|
+
changeStepNo("backward");
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
const onSaveAndCloseWrapper = () => {
|
|
@@ -88,7 +88,7 @@ export const WizardActions = ({
|
|
|
88
88
|
</Button>
|
|
89
89
|
)}
|
|
90
90
|
{hasNextStep && (
|
|
91
|
-
<Button variant={mode ===
|
|
91
|
+
<Button variant={mode === "edit" ? "outline" : "fill"} onClick={onNextWrapper}>
|
|
92
92
|
{nextButtonLabel}
|
|
93
93
|
</Button>
|
|
94
94
|
)}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { createContext, Dispatch, useReducer } from
|
|
2
|
-
import { WizardActions, WizardStateType, reducer } from
|
|
1
|
+
import React, { createContext, Dispatch, useReducer } from "react";
|
|
2
|
+
import { WizardActions, WizardStateType, reducer } from "./wizardStateReducer";
|
|
3
3
|
|
|
4
4
|
const WizardStateContext = createContext<{
|
|
5
5
|
state: WizardStateType;
|
|
6
6
|
dispatch: Dispatch<WizardActions>;
|
|
7
7
|
}>({
|
|
8
8
|
state: {} as WizardStateType,
|
|
9
|
-
dispatch: () => null
|
|
9
|
+
dispatch: () => null
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
export interface Props {
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import React, { useReducer } from
|
|
2
|
-
import { WizardSteps, Props } from
|
|
3
|
-
import { getAllByRole, getByText, render } from
|
|
4
|
-
import { WizardStateContext, Props as ProviderProps } from
|
|
5
|
-
import { WizardStateType, reducer, changeCurrentStepNo } from
|
|
6
|
-
import userEvent from
|
|
1
|
+
import React, { useReducer } from "react";
|
|
2
|
+
import { WizardSteps, Props } from "./WizardSteps";
|
|
3
|
+
import { getAllByRole, getByText, render } from "@testing-library/react";
|
|
4
|
+
import { WizardStateContext, Props as ProviderProps } from "../WizardStateProvider";
|
|
5
|
+
import { WizardStateType, reducer, changeCurrentStepNo } from "../wizardStateReducer";
|
|
6
|
+
import userEvent from "@testing-library/user-event";
|
|
7
7
|
|
|
8
8
|
const initWizardState: WizardStateType = {
|
|
9
9
|
steps: [
|
|
10
10
|
{
|
|
11
|
-
label:
|
|
11
|
+
label: "Step 1"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
label:
|
|
14
|
+
label: "Step 2"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
label:
|
|
18
|
-
disabled: true
|
|
17
|
+
label: "Step 3",
|
|
18
|
+
disabled: true
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
label:
|
|
22
|
-
}
|
|
21
|
+
label: "Step 4"
|
|
22
|
+
}
|
|
23
23
|
],
|
|
24
24
|
currentStepNo: 1,
|
|
25
|
-
stepScreenReaderLabel:
|
|
26
|
-
mode:
|
|
25
|
+
stepScreenReaderLabel: "Step",
|
|
26
|
+
mode: "add"
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const initParams: Props = {
|
|
30
|
-
onStepClick: jest.fn()
|
|
30
|
+
onStepClick: jest.fn()
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const renderWizardSteps = (initReducerState?: WizardStateType) => {
|
|
@@ -51,14 +51,14 @@ const renderWizardSteps = (initReducerState?: WizardStateType) => {
|
|
|
51
51
|
|
|
52
52
|
return {
|
|
53
53
|
...renderObj,
|
|
54
|
-
dispatch
|
|
54
|
+
dispatch
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
const getStepButtons = (container: HTMLElement) => getAllByRole(container,
|
|
58
|
+
const getStepButtons = (container: HTMLElement) => getAllByRole(container, "button");
|
|
59
59
|
|
|
60
|
-
describe(
|
|
61
|
-
it(
|
|
60
|
+
describe("WizardSteps", () => {
|
|
61
|
+
it("renders without crashing", () => {
|
|
62
62
|
const { container, dispatch } = renderWizardSteps();
|
|
63
63
|
const buttons = getStepButtons(container);
|
|
64
64
|
(
|
|
@@ -69,10 +69,10 @@ describe('WizardSteps', () => {
|
|
|
69
69
|
userEvent.click(buttons[0]);
|
|
70
70
|
expect(initParams.onStepClick).toHaveBeenCalledWith(initWizardState.currentStepNo, 0);
|
|
71
71
|
expect(dispatch).toBeCalledWith(changeCurrentStepNo(0));
|
|
72
|
-
expect(buttons[0].querySelector(
|
|
73
|
-
expect(getByText(buttons[1],
|
|
74
|
-
expect(getByText(buttons[2],
|
|
75
|
-
expect(getByText(buttons[3],
|
|
72
|
+
expect(buttons[0].querySelector(".checkmark")).toBeDefined();
|
|
73
|
+
expect(getByText(buttons[1], "2")).toBeDefined();
|
|
74
|
+
expect(getByText(buttons[2], "3")).toBeDefined();
|
|
75
|
+
expect(getByText(buttons[3], "4")).toBeDefined();
|
|
76
76
|
|
|
77
77
|
userEvent.click(buttons[1]);
|
|
78
78
|
userEvent.click(buttons[2]);
|
|
@@ -80,8 +80,8 @@ describe('WizardSteps', () => {
|
|
|
80
80
|
expect(initParams.onStepClick).toHaveBeenCalledTimes(1);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
it(
|
|
84
|
-
const { container, dispatch } = renderWizardSteps({ ...initWizardState, mode:
|
|
83
|
+
it("should allow to click on future and prev steps but not on current and disabled steps when mode is set to `edit`", () => {
|
|
84
|
+
const { container, dispatch } = renderWizardSteps({ ...initWizardState, mode: "edit" });
|
|
85
85
|
const buttons = getStepButtons(container);
|
|
86
86
|
(
|
|
87
87
|
initParams.onStepClick as jest.MockedFunction<typeof initParams.onStepClick>
|
|
@@ -96,8 +96,8 @@ describe('WizardSteps', () => {
|
|
|
96
96
|
expect(initParams.onStepClick).toHaveBeenCalledTimes(1);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
it(
|
|
100
|
-
const { container, dispatch } = renderWizardSteps({ ...initWizardState, mode:
|
|
99
|
+
it("should do not change step when `onStepClick` callback returns false", () => {
|
|
100
|
+
const { container, dispatch } = renderWizardSteps({ ...initWizardState, mode: "edit" });
|
|
101
101
|
const buttons = getStepButtons(container);
|
|
102
102
|
(
|
|
103
103
|
initParams.onStepClick as jest.MockedFunction<typeof initParams.onStepClick>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, useContext } from
|
|
2
|
-
import { WizardStateContext } from
|
|
3
|
-
import { BaseWizardSteps } from
|
|
4
|
-
import { changeCurrentStepNo } from
|
|
1
|
+
import React, { ComponentPropsWithRef, useContext } from "react";
|
|
2
|
+
import { WizardStateContext } from "../WizardStateProvider";
|
|
3
|
+
import { BaseWizardSteps } from "../BaseWizardSteps/BaseWizardSteps";
|
|
4
|
+
import { changeCurrentStepNo } from "../wizardStateReducer";
|
|
5
5
|
|
|
6
|
-
export interface Props extends ComponentPropsWithRef<
|
|
6
|
+
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
7
7
|
onStepClick: (currentStepNo: number, selectedStepNo: number) => boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ export const WizardSteps = React.forwardRef<HTMLDivElement, Props>(
|
|
|
11
11
|
({ onStepClick, ...rest }: Props, ref) => {
|
|
12
12
|
const {
|
|
13
13
|
state: { currentStepNo, mode, stepScreenReaderLabel, steps },
|
|
14
|
-
dispatch
|
|
14
|
+
dispatch
|
|
15
15
|
} = useContext(WizardStateContext);
|
|
16
16
|
|
|
17
17
|
const onClick = (selectedStepNo: number) => {
|
|
@@ -26,7 +26,7 @@ export const WizardSteps = React.forwardRef<HTMLDivElement, Props>(
|
|
|
26
26
|
steps={steps}
|
|
27
27
|
currentStepNo={currentStepNo}
|
|
28
28
|
stepScreenReaderLabel={stepScreenReaderLabel}
|
|
29
|
-
futureStepsClickable={mode ===
|
|
29
|
+
futureStepsClickable={mode === "edit"}
|
|
30
30
|
/>
|
|
31
31
|
);
|
|
32
32
|
}
|