@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.
Files changed (174) hide show
  1. package/coverage.json +4 -4
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.js +1277 -3684
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.modern.js +956 -2767
  6. package/dist/index.modern.js.map +1 -1
  7. package/package.json +4 -5
  8. package/readme.md +9 -57
  9. package/src/components/input-tags/inputTags.component.tsx +1 -1
  10. package/src/components/select/select.component.tsx +1 -1
  11. package/src/components/table/filters/sliderColumnFilter.component.tsx +2 -2
  12. package/src/index.ts +3 -2
  13. package/dist/stores/action/action.actions.d.ts +0 -9
  14. package/dist/stores/action/action.actions.spec.d.ts +0 -1
  15. package/dist/stores/action/action.constant.d.ts +0 -1
  16. package/dist/stores/action/action.reducers.d.ts +0 -7
  17. package/dist/stores/action/action.reducers.spec.d.ts +0 -1
  18. package/dist/stores/action/action.selectors.d.ts +0 -2
  19. package/dist/stores/action/action.selectors.spec.d.ts +0 -1
  20. package/dist/stores/action/index.d.ts +0 -4
  21. package/dist/stores/action-info/action-info.actions.d.ts +0 -5
  22. package/dist/stores/action-info/action-info.actions.spec.d.ts +0 -1
  23. package/dist/stores/action-info/action-info.constant.d.ts +0 -1
  24. package/dist/stores/action-info/action-info.reducers.d.ts +0 -7
  25. package/dist/stores/action-info/action-info.reducers.spec.d.ts +0 -1
  26. package/dist/stores/action-info/action-info.selectors.d.ts +0 -2
  27. package/dist/stores/action-info/action-info.selectors.spec.d.ts +0 -1
  28. package/dist/stores/action-info/index.d.ts +0 -4
  29. package/dist/stores/actions/actions.actions.d.ts +0 -5
  30. package/dist/stores/actions/actions.actions.spec.d.ts +0 -1
  31. package/dist/stores/actions/actions.constant.d.ts +0 -1
  32. package/dist/stores/actions/actions.reducers.d.ts +0 -8
  33. package/dist/stores/actions/actions.reducers.spec.d.ts +0 -1
  34. package/dist/stores/actions/actions.selectors.d.ts +0 -2
  35. package/dist/stores/actions/actions.selectors.spec.d.ts +0 -1
  36. package/dist/stores/actions/index.d.ts +0 -4
  37. package/dist/stores/auth/auth.actions.d.ts +0 -9
  38. package/dist/stores/auth/auth.constant.d.ts +0 -1
  39. package/dist/stores/auth/auth.reducers.d.ts +0 -16
  40. package/dist/stores/auth/auth.reducers.spec.d.ts +0 -1
  41. package/dist/stores/auth/auth.selectors.d.ts +0 -6
  42. package/dist/stores/auth/auth.selectors.spec.d.ts +0 -1
  43. package/dist/stores/auth/auth.utils.d.ts +0 -6
  44. package/dist/stores/auth/auth.utils.spec.d.ts +0 -1
  45. package/dist/stores/auth/getAccess.action.d.ts +0 -1
  46. package/dist/stores/auth/getAccess.action.spec.d.ts +0 -1
  47. package/dist/stores/auth/getProjectAccess.action.d.ts +0 -1
  48. package/dist/stores/auth/index.d.ts +0 -10
  49. package/dist/stores/auth/initAuth.action.d.ts +0 -1
  50. package/dist/stores/auth/initAuth.action.spec.d.ts +0 -1
  51. package/dist/stores/auth/logout.action.d.ts +0 -1
  52. package/dist/stores/auth/logout.action.spec.d.ts +0 -1
  53. package/dist/stores/auth/setUser.action.d.ts +0 -1
  54. package/dist/stores/auth/setUser.action.spec.d.ts +0 -1
  55. package/dist/stores/form/form.actions.d.ts +0 -10
  56. package/dist/stores/form/form.actions.spec.d.ts +0 -1
  57. package/dist/stores/form/form.reducers.d.ts +0 -9
  58. package/dist/stores/form/form.reducers.spec.d.ts +0 -1
  59. package/dist/stores/form/form.selectors.d.ts +0 -2
  60. package/dist/stores/form/form.selectors.spec.d.ts +0 -1
  61. package/dist/stores/form/index.d.ts +0 -3
  62. package/dist/stores/forms/forms.actions.d.ts +0 -9
  63. package/dist/stores/forms/forms.actions.spec.d.ts +0 -1
  64. package/dist/stores/forms/forms.reducers.d.ts +0 -16
  65. package/dist/stores/forms/forms.reducers.spec.d.ts +0 -1
  66. package/dist/stores/forms/forms.selectors.d.ts +0 -10
  67. package/dist/stores/forms/forms.selectors.spec.d.ts +0 -1
  68. package/dist/stores/forms/index.d.ts +0 -3
  69. package/dist/stores/index.d.ts +0 -10
  70. package/dist/stores/index.spec.d.ts +0 -1
  71. package/dist/stores/root/index.d.ts +0 -1
  72. package/dist/stores/root/root.selectors.d.ts +0 -5
  73. package/dist/stores/root/root.selectors.spec.d.ts +0 -1
  74. package/dist/stores/submission/index.d.ts +0 -3
  75. package/dist/stores/submission/submission.actions.d.ts +0 -10
  76. package/dist/stores/submission/submission.actions.spec.d.ts +0 -1
  77. package/dist/stores/submission/submission.reducers.d.ts +0 -11
  78. package/dist/stores/submission/submission.reducers.spec.d.ts +0 -1
  79. package/dist/stores/submission/submission.selectors.d.ts +0 -2
  80. package/dist/stores/submission/submission.selectors.spec.d.ts +0 -1
  81. package/dist/stores/submissions/index.d.ts +0 -3
  82. package/dist/stores/submissions/submissions.actions.d.ts +0 -6
  83. package/dist/stores/submissions/submissions.actions.spec.d.ts +0 -1
  84. package/dist/stores/submissions/submissions.reducers.d.ts +0 -17
  85. package/dist/stores/submissions/submissions.reducers.spec.d.ts +0 -1
  86. package/dist/stores/submissions/submissions.selectors.d.ts +0 -9
  87. package/dist/stores/submissions/submissions.selectors.spec.d.ts +0 -1
  88. package/dist/utils/clean.d.ts +0 -1
  89. package/dist/utils/clean.test.d.ts +0 -1
  90. package/dist/utils/mapRequestParams.d.ts +0 -9
  91. package/dist/utils/mapRequestParams.test.d.ts +0 -1
  92. package/dist/utils/url.d.ts +0 -3
  93. package/dist/utils/url.test.d.ts +0 -1
  94. package/src/stores/action/action.actions.spec.ts +0 -114
  95. package/src/stores/action/action.actions.ts +0 -82
  96. package/src/stores/action/action.constant.ts +0 -1
  97. package/src/stores/action/action.reducers.spec.ts +0 -91
  98. package/src/stores/action/action.reducers.ts +0 -54
  99. package/src/stores/action/action.selectors.spec.ts +0 -19
  100. package/src/stores/action/action.selectors.ts +0 -6
  101. package/src/stores/action/index.ts +0 -4
  102. package/src/stores/action-info/action-info.actions.spec.ts +0 -46
  103. package/src/stores/action-info/action-info.actions.ts +0 -32
  104. package/src/stores/action-info/action-info.constant.ts +0 -1
  105. package/src/stores/action-info/action-info.reducers.spec.ts +0 -60
  106. package/src/stores/action-info/action-info.reducers.ts +0 -44
  107. package/src/stores/action-info/action-info.selectors.spec.ts +0 -19
  108. package/src/stores/action-info/action-info.selectors.ts +0 -7
  109. package/src/stores/action-info/index.ts +0 -4
  110. package/src/stores/actions/actions.actions.spec.ts +0 -62
  111. package/src/stores/actions/actions.actions.ts +0 -34
  112. package/src/stores/actions/actions.constant.ts +0 -1
  113. package/src/stores/actions/actions.reducers.spec.ts +0 -62
  114. package/src/stores/actions/actions.reducers.ts +0 -48
  115. package/src/stores/actions/actions.selectors.spec.ts +0 -34
  116. package/src/stores/actions/actions.selectors.ts +0 -7
  117. package/src/stores/actions/index.ts +0 -4
  118. package/src/stores/auth/auth.actions.ts +0 -13
  119. package/src/stores/auth/auth.constant.ts +0 -1
  120. package/src/stores/auth/auth.reducers.spec.ts +0 -376
  121. package/src/stores/auth/auth.reducers.ts +0 -151
  122. package/src/stores/auth/auth.selectors.spec.ts +0 -47
  123. package/src/stores/auth/auth.selectors.ts +0 -14
  124. package/src/stores/auth/auth.utils.spec.ts +0 -29
  125. package/src/stores/auth/auth.utils.tsx +0 -37
  126. package/src/stores/auth/getAccess.action.spec.ts +0 -257
  127. package/src/stores/auth/getAccess.action.ts +0 -57
  128. package/src/stores/auth/getProjectAccess.action.ts +0 -25
  129. package/src/stores/auth/index.ts +0 -10
  130. package/src/stores/auth/initAuth.action.spec.ts +0 -56
  131. package/src/stores/auth/initAuth.action.ts +0 -29
  132. package/src/stores/auth/logout.action.spec.ts +0 -25
  133. package/src/stores/auth/logout.action.ts +0 -9
  134. package/src/stores/auth/setUser.action.spec.ts +0 -25
  135. package/src/stores/auth/setUser.action.ts +0 -9
  136. package/src/stores/form/form.actions.spec.ts +0 -203
  137. package/src/stores/form/form.actions.ts +0 -84
  138. package/src/stores/form/form.reducers.spec.ts +0 -78
  139. package/src/stores/form/form.reducers.ts +0 -59
  140. package/src/stores/form/form.selectors.spec.ts +0 -19
  141. package/src/stores/form/form.selectors.ts +0 -5
  142. package/src/stores/form/index.ts +0 -3
  143. package/src/stores/forms/forms.actions.spec.ts +0 -91
  144. package/src/stores/forms/forms.actions.ts +0 -44
  145. package/src/stores/forms/forms.reducers.spec.ts +0 -97
  146. package/src/stores/forms/forms.reducers.ts +0 -77
  147. package/src/stores/forms/forms.selectors.spec.ts +0 -39
  148. package/src/stores/forms/forms.selectors.ts +0 -6
  149. package/src/stores/forms/index.ts +0 -3
  150. package/src/stores/index.spec.ts +0 -125
  151. package/src/stores/index.ts +0 -33
  152. package/src/stores/root/index.ts +0 -1
  153. package/src/stores/root/root.selectors.spec.ts +0 -94
  154. package/src/stores/root/root.selectors.ts +0 -23
  155. package/src/stores/submission/index.ts +0 -3
  156. package/src/stores/submission/submission.actions.spec.ts +0 -214
  157. package/src/stores/submission/submission.actions.ts +0 -81
  158. package/src/stores/submission/submission.reducers.spec.ts +0 -96
  159. package/src/stores/submission/submission.reducers.ts +0 -70
  160. package/src/stores/submission/submission.selectors.spec.ts +0 -19
  161. package/src/stores/submission/submission.selectors.ts +0 -5
  162. package/src/stores/submissions/index.ts +0 -3
  163. package/src/stores/submissions/submissions.actions.spec.ts +0 -99
  164. package/src/stores/submissions/submissions.actions.ts +0 -38
  165. package/src/stores/submissions/submissions.reducers.spec.ts +0 -98
  166. package/src/stores/submissions/submissions.reducers.ts +0 -78
  167. package/src/stores/submissions/submissions.selectors.spec.ts +0 -39
  168. package/src/stores/submissions/submissions.selectors.ts +0 -6
  169. package/src/utils/clean.test.ts +0 -7
  170. package/src/utils/clean.ts +0 -12
  171. package/src/utils/mapRequestParams.test.ts +0 -81
  172. package/src/utils/mapRequestParams.ts +0 -36
  173. package/src/utils/url.test.ts +0 -31
  174. package/src/utils/url.ts +0 -23
@@ -1,9 +0,0 @@
1
- import { QueryOptions } from "../interfaces/QueryOptions";
2
- export interface RequestParamsOptions extends QueryOptions {
3
- select: string | string[];
4
- query: {
5
- [key: string]: string;
6
- };
7
- [key: string]: any;
8
- }
9
- export declare function mapRequestParams({ query, pageSize, pageIndex, select, filters, sortBy }: Partial<RequestParamsOptions>): any;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export declare function getFormUrl(formId: string): string;
2
- export declare function getActionUrl(formId: string, actionId?: string): string;
3
- export declare function getSubmissionUrl(formId: string, submissionId?: string): string;
@@ -1 +0,0 @@
1
- export {};
@@ -1,114 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { getActionInfo } from "../action-info";
4
- import {
5
- clearActionError,
6
- deleteAction,
7
- getAction,
8
- receiveAction,
9
- requestAction,
10
- resetAction,
11
- saveAction,
12
- sendAction
13
- } from "./action.actions";
14
-
15
- jest.mock("formiojs/Formio");
16
- jest.mock("../action-info");
17
-
18
- describe("Action actions", () => {
19
- beforeEach(() => {
20
- (getActionInfo as any).mockReturnValue({ type: "actionInfo" });
21
- });
22
- afterEach(() => jest.resetAllMocks());
23
- describe("getAction", () => {
24
- it("should get action", async () => {
25
- const formId = "formId";
26
- const actionId = "actionId";
27
- const dispatch = jest.fn();
28
-
29
- (Formio.prototype.loadAction as any).mockReturnValue({
30
- _id: actionId,
31
- name: "oidc"
32
- });
33
-
34
- await getAction(formId, actionId)(dispatch);
35
-
36
- expect(dispatch).toHaveBeenCalledWith({
37
- type: requestAction.toString(),
38
- name: "action"
39
- });
40
- expect(Formio).toHaveBeenCalledWith("/formId/action/actionId");
41
- expect(Formio.prototype.loadAction).toHaveBeenCalledWith();
42
- expect(getActionInfo).toHaveBeenCalledWith("formId", "oidc");
43
- expect(dispatch).toHaveBeenCalledWith({ type: "actionInfo" });
44
- expect(dispatch).toHaveBeenCalledWith({
45
- type: receiveAction.toString(),
46
- name: "action",
47
- payload: {
48
- action: {
49
- _id: actionId,
50
- name: "oidc"
51
- }
52
- }
53
- });
54
- });
55
- });
56
- describe("saveAction", () => {
57
- it("should save action", async () => {
58
- const formId = "formId";
59
- const actionId = "actionId";
60
- const dispatch = jest.fn();
61
-
62
- (Formio.prototype.saveAction as any).mockReturnValue({
63
- _id: actionId
64
- });
65
-
66
- await saveAction(formId, { _id: actionId })(dispatch);
67
-
68
- expect(dispatch).toHaveBeenCalledWith({
69
- type: clearActionError.toString(),
70
- name: "action"
71
- });
72
- expect(dispatch).toHaveBeenCalledWith({
73
- type: sendAction.toString(),
74
- name: "action",
75
- payload: {
76
- action: { _id: actionId }
77
- }
78
- });
79
- expect(Formio).toHaveBeenCalledWith("/formId/action");
80
- expect(Formio.prototype.saveAction).toHaveBeenCalledWith({
81
- _id: actionId
82
- });
83
- expect(dispatch).toHaveBeenCalledWith({
84
- type: receiveAction.toString(),
85
- name: "action",
86
- payload: {
87
- action: {
88
- _id: actionId
89
- }
90
- }
91
- });
92
- });
93
- });
94
- describe("deleteAction", () => {
95
- it("should delete action", async () => {
96
- const formId = "formId";
97
- const actionId = "actionId";
98
- const dispatch = jest.fn();
99
-
100
- await deleteAction(formId, actionId)(dispatch);
101
-
102
- expect(dispatch).toHaveBeenCalledWith({
103
- type: clearActionError.toString(),
104
- name: "action"
105
- });
106
- expect(Formio).toHaveBeenCalledWith("/formId/action/actionId");
107
- expect(Formio.prototype.deleteAction).toHaveBeenCalledWith();
108
- expect(dispatch).toHaveBeenCalledWith({
109
- type: resetAction.toString(),
110
- name: "action"
111
- });
112
- });
113
- });
114
- });
@@ -1,82 +0,0 @@
1
- import { createAction } from "@tsed/redux-utils";
2
- import { Formio } from "formiojs";
3
- import get from "lodash/get";
4
- import noop from "lodash/noop";
5
-
6
- import { getActionUrl } from "../../utils/url";
7
- import { getActionInfo } from "../action-info";
8
- import { ACTION } from "./action.constant";
9
-
10
- export const clearActionError = createAction();
11
- export const resetAction = createAction();
12
- export const requestAction = createAction();
13
- export const receiveAction = createAction();
14
- export const failAction = createAction();
15
- export const sendAction = createAction();
16
-
17
- function getFormio(formId: string, id: string) {
18
- const url = getActionUrl(formId, id);
19
- return new Formio(url);
20
- }
21
-
22
- export const getAction =
23
- (formId: string, actionId: string, done = noop) =>
24
- async (dispatch: any) => {
25
- dispatch(clearActionError(ACTION));
26
- dispatch(requestAction(ACTION));
27
-
28
- const formio = getFormio(formId, actionId);
29
-
30
- try {
31
- const action = await formio.loadAction();
32
-
33
- dispatch(getActionInfo(formId, action.name));
34
- dispatch(receiveAction(ACTION, { action }));
35
- done(null, action);
36
- } catch (error) {
37
- dispatch(failAction(ACTION, { error }));
38
- done(error);
39
- }
40
- };
41
-
42
- export const saveAction =
43
- (formId: string, action: any, done = noop) =>
44
- async (dispatch: any) => {
45
- dispatch(clearActionError(ACTION));
46
- dispatch(sendAction(ACTION, { action }));
47
-
48
- const formio = getFormio(formId, get(action, "data._id", ""));
49
-
50
- try {
51
- const result = await formio.saveAction(action);
52
- dispatch(receiveAction(ACTION, { action: result }));
53
- done(null, result);
54
- } catch (error) {
55
- dispatch(failAction(ACTION, { error }));
56
- done(error);
57
- }
58
- };
59
-
60
- export const deleteAction = (formId: string, actionId: string, done = noop) => {
61
- return async (dispatch: any) => {
62
- dispatch(clearActionError(ACTION));
63
-
64
- // const state = getState();
65
- // const path = formId.replace("__", "/");
66
- // const form = selectForm("form", state);
67
- // const resource = selectForm("resource", state);
68
- //
69
- // formId = (path === form.path ? form._id : resource._id) || formId;
70
-
71
- const formio = getFormio(formId, actionId);
72
-
73
- try {
74
- await formio.deleteAction();
75
- dispatch(resetAction(ACTION));
76
- done(null);
77
- } catch (error) {
78
- dispatch(failAction(ACTION, { error }));
79
- done(error);
80
- }
81
- };
82
- };
@@ -1 +0,0 @@
1
- export const ACTION = "action";
@@ -1,91 +0,0 @@
1
- import { clearActionError, failAction, receiveAction, requestAction, resetAction, sendAction } from "./action.actions";
2
- import { ACTION } from "./action.constant";
3
- import { actionReducer } from "./action.reducers";
4
-
5
- describe("Action reducer", () => {
6
- it("should return state (resetAction)", () => {
7
- const reducer = actionReducer;
8
- const state = {};
9
- const payload = {};
10
-
11
- expect(reducer.$emit(resetAction.toString(), state, payload)).toEqual({
12
- name: ACTION,
13
- data: {},
14
- error: null,
15
- isActive: false
16
- });
17
- });
18
-
19
- it("should return state (clearActionError)", () => {
20
- const reducer = actionReducer;
21
- const state = {};
22
- const payload = {};
23
-
24
- expect(reducer.$emit(clearActionError.toString(), state, payload)).toEqual({
25
- name: ACTION,
26
- error: null
27
- });
28
- });
29
-
30
- it("should return state (requestAction)", () => {
31
- const reducer = actionReducer;
32
- const state = {};
33
- const payload = {};
34
-
35
- expect(reducer.$emit(requestAction.toString(), state, payload)).toEqual({
36
- name: ACTION,
37
- data: {},
38
- error: null,
39
- isActive: true
40
- });
41
- });
42
-
43
- it("should return state (sendAction)", () => {
44
- const reducer = actionReducer;
45
- const state = {};
46
- const payload = {
47
- action: {
48
- _id: "id"
49
- }
50
- };
51
-
52
- expect(reducer.$emit(sendAction.toString(), state, payload)).toEqual({
53
- name: ACTION,
54
- data: {
55
- _id: "id"
56
- },
57
- error: null,
58
- isActive: true
59
- });
60
- });
61
-
62
- it("should return state (receiveAction)", () => {
63
- const reducer = actionReducer;
64
- const state = {};
65
- const payload = {
66
- action: { _id: "id" }
67
- };
68
-
69
- expect(reducer.$emit(receiveAction.toString(), state, payload)).toEqual({
70
- name: ACTION,
71
- error: null,
72
- data: { _id: "id" },
73
- isActive: false
74
- });
75
- });
76
-
77
- it("should return state (failAction)", () => {
78
- const reducer = actionReducer;
79
- const state = {};
80
- const payload = {
81
- error: new Error("message")
82
- };
83
-
84
- expect(reducer.$emit(failAction.toString(), state, payload)).toEqual({
85
- name: ACTION,
86
- data: {},
87
- error: payload.error,
88
- isActive: false
89
- });
90
- });
91
- });
@@ -1,54 +0,0 @@
1
- import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
2
-
3
- import { ActionSchema } from "../../interfaces";
4
- import { clearActionError, failAction, receiveAction, requestAction, resetAction, sendAction } from "./action.actions";
5
- import { ACTION } from "./action.constant";
6
-
7
- export interface ActionState {
8
- error: null | Error;
9
- data: ActionSchema;
10
- isActive: boolean;
11
- }
12
-
13
- const createInitialState: InitialStateCreator = (): ActionState => ({
14
- error: null,
15
- data: {} as any,
16
- isActive: false
17
- });
18
-
19
- export const actionReducer = createReducer<ActionState>({}, createInitialState)
20
- .on(resetAction, (_: any, _2: any, reset: any) => reset())
21
- .on(clearActionError, (state) => ({
22
- ...state,
23
- error: null
24
- }))
25
- .on(requestAction, (state) => ({
26
- ...state,
27
- error: null,
28
- data: {},
29
- isActive: true
30
- }))
31
- .on(sendAction, (state, { action }) => ({
32
- ...state,
33
- error: null,
34
- data: action,
35
- isActive: true
36
- }))
37
- .on(receiveAction, (state, { action }) => ({
38
- ...state,
39
- error: null,
40
- data: action,
41
- isActive: false
42
- }))
43
- .on(receiveAction, (state, { action }) => ({
44
- ...state,
45
- error: null,
46
- data: action,
47
- isActive: false
48
- }))
49
- .on(failAction, (state, { error }) => ({
50
- ...state,
51
- data: {},
52
- error,
53
- isActive: false
54
- }))(ACTION);
@@ -1,19 +0,0 @@
1
- import { selectAction } from "./action.selectors";
2
-
3
- describe("action Selectors", () => {
4
- describe("selectAction()", () => {
5
- it("should return data", () => {
6
- expect(
7
- selectAction({
8
- action: {
9
- data: {
10
- id: "id"
11
- }
12
- }
13
- })
14
- ).toEqual({
15
- id: "id"
16
- });
17
- });
18
- });
19
- });
@@ -1,6 +0,0 @@
1
- import { ActionSchema } from "../../interfaces";
2
- import { selectRoot } from "../root";
3
- import { ACTION } from "./action.constant";
4
- import { ActionState } from "./action.reducers";
5
-
6
- export const selectAction = (state: Record<string, any>): ActionSchema => selectRoot<ActionState>(ACTION, state).data;
@@ -1,4 +0,0 @@
1
- export * from "./action.actions";
2
- export * from "./action.constant";
3
- export * from "./action.reducers";
4
- export * from "./action.selectors";
@@ -1,46 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { getActionInfo, receiveActionInfo, requestActionInfo } from "./action-info.actions";
4
-
5
- jest.mock("formiojs/Formio");
6
-
7
- describe("ActionInfo actions", () => {
8
- describe("getAction", () => {
9
- it("should get action", async () => {
10
- const formId = "formId";
11
- const actionType = "oidc";
12
- const dispatch = jest.fn();
13
-
14
- (Formio.getProjectUrl as any).mockReturnValue("http://localhost");
15
- (Formio.prototype.actionInfo as any).mockReturnValue({
16
- _id: "actionId",
17
- name: "oidc",
18
- settingsForm: {
19
- action: "/action"
20
- }
21
- });
22
-
23
- await getActionInfo(formId, actionType)(dispatch);
24
-
25
- expect(dispatch).toHaveBeenCalledWith({
26
- type: requestActionInfo.toString(),
27
- name: "actionInfo"
28
- });
29
- expect(Formio).toHaveBeenCalledWith("http://localhost/formId");
30
- expect(Formio.prototype.actionInfo).toHaveBeenCalledWith("oidc");
31
- expect(dispatch).toHaveBeenCalledWith({
32
- type: receiveActionInfo.toString(),
33
- name: "actionInfo",
34
- payload: {
35
- actionInfo: {
36
- _id: "actionId",
37
- name: "oidc",
38
- settingsForm: {
39
- action: "http://localhost/action"
40
- }
41
- }
42
- }
43
- });
44
- });
45
- });
46
- });
@@ -1,32 +0,0 @@
1
- import { createAction } from "@tsed/redux-utils";
2
- import { Formio } from "formiojs";
3
- import noop from "lodash/noop";
4
-
5
- import { getFormUrl } from "../../utils/url";
6
- import { ACTION_INFO } from "./action-info.constant";
7
-
8
- export const resetActionInfo = createAction();
9
- export const requestActionInfo = createAction();
10
- export const receiveActionInfo = createAction();
11
- export const failActionInfo = createAction();
12
-
13
- export const getActionInfo =
14
- (formId: string, actionType: string, done = noop) =>
15
- async (dispatch: any) => {
16
- dispatch(requestActionInfo(ACTION_INFO));
17
-
18
- const url = getFormUrl(formId);
19
- const formio = new Formio(url);
20
-
21
- try {
22
- const actionInfo = await formio.actionInfo(actionType);
23
-
24
- actionInfo.settingsForm.action = Formio.getProjectUrl() + actionInfo.settingsForm.action;
25
-
26
- dispatch(receiveActionInfo(ACTION_INFO, { actionInfo }));
27
- done(null, actionInfo);
28
- } catch (error) {
29
- dispatch(failActionInfo(ACTION_INFO, { error }));
30
- done(error);
31
- }
32
- };
@@ -1 +0,0 @@
1
- export const ACTION_INFO = "actionInfo";
@@ -1,60 +0,0 @@
1
- import { failActionInfo, receiveActionInfo, requestActionInfo, resetActionInfo } from "./action-info.actions";
2
- import { ACTION_INFO } from "./action-info.constant";
3
- import { actionInfoReducer } from "./action-info.reducers";
4
-
5
- describe("ActionInfo reducers", () => {
6
- it("should return state (resetActionInfo)", () => {
7
- const reducer = actionInfoReducer;
8
- const state: any = {};
9
- const payload = {};
10
-
11
- expect(reducer.$emit(resetActionInfo, state, payload)).toEqual({
12
- name: ACTION_INFO,
13
- data: {},
14
- error: null,
15
- isActive: false
16
- });
17
- });
18
- it("should return state (requestActionInfo)", () => {
19
- const reducer = actionInfoReducer;
20
- const state: any = {};
21
- const payload = {};
22
-
23
- expect(reducer.$emit(requestActionInfo, state, payload)).toEqual({
24
- name: ACTION_INFO,
25
- data: {},
26
- error: null,
27
- isActive: true
28
- });
29
- });
30
-
31
- it("should return state (receiveActionInfo)", () => {
32
- const reducer = actionInfoReducer;
33
- const state: any = {};
34
- const payload = {
35
- actionInfo: { _id: "id" }
36
- };
37
-
38
- expect(reducer.$emit(receiveActionInfo, state, payload)).toEqual({
39
- name: ACTION_INFO,
40
- error: null,
41
- data: { _id: "id" },
42
- isActive: false
43
- });
44
- });
45
-
46
- it("should return state (failActionInfo)", () => {
47
- const reducer = actionInfoReducer;
48
- const state: any = {};
49
- const payload = {
50
- error: new Error("message")
51
- };
52
-
53
- expect(reducer.$emit(failActionInfo, state, payload)).toEqual({
54
- name: ACTION_INFO,
55
- data: {},
56
- error: payload.error,
57
- isActive: false
58
- });
59
- });
60
- });
@@ -1,44 +0,0 @@
1
- import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
2
-
3
- import { ActionSchema } from "../../interfaces";
4
- import { failActionInfo, receiveActionInfo, requestActionInfo, resetActionInfo } from "./action-info.actions";
5
- import { ACTION_INFO } from "./action-info.constant";
6
-
7
- export interface ActionInfoState {
8
- error: null | Error;
9
- data?: Partial<ActionSchema>;
10
- isActive: boolean;
11
- }
12
-
13
- const createInitialState: InitialStateCreator<ActionInfoState> = () => ({
14
- error: null,
15
- data: {},
16
- isActive: false
17
- });
18
-
19
- export const actionInfoReducer = createReducer<ActionInfoState>(
20
- {
21
- [resetActionInfo.toString()]: (_, _2, reset) => {
22
- return reset();
23
- },
24
- [requestActionInfo.toString()]: (state) => ({
25
- ...state,
26
- error: null,
27
- data: {},
28
- isActive: true
29
- }),
30
- [receiveActionInfo.toString()]: (state, { actionInfo }) => ({
31
- ...state,
32
- error: null,
33
- data: actionInfo,
34
- isActive: false
35
- }),
36
- [failActionInfo.toString()]: (state, { error }) => ({
37
- ...state,
38
- data: {},
39
- error,
40
- isActive: false
41
- })
42
- },
43
- createInitialState
44
- )(ACTION_INFO);
@@ -1,19 +0,0 @@
1
- import { selectActionInfo } from "./action-info.selectors";
2
-
3
- describe("actions Selectors", () => {
4
- describe("selectActionInfo()", () => {
5
- it("should return actions", () => {
6
- expect(
7
- selectActionInfo({
8
- actionInfo: {
9
- data: {
10
- id: "id"
11
- }
12
- }
13
- })
14
- ).toEqual({
15
- id: "id"
16
- });
17
- });
18
- });
19
- });
@@ -1,7 +0,0 @@
1
- import { ActionSchema } from "../../interfaces";
2
- import { selectRoot } from "../root";
3
- import { ACTION_INFO } from "./action-info.constant";
4
- import { ActionInfoState } from "./action-info.reducers";
5
-
6
- export const selectActionInfo = (state: Record<string, any>): Partial<ActionSchema> =>
7
- selectRoot<ActionInfoState>(ACTION_INFO, state).data!;
@@ -1,4 +0,0 @@
1
- export * from "./action-info.actions";
2
- export * from "./action-info.constant";
3
- export * from "./action-info.reducers";
4
- export * from "./action-info.selectors";
@@ -1,62 +0,0 @@
1
- import { Formio } from "formiojs";
2
-
3
- import { getActions, receiveActions, requestActions, resetActions } from "./actions.actions";
4
-
5
- jest.mock("formiojs");
6
-
7
- describe("Actions actions", () => {
8
- describe("getActions", () => {
9
- it("should return a result", async () => {
10
- const formId = "formId";
11
- const actionId = "actionId";
12
- const dispatch = jest.fn();
13
-
14
- (Formio.prototype.loadActions as any).mockReturnValue([
15
- {
16
- _id: actionId,
17
- name: "oidc"
18
- }
19
- ]);
20
- (Formio.prototype.availableActions as any).mockReturnValue([
21
- {
22
- name: "oidc"
23
- }
24
- ]);
25
-
26
- await getActions(formId)(dispatch);
27
-
28
- expect(dispatch).toHaveBeenCalledWith({
29
- type: resetActions.toString(),
30
- name: "actions"
31
- });
32
- expect(dispatch).toHaveBeenCalledWith({
33
- type: requestActions.toString(),
34
- name: "actions"
35
- });
36
-
37
- expect(Formio).toHaveBeenCalledWith("/formId");
38
- expect(Formio.prototype.loadActions).toHaveBeenCalledWith({
39
- params: {}
40
- });
41
- expect(Formio.prototype.availableActions).toHaveBeenCalledWith();
42
-
43
- expect(dispatch).toHaveBeenCalledWith({
44
- type: receiveActions.toString(),
45
- name: "actions",
46
- payload: {
47
- actions: [
48
- {
49
- _id: actionId,
50
- name: "oidc"
51
- }
52
- ],
53
- availableActions: [
54
- {
55
- name: "oidc"
56
- }
57
- ]
58
- }
59
- });
60
- });
61
- });
62
- });