@tsed/react-formio 1.14.1 → 2.0.1
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/coverage.json +4 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1277 -3684
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +956 -2767
- package/dist/index.modern.js.map +1 -1
- package/package.json +4 -5
- package/readme.md +9 -57
- package/src/components/input-tags/inputTags.component.tsx +1 -1
- package/src/components/select/select.component.tsx +1 -1
- package/src/components/table/filters/sliderColumnFilter.component.tsx +2 -2
- package/src/index.ts +3 -2
- package/dist/stores/action/action.actions.d.ts +0 -9
- package/dist/stores/action/action.actions.spec.d.ts +0 -1
- package/dist/stores/action/action.constant.d.ts +0 -1
- package/dist/stores/action/action.reducers.d.ts +0 -7
- package/dist/stores/action/action.reducers.spec.d.ts +0 -1
- package/dist/stores/action/action.selectors.d.ts +0 -2
- package/dist/stores/action/action.selectors.spec.d.ts +0 -1
- package/dist/stores/action/index.d.ts +0 -4
- package/dist/stores/action-info/action-info.actions.d.ts +0 -5
- package/dist/stores/action-info/action-info.actions.spec.d.ts +0 -1
- package/dist/stores/action-info/action-info.constant.d.ts +0 -1
- package/dist/stores/action-info/action-info.reducers.d.ts +0 -7
- package/dist/stores/action-info/action-info.reducers.spec.d.ts +0 -1
- package/dist/stores/action-info/action-info.selectors.d.ts +0 -2
- package/dist/stores/action-info/action-info.selectors.spec.d.ts +0 -1
- package/dist/stores/action-info/index.d.ts +0 -4
- package/dist/stores/actions/actions.actions.d.ts +0 -5
- package/dist/stores/actions/actions.actions.spec.d.ts +0 -1
- package/dist/stores/actions/actions.constant.d.ts +0 -1
- package/dist/stores/actions/actions.reducers.d.ts +0 -8
- package/dist/stores/actions/actions.reducers.spec.d.ts +0 -1
- package/dist/stores/actions/actions.selectors.d.ts +0 -2
- package/dist/stores/actions/actions.selectors.spec.d.ts +0 -1
- package/dist/stores/actions/index.d.ts +0 -4
- package/dist/stores/auth/auth.actions.d.ts +0 -9
- package/dist/stores/auth/auth.constant.d.ts +0 -1
- package/dist/stores/auth/auth.reducers.d.ts +0 -16
- package/dist/stores/auth/auth.reducers.spec.d.ts +0 -1
- package/dist/stores/auth/auth.selectors.d.ts +0 -6
- package/dist/stores/auth/auth.selectors.spec.d.ts +0 -1
- package/dist/stores/auth/auth.utils.d.ts +0 -6
- package/dist/stores/auth/auth.utils.spec.d.ts +0 -1
- package/dist/stores/auth/getAccess.action.d.ts +0 -1
- package/dist/stores/auth/getAccess.action.spec.d.ts +0 -1
- package/dist/stores/auth/getProjectAccess.action.d.ts +0 -1
- package/dist/stores/auth/index.d.ts +0 -10
- package/dist/stores/auth/initAuth.action.d.ts +0 -1
- package/dist/stores/auth/initAuth.action.spec.d.ts +0 -1
- package/dist/stores/auth/logout.action.d.ts +0 -1
- package/dist/stores/auth/logout.action.spec.d.ts +0 -1
- package/dist/stores/auth/setUser.action.d.ts +0 -1
- package/dist/stores/auth/setUser.action.spec.d.ts +0 -1
- package/dist/stores/form/form.actions.d.ts +0 -10
- package/dist/stores/form/form.actions.spec.d.ts +0 -1
- package/dist/stores/form/form.reducers.d.ts +0 -9
- package/dist/stores/form/form.reducers.spec.d.ts +0 -1
- package/dist/stores/form/form.selectors.d.ts +0 -2
- package/dist/stores/form/form.selectors.spec.d.ts +0 -1
- package/dist/stores/form/index.d.ts +0 -3
- package/dist/stores/forms/forms.actions.d.ts +0 -9
- package/dist/stores/forms/forms.actions.spec.d.ts +0 -1
- package/dist/stores/forms/forms.reducers.d.ts +0 -16
- package/dist/stores/forms/forms.reducers.spec.d.ts +0 -1
- package/dist/stores/forms/forms.selectors.d.ts +0 -10
- package/dist/stores/forms/forms.selectors.spec.d.ts +0 -1
- package/dist/stores/forms/index.d.ts +0 -3
- package/dist/stores/index.d.ts +0 -10
- package/dist/stores/index.spec.d.ts +0 -1
- package/dist/stores/root/index.d.ts +0 -1
- package/dist/stores/root/root.selectors.d.ts +0 -5
- package/dist/stores/root/root.selectors.spec.d.ts +0 -1
- package/dist/stores/submission/index.d.ts +0 -3
- package/dist/stores/submission/submission.actions.d.ts +0 -10
- package/dist/stores/submission/submission.actions.spec.d.ts +0 -1
- package/dist/stores/submission/submission.reducers.d.ts +0 -11
- package/dist/stores/submission/submission.reducers.spec.d.ts +0 -1
- package/dist/stores/submission/submission.selectors.d.ts +0 -2
- package/dist/stores/submission/submission.selectors.spec.d.ts +0 -1
- package/dist/stores/submissions/index.d.ts +0 -3
- package/dist/stores/submissions/submissions.actions.d.ts +0 -6
- package/dist/stores/submissions/submissions.actions.spec.d.ts +0 -1
- package/dist/stores/submissions/submissions.reducers.d.ts +0 -17
- package/dist/stores/submissions/submissions.reducers.spec.d.ts +0 -1
- package/dist/stores/submissions/submissions.selectors.d.ts +0 -9
- package/dist/stores/submissions/submissions.selectors.spec.d.ts +0 -1
- package/dist/utils/clean.d.ts +0 -1
- package/dist/utils/clean.test.d.ts +0 -1
- package/dist/utils/mapRequestParams.d.ts +0 -9
- package/dist/utils/mapRequestParams.test.d.ts +0 -1
- package/dist/utils/url.d.ts +0 -3
- package/dist/utils/url.test.d.ts +0 -1
- package/src/stores/action/action.actions.spec.ts +0 -114
- package/src/stores/action/action.actions.ts +0 -82
- package/src/stores/action/action.constant.ts +0 -1
- package/src/stores/action/action.reducers.spec.ts +0 -91
- package/src/stores/action/action.reducers.ts +0 -54
- package/src/stores/action/action.selectors.spec.ts +0 -19
- package/src/stores/action/action.selectors.ts +0 -6
- package/src/stores/action/index.ts +0 -4
- package/src/stores/action-info/action-info.actions.spec.ts +0 -46
- package/src/stores/action-info/action-info.actions.ts +0 -32
- package/src/stores/action-info/action-info.constant.ts +0 -1
- package/src/stores/action-info/action-info.reducers.spec.ts +0 -60
- package/src/stores/action-info/action-info.reducers.ts +0 -44
- package/src/stores/action-info/action-info.selectors.spec.ts +0 -19
- package/src/stores/action-info/action-info.selectors.ts +0 -7
- package/src/stores/action-info/index.ts +0 -4
- package/src/stores/actions/actions.actions.spec.ts +0 -62
- package/src/stores/actions/actions.actions.ts +0 -34
- package/src/stores/actions/actions.constant.ts +0 -1
- package/src/stores/actions/actions.reducers.spec.ts +0 -62
- package/src/stores/actions/actions.reducers.ts +0 -48
- package/src/stores/actions/actions.selectors.spec.ts +0 -34
- package/src/stores/actions/actions.selectors.ts +0 -7
- package/src/stores/actions/index.ts +0 -4
- package/src/stores/auth/auth.actions.ts +0 -13
- package/src/stores/auth/auth.constant.ts +0 -1
- package/src/stores/auth/auth.reducers.spec.ts +0 -376
- package/src/stores/auth/auth.reducers.ts +0 -151
- package/src/stores/auth/auth.selectors.spec.ts +0 -47
- package/src/stores/auth/auth.selectors.ts +0 -14
- package/src/stores/auth/auth.utils.spec.ts +0 -29
- package/src/stores/auth/auth.utils.tsx +0 -37
- package/src/stores/auth/getAccess.action.spec.ts +0 -257
- package/src/stores/auth/getAccess.action.ts +0 -57
- package/src/stores/auth/getProjectAccess.action.ts +0 -25
- package/src/stores/auth/index.ts +0 -10
- package/src/stores/auth/initAuth.action.spec.ts +0 -56
- package/src/stores/auth/initAuth.action.ts +0 -29
- package/src/stores/auth/logout.action.spec.ts +0 -25
- package/src/stores/auth/logout.action.ts +0 -9
- package/src/stores/auth/setUser.action.spec.ts +0 -25
- package/src/stores/auth/setUser.action.ts +0 -9
- package/src/stores/form/form.actions.spec.ts +0 -203
- package/src/stores/form/form.actions.ts +0 -84
- package/src/stores/form/form.reducers.spec.ts +0 -78
- package/src/stores/form/form.reducers.ts +0 -59
- package/src/stores/form/form.selectors.spec.ts +0 -19
- package/src/stores/form/form.selectors.ts +0 -5
- package/src/stores/form/index.ts +0 -3
- package/src/stores/forms/forms.actions.spec.ts +0 -91
- package/src/stores/forms/forms.actions.ts +0 -44
- package/src/stores/forms/forms.reducers.spec.ts +0 -97
- package/src/stores/forms/forms.reducers.ts +0 -77
- package/src/stores/forms/forms.selectors.spec.ts +0 -39
- package/src/stores/forms/forms.selectors.ts +0 -6
- package/src/stores/forms/index.ts +0 -3
- package/src/stores/index.spec.ts +0 -125
- package/src/stores/index.ts +0 -33
- package/src/stores/root/index.ts +0 -1
- package/src/stores/root/root.selectors.spec.ts +0 -94
- package/src/stores/root/root.selectors.ts +0 -23
- package/src/stores/submission/index.ts +0 -3
- package/src/stores/submission/submission.actions.spec.ts +0 -214
- package/src/stores/submission/submission.actions.ts +0 -81
- package/src/stores/submission/submission.reducers.spec.ts +0 -96
- package/src/stores/submission/submission.reducers.ts +0 -70
- package/src/stores/submission/submission.selectors.spec.ts +0 -19
- package/src/stores/submission/submission.selectors.ts +0 -5
- package/src/stores/submissions/index.ts +0 -3
- package/src/stores/submissions/submissions.actions.spec.ts +0 -99
- package/src/stores/submissions/submissions.actions.ts +0 -38
- package/src/stores/submissions/submissions.reducers.spec.ts +0 -98
- package/src/stores/submissions/submissions.reducers.ts +0 -78
- package/src/stores/submissions/submissions.selectors.spec.ts +0 -39
- package/src/stores/submissions/submissions.selectors.ts +0 -6
- package/src/utils/clean.test.ts +0 -7
- package/src/utils/clean.ts +0 -12
- package/src/utils/mapRequestParams.test.ts +0 -81
- package/src/utils/mapRequestParams.ts +0 -36
- package/src/utils/url.test.ts +0 -31
- package/src/utils/url.ts +0 -23
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Formio } from "formiojs";
|
|
2
|
-
import noop from "lodash/noop";
|
|
3
|
-
|
|
4
|
-
import { failUser, requestUser } from "./auth.actions";
|
|
5
|
-
import { AUTH } from "./auth.constant";
|
|
6
|
-
import { getAccess } from "./getAccess.action";
|
|
7
|
-
import { getProjectAccess } from "./getProjectAccess.action";
|
|
8
|
-
import { logout } from "./logout.action";
|
|
9
|
-
import { setUser } from "./setUser.action";
|
|
10
|
-
|
|
11
|
-
export const initAuth =
|
|
12
|
-
(done = noop) =>
|
|
13
|
-
async (dispatch: any) => {
|
|
14
|
-
dispatch(requestUser(AUTH));
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const [user] = await Promise.all([Formio.currentUser(), getAccess(dispatch), getProjectAccess(dispatch)]);
|
|
18
|
-
|
|
19
|
-
if (user) {
|
|
20
|
-
dispatch(setUser(user));
|
|
21
|
-
} else {
|
|
22
|
-
dispatch(logout());
|
|
23
|
-
}
|
|
24
|
-
} catch (error) {
|
|
25
|
-
dispatch(failUser(AUTH, { error }));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
done();
|
|
29
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Formio } from "formiojs";
|
|
2
|
-
|
|
3
|
-
import { logoutUser } from "./auth.actions";
|
|
4
|
-
import { AUTH } from "./auth.constant";
|
|
5
|
-
import { logout } from "./logout.action";
|
|
6
|
-
|
|
7
|
-
jest.mock("./auth.actions");
|
|
8
|
-
jest.mock("formiojs");
|
|
9
|
-
|
|
10
|
-
describe("logout()", () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
jest.spyOn(Formio, "logout");
|
|
13
|
-
});
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
jest.resetAllMocks();
|
|
16
|
-
});
|
|
17
|
-
it("should call logout", async () => {
|
|
18
|
-
const dispatch = jest.fn();
|
|
19
|
-
|
|
20
|
-
await logout()(dispatch);
|
|
21
|
-
|
|
22
|
-
expect(Formio.logout).toHaveBeenCalledWith();
|
|
23
|
-
expect(logoutUser).toHaveBeenCalledWith(AUTH);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Formio } from "formiojs";
|
|
2
|
-
|
|
3
|
-
import { receiveUser } from "./auth.actions";
|
|
4
|
-
import { AUTH } from "./auth.constant";
|
|
5
|
-
import { setUser } from "./setUser.action";
|
|
6
|
-
|
|
7
|
-
jest.mock("./auth.actions");
|
|
8
|
-
|
|
9
|
-
describe("setUser()", () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
jest.spyOn(Formio, "setUser");
|
|
12
|
-
});
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
jest.resetAllMocks();
|
|
15
|
-
});
|
|
16
|
-
it("should call logout", async () => {
|
|
17
|
-
const dispatch = jest.fn();
|
|
18
|
-
const user = {};
|
|
19
|
-
|
|
20
|
-
await setUser(user)(dispatch);
|
|
21
|
-
|
|
22
|
-
expect(Formio.setUser).toHaveBeenCalledWith(user);
|
|
23
|
-
expect(receiveUser).toHaveBeenCalledWith(AUTH, { user });
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { Formio } from "formiojs";
|
|
2
|
-
|
|
3
|
-
import { deleteForm, failForm, getForm, receiveForm, requestForm, resetForm, saveForm, sendForm } from "./form.actions";
|
|
4
|
-
|
|
5
|
-
jest.mock("formiojs");
|
|
6
|
-
|
|
7
|
-
describe("Form actions", () => {
|
|
8
|
-
describe("getForm", () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
Formio.mockClear();
|
|
12
|
-
});
|
|
13
|
-
it("should return a result", async () => {
|
|
14
|
-
// GIVEN
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
Formio.prototype.loadForm.mockReturnValue(Promise.resolve({}));
|
|
17
|
-
|
|
18
|
-
const dispatch = jest.fn();
|
|
19
|
-
const name = "name";
|
|
20
|
-
const formId = "formId";
|
|
21
|
-
|
|
22
|
-
const getState = () => ({
|
|
23
|
-
[name]: {}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// WHEN
|
|
27
|
-
await new Promise((resolve) => getForm(name, formId, resolve)(dispatch, getState));
|
|
28
|
-
|
|
29
|
-
// THEN
|
|
30
|
-
expect(Formio).toHaveBeenCalledWith("/formId");
|
|
31
|
-
expect(Formio.prototype.loadForm).toHaveBeenCalledWith();
|
|
32
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
33
|
-
name: "name",
|
|
34
|
-
type: requestForm.toString(),
|
|
35
|
-
payload: {
|
|
36
|
-
id: "formId",
|
|
37
|
-
url: "/formId"
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
41
|
-
name: "name",
|
|
42
|
-
type: receiveForm.toString(),
|
|
43
|
-
payload: {
|
|
44
|
-
form: {},
|
|
45
|
-
url: "/formId"
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
it("should do nothing when submission is already loaded", async () => {
|
|
50
|
-
// GIVEN
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
Formio.prototype.loadForm.mockReturnValue(Promise.resolve({}));
|
|
53
|
-
|
|
54
|
-
const dispatch = jest.fn();
|
|
55
|
-
const name = "name";
|
|
56
|
-
const formId = "formId";
|
|
57
|
-
|
|
58
|
-
const getState = () => ({
|
|
59
|
-
[name]: {
|
|
60
|
-
data: {
|
|
61
|
-
_id: formId,
|
|
62
|
-
components: [{}]
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// WHEN
|
|
68
|
-
getForm(name, formId)(dispatch, getState);
|
|
69
|
-
|
|
70
|
-
// THEN
|
|
71
|
-
expect(Formio).not.toHaveBeenCalled();
|
|
72
|
-
});
|
|
73
|
-
it("should throw error", async () => {
|
|
74
|
-
// GIVEN
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
Formio.prototype.loadForm.mockReturnValue(Promise.reject(new Error("message")));
|
|
77
|
-
|
|
78
|
-
const dispatch = jest.fn();
|
|
79
|
-
const name = "name";
|
|
80
|
-
const formId = "formId";
|
|
81
|
-
|
|
82
|
-
const getState = () => ({
|
|
83
|
-
[name]: {}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// WHEN
|
|
87
|
-
await new Promise((resolve) => getForm(name, formId, resolve)(dispatch, getState));
|
|
88
|
-
|
|
89
|
-
// THEN
|
|
90
|
-
expect(Formio).toHaveBeenCalledWith("/formId");
|
|
91
|
-
expect(Formio.prototype.loadForm).toHaveBeenCalledWith();
|
|
92
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
93
|
-
name: "name",
|
|
94
|
-
type: failForm.toString(),
|
|
95
|
-
payload: {
|
|
96
|
-
error: new Error("message")
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
describe("saveForm", () => {
|
|
102
|
-
it("should return a result", async () => {
|
|
103
|
-
// GIVEN
|
|
104
|
-
const dispatch = jest.fn();
|
|
105
|
-
const name = "name";
|
|
106
|
-
const formId = "formId";
|
|
107
|
-
const data = { _id: formId };
|
|
108
|
-
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
Formio.prototype.saveForm.mockReturnValue(Promise.resolve(data));
|
|
111
|
-
// WHEN
|
|
112
|
-
await new Promise((resolve) => saveForm(name, data, resolve)(dispatch));
|
|
113
|
-
|
|
114
|
-
// THEN
|
|
115
|
-
expect(Formio).toHaveBeenCalledWith("/formId");
|
|
116
|
-
expect(Formio.prototype.saveForm).toHaveBeenCalledWith(data);
|
|
117
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
118
|
-
name: "name",
|
|
119
|
-
type: sendForm.toString(),
|
|
120
|
-
payload: {
|
|
121
|
-
form: data
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
125
|
-
name: "name",
|
|
126
|
-
type: receiveForm.toString(),
|
|
127
|
-
payload: {
|
|
128
|
-
form: data,
|
|
129
|
-
url: "/formId"
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
it("should throw error", async () => {
|
|
134
|
-
// GIVEN
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
Formio.prototype.saveForm.mockReturnValue(Promise.reject(new Error("message")));
|
|
137
|
-
|
|
138
|
-
const dispatch = jest.fn();
|
|
139
|
-
const name = "name";
|
|
140
|
-
const formId = "formId";
|
|
141
|
-
const data = { _id: formId };
|
|
142
|
-
|
|
143
|
-
// WHEN
|
|
144
|
-
await new Promise((resolve) => saveForm(name, data, resolve)(dispatch));
|
|
145
|
-
|
|
146
|
-
// THEN
|
|
147
|
-
expect(Formio).toHaveBeenCalledWith("/formId");
|
|
148
|
-
expect(Formio.prototype.saveForm).toHaveBeenCalledWith(data);
|
|
149
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
150
|
-
name: "name",
|
|
151
|
-
type: failForm.toString(),
|
|
152
|
-
payload: {
|
|
153
|
-
error: new Error("message")
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe("deleteForm", () => {
|
|
159
|
-
it("should return a result", async () => {
|
|
160
|
-
// GIVEN
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
Formio.prototype.deleteForm.mockReturnValue(Promise.resolve({}));
|
|
163
|
-
|
|
164
|
-
const dispatch = jest.fn();
|
|
165
|
-
const name = "name";
|
|
166
|
-
const formId = "formId";
|
|
167
|
-
|
|
168
|
-
// WHEN
|
|
169
|
-
await new Promise((resolve) => deleteForm(name, formId, resolve)(dispatch));
|
|
170
|
-
|
|
171
|
-
// THEN
|
|
172
|
-
expect(Formio).toHaveBeenCalledWith("/formId");
|
|
173
|
-
expect(Formio.prototype.deleteForm).toHaveBeenCalledWith();
|
|
174
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
175
|
-
name: "name",
|
|
176
|
-
type: resetForm.toString()
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
it("should throw error", async () => {
|
|
180
|
-
// GIVEN
|
|
181
|
-
// @ts-ignore
|
|
182
|
-
Formio.prototype.deleteForm.mockReturnValue(Promise.reject(new Error("message")));
|
|
183
|
-
|
|
184
|
-
const dispatch = jest.fn();
|
|
185
|
-
const name = "name";
|
|
186
|
-
const formId = "formId";
|
|
187
|
-
|
|
188
|
-
// WHEN
|
|
189
|
-
await new Promise((resolve) => deleteForm(name, formId, resolve)(dispatch));
|
|
190
|
-
|
|
191
|
-
// THEN
|
|
192
|
-
expect(Formio).toHaveBeenCalledWith("/formId");
|
|
193
|
-
expect(Formio.prototype.deleteForm).toHaveBeenCalledWith();
|
|
194
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
195
|
-
name: "name",
|
|
196
|
-
type: failForm.toString(),
|
|
197
|
-
payload: {
|
|
198
|
-
error: new Error("message")
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { createAction } from "@tsed/redux-utils";
|
|
2
|
-
import { Formio } from "formiojs";
|
|
3
|
-
import noop from "lodash/noop";
|
|
4
|
-
|
|
5
|
-
import { FormSchema } from "../../interfaces";
|
|
6
|
-
import { getFormUrl } from "../../utils/url";
|
|
7
|
-
import { getActions } from "../actions";
|
|
8
|
-
import { selectForm } from "./form.selectors";
|
|
9
|
-
|
|
10
|
-
export const clearFormError = createAction();
|
|
11
|
-
export const requestForm = createAction();
|
|
12
|
-
export const receiveForm = createAction();
|
|
13
|
-
export const failForm = createAction();
|
|
14
|
-
export const resetForm = createAction();
|
|
15
|
-
export const sendForm = createAction();
|
|
16
|
-
|
|
17
|
-
function shouldGet(form: Partial<FormSchema>, id: string) {
|
|
18
|
-
return form && form.components && Array.isArray(form.components) && form.components.length && form._id === id;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const getForm =
|
|
22
|
-
(name: string, id = "", done = noop) =>
|
|
23
|
-
async (dispatch: any, getState: any) => {
|
|
24
|
-
dispatch(clearFormError(name));
|
|
25
|
-
// Check to see if the form is already loaded.
|
|
26
|
-
const form = selectForm(name, getState());
|
|
27
|
-
|
|
28
|
-
if (shouldGet(form, id)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const url = getFormUrl(id);
|
|
33
|
-
const formio = new Formio(url);
|
|
34
|
-
|
|
35
|
-
dispatch(requestForm(name, { id, url }));
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const form = await formio.loadForm();
|
|
39
|
-
|
|
40
|
-
dispatch(receiveForm(name, { form, url }));
|
|
41
|
-
dispatch(getActions(form._id));
|
|
42
|
-
done(null, form);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
dispatch(failForm(name, { error }));
|
|
45
|
-
done({ error });
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const saveForm =
|
|
50
|
-
(name: string, form: Partial<FormSchema>, done = noop) =>
|
|
51
|
-
async (dispatch: any) => {
|
|
52
|
-
dispatch(clearFormError(name));
|
|
53
|
-
dispatch(sendForm(name, { form }));
|
|
54
|
-
|
|
55
|
-
const id = form._id || "";
|
|
56
|
-
const url = getFormUrl(id);
|
|
57
|
-
const formio = new Formio(url);
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const result = await formio.saveForm(form);
|
|
61
|
-
dispatch(receiveForm(name, { form: result, url: getFormUrl(result._id) }));
|
|
62
|
-
done(null, result);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
dispatch(failForm(name, { error }));
|
|
65
|
-
done(error);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const deleteForm =
|
|
70
|
-
(name: string, id: string, done = noop) =>
|
|
71
|
-
async (dispatch: any) => {
|
|
72
|
-
dispatch(clearFormError(name));
|
|
73
|
-
const url = getFormUrl(id);
|
|
74
|
-
const formio = new Formio(url);
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
await formio.deleteForm();
|
|
78
|
-
dispatch(resetForm(name));
|
|
79
|
-
done();
|
|
80
|
-
} catch (error) {
|
|
81
|
-
dispatch(failForm(name, { error }));
|
|
82
|
-
done({ error });
|
|
83
|
-
}
|
|
84
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { clearFormError, failForm, receiveForm, requestForm, resetForm } from "./form.actions";
|
|
2
|
-
import { formReducer } from "./form.reducers";
|
|
3
|
-
|
|
4
|
-
describe("Form reducer", () => {
|
|
5
|
-
it("should return state (resetForm)", () => {
|
|
6
|
-
const reducer = formReducer("name");
|
|
7
|
-
const state: any = {};
|
|
8
|
-
const payload = {};
|
|
9
|
-
|
|
10
|
-
expect(reducer.$emit(resetForm, state, payload)).toEqual({
|
|
11
|
-
name: "name",
|
|
12
|
-
error: null,
|
|
13
|
-
data: {},
|
|
14
|
-
id: "",
|
|
15
|
-
isActive: false,
|
|
16
|
-
lastUpdated: 0,
|
|
17
|
-
url: ""
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
it("should return state (clearFormError)", () => {
|
|
21
|
-
const reducer = formReducer("name");
|
|
22
|
-
const state: any = {};
|
|
23
|
-
const payload = {};
|
|
24
|
-
|
|
25
|
-
expect(reducer.$emit(clearFormError, state, payload)).toEqual({
|
|
26
|
-
name: "name",
|
|
27
|
-
error: null
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
it("should return state (requestForm)", () => {
|
|
31
|
-
const reducer = formReducer("name");
|
|
32
|
-
const state: any = {};
|
|
33
|
-
const payload = {};
|
|
34
|
-
|
|
35
|
-
expect(reducer.$emit(requestForm, state, payload)).toEqual({
|
|
36
|
-
name: "name",
|
|
37
|
-
error: null,
|
|
38
|
-
data: {},
|
|
39
|
-
isActive: true
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should return state (receiveForm)", () => {
|
|
44
|
-
const reducer = formReducer("name");
|
|
45
|
-
const state: any = {};
|
|
46
|
-
const payload = {
|
|
47
|
-
form: {
|
|
48
|
-
_id: "id"
|
|
49
|
-
},
|
|
50
|
-
url: "url"
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
expect(reducer.$emit(receiveForm, state, payload)).toEqual({
|
|
54
|
-
name: "name",
|
|
55
|
-
error: null,
|
|
56
|
-
data: {
|
|
57
|
-
_id: "id"
|
|
58
|
-
},
|
|
59
|
-
id: "id",
|
|
60
|
-
isActive: false,
|
|
61
|
-
url: "url"
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should return state (failForm)", () => {
|
|
66
|
-
const reducer: any = formReducer("name");
|
|
67
|
-
const state = {};
|
|
68
|
-
const payload = {
|
|
69
|
-
error: new Error("message")
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
expect(reducer.$emit(failForm, state, payload)).toEqual({
|
|
73
|
-
name: "name",
|
|
74
|
-
error: payload.error,
|
|
75
|
-
isActive: false
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
|
|
2
|
-
|
|
3
|
-
import { FormSchema } from "../../interfaces";
|
|
4
|
-
import { clearFormError, failForm, receiveForm, requestForm, resetForm, sendForm } from "./form.actions";
|
|
5
|
-
|
|
6
|
-
export interface FormState {
|
|
7
|
-
error: null | Error;
|
|
8
|
-
data?: Partial<FormSchema>;
|
|
9
|
-
isActive: boolean;
|
|
10
|
-
lastUpdated: number;
|
|
11
|
-
url: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const createInitialState: InitialStateCreator<FormState> = () => ({
|
|
15
|
-
id: "",
|
|
16
|
-
isActive: false,
|
|
17
|
-
lastUpdated: 0,
|
|
18
|
-
data: {},
|
|
19
|
-
url: "",
|
|
20
|
-
error: null
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const formReducer = createReducer<FormState>(
|
|
24
|
-
{
|
|
25
|
-
[resetForm.toString()]: (_, _2, reset) => reset(),
|
|
26
|
-
[clearFormError.toString()]: (state) => ({
|
|
27
|
-
...state,
|
|
28
|
-
error: null
|
|
29
|
-
}),
|
|
30
|
-
[requestForm.toString()]: (state, { id, url }) => ({
|
|
31
|
-
...state,
|
|
32
|
-
isActive: true,
|
|
33
|
-
id,
|
|
34
|
-
url,
|
|
35
|
-
data: {},
|
|
36
|
-
error: null
|
|
37
|
-
}),
|
|
38
|
-
[receiveForm.toString()]: (state, { form, url }) => ({
|
|
39
|
-
...state,
|
|
40
|
-
isActive: false,
|
|
41
|
-
id: form._id,
|
|
42
|
-
data: form,
|
|
43
|
-
url: url || state.url,
|
|
44
|
-
error: null
|
|
45
|
-
}),
|
|
46
|
-
[failForm.toString()]: (state, payload) => ({
|
|
47
|
-
...state,
|
|
48
|
-
error: payload.error,
|
|
49
|
-
isActive: false
|
|
50
|
-
}),
|
|
51
|
-
[sendForm.toString()]: (state, { form, url }) => ({
|
|
52
|
-
...state,
|
|
53
|
-
data: form,
|
|
54
|
-
url,
|
|
55
|
-
isActive: true
|
|
56
|
-
})
|
|
57
|
-
},
|
|
58
|
-
createInitialState
|
|
59
|
-
);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { selectForm } from "./form.selectors";
|
|
2
|
-
|
|
3
|
-
describe("form Selectors", () => {
|
|
4
|
-
describe("selectForm()", () => {
|
|
5
|
-
it("should return data", () => {
|
|
6
|
-
expect(
|
|
7
|
-
selectForm("form", {
|
|
8
|
-
form: {
|
|
9
|
-
data: {
|
|
10
|
-
id: "id"
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
).toEqual({
|
|
15
|
-
id: "id"
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
});
|
package/src/stores/form/index.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Formio } from "formiojs";
|
|
2
|
-
|
|
3
|
-
import { mapRequestParams } from "../../utils/mapRequestParams";
|
|
4
|
-
import { failForms, getForms, receiveForms, requestForms } from "./forms.actions";
|
|
5
|
-
|
|
6
|
-
jest.mock("formiojs");
|
|
7
|
-
jest.mock("../../utils/mapRequestParams");
|
|
8
|
-
|
|
9
|
-
describe("Forms actions", () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
(mapRequestParams as any).mockImplementation((o: any) => o);
|
|
12
|
-
});
|
|
13
|
-
afterEach(() => jest.resetAllMocks());
|
|
14
|
-
describe("getForms", () => {
|
|
15
|
-
it("should return a result", async () => {
|
|
16
|
-
// GIVEN
|
|
17
|
-
(Formio as any).prototype.loadForms.mockReturnValue(Promise.resolve([{}]));
|
|
18
|
-
(Formio as any).getProjectUrl.mockReturnValue("https://formio");
|
|
19
|
-
const dispatch = jest.fn();
|
|
20
|
-
const name = "name";
|
|
21
|
-
const parameters = {
|
|
22
|
-
pageSize: 10,
|
|
23
|
-
pageIndex: 0
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const getState = () => ({
|
|
27
|
-
[name]: {
|
|
28
|
-
parameters
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// WHEN
|
|
33
|
-
await new Promise((resolve) => getForms(name, parameters, resolve)(dispatch, getState));
|
|
34
|
-
|
|
35
|
-
// THEN
|
|
36
|
-
expect(Formio).toHaveBeenCalledWith("https://formio/form");
|
|
37
|
-
expect(Formio.prototype.loadForms).toHaveBeenCalledWith({
|
|
38
|
-
params: parameters
|
|
39
|
-
});
|
|
40
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
41
|
-
name: "name",
|
|
42
|
-
type: requestForms.toString(),
|
|
43
|
-
payload: { parameters }
|
|
44
|
-
});
|
|
45
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
46
|
-
name: "name",
|
|
47
|
-
payload: {
|
|
48
|
-
forms: [{}]
|
|
49
|
-
},
|
|
50
|
-
type: receiveForms.toString()
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
it("should return a error", async () => {
|
|
54
|
-
// GIVEN
|
|
55
|
-
(Formio.prototype.loadForms as any).mockReturnValue(Promise.reject(new Error("message")));
|
|
56
|
-
(Formio.getProjectUrl as any).mockReturnValue("https://formio");
|
|
57
|
-
|
|
58
|
-
const dispatch = jest.fn();
|
|
59
|
-
const name = "name";
|
|
60
|
-
const parameters = {
|
|
61
|
-
pageSize: 10,
|
|
62
|
-
pageIndex: 0
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const getState = () => ({
|
|
66
|
-
[name]: {
|
|
67
|
-
parameters
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// WHEN
|
|
72
|
-
await new Promise((resolve) => getForms(name, parameters, resolve)(dispatch, getState));
|
|
73
|
-
|
|
74
|
-
// THEN
|
|
75
|
-
expect(Formio).toHaveBeenCalledWith("https://formio/form");
|
|
76
|
-
expect(Formio.prototype.loadForms).toHaveBeenCalledWith({
|
|
77
|
-
params: parameters
|
|
78
|
-
});
|
|
79
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
80
|
-
name: "name",
|
|
81
|
-
type: requestForms.toString(),
|
|
82
|
-
payload: { parameters }
|
|
83
|
-
});
|
|
84
|
-
expect(dispatch).toHaveBeenCalledWith({
|
|
85
|
-
name: "name",
|
|
86
|
-
payload: { error: new Error("message") },
|
|
87
|
-
type: failForms.toString()
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { createAction } from "@tsed/redux-utils";
|
|
2
|
-
import { Formio } from "formiojs";
|
|
3
|
-
import noop from "lodash/noop";
|
|
4
|
-
|
|
5
|
-
import { FormSchema } from "../../interfaces";
|
|
6
|
-
import type { RequestParamsOptions } from "../../utils/mapRequestParams";
|
|
7
|
-
import { mapRequestParams } from "../../utils/mapRequestParams";
|
|
8
|
-
import { selectFormsParameters } from "./forms.selectors";
|
|
9
|
-
|
|
10
|
-
export const resetForms = createAction();
|
|
11
|
-
export const requestForms = createAction<{
|
|
12
|
-
parameters: Partial<RequestParamsOptions>;
|
|
13
|
-
}>();
|
|
14
|
-
export const receiveForms = createAction<{ forms: FormSchema[] }>();
|
|
15
|
-
export const failForms = createAction();
|
|
16
|
-
|
|
17
|
-
export type GetFormsCB = (err: any, forms?: FormSchema[]) => void;
|
|
18
|
-
|
|
19
|
-
export const getForms =
|
|
20
|
-
(name: string, parameters: Partial<RequestParamsOptions>, done: GetFormsCB = noop) =>
|
|
21
|
-
async (dispatch: any, getState: any) => {
|
|
22
|
-
dispatch(requestForms(name, { parameters }));
|
|
23
|
-
|
|
24
|
-
const formio = new Formio(`${Formio.getProjectUrl()}/form`);
|
|
25
|
-
const requestParams = mapRequestParams(selectFormsParameters(name, getState()));
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const result: FormSchema[] = await formio.loadForms({
|
|
29
|
-
params: requestParams
|
|
30
|
-
});
|
|
31
|
-
dispatch(receiveForms(name, { forms: result }));
|
|
32
|
-
done(null, result);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
dispatch(failForms(name, { error }));
|
|
35
|
-
done(error);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const refreshForms = (name: string, done = noop) => {
|
|
40
|
-
return async (dispatch: any, getState: any) => {
|
|
41
|
-
const parameters = selectFormsParameters(name, getState());
|
|
42
|
-
return getForms(name, parameters, done)(dispatch, getState);
|
|
43
|
-
};
|
|
44
|
-
};
|