@tsed/react-formio 1.13.0 → 1.13.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/.eslintignore +13 -0
- package/.eslintrc.js +7 -0
- package/coverage.json +6 -0
- package/dist/components/actions-table/actionsTable.component.d.ts +0 -1
- package/dist/components/actions-table/actionsTable.stories.d.ts +0 -1
- package/dist/components/alert/alert.component.d.ts +1 -2
- package/dist/components/alert/alert.stories.d.ts +0 -1
- package/dist/components/card/card.stories.d.ts +0 -1
- package/dist/components/form/form.component.d.ts +1 -2
- package/dist/components/form/form.component.spec.d.ts +1 -0
- package/dist/components/form/form.stories.d.ts +3745 -172
- package/dist/components/form/useForm.hook.d.ts +1 -2
- package/dist/components/form-access/formAccess.stories.d.ts +1 -2
- package/dist/components/form-action/formAction.stories.d.ts +0 -1
- package/dist/components/form-builder/formBuilder.stories.d.ts +518 -153
- package/dist/components/form-control/formControl.component.d.ts +2 -2
- package/dist/components/form-control/formControl.component.spec.d.ts +1 -0
- package/dist/components/form-control/formControl.stories.d.ts +57 -0
- package/dist/components/form-edit/formEdit.component.d.ts +0 -1
- package/dist/components/form-edit/formEdit.stories.d.ts +18 -19
- package/dist/components/form-settings/formSettings.component.d.ts +0 -1
- package/dist/components/form-settings/formSettings.stories.d.ts +1 -2
- package/dist/components/forms-table/components/formCell.component.d.ts +0 -1
- package/dist/components/forms-table/formsTable.component.d.ts +0 -1
- package/dist/components/forms-table/formsTable.stories.d.ts +0 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/input-tags/inputTags.component.d.ts +0 -1
- package/dist/components/input-tags/inputTags.stories.d.ts +2 -3
- package/dist/components/input-text/inputText.component.d.ts +0 -1
- package/dist/components/input-text/inputText.stories.d.ts +0 -1
- package/dist/components/loader/loader.component.d.ts +1 -1
- package/dist/components/loader/loader.stories.d.ts +0 -1
- package/dist/components/modal/modal.component.d.ts +1 -1
- package/dist/components/modal/modal.stories.d.ts +0 -1
- package/dist/components/pagination/pagination.component.d.ts +0 -1
- package/dist/components/pagination/pagination.stories.d.ts +0 -1
- package/dist/components/react-component/reactComponent.component.d.ts +3 -3
- package/dist/components/select/select.stories.d.ts +2 -3
- package/dist/components/submissions-table/submissionsTable.component.d.ts +0 -1
- package/dist/components/submissions-table/submissionsTable.stories.d.ts +13 -14
- package/dist/components/table/components/defaultArrowSort.component.d.ts +0 -1
- package/dist/components/table/components/defaultCell.component.d.ts +0 -1
- package/dist/components/table/components/defaultCellHeader.component.d.ts +1 -2
- package/dist/components/table/components/defaultCellOperations.component.d.ts +0 -1
- package/dist/components/table/components/defaultOperationButton.component.d.ts +0 -1
- package/dist/components/table/filters/defaultColumnFilter.component.d.ts +0 -1
- package/dist/components/table/filters/selectColumnFilter.component.d.ts +0 -1
- package/dist/components/table/filters/sliderColumnFilter.component.d.ts +0 -1
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/table/table.stories.d.ts +4 -5
- package/dist/components/tabs/tabs.component.stories.d.ts +0 -1
- package/dist/hooks/useTooltip.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7936 -7913
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +7375 -7347
- package/dist/index.modern.js.map +1 -1
- package/dist/stores/actions/index.d.ts +1 -1
- package/dist/stores/auth/auth.selectors.d.ts +1 -1
- package/dist/stores/auth/index.d.ts +4 -4
- package/dist/stores/index.d.ts +2 -2
- package/jest.config.js +6 -1
- package/package.json +8 -5
- package/src/components/__fixtures__/form.fixture.json +23 -0
- package/src/components/actions-table/actionsTable.component.spec.tsx +11 -11
- package/src/components/actions-table/actionsTable.component.tsx +8 -9
- package/src/components/actions-table/actionsTable.stories.tsx +1 -0
- package/src/components/alert/alert.component.spec.tsx +21 -19
- package/src/components/alert/alert.stories.tsx +1 -0
- package/src/components/card/card.component.spec.tsx +5 -4
- package/src/components/card/card.stories.tsx +1 -0
- package/src/components/form/form.component.spec.tsx +57 -0
- package/src/components/form/form.component.tsx +4 -3
- package/src/components/form/form.stories.tsx +157 -65
- package/src/components/form/useForm.hook.ts +35 -33
- package/src/components/form-access/formAccess.component.tsx +3 -2
- package/src/components/form-access/formAccess.schema.ts +1 -0
- package/src/components/form-access/formAccess.stories.tsx +1 -0
- package/src/components/form-access/formAccess.utils.ts +6 -5
- package/src/components/form-action/formAction.component.tsx +5 -4
- package/src/components/form-action/formAction.stories.tsx +225 -227
- package/src/components/form-builder/formBuilder.component.tsx +2 -1
- package/src/components/form-builder/formBuilder.stories.tsx +1 -0
- package/src/components/form-control/formControl.component.spec.tsx +76 -0
- package/src/components/form-control/formControl.component.tsx +15 -7
- package/src/components/form-control/formControl.stories.tsx +65 -0
- package/src/components/form-edit/formCtas.component.tsx +10 -9
- package/src/components/form-edit/formEdit.component.tsx +2 -1
- package/src/components/form-edit/formEdit.reducer.ts +1 -0
- package/src/components/form-edit/formEdit.stories.tsx +1 -0
- package/src/components/form-edit/formParameters.component.tsx +1 -0
- package/src/components/form-edit/useFormEdit.hook.ts +1 -0
- package/src/components/form-settings/formSettings.component.spec.tsx +7 -6
- package/src/components/form-settings/formSettings.component.tsx +12 -14
- package/src/components/form-settings/formSettings.stories.tsx +1 -0
- package/src/components/form-settings/formSettings.utils.ts +4 -3
- package/src/components/forms-table/components/formCell.component.tsx +1 -0
- package/src/components/forms-table/formsTable.component.tsx +23 -25
- package/src/components/forms-table/formsTable.stories.tsx +1 -0
- package/src/components/index.ts +2 -2
- package/src/components/input-tags/inputTags.component.tsx +7 -6
- package/src/components/input-tags/inputTags.stories.tsx +1 -0
- package/src/components/input-text/inputText.component.spec.tsx +13 -12
- package/src/components/input-text/inputText.component.tsx +4 -3
- package/src/components/input-text/inputText.stories.tsx +1 -0
- package/src/components/loader/loader.component.spec.tsx +6 -5
- package/src/components/loader/loader.component.tsx +1 -0
- package/src/components/loader/loader.stories.tsx +1 -0
- package/src/components/modal/modal.component.spec.tsx +36 -33
- package/src/components/modal/modal.component.tsx +3 -3
- package/src/components/modal/modal.stories.tsx +1 -0
- package/src/components/modal/removeModal.component.tsx +1 -0
- package/src/components/pagination/pagination.component.spec.tsx +24 -21
- package/src/components/pagination/pagination.component.tsx +1 -0
- package/src/components/pagination/pagination.stories.tsx +1 -0
- package/src/components/react-component/reactComponent.component.tsx +11 -7
- package/src/components/select/select.component.spec.tsx +17 -18
- package/src/components/select/select.component.tsx +3 -2
- package/src/components/select/select.stories.tsx +1 -0
- package/src/components/submissions-table/submissionsTable.component.tsx +3 -2
- package/src/components/submissions-table/submissionsTable.stories.tsx +1 -0
- package/src/components/table/components/defaultArrowSort.component.tsx +1 -0
- package/src/components/table/components/defaultCellHeader.component.tsx +1 -1
- package/src/components/table/components/defaultCellOperations.component.tsx +1 -0
- package/src/components/table/components/defaultOperationButton.component.tsx +1 -0
- package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +5 -3
- package/src/components/table/filters/defaultColumnFilter.component.tsx +1 -0
- package/src/components/table/filters/selectColumnFilter.component.spec.tsx +9 -7
- package/src/components/table/filters/selectColumnFilter.component.tsx +1 -0
- package/src/components/table/index.ts +1 -1
- package/src/components/table/table.component.tsx +5 -4
- package/src/components/table/table.stories.tsx +2 -1
- package/src/components/table/utils/mapFormToColumns.tsx +3 -2
- package/src/components/table/utils/useOperations.hook.tsx +1 -0
- package/src/components/tabs/tabs.component.spec.tsx +6 -5
- package/src/components/tabs/tabs.component.stories.tsx +1 -0
- package/src/components/tabs/tabs.component.tsx +11 -5
- package/src/hooks/useTooltip.ts +1 -1
- package/src/index.ts +3 -4
- package/src/interfaces/Operation.ts +1 -0
- package/src/stores/action/action.actions.spec.ts +1 -0
- package/src/stores/action/action.actions.ts +1 -0
- package/src/stores/action/action.reducers.ts +1 -1
- package/src/stores/action-info/action-info.actions.spec.ts +1 -0
- package/src/stores/action-info/action-info.actions.ts +2 -1
- package/src/stores/action-info/action-info.reducers.ts +2 -1
- package/src/stores/action-info/action-info.selectors.ts +2 -1
- package/src/stores/actions/actions.actions.spec.ts +1 -0
- package/src/stores/actions/actions.actions.ts +1 -0
- package/src/stores/actions/actions.reducers.ts +1 -0
- package/src/stores/actions/index.ts +1 -1
- package/src/stores/auth/auth.actions.ts +1 -0
- package/src/stores/auth/auth.reducers.ts +1 -0
- package/src/stores/auth/auth.selectors.ts +1 -0
- package/src/stores/auth/auth.utils.tsx +3 -2
- package/src/stores/auth/getAccess.action.spec.ts +1 -0
- package/src/stores/auth/getAccess.action.ts +3 -2
- package/src/stores/auth/getProjectAccess.action.ts +1 -0
- package/src/stores/auth/index.ts +4 -4
- package/src/stores/auth/initAuth.action.spec.ts +1 -0
- package/src/stores/auth/initAuth.action.ts +1 -0
- package/src/stores/auth/logout.action.spec.ts +2 -0
- package/src/stores/auth/logout.action.ts +1 -0
- package/src/stores/auth/setUser.action.spec.ts +1 -0
- package/src/stores/auth/setUser.action.ts +1 -0
- package/src/stores/form/form.actions.spec.ts +1 -0
- package/src/stores/form/form.actions.ts +1 -0
- package/src/stores/form/form.reducers.ts +1 -0
- package/src/stores/form/form.selectors.ts +1 -1
- package/src/stores/forms/forms.actions.spec.ts +1 -0
- package/src/stores/forms/forms.actions.ts +1 -0
- package/src/stores/forms/forms.reducers.ts +1 -0
- package/src/stores/index.ts +3 -2
- package/src/stores/root/root.selectors.ts +3 -3
- package/src/stores/submission/submission.actions.spec.ts +1 -0
- package/src/stores/submission/submission.actions.ts +1 -0
- package/src/stores/submission/submission.reducers.ts +1 -0
- package/src/stores/submissions/submissions.actions.spec.ts +1 -0
- package/src/stores/submissions/submissions.actions.ts +1 -0
- package/src/stores/submissions/submissions.reducers.ts +1 -0
- package/tsconfig.json +10 -27
- package/tsconfig.node.json +8 -0
- package/craco.config.js +0 -11
- package/tsconfig.test.json +0 -6
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { render } from "@testing-library/react";
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
|
+
|
|
3
4
|
import { Sandbox } from "./loader.stories";
|
|
4
5
|
describe("Loader", () => {
|
|
5
6
|
it("should render a component (when isActive = true)", () => {
|
|
6
|
-
|
|
7
|
+
render(<Sandbox isActive={true} />);
|
|
7
8
|
|
|
8
|
-
const icon = getByTestId("icon_radio-circle");
|
|
9
|
+
const icon = screen.getByTestId("icon_radio-circle");
|
|
9
10
|
|
|
10
11
|
expect(icon).toBeTruthy();
|
|
11
12
|
expect(icon).toBeInTheDocument();
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
it("should render a component (when isActive = false)", () => {
|
|
15
|
-
|
|
16
|
+
render(<Sandbox isActive={false} />);
|
|
16
17
|
|
|
17
|
-
const icon = queryByTestId("icon_radio-circle");
|
|
18
|
+
const icon = screen.queryByTestId("icon_radio-circle");
|
|
18
19
|
|
|
19
20
|
expect(icon).toBeFalsy();
|
|
20
21
|
expect(icon).not.toBeInTheDocument();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import "@testing-library/jest-dom/extend-expect";
|
|
2
|
+
|
|
2
3
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
4
|
import React from "react";
|
|
5
|
+
|
|
4
6
|
import { WithFooter, WithTitle } from "./modal.stories";
|
|
5
7
|
|
|
6
8
|
describe("Modal", () => {
|
|
@@ -8,69 +10,70 @@ describe("Modal", () => {
|
|
|
8
10
|
it("should display the modal when we click on the button", async () => {
|
|
9
11
|
const onClose = jest.fn();
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
render(<WithTitle {...WithTitle.args} onClose={onClose} />);
|
|
12
14
|
|
|
13
|
-
expect(queryByTestId("modalTitle")).toBeFalsy();
|
|
14
|
-
expect(queryByTestId("modalBody")).toBeFalsy();
|
|
15
|
-
expect(queryByTestId("modalFooter")).toBeFalsy();
|
|
15
|
+
expect(screen.queryByTestId("modalTitle")).toBeFalsy();
|
|
16
|
+
expect(screen.queryByTestId("modalBody")).toBeFalsy();
|
|
17
|
+
expect(screen.queryByTestId("modalFooter")).toBeFalsy();
|
|
16
18
|
|
|
17
19
|
fireEvent.click(screen.getByRole("button", { name: "Open modal" }));
|
|
18
20
|
|
|
19
|
-
await findByTestId("modalTitle");
|
|
21
|
+
await screen.findByTestId("modalTitle");
|
|
20
22
|
|
|
21
|
-
expect(getByTestId("modalTitle")).toBeTruthy();
|
|
22
|
-
expect(getByTestId("modalTitle")).toHaveTextContent("Modal title");
|
|
23
|
-
expect(getByTestId("modalBody")).toBeTruthy();
|
|
24
|
-
expect(getByTestId("modalBody")).toHaveTextContent("Hello body");
|
|
25
|
-
expect(queryByTestId("modalFooter")).toBeFalsy();
|
|
23
|
+
expect(screen.getByTestId("modalTitle")).toBeTruthy();
|
|
24
|
+
expect(screen.getByTestId("modalTitle")).toHaveTextContent("Modal title");
|
|
25
|
+
expect(screen.getByTestId("modalBody")).toBeTruthy();
|
|
26
|
+
expect(screen.getByTestId("modalBody")).toHaveTextContent("Hello body");
|
|
27
|
+
expect(screen.queryByTestId("modalFooter")).toBeFalsy();
|
|
26
28
|
|
|
27
29
|
fireEvent.click(screen.getByTestId("closeModal"));
|
|
28
30
|
|
|
29
|
-
expect(queryByTestId("modalTitle")).toBeFalsy();
|
|
30
|
-
expect(queryByTestId("modalBody")).toBeFalsy();
|
|
31
|
-
expect(queryByTestId("modalFooter")).toBeFalsy();
|
|
31
|
+
expect(screen.queryByTestId("modalTitle")).toBeFalsy();
|
|
32
|
+
expect(screen.queryByTestId("modalBody")).toBeFalsy();
|
|
33
|
+
expect(screen.queryByTestId("modalFooter")).toBeFalsy();
|
|
32
34
|
expect(onClose).toHaveBeenCalledWith();
|
|
33
35
|
});
|
|
34
36
|
});
|
|
35
37
|
|
|
36
38
|
describe("WithFooter", () => {
|
|
37
39
|
it("should display the modal when we click on the button", async () => {
|
|
38
|
-
|
|
40
|
+
render(<WithFooter {...WithFooter.args} />);
|
|
39
41
|
|
|
40
|
-
expect(queryByTestId("modalTitle")).toBeFalsy();
|
|
41
|
-
expect(queryByTestId("modalBody")).toBeFalsy();
|
|
42
|
-
expect(queryByTestId("modalFooter")).toBeFalsy();
|
|
42
|
+
expect(screen.queryByTestId("modalTitle")).toBeFalsy();
|
|
43
|
+
expect(screen.queryByTestId("modalBody")).toBeFalsy();
|
|
44
|
+
expect(screen.queryByTestId("modalFooter")).toBeFalsy();
|
|
43
45
|
|
|
44
|
-
fireEvent.click(getByRole("button", { name: "Open modal" }));
|
|
46
|
+
fireEvent.click(screen.getByRole("button", { name: "Open modal" }));
|
|
45
47
|
|
|
46
|
-
await findByTestId("modalTitle");
|
|
48
|
+
await screen.findByTestId("modalTitle");
|
|
47
49
|
|
|
48
|
-
expect(getByTestId("modalTitle")).toBeTruthy();
|
|
49
|
-
expect(getByTestId("modalTitle")).toHaveTextContent("Modal title");
|
|
50
|
-
expect(getByTestId("modalBody")).toBeTruthy();
|
|
51
|
-
expect(getByTestId("modalBody")).toHaveTextContent("Hello body");
|
|
52
|
-
expect(getByTestId("modalFooter")).toBeTruthy();
|
|
50
|
+
expect(screen.getByTestId("modalTitle")).toBeTruthy();
|
|
51
|
+
expect(screen.getByTestId("modalTitle")).toHaveTextContent("Modal title");
|
|
52
|
+
expect(screen.getByTestId("modalBody")).toBeTruthy();
|
|
53
|
+
expect(screen.getByTestId("modalBody")).toHaveTextContent("Hello body");
|
|
54
|
+
expect(screen.getByTestId("modalFooter")).toBeTruthy();
|
|
53
55
|
|
|
54
56
|
fireEvent.click(screen.getByTestId("customCloseModal"));
|
|
55
57
|
|
|
56
|
-
expect(queryByTestId("modalTitle")).toBeFalsy();
|
|
57
|
-
expect(queryByTestId("modalBody")).toBeFalsy();
|
|
58
|
-
expect(queryByTestId("modalFooter")).toBeFalsy();
|
|
58
|
+
expect(screen.queryByTestId("modalTitle")).toBeFalsy();
|
|
59
|
+
expect(screen.queryByTestId("modalBody")).toBeFalsy();
|
|
60
|
+
expect(screen.queryByTestId("modalFooter")).toBeFalsy();
|
|
59
61
|
});
|
|
60
62
|
it("should call the onSubmit listener", async () => {
|
|
61
63
|
const onSubmit = jest.fn();
|
|
62
|
-
const { getByRole, queryByTestId, findByTestId } = render(<WithFooter {...WithFooter.args} onSubmit={onSubmit} />);
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
render(<WithFooter {...WithFooter.args} onSubmit={onSubmit} />);
|
|
66
|
+
|
|
67
|
+
fireEvent.click(screen.getByRole("button", { name: "Open modal" }));
|
|
65
68
|
|
|
66
|
-
await findByTestId("modalTitle");
|
|
69
|
+
await screen.findByTestId("modalTitle");
|
|
67
70
|
|
|
68
71
|
fireEvent.click(screen.getByTestId("customSubmitModal"));
|
|
69
72
|
|
|
70
73
|
expect(onSubmit).toHaveBeenCalled();
|
|
71
|
-
expect(queryByTestId("modalTitle")).toBeFalsy();
|
|
72
|
-
expect(queryByTestId("modalBody")).toBeFalsy();
|
|
73
|
-
expect(queryByTestId("modalFooter")).toBeFalsy();
|
|
74
|
+
expect(screen.queryByTestId("modalTitle")).toBeFalsy();
|
|
75
|
+
expect(screen.queryByTestId("modalBody")).toBeFalsy();
|
|
76
|
+
expect(screen.queryByTestId("modalFooter")).toBeFalsy();
|
|
74
77
|
});
|
|
75
78
|
});
|
|
76
79
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
2
2
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
3
|
-
import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
|
|
4
3
|
import noop from "lodash";
|
|
4
|
+
import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
|
|
5
5
|
|
|
6
6
|
export function useModal() {
|
|
7
7
|
const [show, setShowModal] = useState(false);
|
|
@@ -37,8 +37,8 @@ export function Modal({
|
|
|
37
37
|
className = "",
|
|
38
38
|
...props
|
|
39
39
|
}: PropsWithChildren<ModalProps>) {
|
|
40
|
-
const titleRef = useRef<HTMLDivElement>();
|
|
41
|
-
const footerRef = useRef<HTMLDivElement>();
|
|
40
|
+
const titleRef: any = useRef<HTMLDivElement>();
|
|
41
|
+
const footerRef: any = useRef<HTMLDivElement>();
|
|
42
42
|
const [maxHeight, setMaxHeight] = useState<string>();
|
|
43
43
|
|
|
44
44
|
const onClickClose = () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import classnames from "classnames";
|
|
2
2
|
import noop from "lodash/noop";
|
|
3
3
|
import React, { PropsWithChildren, useState } from "react";
|
|
4
|
+
|
|
4
5
|
import { iconClass } from "../../utils/iconClass";
|
|
5
6
|
import { InputText } from "../input-text/inputText.component";
|
|
6
7
|
import { Modal, ModalProps } from "./modal.component";
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { render, screen
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
|
+
|
|
3
4
|
import { Sandbox } from "./pagination.stories";
|
|
4
5
|
|
|
5
6
|
describe("Pagination", () => {
|
|
6
7
|
it("should render the pagination component", () => {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
render(<Sandbox {...Sandbox.args} />);
|
|
9
|
+
|
|
10
|
+
const paginationBtn = screen.queryAllByTestId("pagination-button");
|
|
9
11
|
const allBtnBlocks = paginationBtn.map((bloc) => bloc.textContent);
|
|
10
|
-
const select = getByTestId("select_page");
|
|
12
|
+
const select = screen.getByTestId("select_page");
|
|
11
13
|
|
|
12
|
-
expect(container).toBeInTheDocument();
|
|
13
14
|
paginationBtn.forEach((child) => expect(child).toBeInTheDocument());
|
|
14
15
|
expect(select).toBeInTheDocument();
|
|
15
16
|
expect(allBtnBlocks[0]).toBe("Previous");
|
|
@@ -18,11 +19,11 @@ describe("Pagination", () => {
|
|
|
18
19
|
|
|
19
20
|
it("should call previousPage() callback", () => {
|
|
20
21
|
const previousPageSpy = jest.fn();
|
|
21
|
-
|
|
22
|
-
const paginationBtn = queryAllByTestId("pagination-button");
|
|
22
|
+
render(<Sandbox previousPage={previousPageSpy} canPreviousPage={true} />);
|
|
23
|
+
const paginationBtn = screen.queryAllByTestId("pagination-button");
|
|
23
24
|
const btnPreviousPage = paginationBtn.find((btn) => btn.textContent === "Previous");
|
|
24
25
|
|
|
25
|
-
fireEvent.click(btnPreviousPage);
|
|
26
|
+
fireEvent.click(btnPreviousPage!);
|
|
26
27
|
|
|
27
28
|
expect(previousPageSpy).toHaveBeenCalledTimes(1);
|
|
28
29
|
});
|
|
@@ -40,13 +41,14 @@ describe("Pagination", () => {
|
|
|
40
41
|
const gotoPageSpy = jest.fn();
|
|
41
42
|
let page: number;
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
render(<Sandbox {...Sandbox.args} gotoPage={gotoPageSpy} />);
|
|
45
|
+
|
|
46
|
+
const paginationBtn = screen.queryAllByTestId("pagination-button");
|
|
45
47
|
const buttonsPage = paginationBtn.filter((btn) => btn.textContent !== "Previous" && btn.textContent !== "Next");
|
|
46
48
|
|
|
47
49
|
buttonsPage.forEach((btn) => {
|
|
48
50
|
if (btn.textContent !== "...") {
|
|
49
|
-
page = +btn.textContent
|
|
51
|
+
page = +btn.textContent!;
|
|
50
52
|
fireEvent.click(btn);
|
|
51
53
|
// eslint-disable-next-line jest/no-conditional-expect
|
|
52
54
|
expect(gotoPageSpy).toHaveBeenCalled();
|
|
@@ -58,8 +60,9 @@ describe("Pagination", () => {
|
|
|
58
60
|
|
|
59
61
|
it("should have Previous button disabled and not clickable", () => {
|
|
60
62
|
const previousPageSpy = jest.fn();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
render(<Sandbox canPreviousPage={false} previousPage={previousPageSpy} {...Sandbox.args} />);
|
|
64
|
+
|
|
65
|
+
const previousButton = screen.getByText("Previous");
|
|
63
66
|
|
|
64
67
|
expect(previousButton).toHaveAttribute("disabled");
|
|
65
68
|
fireEvent.click(previousButton);
|
|
@@ -68,9 +71,9 @@ describe("Pagination", () => {
|
|
|
68
71
|
|
|
69
72
|
it("should have Previous button NOT disabled and clickable", () => {
|
|
70
73
|
const previousPageSpy = jest.fn();
|
|
71
|
-
|
|
74
|
+
render(<Sandbox {...Sandbox.args} canPreviousPage={true} previousPage={previousPageSpy} />);
|
|
72
75
|
|
|
73
|
-
const previousButton = getByText("Previous");
|
|
76
|
+
const previousButton = screen.getByText("Previous");
|
|
74
77
|
|
|
75
78
|
expect(previousButton).not.toHaveAttribute("disabled");
|
|
76
79
|
fireEvent.click(previousButton);
|
|
@@ -79,9 +82,9 @@ describe("Pagination", () => {
|
|
|
79
82
|
|
|
80
83
|
it("should have Next button disabled and not clickable", () => {
|
|
81
84
|
const nextPageSpy = jest.fn();
|
|
82
|
-
|
|
85
|
+
render(<Sandbox canNextPage={false} nextPage={nextPageSpy} {...Sandbox.args} />);
|
|
83
86
|
|
|
84
|
-
const nextButton = getByText("Next");
|
|
87
|
+
const nextButton = screen.getByText("Next");
|
|
85
88
|
expect(nextButton).toHaveAttribute("disabled");
|
|
86
89
|
fireEvent.click(nextButton);
|
|
87
90
|
expect(nextPageSpy).not.toHaveBeenCalled();
|
|
@@ -89,8 +92,8 @@ describe("Pagination", () => {
|
|
|
89
92
|
|
|
90
93
|
it("should have Next button NOT disabled and clickable", () => {
|
|
91
94
|
const nextPageSpy = jest.fn();
|
|
92
|
-
|
|
93
|
-
const nextButton = getByText("Next");
|
|
95
|
+
render(<Sandbox canNextPage={true} nextPage={nextPageSpy} {...Sandbox.args} />);
|
|
96
|
+
const nextButton = screen.getByText("Next");
|
|
94
97
|
expect(nextButton).not.toHaveAttribute("disabled");
|
|
95
98
|
fireEvent.click(nextButton);
|
|
96
99
|
expect(nextPageSpy).toHaveBeenCalled();
|
|
@@ -99,8 +102,8 @@ describe("Pagination", () => {
|
|
|
99
102
|
it("should correctly render select component", () => {
|
|
100
103
|
const pageSizes = [10, 25, 50, 100, 200, 500];
|
|
101
104
|
|
|
102
|
-
|
|
103
|
-
const selectComp = getByTestId("select_page");
|
|
105
|
+
render(<Sandbox {...Sandbox.args} pageSizes={pageSizes} />);
|
|
106
|
+
const selectComp = screen.getByTestId("select_page");
|
|
104
107
|
const selectChilds = Array.prototype.map.call(selectComp, function (child) {
|
|
105
108
|
return +child.textContent;
|
|
106
109
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Components, ComponentSchema } from "formiojs";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
|
+
|
|
3
4
|
import { Submission } from "../../interfaces/Submission";
|
|
4
5
|
|
|
5
6
|
export class ReactComponent<Data = any> extends Components.components.field {
|
|
6
7
|
public reactInstance: any;
|
|
7
|
-
public shouldSetValue
|
|
8
|
-
private dataForSetting
|
|
8
|
+
public shouldSetValue?: boolean;
|
|
9
|
+
private dataForSetting?: Data;
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* This is the first phase of component building where the component is instantiated.
|
|
@@ -14,13 +15,13 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
14
15
|
* @param options - Any options passed into the renderer.
|
|
15
16
|
* @param data - The submission data where this component's data exists.
|
|
16
17
|
*/
|
|
17
|
-
// eslint-disable-next-line no-useless-constructor
|
|
18
|
+
// eslint-disable-next-line no-useless-constructor,import/no-anonymous-default-export
|
|
18
19
|
constructor(component: ComponentSchema, options: any, data: Submission<Data>) {
|
|
19
20
|
super(component, options, data);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
get $reactNode() {
|
|
23
|
-
return this.refs[`react-${this.id}`];
|
|
24
|
+
return (this.refs as any)[`react-${this.id}`];
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -67,7 +68,9 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
67
68
|
[`react-${this.id}`]: "single"
|
|
68
69
|
});
|
|
69
70
|
|
|
71
|
+
// @ts-ignore
|
|
70
72
|
if (this.refs[`react-${this.id}`]) {
|
|
73
|
+
// @ts-ignore
|
|
71
74
|
this.reactInstance = this.attachReact(this.refs[`react-${this.id}`]);
|
|
72
75
|
|
|
73
76
|
if (this.shouldSetValue) {
|
|
@@ -82,7 +85,9 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
82
85
|
* or it is being removed from the form.
|
|
83
86
|
*/
|
|
84
87
|
detach() {
|
|
88
|
+
// @ts-ignore
|
|
85
89
|
if (this.refs[`react-${this.id}`]) {
|
|
90
|
+
// @ts-ignore
|
|
86
91
|
this.detachReact(this.refs[`react-${this.id}`]);
|
|
87
92
|
}
|
|
88
93
|
super.detach();
|
|
@@ -122,8 +127,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
122
127
|
* @param value
|
|
123
128
|
* @param flags
|
|
124
129
|
*/
|
|
125
|
-
|
|
126
|
-
setValue(value: any, flags?: any): boolean {
|
|
130
|
+
setValue(value: any, flags?: any) {
|
|
127
131
|
if (this.reactInstance) {
|
|
128
132
|
this.reactInstance.setState({
|
|
129
133
|
value: value
|
|
@@ -134,7 +138,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
|
|
|
134
138
|
this.dataForSetting = value;
|
|
135
139
|
}
|
|
136
140
|
|
|
137
|
-
return
|
|
141
|
+
return false;
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
/**
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
1
2
|
import React from "react";
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import { Choicesjs, Sandbox } from "./select.stories";
|
|
4
5
|
|
|
5
6
|
describe("Select", () => {
|
|
6
7
|
describe("select component Sandbox version", () => {
|
|
7
8
|
it("should render the select component", () => {
|
|
8
|
-
|
|
9
|
+
render(<Sandbox {...Sandbox.args} name={"test-sandbox"} />);
|
|
9
10
|
|
|
10
|
-
expect(getByTestId("select_test-sandbox")).toBeInTheDocument();
|
|
11
|
+
expect(screen.getByTestId("select_test-sandbox")).toBeInTheDocument();
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
it("should render the select component with a different size", () => {
|
|
14
|
-
|
|
15
|
-
const select = getByTestId("select_test-sandbox");
|
|
15
|
+
render(<Sandbox {...Sandbox.args} size='small' name={"test-sandbox"} />);
|
|
16
|
+
const select = screen.getByTestId("select_test-sandbox");
|
|
16
17
|
expect(select).toBeInTheDocument();
|
|
17
18
|
expect(select).toHaveClass("form-control-small");
|
|
18
19
|
});
|
|
@@ -25,11 +26,11 @@ describe("Select", () => {
|
|
|
25
26
|
|
|
26
27
|
const placeHolderTest = "Placeholder test";
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
render(<Sandbox {...Sandbox.args} placeholder={placeHolderTest} choices={choices} name={"test-sandbox"} />);
|
|
29
30
|
|
|
30
|
-
expect(getByRole("option", { name: "Placeholder test" })).toBeInTheDocument();
|
|
31
|
-
expect(getByRole("option", { name: "test1" })).toBeInTheDocument();
|
|
32
|
-
expect(getByRole("option", { name: "test2" })).toBeInTheDocument();
|
|
31
|
+
expect(screen.getByRole("option", { name: "Placeholder test" })).toBeInTheDocument();
|
|
32
|
+
expect(screen.getByRole("option", { name: "test1" })).toBeInTheDocument();
|
|
33
|
+
expect(screen.getByRole("option", { name: "test2" })).toBeInTheDocument();
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
it("should have Placeholder label as selected option by default", () => {
|
|
@@ -39,8 +40,8 @@ describe("Select", () => {
|
|
|
39
40
|
];
|
|
40
41
|
const placeHolderTest = "Placeholder test";
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
const option = getByRole("option", { name: placeHolderTest }) as HTMLOptionElement;
|
|
43
|
+
render(<Sandbox {...Sandbox.args} placeholder={placeHolderTest} choices={choices} name={"test-sandbox"} />);
|
|
44
|
+
const option = screen.getByRole("option", { name: placeHolderTest }) as HTMLOptionElement;
|
|
44
45
|
|
|
45
46
|
expect(option.selected).toBeTruthy();
|
|
46
47
|
});
|
|
@@ -53,15 +54,13 @@ describe("Select", () => {
|
|
|
53
54
|
const placeHolderTest = "Placeholder test";
|
|
54
55
|
const onChange = jest.fn();
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
<Sandbox {...Sandbox.args} placeholder={placeHolderTest} choices={choices} name={"test-sandbox"} onChange={onChange} />
|
|
58
|
-
);
|
|
57
|
+
render(<Sandbox {...Sandbox.args} placeholder={placeHolderTest} choices={choices} name={"test-sandbox"} onChange={onChange} />);
|
|
59
58
|
|
|
60
|
-
fireEvent.change(getByTestId("select_test-sandbox"), {
|
|
59
|
+
fireEvent.change(screen.getByTestId("select_test-sandbox"), {
|
|
61
60
|
target: { value: "value1" }
|
|
62
61
|
});
|
|
63
62
|
|
|
64
|
-
const option = getByRole("option", { name: "test1" }) as HTMLOptionElement;
|
|
63
|
+
const option = screen.getByRole("option", { name: "test1" }) as HTMLOptionElement;
|
|
65
64
|
|
|
66
65
|
expect(option.selected).toBeTruthy();
|
|
67
66
|
expect(onChange).toHaveBeenCalledWith("test-sandbox", "value1");
|
|
@@ -76,11 +75,11 @@ describe("Select", () => {
|
|
|
76
75
|
];
|
|
77
76
|
const placeHolderTest = "Placeholder test";
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
render(
|
|
80
79
|
<Choicesjs {...Choicesjs.args} layout={"choicesjs"} choices={choices} placeholder={placeHolderTest} name={"test-choicesjs"} />
|
|
81
80
|
);
|
|
82
81
|
|
|
83
|
-
expect(getByRole("option", { name: "test1" })).toBeInTheDocument();
|
|
82
|
+
expect(screen.getByRole("option", { name: "test1" })).toBeInTheDocument();
|
|
84
83
|
});
|
|
85
84
|
});
|
|
86
85
|
});
|
|
@@ -2,6 +2,7 @@ import Choices from "choices.js";
|
|
|
2
2
|
import classnames from "classnames";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import React, { ReactElement, useEffect, useRef } from "react";
|
|
5
|
+
|
|
5
6
|
import { getEventValue } from "../../utils/getEventValue";
|
|
6
7
|
import { FormControl, FormControlProps } from "../form-control/formControl.component";
|
|
7
8
|
|
|
@@ -33,7 +34,7 @@ export function Select<T = any>({
|
|
|
33
34
|
layout,
|
|
34
35
|
...props
|
|
35
36
|
}: SelectProps<T>): ReactElement {
|
|
36
|
-
const ref = useRef();
|
|
37
|
+
const ref = useRef<any>();
|
|
37
38
|
|
|
38
39
|
useEffect(() => {
|
|
39
40
|
let instance: any;
|
|
@@ -75,7 +76,7 @@ export function Select<T = any>({
|
|
|
75
76
|
value={value || ("" as any)}
|
|
76
77
|
placeholder={placeholder}
|
|
77
78
|
onChange={(event) => {
|
|
78
|
-
onChange(name, getEventValue(event));
|
|
79
|
+
onChange && onChange(name, getEventValue(event));
|
|
79
80
|
}}
|
|
80
81
|
>
|
|
81
82
|
{choices.map(({ label, value }) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
|
|
2
3
|
import { FormSchema, Submission } from "../../interfaces";
|
|
3
4
|
import { Table, TableProps } from "../table/table.component";
|
|
4
5
|
import { mapFormToColumns } from "../table/utils/mapFormToColumns";
|
|
@@ -8,7 +9,7 @@ export type SubmissionsTableProps = Omit<TableProps<Submission>, "columns"> & {
|
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
export function SubmissionsTable({ form, ...props }: SubmissionsTableProps) {
|
|
11
|
-
const columns: any[]
|
|
12
|
+
const columns: any[] | undefined = form && mapFormToColumns(form);
|
|
12
13
|
|
|
13
|
-
return <Table {...props} columns={columns} />;
|
|
14
|
+
return <Table {...props} columns={columns!} />;
|
|
14
15
|
}
|
|
@@ -5,7 +5,7 @@ export interface DefaultCellHeaderProps<Data extends object = any> extends Recor
|
|
|
5
5
|
column: HeaderGroup<Data>;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export function DefaultCellHeader<Data extends Record<string, unknown> = {}>({ column }: DefaultCellHeaderProps) {
|
|
8
|
+
export function DefaultCellHeader<Data extends Record<string, unknown> = {}>({ column }: DefaultCellHeaderProps<Data>) {
|
|
9
9
|
return (
|
|
10
10
|
<div className={"table-cell-header"}>
|
|
11
11
|
<div className='table-cell-header__label' {...column.getSortByToggleProps()}>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import "@testing-library/jest-dom/extend-expect";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
3
4
|
import React from "react";
|
|
5
|
+
|
|
4
6
|
import { DefaultColumnFilter } from "./defaultColumnFilter.component";
|
|
5
7
|
|
|
6
8
|
describe("DefaultColumnFilter", () => {
|
|
@@ -12,12 +14,12 @@ describe("DefaultColumnFilter", () => {
|
|
|
12
14
|
column: { id: "id", filterValue: "", setFilter: jest.fn() }
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
render(
|
|
16
18
|
// @ts-ignore
|
|
17
19
|
<DefaultColumnFilter {...props} />
|
|
18
20
|
);
|
|
19
21
|
|
|
20
|
-
const input = getByRole("textbox");
|
|
22
|
+
const input = screen.getByRole("textbox");
|
|
21
23
|
|
|
22
24
|
// eslint-disable-next-line testing-library/no-unnecessary-act
|
|
23
25
|
await act(async () => {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import "@testing-library/jest-dom/extend-expect";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
3
4
|
import React from "react";
|
|
5
|
+
|
|
4
6
|
import { SelectColumnFilter } from "./selectColumnFilter.component";
|
|
5
7
|
|
|
6
8
|
describe("SelectColumnFilter", () => {
|
|
@@ -15,13 +17,13 @@ describe("SelectColumnFilter", () => {
|
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
render(
|
|
19
21
|
// @ts-ignore
|
|
20
22
|
<SelectColumnFilter {...props} />
|
|
21
23
|
);
|
|
22
24
|
|
|
23
|
-
expect(getByText("select-choice-1")).toBeDefined();
|
|
24
|
-
expect(getByText("select-choice-2")).toBeDefined();
|
|
25
|
+
expect(screen.getByText("select-choice-1")).toBeDefined();
|
|
26
|
+
expect(screen.getByText("select-choice-2")).toBeDefined();
|
|
25
27
|
});
|
|
26
28
|
it("should display select with custom choices", async () => {
|
|
27
29
|
const mockSetFilter = jest.fn();
|
|
@@ -35,12 +37,12 @@ describe("SelectColumnFilter", () => {
|
|
|
35
37
|
}
|
|
36
38
|
};
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
render(
|
|
39
41
|
// @ts-ignore
|
|
40
42
|
<SelectColumnFilter {...props} />
|
|
41
43
|
);
|
|
42
44
|
|
|
43
|
-
expect(queryByText("select-choice-1")).toBeNull();
|
|
44
|
-
expect(getByText("fake-choice")).toBeDefined();
|
|
45
|
+
expect(screen.queryByText("select-choice-1")).toBeNull();
|
|
46
|
+
expect(screen.getByText("fake-choice")).toBeDefined();
|
|
45
47
|
});
|
|
46
48
|
});
|