@truedat/dd 8.4.3 → 8.4.5
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/package.json +3 -3
- package/src/components/StructureGrantCartCheckout.js +227 -73
- package/src/components/StructureGrantCartInformation.js +11 -0
- package/src/components/StructureGrantCartUserSelector.js +25 -10
- package/src/components/__tests__/StructureGrantCartCheckout.spec.js +213 -12
- package/src/components/__tests__/__snapshots__/StructureGrantCartCheckout.spec.js.snap +807 -81
- package/src/components/__tests__/__snapshots__/StructureGrantCartInformation.spec.js.snap +0 -31
- package/src/reducers/grantRequestsCart.js +13 -0
- package/src/routines.js +3 -0
|
@@ -14,6 +14,14 @@ jest.mock("../../hooks/useCheckoutGrantRequest", () => ({
|
|
|
14
14
|
useCheckoutGrantRequest: jest.fn(),
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
+
jest.mock("../../hooks/useTemplatesByIds", () => ({
|
|
18
|
+
useTemplatesByIds: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock("@truedat/auth/hooks/useUsers", () => ({
|
|
22
|
+
useGrantRequestableUsers: jest.fn(),
|
|
23
|
+
}));
|
|
24
|
+
|
|
17
25
|
jest.mock("react-redux", () => {
|
|
18
26
|
const actual = jest.requireActual("react-redux");
|
|
19
27
|
return {
|
|
@@ -23,8 +31,14 @@ jest.mock("react-redux", () => {
|
|
|
23
31
|
});
|
|
24
32
|
|
|
25
33
|
const { useWebContext } = require("@truedat/core/webContext");
|
|
26
|
-
const {
|
|
27
|
-
|
|
34
|
+
const {
|
|
35
|
+
useTemplateRelations,
|
|
36
|
+
} = require("@truedat/df/hooks/useTemplateRelations");
|
|
37
|
+
const {
|
|
38
|
+
useCheckoutGrantRequest,
|
|
39
|
+
} = require("../../hooks/useCheckoutGrantRequest");
|
|
40
|
+
const { useTemplatesByIds } = require("../../hooks/useTemplatesByIds");
|
|
41
|
+
const { useGrantRequestableUsers } = require("@truedat/auth/hooks/useUsers");
|
|
28
42
|
const { useDispatch } = require("react-redux");
|
|
29
43
|
|
|
30
44
|
const grantRequestsCartWithModification = {
|
|
@@ -69,19 +83,100 @@ const grantRequestsCartMultiGroup = {
|
|
|
69
83
|
validCart: false,
|
|
70
84
|
user: { id: "1", valid: true },
|
|
71
85
|
structures: [
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
{
|
|
87
|
+
id: 101,
|
|
88
|
+
system_id: 10,
|
|
89
|
+
system: { id: 10, name: "System A" },
|
|
90
|
+
domain_ids: [1],
|
|
91
|
+
domains: [{ id: 1, name: "Domain 1" }],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 102,
|
|
95
|
+
system_id: 10,
|
|
96
|
+
system: { id: 10, name: "System A" },
|
|
97
|
+
domain_ids: [1],
|
|
98
|
+
domains: [{ id: 1, name: "Domain 1" }],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 201,
|
|
102
|
+
system_id: 20,
|
|
103
|
+
system: { id: 20, name: "System B" },
|
|
104
|
+
domain_ids: [2],
|
|
105
|
+
domains: [{ id: 2, name: "Domain 2" }],
|
|
106
|
+
},
|
|
75
107
|
],
|
|
76
108
|
groupTemplates: {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
109
|
+
nodomain_10_1: { template: "Template A", templateContent: {}, valid: true },
|
|
110
|
+
nodomain_20_2: {
|
|
111
|
+
template: "Template B",
|
|
112
|
+
templateContent: {},
|
|
113
|
+
valid: false,
|
|
114
|
+
},
|
|
80
115
|
},
|
|
81
116
|
};
|
|
82
117
|
|
|
118
|
+
const grantRequestsCartWithDomainGrouping = {
|
|
119
|
+
template: null,
|
|
120
|
+
templateContent: {},
|
|
121
|
+
modificationGrant: null,
|
|
122
|
+
validCart: false,
|
|
123
|
+
user: { id: "1", valid: true },
|
|
124
|
+
structures: [
|
|
125
|
+
{
|
|
126
|
+
id: 101,
|
|
127
|
+
system_id: 10,
|
|
128
|
+
system: { id: 10, name: "System A" },
|
|
129
|
+
domain_ids: [1],
|
|
130
|
+
domains: [{ id: 1, name: "Domain 1" }],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 102,
|
|
134
|
+
system_id: 10,
|
|
135
|
+
system: { id: 10, name: "System A" },
|
|
136
|
+
domain_ids: [2],
|
|
137
|
+
domains: [{ id: 2, name: "Domain 2" }],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: 103,
|
|
141
|
+
system_id: 10,
|
|
142
|
+
system: { id: 10, name: "System A" },
|
|
143
|
+
domain_ids: [1, 2],
|
|
144
|
+
domains: [
|
|
145
|
+
{ id: 1, name: "Domain 1" },
|
|
146
|
+
{ id: 2, name: "Domain 2" },
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
groupTemplates: {},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const grantRequestsCartSingleDomain = {
|
|
154
|
+
template: null,
|
|
155
|
+
templateContent: {},
|
|
156
|
+
modificationGrant: null,
|
|
157
|
+
validCart: false,
|
|
158
|
+
user: { id: "1", valid: true },
|
|
159
|
+
structures: [
|
|
160
|
+
{
|
|
161
|
+
id: 101,
|
|
162
|
+
system_id: 10,
|
|
163
|
+
system: { id: 10, name: "System A" },
|
|
164
|
+
domain_ids: [1],
|
|
165
|
+
domains: [{ id: 1, name: "Domain 1" }],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: 102,
|
|
169
|
+
system_id: 10,
|
|
170
|
+
system: { id: 10, name: "System A" },
|
|
171
|
+
domain_ids: [1],
|
|
172
|
+
domains: [{ id: 1, name: "Domain 1" }],
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
groupTemplates: {},
|
|
176
|
+
};
|
|
177
|
+
|
|
83
178
|
describe("StructureGrantCartCheckout", () => {
|
|
84
|
-
const mockTrigger = jest.fn();
|
|
179
|
+
const mockTrigger = jest.fn().mockResolvedValue({});
|
|
85
180
|
const mockDispatch = jest.fn();
|
|
86
181
|
const mockInitGroupTemplates = jest.fn();
|
|
87
182
|
const mockSelectGrantRequestTemplateForGroup = jest.fn();
|
|
@@ -103,6 +198,8 @@ describe("StructureGrantCartCheckout", () => {
|
|
|
103
198
|
trigger: mockTrigger,
|
|
104
199
|
isMutating: false,
|
|
105
200
|
});
|
|
201
|
+
useTemplatesByIds.mockReturnValue({});
|
|
202
|
+
useGrantRequestableUsers.mockReturnValue({ users: [], trigger: jest.fn() });
|
|
106
203
|
useDispatch.mockReturnValue(mockDispatch);
|
|
107
204
|
});
|
|
108
205
|
|
|
@@ -116,7 +213,7 @@ describe("StructureGrantCartCheckout", () => {
|
|
|
116
213
|
useTemplateRelations.mockReturnValue({ resource: [] });
|
|
117
214
|
const rendered = render(
|
|
118
215
|
<StructureGrantCartCheckout {...defaultProps} />,
|
|
119
|
-
renderOpts
|
|
216
|
+
renderOpts,
|
|
120
217
|
);
|
|
121
218
|
await waitForLoad(rendered);
|
|
122
219
|
expect(rendered.container).toMatchSnapshot();
|
|
@@ -129,7 +226,10 @@ describe("StructureGrantCartCheckout", () => {
|
|
|
129
226
|
...defaultProps,
|
|
130
227
|
grantRequestsCart: grantRequestsCartSingle,
|
|
131
228
|
};
|
|
132
|
-
const rendered = render(
|
|
229
|
+
const rendered = render(
|
|
230
|
+
<StructureGrantCartCheckout {...props} />,
|
|
231
|
+
renderOpts,
|
|
232
|
+
);
|
|
133
233
|
await waitForLoad(rendered);
|
|
134
234
|
expect(rendered.container).toMatchSnapshot();
|
|
135
235
|
});
|
|
@@ -151,7 +251,108 @@ describe("StructureGrantCartCheckout", () => {
|
|
|
151
251
|
};
|
|
152
252
|
const rendered = render(
|
|
153
253
|
<StructureGrantCartCheckout {...defaultProps} />,
|
|
154
|
-
multiRenderOpts
|
|
254
|
+
multiRenderOpts,
|
|
255
|
+
);
|
|
256
|
+
await waitForLoad(rendered);
|
|
257
|
+
expect(rendered.container).toMatchSnapshot();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("matches snapshot with group_by_domain enabled for system - shows domain titles", async () => {
|
|
261
|
+
useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
|
|
262
|
+
useTemplateRelations.mockReturnValue({
|
|
263
|
+
resource: [{ resource_id: 10, template_id: 1, group_by_domain: true }],
|
|
264
|
+
default: { template_id: 1, group_by_domain: true },
|
|
265
|
+
});
|
|
266
|
+
const props = {
|
|
267
|
+
...defaultProps,
|
|
268
|
+
grantRequestsCart: grantRequestsCartWithDomainGrouping,
|
|
269
|
+
};
|
|
270
|
+
const renderOpts = {
|
|
271
|
+
state: { grantRequestsCart: grantRequestsCartWithDomainGrouping },
|
|
272
|
+
mocks: [
|
|
273
|
+
singleTemplateMock({ scope: "gr" }),
|
|
274
|
+
domainsMock({ action: "createForeignGrantRequest" }),
|
|
275
|
+
],
|
|
276
|
+
};
|
|
277
|
+
const rendered = render(
|
|
278
|
+
<StructureGrantCartCheckout {...props} />,
|
|
279
|
+
renderOpts,
|
|
280
|
+
);
|
|
281
|
+
await waitForLoad(rendered);
|
|
282
|
+
expect(rendered.container).toMatchSnapshot();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("matches snapshot with gr scope - shows system titles", async () => {
|
|
286
|
+
useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
|
|
287
|
+
useTemplateRelations.mockReturnValue({
|
|
288
|
+
resource: [
|
|
289
|
+
{ resource_id: 10, template_id: 1 },
|
|
290
|
+
{ resource_id: 20, template_id: 2 },
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
const props = {
|
|
294
|
+
...defaultProps,
|
|
295
|
+
grantRequestsCart: grantRequestsCartMultiGroup,
|
|
296
|
+
};
|
|
297
|
+
const renderOpts = {
|
|
298
|
+
state: { grantRequestsCart: grantRequestsCartMultiGroup },
|
|
299
|
+
mocks: [
|
|
300
|
+
singleTemplateMock({ scope: "gr" }),
|
|
301
|
+
domainsMock({ action: "createForeignGrantRequest" }),
|
|
302
|
+
],
|
|
303
|
+
};
|
|
304
|
+
const rendered = render(
|
|
305
|
+
<StructureGrantCartCheckout {...props} />,
|
|
306
|
+
renderOpts,
|
|
307
|
+
);
|
|
308
|
+
await waitForLoad(rendered);
|
|
309
|
+
expect(rendered.container).toMatchSnapshot();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("matches snapshot without gr scope - does not show system or domain titles", async () => {
|
|
313
|
+
useWebContext.mockReturnValue({ scopesWithRelations: [] });
|
|
314
|
+
useTemplateRelations.mockReturnValue({
|
|
315
|
+
resource: [],
|
|
316
|
+
});
|
|
317
|
+
const props = {
|
|
318
|
+
...defaultProps,
|
|
319
|
+
grantRequestsCart: grantRequestsCartMultiGroup,
|
|
320
|
+
};
|
|
321
|
+
const renderOpts = {
|
|
322
|
+
state: { grantRequestsCart: grantRequestsCartMultiGroup },
|
|
323
|
+
mocks: [
|
|
324
|
+
singleTemplateMock({ scope: "gr" }),
|
|
325
|
+
domainsMock({ action: "createForeignGrantRequest" }),
|
|
326
|
+
],
|
|
327
|
+
};
|
|
328
|
+
const rendered = render(
|
|
329
|
+
<StructureGrantCartCheckout {...props} />,
|
|
330
|
+
renderOpts,
|
|
331
|
+
);
|
|
332
|
+
await waitForLoad(rendered);
|
|
333
|
+
expect(rendered.container).toMatchSnapshot();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("matches snapshot with single domain - shows singular domain message", async () => {
|
|
337
|
+
useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
|
|
338
|
+
useTemplateRelations.mockReturnValue({
|
|
339
|
+
resource: [{ resource_id: 10, template_id: 1, group_by_domain: true }],
|
|
340
|
+
default: { template_id: 1, group_by_domain: true },
|
|
341
|
+
});
|
|
342
|
+
const props = {
|
|
343
|
+
...defaultProps,
|
|
344
|
+
grantRequestsCart: grantRequestsCartSingleDomain,
|
|
345
|
+
};
|
|
346
|
+
const renderOpts = {
|
|
347
|
+
state: { grantRequestsCart: grantRequestsCartSingleDomain },
|
|
348
|
+
mocks: [
|
|
349
|
+
singleTemplateMock({ scope: "gr" }),
|
|
350
|
+
domainsMock({ action: "createForeignGrantRequest" }),
|
|
351
|
+
],
|
|
352
|
+
};
|
|
353
|
+
const rendered = render(
|
|
354
|
+
<StructureGrantCartCheckout {...props} />,
|
|
355
|
+
renderOpts,
|
|
155
356
|
);
|
|
156
357
|
await waitForLoad(rendered);
|
|
157
358
|
expect(rendered.container).toMatchSnapshot();
|