@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,6 +1,6 @@
|
|
|
1
1
|
import { RoleSchema, Submission } from "../../interfaces";
|
|
2
2
|
import { AuthState } from "./auth.reducers";
|
|
3
3
|
export declare const selectAuth: (state: any) => AuthState<any>;
|
|
4
|
-
export declare const selectUser: <User = any>(state: any) => Submission<User
|
|
4
|
+
export declare const selectUser: <User = any>(state: any) => Submission<User> | null;
|
|
5
5
|
export declare const selectRoles: (state: any) => Record<string, RoleSchema>;
|
|
6
6
|
export declare const selectIsAuthenticated: (state: any) => boolean;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from "./auth.constant";
|
|
2
|
-
export * from "./auth.utils";
|
|
3
1
|
export * from "./auth.actions";
|
|
2
|
+
export * from "./auth.constant";
|
|
4
3
|
export * from "./auth.reducers";
|
|
5
4
|
export * from "./auth.selectors";
|
|
6
|
-
export * from "./
|
|
5
|
+
export * from "./auth.utils";
|
|
7
6
|
export * from "./getAccess.action";
|
|
7
|
+
export * from "./getProjectAccess.action";
|
|
8
|
+
export * from "./initAuth.action";
|
|
8
9
|
export * from "./logout.action";
|
|
9
10
|
export * from "./setUser.action";
|
|
10
|
-
export * from "./initAuth.action";
|
package/dist/stores/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from "./auth";
|
|
2
1
|
export * from "./action";
|
|
3
2
|
export * from "./action-info";
|
|
4
3
|
export * from "./actions";
|
|
4
|
+
export * from "./auth";
|
|
5
5
|
export * from "./form";
|
|
6
6
|
export * from "./forms";
|
|
7
|
+
export * from "./root";
|
|
7
8
|
export * from "./submission";
|
|
8
9
|
export * from "./submissions";
|
|
9
|
-
export * from "./root";
|
|
10
10
|
export declare const defaultFormioReducer: Record<string, import("@tsed/redux-utils").ReduceFunction<any, any>>;
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.3",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.modern.js",
|
|
7
7
|
"source": "src/index.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"
|
|
9
|
+
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
|
|
10
|
+
"lint:fix": "yarn lint --fix",
|
|
11
|
+
"test": "cross-env NODE_ENV=test jest --coverage",
|
|
12
|
+
"test:coverage:update": "write-coverage",
|
|
10
13
|
"build": "microbundle --no-compress --format modern,cjs --jsx React.createElement",
|
|
11
14
|
"watch": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement"
|
|
12
15
|
},
|
|
13
16
|
"dependencies": {
|
|
14
|
-
"@tsed/redux-utils": "1.13.
|
|
17
|
+
"@tsed/redux-utils": "1.13.3",
|
|
15
18
|
"eventemitter2": "^6.4.3",
|
|
16
19
|
"prop-types": "^15.7.2"
|
|
17
20
|
},
|
|
@@ -26,8 +29,8 @@
|
|
|
26
29
|
"tooltip.js": ">=1.3.3"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"@tsed/tailwind": "1.13.
|
|
30
|
-
"@tsed/tailwind-formio": "1.13.
|
|
32
|
+
"@tsed/tailwind": "1.13.3",
|
|
33
|
+
"@tsed/tailwind-formio": "1.13.3"
|
|
31
34
|
},
|
|
32
35
|
"repository": "https://github.com/TypedProject/tsed-formio",
|
|
33
36
|
"bugs": {
|
|
@@ -1966,6 +1966,29 @@
|
|
|
1966
1966
|
"id": "em22wkd",
|
|
1967
1967
|
"defaultValue": null
|
|
1968
1968
|
},
|
|
1969
|
+
{
|
|
1970
|
+
"label": "Edit Grid",
|
|
1971
|
+
"tableView": false,
|
|
1972
|
+
"rowDrafts": false,
|
|
1973
|
+
"key": "editGrid",
|
|
1974
|
+
"type": "editgrid",
|
|
1975
|
+
"displayAsTable": false,
|
|
1976
|
+
"input": true,
|
|
1977
|
+
"components": [
|
|
1978
|
+
{
|
|
1979
|
+
"label": "Currency",
|
|
1980
|
+
"mask": false,
|
|
1981
|
+
"spellcheck": true,
|
|
1982
|
+
"tableView": true,
|
|
1983
|
+
"currency": "USD",
|
|
1984
|
+
"inputFormat": "plain",
|
|
1985
|
+
"key": "currency",
|
|
1986
|
+
"type": "currency",
|
|
1987
|
+
"input": true,
|
|
1988
|
+
"delimiter": true
|
|
1989
|
+
}
|
|
1990
|
+
]
|
|
1991
|
+
},
|
|
1969
1992
|
{
|
|
1970
1993
|
"type": "button",
|
|
1971
1994
|
"label": "Submit",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { fireEvent, render } from "@testing-library/react";
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
2
|
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import React from "react";
|
|
4
4
|
|
|
5
5
|
import { Sandbox } from "./actionsTable.stories";
|
|
6
6
|
|
|
@@ -8,11 +8,11 @@ describe("ActionsTable", () => {
|
|
|
8
8
|
it("should render the table actions", async () => {
|
|
9
9
|
const onAddAction = jest.fn();
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
|
|
12
12
|
|
|
13
|
-
const btn = getByRole("button", { name: /add action/i });
|
|
14
|
-
const cells = getAllByRole("cell");
|
|
15
|
-
const options = getAllByRole("option");
|
|
13
|
+
const btn = screen.getByRole("button", { name: /add action/i });
|
|
14
|
+
const cells = screen.getAllByRole("cell");
|
|
15
|
+
const options = screen.getAllByRole("option");
|
|
16
16
|
|
|
17
17
|
expect(btn).toHaveProperty("disabled");
|
|
18
18
|
expect(btn.innerHTML).toMatch("Add action");
|
|
@@ -25,9 +25,9 @@ describe("ActionsTable", () => {
|
|
|
25
25
|
it("should not call addAction when the default item is selected", async () => {
|
|
26
26
|
const onAddAction = jest.fn();
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
|
|
29
29
|
|
|
30
|
-
const btn = getByRole("button", { name: /add action/i });
|
|
30
|
+
const btn = screen.getByRole("button", { name: /add action/i });
|
|
31
31
|
|
|
32
32
|
await fireEvent.click(btn);
|
|
33
33
|
expect(onAddAction).not.toHaveBeenCalled();
|
|
@@ -35,10 +35,10 @@ describe("ActionsTable", () => {
|
|
|
35
35
|
it("should call addAction with the selected action", async () => {
|
|
36
36
|
const onAddAction = jest.fn();
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
|
|
39
39
|
|
|
40
|
-
const btn = getByRole("button", { name: /add action/i });
|
|
41
|
-
const select = getByRole("combobox");
|
|
40
|
+
const btn = screen.getByRole("button", { name: /add action/i });
|
|
41
|
+
const select = screen.getByRole("combobox");
|
|
42
42
|
|
|
43
43
|
await userEvent.selectOptions(select, String(Sandbox.args.availableActions[1].value));
|
|
44
44
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import classnames from "classnames";
|
|
2
2
|
import noop from "lodash/noop";
|
|
3
3
|
import React, { useState } from "react";
|
|
4
|
+
|
|
4
5
|
import { ActionSchema } from "../../interfaces";
|
|
5
6
|
import { iconClass } from "../../utils/iconClass";
|
|
6
7
|
import { Select } from "../select/select.component";
|
|
@@ -21,15 +22,13 @@ export function ActionsTable({
|
|
|
21
22
|
const { i18n = (f: string) => f } = props;
|
|
22
23
|
const [currentAction, setAction] = useState("");
|
|
23
24
|
|
|
24
|
-
const columns =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
];
|
|
32
|
-
}, []);
|
|
25
|
+
const columns = [
|
|
26
|
+
{
|
|
27
|
+
Header: i18n("Actions"),
|
|
28
|
+
accessor: "title",
|
|
29
|
+
id: "title"
|
|
30
|
+
}
|
|
31
|
+
];
|
|
33
32
|
|
|
34
33
|
return (
|
|
35
34
|
<Table {...props} disableFilters={disableFilters} disablePagination={disablePagination} columns={columns}>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
1
2
|
import React from "react";
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import { Sandbox } from "./alert.stories";
|
|
4
5
|
|
|
5
6
|
describe("Alert component", () => {
|
|
@@ -11,9 +12,10 @@ describe("Alert component", () => {
|
|
|
11
12
|
|
|
12
13
|
it("should display an error when the error is in string format", () => {
|
|
13
14
|
const error = "error in string format";
|
|
14
|
-
const { getByRole } = render(<Sandbox {...Sandbox.args} error={error} />);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
render(<Sandbox {...Sandbox.args} error={error} />);
|
|
17
|
+
|
|
18
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
17
19
|
|
|
18
20
|
expect(alert).toBeInTheDocument();
|
|
19
21
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -23,13 +25,13 @@ describe("Alert component", () => {
|
|
|
23
25
|
it("should display error(s) when the error is an array", () => {
|
|
24
26
|
const arrayOfErrors = ["first error", "second error", "third error"];
|
|
25
27
|
const joinedErrors = arrayOfErrors.map((error) => error).join("");
|
|
26
|
-
|
|
28
|
+
render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
|
|
27
29
|
|
|
28
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
30
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
29
31
|
|
|
30
32
|
expect(alert).toBeInTheDocument();
|
|
31
33
|
expect(alert).toHaveClass("alert alert-danger");
|
|
32
|
-
expect(getByText(joinedErrors)).toBeInTheDocument();
|
|
34
|
+
expect(screen.getByText(joinedErrors)).toBeInTheDocument();
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
it("should display error's names paths and messages when the error is an object that has an 'errors' property that contains an array of error objects", () => {
|
|
@@ -40,9 +42,9 @@ describe("Alert component", () => {
|
|
|
40
42
|
{ name: "third error", path: "/path", message: "message" }
|
|
41
43
|
]
|
|
42
44
|
};
|
|
43
|
-
|
|
45
|
+
render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
|
|
44
46
|
|
|
45
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
47
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
46
48
|
|
|
47
49
|
expect(alert).toBeInTheDocument();
|
|
48
50
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -51,33 +53,33 @@ describe("Alert component", () => {
|
|
|
51
53
|
|
|
52
54
|
it("should display an error message when the error is a standard error", () => {
|
|
53
55
|
const standardError = { message: "first error" };
|
|
54
|
-
|
|
56
|
+
render(<Sandbox {...Sandbox.args} error={standardError} />);
|
|
55
57
|
|
|
56
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
58
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
57
59
|
|
|
58
60
|
expect(alert).toBeInTheDocument();
|
|
59
61
|
expect(alert).toHaveClass("alert alert-danger");
|
|
60
|
-
expect(getByText(standardError.message)).toBeInTheDocument();
|
|
62
|
+
expect(screen.getByText(standardError.message)).toBeInTheDocument();
|
|
61
63
|
});
|
|
62
64
|
|
|
63
65
|
it("should display error(s) message(s) when the error is a joi validation error", () => {
|
|
64
66
|
const joiValidationError = { name: "ValidationError", details: [{ message: "message 1" }, { message: "message 2" }] };
|
|
65
|
-
|
|
67
|
+
render(<Sandbox {...Sandbox.args} error={joiValidationError} />);
|
|
66
68
|
|
|
67
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
69
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
68
70
|
|
|
69
71
|
expect(alert).toBeInTheDocument();
|
|
70
72
|
expect(alert).toHaveClass("alert alert-danger");
|
|
71
|
-
expect(getByText("message 1")).toBeInTheDocument();
|
|
72
|
-
expect(getByText("message 2")).toBeInTheDocument();
|
|
73
|
+
expect(screen.getByText("message 1")).toBeInTheDocument();
|
|
74
|
+
expect(screen.getByText("message 2")).toBeInTheDocument();
|
|
73
75
|
});
|
|
74
76
|
|
|
75
77
|
it("should display a custom error message that asks to reload the form when a conflict error occurs in a form", () => {
|
|
76
78
|
const error = { _id: "some id", display: "some value" };
|
|
77
79
|
const messageReturned = "Another user has saved this form already. Please reload and re-apply your changes.";
|
|
78
|
-
|
|
80
|
+
render(<Sandbox {...Sandbox.args} error={error} />);
|
|
79
81
|
|
|
80
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
82
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
81
83
|
|
|
82
84
|
expect(alert).toBeInTheDocument();
|
|
83
85
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -86,9 +88,9 @@ describe("Alert component", () => {
|
|
|
86
88
|
|
|
87
89
|
it("should display an error message by default when the error format does not match any of the conditions of the formatError() handler", () => {
|
|
88
90
|
const messageError: string = "An error occurred. See console logs for details.";
|
|
89
|
-
|
|
91
|
+
render(<Sandbox {...Sandbox.args} error={true} />);
|
|
90
92
|
|
|
91
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
93
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
92
94
|
|
|
93
95
|
expect(alert).toBeInTheDocument();
|
|
94
96
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -1,13 +1,14 @@
|
|
|
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 "./card.stories";
|
|
4
5
|
|
|
5
6
|
describe("Card", () => {
|
|
6
7
|
it("should render the card component", () => {
|
|
7
|
-
|
|
8
|
+
render(<Sandbox {...Sandbox.args} />);
|
|
8
9
|
|
|
9
|
-
const title = getByRole("heading");
|
|
10
|
-
const body = getByRole("article");
|
|
10
|
+
const title = screen.getByRole("heading");
|
|
11
|
+
const body = screen.getByRole("article");
|
|
11
12
|
|
|
12
13
|
expect(title).toHaveTextContent("label");
|
|
13
14
|
expect(body).toHaveTextContent("test");
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { screen } from "@testing-library/react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
import { Form } from "./form.component";
|
|
5
|
+
|
|
6
|
+
async function createFixture(props: any = {}) {
|
|
7
|
+
const onSubmit = jest.fn();
|
|
8
|
+
const form = {
|
|
9
|
+
type: "form",
|
|
10
|
+
display: "form",
|
|
11
|
+
tags: [],
|
|
12
|
+
components: [
|
|
13
|
+
{
|
|
14
|
+
label: "First name",
|
|
15
|
+
placeholder: "Fill first name",
|
|
16
|
+
widget: {
|
|
17
|
+
type: "input"
|
|
18
|
+
},
|
|
19
|
+
errorLabel: "",
|
|
20
|
+
key: "firstName",
|
|
21
|
+
inputType: "text",
|
|
22
|
+
type: "textfield",
|
|
23
|
+
id: "eqb1o4r",
|
|
24
|
+
defaultValue: ""
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: "Submit form",
|
|
28
|
+
showValidations: false,
|
|
29
|
+
tableView: false,
|
|
30
|
+
key: "submit",
|
|
31
|
+
type: "button",
|
|
32
|
+
input: true
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
render(<Form {...props} form={form} onSubmit={onSubmit} />);
|
|
38
|
+
|
|
39
|
+
return { onSubmit };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("Form", () => {
|
|
43
|
+
it("should render the Form", async () => {
|
|
44
|
+
await createFixture({
|
|
45
|
+
data: [],
|
|
46
|
+
model: "MyForm",
|
|
47
|
+
groups: ["creation"],
|
|
48
|
+
params: {
|
|
49
|
+
env: "prod"
|
|
50
|
+
},
|
|
51
|
+
isActive: false
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(screen.getByTestId("formioContainer")).toBeInTheDocument();
|
|
55
|
+
expect(screen.getByText("First name")).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import AllComponents from "formiojs/components";
|
|
2
1
|
import { Components } from "formiojs";
|
|
2
|
+
import AllComponents from "formiojs/components";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import React from "react";
|
|
5
|
+
|
|
5
6
|
import { useForm, UseFormHookProps } from "./useForm.hook";
|
|
6
7
|
|
|
7
8
|
Components.setComponents(AllComponents);
|
|
@@ -14,10 +15,10 @@ export interface FormProps<Data = any> extends UseFormHookProps<Data> {
|
|
|
14
15
|
className?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export function Form(props: Partial<FormProps
|
|
18
|
+
export function Form<Data = any>(props: Partial<FormProps<Data>>) {
|
|
18
19
|
const { element } = useForm(props);
|
|
19
20
|
|
|
20
|
-
return <div data-testid={
|
|
21
|
+
return <div data-testid={`formioContainer${props.name || ""}`} ref={element} className={props.className} />;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
Form.propTypes = {
|