@wise/dynamic-flow-client-internal 5.28.1 → 5.28.2
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/build/dynamicFlow/DynamicFlow.js +11 -0
- package/build/dynamicFlow/DynamicFlowModal.js +21 -0
- package/build/dynamicFlow/DynamicFlowWiseProps.js +1 -0
- package/build/dynamicFlow/DynamicFlowWithRef.js +19 -0
- package/build/dynamicFlow/context-menu/useContextMenu.js +33 -0
- package/build/dynamicFlow/context-menu/useDFContextMenu.js +135 -0
- package/build/dynamicFlow/context-menu/useDFContextMenu.test.js +101 -0
- package/build/dynamicFlow/getMergedRenderers.js +36 -0
- package/build/dynamicFlow/messages.js +13 -0
- package/build/dynamicFlow/renderers.js +10 -0
- package/build/dynamicFlow/telemetry/app-version.js +4 -0
- package/build/dynamicFlow/telemetry/dispatchAnalyticsEvent.js +8 -0
- package/build/dynamicFlow/telemetry/getLogEvent.js +22 -0
- package/build/dynamicFlow/telemetry/getTrackEvent.js +39 -0
- package/build/dynamicFlow/telemetry/index.js +2 -0
- package/build/dynamicFlow/useCreateSnackBar.js +9 -0
- package/build/dynamicFlow/useOnCopy.js +16 -0
- package/build/dynamicFlow/useWiseHttpClient.js +24 -0
- package/build/dynamicFlow/useWiseToCoreProps.js +42 -0
- package/build/i18n/de.json +3 -3
- package/build/i18n/fr.json +1 -1
- package/build/i18n/hu.json +1 -1
- package/build/i18n/id.json +1 -1
- package/build/i18n/index.js +43 -0
- package/build/i18n/pt.json +1 -1
- package/build/i18n/ru.json +1 -1
- package/build/i18n/zh_HK.json +1 -1
- package/build/index.js +6 -0
- package/build/main.js +10 -10
- package/build/main.mjs +10 -10
- package/build/stories/ButtonLoader.story.js +109 -0
- package/build/stories/ContainerQueries.story.js +74 -0
- package/build/stories/DynamicFlow.story.js +37 -0
- package/build/stories/DynamicFlowWithRef.story.js +72 -0
- package/build/stories/Editable.story.js +58 -0
- package/build/stories/Initialisation.story.js +33 -0
- package/build/stories/PinnedButtons.story.js +94 -0
- package/build/stories/SCAIntegration.story.js +67 -0
- package/build/stories/utils/fixtureHttpClient.js +59 -0
- package/build/test-utils/NeptuneProviders.js +11 -0
- package/build/test-utils/index.js +4 -0
- package/build/test-utils/respond-with.js +6 -0
- package/build/test-utils/rtl-utils.js +7 -0
- package/build/test-utils/wait.js +3 -0
- package/build/tests/DynamicFlow.test.js +177 -0
- package/build/tests/HideStepTitle.test.js +58 -0
- package/build/tests/RequestCache.test.js +34 -0
- package/build/tests/SCARejectionHandling.test.js +71 -0
- package/build/tests/Subflow.Wise.test.js +650 -0
- package/build/tests/events.test.js +124 -0
- package/build/tests/logging.test.js +12 -0
- package/build/tests/onNotification.test.js +96 -0
- package/build/tests/renderers/ControlAndTags.test.js +225 -0
- package/build/tests/renderers/ImageRenderer.test.js +129 -0
- package/build/tests/renderers/RadioInputRendererComponent.test.js +89 -0
- package/build/tests/renderers/ReviewRenderer.test.js +41 -0
- package/build/tests/renderers/TextInputRenderer.test.js +44 -0
- package/build/tests/renderers/TimeZoneHeader.test.js +19 -0
- package/build/tests/renderers/UploadInputRenderer.maxSize.test.js +22 -0
- package/build/tests/renderers/value-utils.test.js +24 -0
- package/build/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { renderWithProviders, respondWith, wait } from '../test-utils';
|
|
3
|
+
import { DynamicFlow } from '../dynamicFlow/DynamicFlow';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
import { screen, waitFor } from '@testing-library/react';
|
|
6
|
+
import { act } from 'react';
|
|
7
|
+
import { respondWithDelay } from '../test-utils/respond-with';
|
|
8
|
+
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTimeAsync });
|
|
9
|
+
describe('Subflow', () => {
|
|
10
|
+
const getDefaultProps = () => ({
|
|
11
|
+
flowId: 'flow-id',
|
|
12
|
+
customFetch: vi.fn(),
|
|
13
|
+
onCompletion: vi.fn(),
|
|
14
|
+
onError: vi.fn(),
|
|
15
|
+
onEvent: vi.fn(),
|
|
16
|
+
onLog: vi.fn(),
|
|
17
|
+
});
|
|
18
|
+
const cases = [
|
|
19
|
+
[
|
|
20
|
+
'given a subflow behavior on a trigger',
|
|
21
|
+
(subflow) => ({
|
|
22
|
+
mockHttpClient: vi.fn(),
|
|
23
|
+
initialStep: {
|
|
24
|
+
id: 'my-step',
|
|
25
|
+
title: 'Step',
|
|
26
|
+
schemas: [],
|
|
27
|
+
layout: [
|
|
28
|
+
{
|
|
29
|
+
type: 'button',
|
|
30
|
+
title: 'Open subflow',
|
|
31
|
+
behavior: subflow,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'given a subflow response',
|
|
39
|
+
(subflow) => ({
|
|
40
|
+
mockHttpClient: vi
|
|
41
|
+
.fn()
|
|
42
|
+
.mockImplementationOnce(async () => respondWith(subflow, { headers: [['X-DF-Response-Type', 'subflow']] })),
|
|
43
|
+
initialStep: {
|
|
44
|
+
id: 'my-step',
|
|
45
|
+
title: 'Step',
|
|
46
|
+
schemas: [],
|
|
47
|
+
layout: [
|
|
48
|
+
{
|
|
49
|
+
type: 'button',
|
|
50
|
+
title: 'Open subflow',
|
|
51
|
+
behavior: {
|
|
52
|
+
type: 'action',
|
|
53
|
+
action: {
|
|
54
|
+
url: '/start-subflow',
|
|
55
|
+
method: 'POST',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
];
|
|
64
|
+
const modallyPresentedSubflow = {
|
|
65
|
+
type: 'subflow',
|
|
66
|
+
referrerId: 'flow-a',
|
|
67
|
+
launchConfig: {
|
|
68
|
+
type: 'dynamic',
|
|
69
|
+
request: {
|
|
70
|
+
url: '/subflow-url',
|
|
71
|
+
method: 'GET',
|
|
72
|
+
},
|
|
73
|
+
presentation: {
|
|
74
|
+
type: 'modal',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
describe.each(cases)('%s', (name, getProps) => {
|
|
79
|
+
describe('given the subflow is modally presented', () => {
|
|
80
|
+
const subflow = modallyPresentedSubflow;
|
|
81
|
+
it('displays the subflow modally with the correct events', async () => {
|
|
82
|
+
const onEvent = vi.fn();
|
|
83
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
84
|
+
const httpClient = mockHttpClient.mockResolvedValueOnce(respondWith({
|
|
85
|
+
id: 'subflow-step',
|
|
86
|
+
title: 'Subflow Step',
|
|
87
|
+
schemas: [],
|
|
88
|
+
layout: [],
|
|
89
|
+
}));
|
|
90
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
91
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
92
|
+
await waitFor(() => {
|
|
93
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
// content is still behind the modal
|
|
96
|
+
expect(screen.getByText('Open subflow')).toBeInTheDocument();
|
|
97
|
+
expect(onEvent).toHaveBeenCalledWith('Dynamic Flow - Initiated', expect.objectContaining({
|
|
98
|
+
integrationId: 'flow-id',
|
|
99
|
+
referrerId: 'flow-a',
|
|
100
|
+
}));
|
|
101
|
+
});
|
|
102
|
+
it('the modal close button cancels the subflow', async () => {
|
|
103
|
+
const onEvent = vi.fn();
|
|
104
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
105
|
+
const httpClient = mockHttpClient.mockResolvedValueOnce(respondWith({
|
|
106
|
+
id: 'subflow-step',
|
|
107
|
+
title: 'Subflow Step',
|
|
108
|
+
schemas: [],
|
|
109
|
+
layout: [],
|
|
110
|
+
}));
|
|
111
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
112
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
113
|
+
await waitFor(() => {
|
|
114
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
115
|
+
});
|
|
116
|
+
await user.click(screen.getByRole('button', { name: /close/i }));
|
|
117
|
+
await waitFor(() => {
|
|
118
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
it('refreshAfter is suspended when the subflow modal is open', async () => {
|
|
122
|
+
const refreshAfter = new Date(Date.now() + 1000).toISOString();
|
|
123
|
+
const onEvent = vi.fn();
|
|
124
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
125
|
+
const httpClient = mockHttpClient.mockImplementation(async (input) => {
|
|
126
|
+
if (input === '/polling-url') {
|
|
127
|
+
return respondWith('', { status: 200 });
|
|
128
|
+
}
|
|
129
|
+
return respondWith({
|
|
130
|
+
id: 'subflow-step',
|
|
131
|
+
title: 'Subflow Step',
|
|
132
|
+
schemas: [],
|
|
133
|
+
layout: [],
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: Object.assign(Object.assign({}, initialStep), { refreshAfter, refreshUrl: '/refresh' }), customFetch: httpClient, onEvent: onEvent })));
|
|
137
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
138
|
+
await act(async () => vi.advanceTimersByTimeAsync(1100));
|
|
139
|
+
expect(httpClient).not.toHaveBeenCalledWith('/refresh', expect.anything());
|
|
140
|
+
httpClient.mockClear();
|
|
141
|
+
await user.click(screen.getByRole('button', { name: /close/i }));
|
|
142
|
+
});
|
|
143
|
+
it('refreshAfter is resumed when the subflow modal is closed', async () => {
|
|
144
|
+
const refreshAfter = new Date(Date.now() + 2000).toISOString();
|
|
145
|
+
const onEvent = vi.fn();
|
|
146
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
147
|
+
const httpClient = mockHttpClient.mockReturnValueOnce(respondWith({
|
|
148
|
+
id: 'subflow-step',
|
|
149
|
+
title: 'Subflow Step',
|
|
150
|
+
schemas: [],
|
|
151
|
+
layout: [],
|
|
152
|
+
}));
|
|
153
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: Object.assign(Object.assign({}, initialStep), { refreshAfter, refreshUrl: '/refresh' }), customFetch: httpClient, onEvent: onEvent })));
|
|
154
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
155
|
+
await act(async () => vi.advanceTimersByTimeAsync(5000));
|
|
156
|
+
await user.click(screen.getByRole('button', { name: /close/i }));
|
|
157
|
+
// the timer isn't being started reliably in before the assertions
|
|
158
|
+
// (i.e. there are no fake timers to advance yet), so adding a manual wait
|
|
159
|
+
await act(async () => wait(500));
|
|
160
|
+
await waitFor(() => {
|
|
161
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
162
|
+
});
|
|
163
|
+
await act(async () => {
|
|
164
|
+
await vi.advanceTimersByTimeAsync(1000);
|
|
165
|
+
});
|
|
166
|
+
await waitFor(async () => {
|
|
167
|
+
expect(httpClient).toHaveBeenCalledWith('/refresh', expect.anything());
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
describe('given the subflow is push presented', () => {
|
|
172
|
+
const subflow = {
|
|
173
|
+
type: 'subflow',
|
|
174
|
+
referrerId: 'flow-a',
|
|
175
|
+
launchConfig: {
|
|
176
|
+
type: 'dynamic',
|
|
177
|
+
request: {
|
|
178
|
+
url: '/subflow-url',
|
|
179
|
+
method: 'GET',
|
|
180
|
+
},
|
|
181
|
+
presentation: {
|
|
182
|
+
type: 'push',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
it('displays the subflow with the correct events', async () => {
|
|
187
|
+
const onEvent = vi.fn();
|
|
188
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
189
|
+
const httpClient = mockHttpClient.mockResolvedValueOnce(respondWith({
|
|
190
|
+
id: 'subflow-step',
|
|
191
|
+
title: 'Subflow Step',
|
|
192
|
+
schemas: [],
|
|
193
|
+
layout: [],
|
|
194
|
+
}));
|
|
195
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
196
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
197
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
198
|
+
// parent content is gone
|
|
199
|
+
expect(screen.queryByText('Open subflow')).not.toBeInTheDocument();
|
|
200
|
+
expect(onEvent).toHaveBeenCalledWith('Dynamic Flow - Initiated', expect.objectContaining({
|
|
201
|
+
integrationId: 'flow-id',
|
|
202
|
+
referrerId: 'flow-a',
|
|
203
|
+
}));
|
|
204
|
+
});
|
|
205
|
+
it('displays the back button which cancels the subflow', async () => {
|
|
206
|
+
const onEvent = vi.fn();
|
|
207
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
208
|
+
const httpClient = mockHttpClient.mockResolvedValueOnce(respondWith({
|
|
209
|
+
id: 'subflow-step',
|
|
210
|
+
title: 'Subflow Step',
|
|
211
|
+
schemas: [],
|
|
212
|
+
layout: [],
|
|
213
|
+
}));
|
|
214
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
215
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
216
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
217
|
+
await user.click(screen.getByRole('button', { name: /back/i }));
|
|
218
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe('when a subflow completes', () => {
|
|
222
|
+
describe('the onCompletion behavior is an action', () => {
|
|
223
|
+
const subflow = {
|
|
224
|
+
type: 'subflow',
|
|
225
|
+
referrerId: 'flow-a',
|
|
226
|
+
launchConfig: {
|
|
227
|
+
type: 'dynamic',
|
|
228
|
+
request: {
|
|
229
|
+
url: '/subflow-url',
|
|
230
|
+
method: 'GET',
|
|
231
|
+
},
|
|
232
|
+
presentation: {
|
|
233
|
+
type: 'push',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
onCompletion: {
|
|
237
|
+
type: 'action',
|
|
238
|
+
action: {
|
|
239
|
+
url: '/subflow-completion',
|
|
240
|
+
data: {
|
|
241
|
+
parentData: 'asdf',
|
|
242
|
+
duplicatedData: 'abc',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
it('removes the subflow and the action is triggered merging the parent content with the subflow result', async () => {
|
|
248
|
+
const onEvent = vi.fn();
|
|
249
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
250
|
+
const httpClient = mockHttpClient
|
|
251
|
+
.mockResolvedValueOnce(respondWith({
|
|
252
|
+
id: 'subflow-step',
|
|
253
|
+
title: 'Subflow Step',
|
|
254
|
+
schemas: [],
|
|
255
|
+
layout: [
|
|
256
|
+
{
|
|
257
|
+
type: 'button',
|
|
258
|
+
title: 'Complete subflow',
|
|
259
|
+
behavior: {
|
|
260
|
+
type: 'action',
|
|
261
|
+
action: {
|
|
262
|
+
exit: true,
|
|
263
|
+
result: {
|
|
264
|
+
subflowData: 'asdf',
|
|
265
|
+
duplicatedData: 'def',
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
}))
|
|
272
|
+
.mockResolvedValueOnce(respondWith({
|
|
273
|
+
id: 'step-2',
|
|
274
|
+
title: 'Step 2',
|
|
275
|
+
schemas: [],
|
|
276
|
+
layout: [],
|
|
277
|
+
}));
|
|
278
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { features: { nativeBack: true }, initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
279
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
280
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
281
|
+
await user.click(screen.getByRole('button', { name: 'Complete subflow' }));
|
|
282
|
+
expect(onEvent).toHaveBeenCalledWith('Dynamic Flow - Succeeded', expect.objectContaining({
|
|
283
|
+
referrerId: 'flow-a',
|
|
284
|
+
integrationId: 'flow-id',
|
|
285
|
+
}));
|
|
286
|
+
expect(httpClient).toHaveBeenCalledWith('/subflow-completion', expect.objectContaining({
|
|
287
|
+
body: JSON.stringify({
|
|
288
|
+
parentData: 'asdf',
|
|
289
|
+
duplicatedData: 'def',
|
|
290
|
+
subflowData: 'asdf',
|
|
291
|
+
}),
|
|
292
|
+
}));
|
|
293
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
294
|
+
});
|
|
295
|
+
it('shows the loader on the final step of the subflow, while the onCompletion behavior is running', async () => {
|
|
296
|
+
const onEvent = vi.fn();
|
|
297
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
298
|
+
const httpClient = mockHttpClient
|
|
299
|
+
.mockResolvedValueOnce(respondWith({
|
|
300
|
+
id: 'subflow-step',
|
|
301
|
+
title: 'Subflow Step',
|
|
302
|
+
schemas: [],
|
|
303
|
+
layout: [
|
|
304
|
+
{
|
|
305
|
+
type: 'button',
|
|
306
|
+
title: 'Complete subflow',
|
|
307
|
+
behavior: {
|
|
308
|
+
type: 'action',
|
|
309
|
+
action: {
|
|
310
|
+
exit: true,
|
|
311
|
+
result: {
|
|
312
|
+
subflowData: 'asdf',
|
|
313
|
+
duplicatedData: 'def',
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
}))
|
|
320
|
+
.mockImplementationOnce(async () => {
|
|
321
|
+
return respondWithDelay({ id: 'second-step', title: 'Next parent step', layout: [], schemas: [] }, 1000);
|
|
322
|
+
});
|
|
323
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
324
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
325
|
+
await waitFor(() => {
|
|
326
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
327
|
+
});
|
|
328
|
+
await user.click(screen.getByRole('button', { name: 'Complete subflow' }));
|
|
329
|
+
// the button label is replaced with 'loading' when it's loading...
|
|
330
|
+
expect(screen.getByRole('button', { name: 'loading' })).toBeDisabled();
|
|
331
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
332
|
+
await waitFor(() => {
|
|
333
|
+
expect(screen.getByText('Next parent step')).toBeInTheDocument();
|
|
334
|
+
});
|
|
335
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
describe('when the behavior is a refresh', () => {
|
|
339
|
+
const subflow = {
|
|
340
|
+
type: 'subflow',
|
|
341
|
+
referrerId: 'flow-a',
|
|
342
|
+
launchConfig: {
|
|
343
|
+
type: 'dynamic',
|
|
344
|
+
request: {
|
|
345
|
+
url: '/subflow-url',
|
|
346
|
+
method: 'GET',
|
|
347
|
+
},
|
|
348
|
+
presentation: {
|
|
349
|
+
type: 'push',
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
onCompletion: {
|
|
353
|
+
type: 'refresh',
|
|
354
|
+
},
|
|
355
|
+
};
|
|
356
|
+
it('removes the subflow and does not merge the result into the request', async () => {
|
|
357
|
+
const onEvent = vi.fn();
|
|
358
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
359
|
+
const httpClient = mockHttpClient
|
|
360
|
+
.mockResolvedValueOnce(respondWith({
|
|
361
|
+
id: 'subflow-step',
|
|
362
|
+
title: 'Subflow Step',
|
|
363
|
+
schemas: [],
|
|
364
|
+
layout: [
|
|
365
|
+
{
|
|
366
|
+
type: 'button',
|
|
367
|
+
title: 'Complete subflow',
|
|
368
|
+
behavior: {
|
|
369
|
+
type: 'action',
|
|
370
|
+
action: {
|
|
371
|
+
exit: true,
|
|
372
|
+
result: {
|
|
373
|
+
subflowData: 'asdf',
|
|
374
|
+
duplicatedData: 'def',
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
}))
|
|
381
|
+
.mockResolvedValueOnce(respondWith({
|
|
382
|
+
id: 'step-2',
|
|
383
|
+
title: 'Step 2',
|
|
384
|
+
schemas: [],
|
|
385
|
+
layout: [],
|
|
386
|
+
}));
|
|
387
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { features: { nativeBack: true }, initialStep: Object.assign(Object.assign({}, initialStep), { refreshUrl: '/refresh' }), customFetch: httpClient, onEvent: onEvent })));
|
|
388
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
389
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
390
|
+
await user.click(screen.getByRole('button', { name: 'Complete subflow' }));
|
|
391
|
+
expect(httpClient).toHaveBeenCalledWith('/refresh', expect.objectContaining({
|
|
392
|
+
body: 'null',
|
|
393
|
+
}));
|
|
394
|
+
});
|
|
395
|
+
it('immediately closes the subflow, and shows the loader on the parent', async () => {
|
|
396
|
+
const onEvent = vi.fn();
|
|
397
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
398
|
+
const httpClient = mockHttpClient
|
|
399
|
+
.mockResolvedValueOnce(respondWith({
|
|
400
|
+
id: 'subflow-step',
|
|
401
|
+
title: 'Subflow Step',
|
|
402
|
+
schemas: [],
|
|
403
|
+
layout: [
|
|
404
|
+
{
|
|
405
|
+
type: 'button',
|
|
406
|
+
title: 'Complete subflow',
|
|
407
|
+
behavior: {
|
|
408
|
+
type: 'refresh',
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
}))
|
|
413
|
+
.mockImplementationOnce(async () => {
|
|
414
|
+
return respondWithDelay({ id: 'second-step', title: 'Next parent step', layout: [], schemas: [] }, 1000);
|
|
415
|
+
});
|
|
416
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
417
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
418
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
419
|
+
await user.click(screen.getByRole('button', { name: 'Complete subflow' }));
|
|
420
|
+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
421
|
+
await waitFor(() => {
|
|
422
|
+
expect(screen.getByText('Next parent step')).toBeInTheDocument();
|
|
423
|
+
});
|
|
424
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
describe('when a subflow fails', () => {
|
|
429
|
+
describe('and the onError behavior is an action', () => {
|
|
430
|
+
const subflow = {
|
|
431
|
+
type: 'subflow',
|
|
432
|
+
referrerId: 'flow-a',
|
|
433
|
+
launchConfig: {
|
|
434
|
+
type: 'dynamic',
|
|
435
|
+
request: {
|
|
436
|
+
url: '/subflow-url',
|
|
437
|
+
method: 'GET',
|
|
438
|
+
},
|
|
439
|
+
presentation: {
|
|
440
|
+
type: 'push',
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
onError: {
|
|
444
|
+
type: 'action',
|
|
445
|
+
action: {
|
|
446
|
+
url: '/subflow-error',
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
it('removes the subflow and triggers the behavior', async () => {
|
|
451
|
+
const onEvent = vi.fn();
|
|
452
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
453
|
+
const httpClient = mockHttpClient
|
|
454
|
+
.mockResolvedValueOnce(respondWith({
|
|
455
|
+
id: 'subflow-step',
|
|
456
|
+
title: 'Subflow Step',
|
|
457
|
+
schemas: [],
|
|
458
|
+
refreshUrl: '/bad-refresh',
|
|
459
|
+
layout: [
|
|
460
|
+
{
|
|
461
|
+
type: 'button',
|
|
462
|
+
title: 'Trigger flow error',
|
|
463
|
+
behavior: {
|
|
464
|
+
type: 'refresh',
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
}))
|
|
469
|
+
.mockResolvedValueOnce(respondWith({}, { status: 400 }))
|
|
470
|
+
.mockResolvedValueOnce(respondWith({
|
|
471
|
+
id: 'step-2',
|
|
472
|
+
title: 'Step 2',
|
|
473
|
+
schemas: [],
|
|
474
|
+
layout: [],
|
|
475
|
+
}));
|
|
476
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { features: { nativeBack: true }, initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
477
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
478
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
479
|
+
await user.click(screen.getByRole('button', { name: 'Trigger flow error' }));
|
|
480
|
+
expect(httpClient).toHaveBeenCalledWith('/subflow-error', expect.objectContaining({
|
|
481
|
+
body: undefined,
|
|
482
|
+
}));
|
|
483
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
describe('when that subflow launches another subflow', () => {
|
|
488
|
+
const subflow = {
|
|
489
|
+
type: 'subflow',
|
|
490
|
+
referrerId: 'flow-a',
|
|
491
|
+
resultKey: 'child-data',
|
|
492
|
+
launchConfig: {
|
|
493
|
+
type: 'dynamic',
|
|
494
|
+
request: {
|
|
495
|
+
url: '/subflow-url',
|
|
496
|
+
method: 'GET',
|
|
497
|
+
},
|
|
498
|
+
presentation: {
|
|
499
|
+
type: 'modal',
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
onCompletion: {
|
|
503
|
+
type: 'action',
|
|
504
|
+
action: {
|
|
505
|
+
url: '/subflow-submit',
|
|
506
|
+
data: { subflow1: 'abc' },
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
onError: {
|
|
510
|
+
type: 'action',
|
|
511
|
+
action: {
|
|
512
|
+
url: '/subflow-error',
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
const subflow2 = {
|
|
517
|
+
type: 'subflow',
|
|
518
|
+
referrerId: 'flow-b',
|
|
519
|
+
launchConfig: {
|
|
520
|
+
type: 'dynamic',
|
|
521
|
+
request: {
|
|
522
|
+
url: '/subflow-url',
|
|
523
|
+
method: 'GET',
|
|
524
|
+
},
|
|
525
|
+
presentation: {
|
|
526
|
+
type: 'modal',
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
onCompletion: {
|
|
530
|
+
type: 'action',
|
|
531
|
+
action: {
|
|
532
|
+
exit: true,
|
|
533
|
+
result: { subflow2: 'def' },
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
onError: {
|
|
537
|
+
type: 'action',
|
|
538
|
+
action: {
|
|
539
|
+
url: '/subflow-error',
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
};
|
|
543
|
+
it('uses correct referrerId and merges data according to the resultKey', async () => {
|
|
544
|
+
const onEvent = vi.fn();
|
|
545
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
546
|
+
const httpClient = mockHttpClient
|
|
547
|
+
.mockResolvedValueOnce(respondWith({
|
|
548
|
+
id: 'subflow-step',
|
|
549
|
+
title: 'Subflow Step',
|
|
550
|
+
schemas: [],
|
|
551
|
+
layout: [
|
|
552
|
+
{
|
|
553
|
+
type: 'button',
|
|
554
|
+
title: 'Another subflow',
|
|
555
|
+
behavior: {
|
|
556
|
+
type: 'action',
|
|
557
|
+
action: {
|
|
558
|
+
url: '/test',
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
],
|
|
563
|
+
}))
|
|
564
|
+
.mockResolvedValueOnce(respondWith(subflow2, { headers: [['X-DF-Response-Type', 'subflow']] }))
|
|
565
|
+
.mockResolvedValueOnce(respondWith({
|
|
566
|
+
id: 'subflow-step',
|
|
567
|
+
title: 'Subflow Step 2',
|
|
568
|
+
schemas: [],
|
|
569
|
+
layout: [
|
|
570
|
+
{
|
|
571
|
+
type: 'button',
|
|
572
|
+
title: 'Close subflow',
|
|
573
|
+
behavior: {
|
|
574
|
+
type: 'action',
|
|
575
|
+
action: {
|
|
576
|
+
exit: true,
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
],
|
|
581
|
+
}))
|
|
582
|
+
.mockResolvedValueOnce(respondWith({ value1: 'abc' }, { headers: [['X-DF-Response-Type', 'exit']] }));
|
|
583
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: initialStep, customFetch: httpClient, onEvent: onEvent })));
|
|
584
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
585
|
+
await waitFor(() => {
|
|
586
|
+
expect(screen.getByText('Subflow Step')).toBeInTheDocument();
|
|
587
|
+
});
|
|
588
|
+
expect(onEvent).toHaveBeenCalledWith('Dynamic Flow - Initiated', expect.objectContaining({
|
|
589
|
+
referrerId: 'flow-a',
|
|
590
|
+
}));
|
|
591
|
+
await user.click(screen.getByRole('button', { name: 'Another subflow' }));
|
|
592
|
+
await waitFor(() => {
|
|
593
|
+
expect(screen.getByText('Subflow Step 2')).toBeInTheDocument();
|
|
594
|
+
});
|
|
595
|
+
expect(onEvent).toHaveBeenCalledWith('Dynamic Flow - Initiated', expect.objectContaining({
|
|
596
|
+
referrerId: 'flow-b',
|
|
597
|
+
}));
|
|
598
|
+
await user.click(screen.getByRole('button', { name: 'Close subflow' }));
|
|
599
|
+
await waitFor(() => {
|
|
600
|
+
expect(httpClient).toHaveBeenLastCalledWith('/subflow-submit', expect.objectContaining({
|
|
601
|
+
body: JSON.stringify({ subflow1: 'abc', 'child-data': { subflow2: 'def' } }),
|
|
602
|
+
}));
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
describe.each([cases[0]])('%s', (name, getProps) => {
|
|
608
|
+
describe('given the subflow is modally presented', () => {
|
|
609
|
+
const subflow = modallyPresentedSubflow;
|
|
610
|
+
it('any polling requests are paused when the subflow modal is open, and resumed when the subflow modal is closed', async () => {
|
|
611
|
+
const polling = {
|
|
612
|
+
url: '/polling-url',
|
|
613
|
+
maxAttempts: 100,
|
|
614
|
+
interval: 200,
|
|
615
|
+
onError: { behavior: { type: 'link', url: '/error' } },
|
|
616
|
+
};
|
|
617
|
+
const onEvent = vi.fn();
|
|
618
|
+
const { initialStep, mockHttpClient } = getProps(subflow);
|
|
619
|
+
const httpClient = mockHttpClient.mockImplementation(async (input) => {
|
|
620
|
+
if (input === '/polling-url') {
|
|
621
|
+
return respondWith('', { status: 200 });
|
|
622
|
+
}
|
|
623
|
+
if (input === '/start-subflow') {
|
|
624
|
+
return respondWith(subflow, { headers: [['X-DF-Response-Type', 'subflow']] });
|
|
625
|
+
}
|
|
626
|
+
return respondWith({
|
|
627
|
+
id: 'subflow-step',
|
|
628
|
+
title: 'Subflow Step',
|
|
629
|
+
schemas: [],
|
|
630
|
+
layout: [],
|
|
631
|
+
});
|
|
632
|
+
});
|
|
633
|
+
renderWithProviders(_jsx(DynamicFlow, Object.assign({}, getDefaultProps(), { initialStep: Object.assign(Object.assign({}, initialStep), { polling }), customFetch: httpClient, onEvent: onEvent })));
|
|
634
|
+
await act(async () => vi.advanceTimersByTimeAsync(200));
|
|
635
|
+
expect(httpClient).toHaveBeenCalledWith('/polling-url', expect.anything());
|
|
636
|
+
httpClient.mockClear();
|
|
637
|
+
await user.click(screen.getByRole('button', { name: 'Open subflow' }));
|
|
638
|
+
// await act(async () => vi.advanceTimersByTimeAsync(400));
|
|
639
|
+
expect(httpClient).not.toHaveBeenCalledWith('/polling-url', expect.anything());
|
|
640
|
+
httpClient.mockClear();
|
|
641
|
+
await user.click(screen.getByRole('button', { name: /close/i }));
|
|
642
|
+
await waitFor(() => {
|
|
643
|
+
expect(screen.queryByText('Subflow Step')).not.toBeInTheDocument();
|
|
644
|
+
});
|
|
645
|
+
await act(async () => vi.advanceTimersByTimeAsync(200));
|
|
646
|
+
expect(httpClient).toHaveBeenCalledWith('/polling-url', expect.anything());
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
});
|