@incodetech/web 2.0.0-alpha.1 → 2.0.0-alpha.10

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 (209) hide show
  1. package/dist/base.css +1071 -0
  2. package/dist/browser-ponyfill-B6W6hHVY.js +344 -0
  3. package/dist/email/email.es.js +145 -0
  4. package/dist/email/styles.css +123 -0
  5. package/dist/flow/flow.es.js +555 -0
  6. package/dist/flow/styles.css +1119 -0
  7. package/dist/incodeModule-Dv8Qllrv.js +254 -0
  8. package/dist/index.es.js +6 -0
  9. package/dist/instance-B-q0ZREN.js +2140 -0
  10. package/dist/otpInput-BtoZe0Wz.js +151 -0
  11. package/dist/page-Dh_Zw2ik.js +234 -0
  12. package/dist/phone/phone.es.js +3441 -0
  13. package/dist/phone/styles.css +305 -0
  14. package/dist/selfie/selfie.es.js +893 -0
  15. package/dist/selfie/styles.css +590 -0
  16. package/dist/selfieTutorial-C-u5GufD.js +29 -0
  17. package/dist/setup-wNL83jmW.js +20 -0
  18. package/dist/themes/dark.css +652 -0
  19. package/dist/themes/light.css +543 -0
  20. package/dist/title-BfO5Dlzk.js +25 -0
  21. package/dist/types/base.d.ts +1 -0
  22. package/dist/types/dark.d.ts +1 -0
  23. package/dist/types/email.d.ts +57 -0
  24. package/dist/types/flow.d.ts +69 -0
  25. package/dist/types/index.d.ts +38 -0
  26. package/dist/types/light.d.ts +1 -0
  27. package/dist/types/phone.d.ts +58 -0
  28. package/dist/types/selfie.d.ts +31 -0
  29. package/dist/types/styles.d.ts +1 -0
  30. package/dist/types/themes/dark.d.ts +1 -0
  31. package/dist/types/themes/light.d.ts +1 -0
  32. package/dist/uiConfig-CQ1W9cUD.js +23 -0
  33. package/dist/vendor-preact-CK0WeTOR.js +584 -0
  34. package/package.json +32 -26
  35. package/dev/README.md +0 -163
  36. package/dev/getToken.ts +0 -36
  37. package/dev/headless.html +0 -875
  38. package/dev/index.html +0 -366
  39. package/dev/main-headless.tsx +0 -1332
  40. package/dev/main-orchestrated-flow.tsx +0 -1158
  41. package/dev/main-preact.tsx +0 -323
  42. package/dev/main-simplified.tsx +0 -123
  43. package/dev/main-web-component.tsx +0 -256
  44. package/dev/main.tsx +0 -332
  45. package/dev/manual.html +0 -27
  46. package/dev/orchestrated-flow.html +0 -64
  47. package/dev/simplified.html +0 -64
  48. package/dev/tiktok-logo.svg +0 -7
  49. package/src/defineCustomElement.tsx +0 -30
  50. package/src/email/email.test.tsx +0 -368
  51. package/src/email/email.tsx +0 -255
  52. package/src/email/emailInput.test.tsx +0 -264
  53. package/src/email/emailInput.tsx +0 -85
  54. package/src/email/styles.css +0 -59
  55. package/src/flow/flow.test.tsx +0 -796
  56. package/src/flow/flow.tsx +0 -292
  57. package/src/flow/flowCompleted.css +0 -30
  58. package/src/flow/flowCompleted.test.tsx +0 -331
  59. package/src/flow/flowCompleted.tsx +0 -121
  60. package/src/flow/flowInit.test.ts +0 -264
  61. package/src/flow/flowInit.ts +0 -94
  62. package/src/flow/flowStart.css +0 -58
  63. package/src/flow/flowStart.test.tsx +0 -49
  64. package/src/flow/flowStart.tsx +0 -41
  65. package/src/flow/incode-logo.svg +0 -8
  66. package/src/flow/index.ts +0 -7
  67. package/src/flow/preloadFlow.test.ts +0 -421
  68. package/src/flow/preloadFlow.ts +0 -171
  69. package/src/flow/styles.css +0 -9
  70. package/src/flow/unsupportedModule.css +0 -21
  71. package/src/flow/unsupportedModule.tsx +0 -39
  72. package/src/flow/useFlowInitialization.test.tsx +0 -292
  73. package/src/flow/useFlowInitialization.ts +0 -128
  74. package/src/flow/useModuleLoader.test.tsx +0 -212
  75. package/src/flow/useModuleLoader.ts +0 -92
  76. package/src/hooks/index.ts +0 -1
  77. package/src/hooks/useManager.test.ts +0 -91
  78. package/src/hooks/useManager.ts +0 -40
  79. package/src/i18n/index.ts +0 -3
  80. package/src/i18n/instance.ts +0 -16
  81. package/src/i18n/setup.ts +0 -184
  82. package/src/i18n/useTranslation.ts +0 -42
  83. package/src/index.ts +0 -27
  84. package/src/permissions/assets/android-dots-icon.svg +0 -7
  85. package/src/permissions/assets/android-settings-icon.svg +0 -16
  86. package/src/permissions/assets/android-toggle-icon.svg +0 -20
  87. package/src/permissions/assets/bank-card-icon.svg +0 -14
  88. package/src/permissions/assets/camera-icon.svg +0 -12
  89. package/src/permissions/assets/camera-ios.svg +0 -53
  90. package/src/permissions/assets/check-icon.svg +0 -8
  91. package/src/permissions/assets/chrome-icon.svg +0 -43
  92. package/src/permissions/assets/password-icon.svg +0 -11
  93. package/src/permissions/assets/permissions-img.svg +0 -51
  94. package/src/permissions/assets/safari-icon.svg +0 -37
  95. package/src/permissions/assets/settings-icon.svg +0 -33
  96. package/src/permissions/assets/toggle-icon.svg +0 -19
  97. package/src/permissions/assets/warning-icon.svg +0 -6
  98. package/src/permissions/boldWithArrow.css +0 -9
  99. package/src/permissions/boldWithArrow.tsx +0 -41
  100. package/src/permissions/denied.css +0 -37
  101. package/src/permissions/denied.tsx +0 -29
  102. package/src/permissions/deniedAndroid.tsx +0 -56
  103. package/src/permissions/deniedDesktop.css +0 -9
  104. package/src/permissions/deniedDesktop.tsx +0 -64
  105. package/src/permissions/deniedIOS.tsx +0 -73
  106. package/src/permissions/deniedInstructions.tsx +0 -19
  107. package/src/permissions/iconWrapper.css +0 -9
  108. package/src/permissions/iconWrapper.tsx +0 -15
  109. package/src/permissions/learnMore.css +0 -37
  110. package/src/permissions/learnMore.tsx +0 -85
  111. package/src/permissions/numberedStep.css +0 -13
  112. package/src/permissions/numberedStep.tsx +0 -14
  113. package/src/permissions/permissions.css +0 -13
  114. package/src/permissions/permissions.tsx +0 -68
  115. package/src/phone/phone.tsx +0 -246
  116. package/src/phone/phoneInput.test.tsx +0 -275
  117. package/src/phone/phoneInput.tsx +0 -249
  118. package/src/phone/styles.css +0 -158
  119. package/src/selfie/cameraButton.css +0 -13
  120. package/src/selfie/cameraButton.tsx +0 -35
  121. package/src/selfie/capture.css +0 -57
  122. package/src/selfie/capture.tsx +0 -232
  123. package/src/selfie/errorModal.tsx +0 -218
  124. package/src/selfie/errorModalContent.css +0 -33
  125. package/src/selfie/errorModalContent.tsx +0 -44
  126. package/src/selfie/faceOutline.css +0 -5
  127. package/src/selfie/faceOutline.tsx +0 -22
  128. package/src/selfie/loadingBorder.css +0 -12
  129. package/src/selfie/loadingBorder.tsx +0 -77
  130. package/src/selfie/manualCaptureButton.css +0 -13
  131. package/src/selfie/manualCaptureButton.tsx +0 -35
  132. package/src/selfie/noMoreAttemptsModal.tsx +0 -44
  133. package/src/selfie/notification.css +0 -9
  134. package/src/selfie/notification.tsx +0 -36
  135. package/src/selfie/retryErrorModal.tsx +0 -56
  136. package/src/selfie/selfie.test.tsx +0 -458
  137. package/src/selfie/selfie.tsx +0 -83
  138. package/src/selfie/selfieTutorial.json +0 -2626
  139. package/src/selfie/styles.css +0 -1
  140. package/src/selfie/tutorial.test.tsx +0 -200
  141. package/src/selfie/tutorial.tsx +0 -43
  142. package/src/setup.ts +0 -33
  143. package/src/shared/baseTutorial/baseTutorial.css +0 -21
  144. package/src/shared/baseTutorial/baseTutorial.test.tsx +0 -184
  145. package/src/shared/baseTutorial/baseTutorial.tsx +0 -55
  146. package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +0 -267
  147. package/src/shared/baseTutorial/replaceBaseTutorial.ts +0 -68
  148. package/src/shared/button/button.css +0 -55
  149. package/src/shared/button/button.test.tsx +0 -101
  150. package/src/shared/button/button.tsx +0 -47
  151. package/src/shared/componentRoot/incodeComponent.tsx +0 -12
  152. package/src/shared/countries/countries.test.ts +0 -75
  153. package/src/shared/countries/countries.ts +0 -139
  154. package/src/shared/countries/index.ts +0 -6
  155. package/src/shared/icons/chevronDown.tsx +0 -22
  156. package/src/shared/icons/index.ts +0 -2
  157. package/src/shared/icons/successIcon.css +0 -5
  158. package/src/shared/icons/successIcon.test.tsx +0 -40
  159. package/src/shared/icons/successIcon.tsx +0 -26
  160. package/src/shared/loader/loadingIcon.css +0 -28
  161. package/src/shared/loader/loadingIcon.tsx +0 -67
  162. package/src/shared/lottie/lottie.tsx +0 -108
  163. package/src/shared/otpInput/otpInput.css +0 -85
  164. package/src/shared/otpInput/otpInput.test.tsx +0 -356
  165. package/src/shared/otpInput/otpInput.tsx +0 -241
  166. package/src/shared/page/incode-logo.svg +0 -3
  167. package/src/shared/page/page.css +0 -47
  168. package/src/shared/page/page.test.tsx +0 -97
  169. package/src/shared/page/page.tsx +0 -91
  170. package/src/shared/page/pageUiConfig.test.ts +0 -112
  171. package/src/shared/page/pageUiConfig.ts +0 -64
  172. package/src/shared/page/verifiedByIncode.css +0 -5
  173. package/src/shared/page/verifiedByIncode.tsx +0 -75
  174. package/src/shared/spacer/spacer.css +0 -149
  175. package/src/shared/spacer/spacer.test.tsx +0 -143
  176. package/src/shared/spacer/spacer.tsx +0 -88
  177. package/src/shared/spinner/index.ts +0 -2
  178. package/src/shared/spinner/spinner.css +0 -28
  179. package/src/shared/spinner/spinner.test.tsx +0 -82
  180. package/src/shared/spinner/spinner.tsx +0 -65
  181. package/src/shared/title/title.css +0 -7
  182. package/src/shared/title/title.tsx +0 -12
  183. package/src/shared/uiConfig/uiConfig.ts +0 -36
  184. package/src/shared/webComponent/incodeModule.ts +0 -29
  185. package/src/shared/webComponent/registerIncodeElement.ts +0 -15
  186. package/src/styles/__mocks__/fetchTheme.ts +0 -19
  187. package/src/styles/applyTheme.ts +0 -37
  188. package/src/styles/cn.test.tsx +0 -57
  189. package/src/styles/cn.tsx +0 -21
  190. package/src/styles/core.css +0 -12
  191. package/src/styles/fetchTheme.test.ts +0 -390
  192. package/src/styles/fetchTheme.ts +0 -88
  193. package/src/styles/generatePalette.ts +0 -111
  194. package/src/styles/reset.css +0 -65
  195. package/src/styles/resolveCssVariableToHex.ts +0 -28
  196. package/src/styles/tailwind.css +0 -291
  197. package/src/styles/themeTypes.ts +0 -18
  198. package/src/styles/tokens/colors.css +0 -190
  199. package/src/styles/tokens/components.css +0 -174
  200. package/src/styles/tokens/index.css +0 -4
  201. package/src/styles/tokens/primitives.css +0 -129
  202. package/src/styles/tokens/semantic.css +0 -51
  203. package/src/svg.d.ts +0 -4
  204. package/src/types/assets.d.ts +0 -1
  205. package/src/types/custom-elements.d.ts +0 -104
  206. package/tsconfig.json +0 -22
  207. package/vite.config.ts +0 -260
  208. package/vitest.config.ts +0 -40
  209. package/vitest.setup.ts +0 -16
@@ -1,796 +0,0 @@
1
- import { render, screen, waitFor } from '@testing-library/preact';
2
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
- import { IncodeFlow } from './flow';
4
-
5
- // Mock the setup module
6
- const mockSetup = vi.fn().mockResolvedValue(undefined);
7
- vi.mock('../setup', () => ({
8
- setup: (...args: unknown[]) => mockSetup(...args),
9
- }));
10
-
11
- // Mock warmupWasm
12
- const mockWarmupWasm = vi.fn().mockResolvedValue(undefined);
13
-
14
- vi.mock('@incodetech/core', () => ({
15
- warmupWasm: (...args: unknown[]) => mockWarmupWasm(...args),
16
- api: {
17
- get: vi.fn().mockResolvedValue({
18
- data: {
19
- theme: 'https://example.com/theme.json',
20
- 'logo.png': 'https://example.com/logo.png',
21
- },
22
- }),
23
- },
24
- }));
25
-
26
- // Mock the flow manager
27
- const mockLoad = vi.fn();
28
- const mockCompleteModule = vi.fn();
29
- const mockStop = vi.fn();
30
-
31
- // Use a flexible type for mock state to accommodate different flow states
32
- type MockState = {
33
- status: string;
34
- error?: string;
35
- currentStep?: string;
36
- currentStepIndex?: number;
37
- steps?: string[];
38
- config?: Record<string, unknown>;
39
- flow?: Record<string, unknown>;
40
- finishStatus?: {
41
- redirectionUrl: string;
42
- action: 'approved' | 'rejected' | 'none';
43
- scoreStatus: string;
44
- };
45
- };
46
-
47
- let mockState: MockState = { status: 'idle' };
48
- let mockSubscribers: Array<(state: MockState) => void> = [];
49
-
50
- const mockFlowManager = {
51
- load: mockLoad,
52
- completeModule: mockCompleteModule,
53
- getState: () => mockState,
54
- subscribe: (cb: (state: MockState) => void) => {
55
- mockSubscribers.push(cb);
56
- return () => {
57
- mockSubscribers = mockSubscribers.filter((s) => s !== cb);
58
- };
59
- },
60
- stop: mockStop,
61
- };
62
-
63
- vi.mock('@incodetech/core/flow', () => ({
64
- createOrchestratedFlowManager: vi.fn(() => mockFlowManager),
65
- getRequiredWasmPipelines: vi.fn((flow) => {
66
- // Return pipelines based on flow modules
67
- const modules = flow?.flowModules || [];
68
- const pipelines: string[] = [];
69
- for (const mod of modules) {
70
- if (mod.key === 'SELFIE') pipelines.push('selfie');
71
- if (mod.key === 'ID') pipelines.push('idCapture');
72
- }
73
- return pipelines;
74
- }),
75
- }));
76
-
77
- // Mock UI components with lazy loading behavior
78
- let mockPhoneOnError: ((error?: string) => void) | undefined;
79
- let mockPhoneOnFinish: (() => void) | undefined;
80
- let mockEmailOnError: ((error?: string) => void) | undefined;
81
- let mockEmailOnFinish: (() => void) | undefined;
82
- let mockSelfieOnError: ((error?: string) => void) | undefined;
83
-
84
- const MockPhone = vi.fn(
85
- (props: { onError?: (error?: string) => void; onFinish?: () => void }) => {
86
- mockPhoneOnError = props.onError;
87
- mockPhoneOnFinish = props.onFinish;
88
- return <div data-testid="phone-component">Phone</div>;
89
- },
90
- );
91
- const MockEmail = vi.fn(
92
- (props: { onError?: (error?: string) => void; onFinish?: () => void }) => {
93
- mockEmailOnError = props.onError;
94
- mockEmailOnFinish = props.onFinish;
95
- return <div data-testid="email-component">Email</div>;
96
- },
97
- );
98
- const MockSelfie = vi.fn((props: { onError?: (error?: string) => void }) => {
99
- mockSelfieOnError = props.onError;
100
- return <div data-testid="selfie-component">Selfie</div>;
101
- });
102
-
103
- vi.mock('../phone/phone', () => ({
104
- Phone: MockPhone,
105
- }));
106
-
107
- vi.mock('../email/email', () => ({
108
- Email: MockEmail,
109
- }));
110
-
111
- vi.mock('../selfie/selfie', () => ({
112
- Selfie: MockSelfie,
113
- }));
114
-
115
- // Mock Spinner component - must be inline to avoid hoisting issues
116
- vi.mock('../shared/spinner', () => ({
117
- Spinner: (props: {
118
- title?: string;
119
- subtitle?: string;
120
- size?: string;
121
- fullScreen?: boolean;
122
- }) => (
123
- <div
124
- data-testid="spinner"
125
- data-title={props.title}
126
- data-subtitle={props.subtitle}
127
- data-size={props.size}
128
- >
129
- Spinner
130
- </div>
131
- ),
132
- }));
133
-
134
- // Helper to update mock state and notify subscribers
135
- function updateMockState(newState: MockState) {
136
- mockState = newState;
137
- for (const cb of mockSubscribers) {
138
- cb(mockState);
139
- }
140
- }
141
-
142
- // Default props for tests
143
- const defaultProps = {
144
- apiURL: 'https://api.test.com',
145
- token: 'test-token',
146
- onComplete: vi.fn(),
147
- };
148
-
149
- describe('IncodeFlow', () => {
150
- beforeEach(() => {
151
- vi.clearAllMocks();
152
- mockState = { status: 'idle' };
153
- mockSubscribers = [];
154
- mockPhoneOnError = undefined;
155
- mockPhoneOnFinish = undefined;
156
- mockEmailOnError = undefined;
157
- mockEmailOnFinish = undefined;
158
- mockSelfieOnError = undefined;
159
- });
160
-
161
- afterEach(() => {
162
- vi.restoreAllMocks();
163
- });
164
-
165
- describe('Initialization', () => {
166
- it('should show spinner during initialization', () => {
167
- render(<IncodeFlow {...defaultProps} />);
168
-
169
- expect(screen.getByTestId('spinner')).toBeTruthy();
170
- });
171
-
172
- it('should initialize with external token', async () => {
173
- render(<IncodeFlow {...defaultProps} token="external-token" />);
174
-
175
- await waitFor(() => {
176
- expect(mockSetup).toHaveBeenCalledWith(
177
- expect.objectContaining({
178
- apiURL: 'https://api.test.com',
179
- token: 'external-token',
180
- }),
181
- );
182
- });
183
- });
184
-
185
- it('should handle initialization error', async () => {
186
- const onError = vi.fn();
187
- mockSetup.mockRejectedValueOnce(new Error('Network error'));
188
-
189
- render(<IncodeFlow {...defaultProps} onError={onError} />);
190
-
191
- await waitFor(() => {
192
- expect(screen.getByText(/Network error/)).toBeTruthy();
193
- expect(onError).toHaveBeenCalledWith('Network error');
194
- });
195
- });
196
- });
197
-
198
- describe('Flow States', () => {
199
- it('should show spinner during flow loading', async () => {
200
- render(<IncodeFlow {...defaultProps} />);
201
-
202
- await waitFor(() => {
203
- expect(mockSetup).toHaveBeenCalled();
204
- });
205
-
206
- updateMockState({ status: 'loading' });
207
-
208
- await waitFor(() => {
209
- expect(screen.getByTestId('spinner')).toBeTruthy();
210
- });
211
- });
212
-
213
- it('should show flow error state', async () => {
214
- const onError = vi.fn();
215
- render(<IncodeFlow {...defaultProps} onError={onError} />);
216
-
217
- await waitFor(() => {
218
- expect(mockSetup).toHaveBeenCalled();
219
- });
220
-
221
- updateMockState({ status: 'error', error: 'Flow failed to load' });
222
-
223
- await waitFor(() => {
224
- expect(screen.getByText(/Flow failed to load/)).toBeTruthy();
225
- expect(onError).toHaveBeenCalledWith('Flow failed to load');
226
- });
227
- });
228
-
229
- it('should call onComplete when flow finishes', async () => {
230
- const onComplete = vi.fn();
231
- render(<IncodeFlow {...defaultProps} onComplete={onComplete} />);
232
-
233
- await waitFor(() => {
234
- expect(mockSetup).toHaveBeenCalled();
235
- });
236
-
237
- const finishStatus = {
238
- redirectionUrl: 'https://example.com/done',
239
- action: 'approved' as const,
240
- scoreStatus: 'OK' as const,
241
- };
242
-
243
- updateMockState({
244
- status: 'finished',
245
- finishStatus,
246
- flow: { flowId: 'test-flow' },
247
- });
248
-
249
- await waitFor(() => {
250
- expect(onComplete).toHaveBeenCalledWith(finishStatus);
251
- });
252
- });
253
- });
254
-
255
- describe('Module Loading', () => {
256
- it('should load and render Phone module', async () => {
257
- render(<IncodeFlow {...defaultProps} />);
258
-
259
- await waitFor(() => {
260
- expect(mockSetup).toHaveBeenCalled();
261
- });
262
-
263
- updateMockState({
264
- status: 'ready',
265
- currentStep: 'PHONE',
266
- currentStepIndex: 0,
267
- steps: ['PHONE'],
268
- config: { otpVerification: true, otpExpirationInMinutes: 5 },
269
- flow: { disableLaunchScreen: true, flowModules: [] },
270
- });
271
-
272
- await waitFor(
273
- () => {
274
- expect(screen.getByTestId('phone-component')).toBeTruthy();
275
- },
276
- { timeout: 10_000 },
277
- );
278
- });
279
-
280
- it('should load and render Email module', async () => {
281
- render(<IncodeFlow {...defaultProps} />);
282
-
283
- await waitFor(() => {
284
- expect(mockSetup).toHaveBeenCalled();
285
- });
286
-
287
- updateMockState({
288
- status: 'ready',
289
- currentStep: 'EMAIL',
290
- currentStepIndex: 0,
291
- steps: ['EMAIL'],
292
- config: {
293
- otpVerification: true,
294
- otpExpirationInMinutes: 5,
295
- prefill: false,
296
- },
297
- flow: { disableLaunchScreen: true, flowModules: [] },
298
- });
299
-
300
- await waitFor(() => {
301
- expect(screen.getByTestId('email-component')).toBeTruthy();
302
- });
303
- });
304
-
305
- it('should load and render Selfie module', async () => {
306
- render(<IncodeFlow {...defaultProps} />);
307
-
308
- await waitFor(() => {
309
- expect(mockSetup).toHaveBeenCalled();
310
- });
311
-
312
- updateMockState({
313
- status: 'ready',
314
- currentStep: 'SELFIE',
315
- currentStepIndex: 0,
316
- steps: ['SELFIE'],
317
- config: { showTutorial: true },
318
- flow: { disableLaunchScreen: true, flowModules: [] },
319
- });
320
-
321
- await waitFor(() => {
322
- expect(screen.getByTestId('selfie-component')).toBeTruthy();
323
- });
324
- });
325
-
326
- it('should show unsupported module message for unknown modules', async () => {
327
- render(<IncodeFlow {...defaultProps} />);
328
-
329
- await waitFor(() => {
330
- expect(mockSetup).toHaveBeenCalled();
331
- });
332
-
333
- updateMockState({
334
- status: 'ready',
335
- currentStep: 'UNKNOWN_MODULE',
336
- currentStepIndex: 0,
337
- steps: ['UNKNOWN_MODULE'],
338
- config: {},
339
- flow: { disableLaunchScreen: true, flowModules: [] },
340
- });
341
-
342
- await waitFor(() => {
343
- // The UnsupportedModule component is rendered - check for the i18n key or the test button
344
- expect(
345
- screen.getByTestId('unsupported-module-next-button'),
346
- ).toBeTruthy();
347
- });
348
- });
349
-
350
- it('should call onModuleLoading and onModuleLoaded callbacks', async () => {
351
- const onModuleLoading = vi.fn();
352
- const onModuleLoaded = vi.fn();
353
-
354
- render(
355
- <IncodeFlow
356
- {...defaultProps}
357
- onModuleLoading={onModuleLoading}
358
- onModuleLoaded={onModuleLoaded}
359
- />,
360
- );
361
-
362
- await waitFor(() => {
363
- expect(mockSetup).toHaveBeenCalled();
364
- });
365
-
366
- updateMockState({
367
- status: 'ready',
368
- currentStep: 'PHONE',
369
- currentStepIndex: 0,
370
- steps: ['PHONE'],
371
- config: { otpVerification: true, otpExpirationInMinutes: 5 },
372
- flow: { disableLaunchScreen: true, flowModules: [] },
373
- });
374
-
375
- await waitFor(() => {
376
- expect(onModuleLoading).toHaveBeenCalledWith('PHONE');
377
- });
378
-
379
- await waitFor(() => {
380
- expect(onModuleLoaded).toHaveBeenCalledWith('PHONE');
381
- });
382
- });
383
-
384
- it('should call flowManager.completeModule when Phone module finishes', async () => {
385
- render(<IncodeFlow {...defaultProps} />);
386
-
387
- await waitFor(() => {
388
- expect(mockSetup).toHaveBeenCalled();
389
- });
390
-
391
- updateMockState({
392
- status: 'ready',
393
- currentStep: 'PHONE',
394
- currentStepIndex: 0,
395
- steps: ['PHONE'],
396
- config: { otpVerification: true, otpExpirationInMinutes: 5 },
397
- flow: { disableLaunchScreen: true, flowModules: [] },
398
- });
399
-
400
- await waitFor(() => {
401
- expect(screen.getByTestId('phone-component')).toBeTruthy();
402
- });
403
-
404
- if (mockPhoneOnFinish) {
405
- mockPhoneOnFinish();
406
- }
407
-
408
- expect(mockCompleteModule).toHaveBeenCalled();
409
- });
410
-
411
- it('should call flowManager.completeModule when Email module finishes', async () => {
412
- render(<IncodeFlow {...defaultProps} />);
413
-
414
- await waitFor(() => {
415
- expect(mockSetup).toHaveBeenCalled();
416
- });
417
-
418
- updateMockState({
419
- status: 'ready',
420
- currentStep: 'EMAIL',
421
- currentStepIndex: 0,
422
- steps: ['EMAIL'],
423
- config: {
424
- otpVerification: true,
425
- otpExpirationInMinutes: 5,
426
- prefill: false,
427
- },
428
- flow: { disableLaunchScreen: true, flowModules: [] },
429
- });
430
-
431
- await waitFor(() => {
432
- expect(screen.getByTestId('email-component')).toBeTruthy();
433
- });
434
-
435
- if (mockEmailOnFinish) {
436
- mockEmailOnFinish();
437
- }
438
-
439
- expect(mockCompleteModule).toHaveBeenCalled();
440
- });
441
- });
442
-
443
- describe('WASM Warmup', () => {
444
- it('should warmup WASM when flow requires selfie pipeline', async () => {
445
- const onWasmWarmup = vi.fn();
446
- const wasmConfig = {
447
- wasmPath: '/wasm/ml.wasm',
448
- glueCodePath: '/wasm/ml.js',
449
- };
450
-
451
- render(
452
- <IncodeFlow
453
- {...defaultProps}
454
- wasmConfig={wasmConfig}
455
- onWasmWarmup={onWasmWarmup}
456
- />,
457
- );
458
-
459
- await waitFor(() => {
460
- expect(mockSetup).toHaveBeenCalled();
461
- });
462
-
463
- updateMockState({
464
- status: 'ready',
465
- currentStep: 'SELFIE',
466
- currentStepIndex: 0,
467
- steps: ['SELFIE'],
468
- config: {},
469
- flow: {
470
- disableLaunchScreen: true,
471
- flowModules: [{ key: 'SELFIE', configuration: {} }],
472
- },
473
- });
474
-
475
- await waitFor(() => {
476
- expect(onWasmWarmup).toHaveBeenCalledWith(['selfie']);
477
- expect(mockWarmupWasm).toHaveBeenCalledWith(
478
- expect.objectContaining({
479
- wasmPath: '/wasm/ml.wasm',
480
- glueCodePath: '/wasm/ml.js',
481
- pipelines: ['selfie'],
482
- }),
483
- );
484
- });
485
- });
486
-
487
- it('should not warmup WASM when flow does not require ML', async () => {
488
- const onWasmWarmup = vi.fn();
489
- const wasmConfig = {
490
- wasmPath: '/wasm/ml.wasm',
491
- glueCodePath: '/wasm/ml.js',
492
- };
493
-
494
- render(
495
- <IncodeFlow
496
- {...defaultProps}
497
- wasmConfig={wasmConfig}
498
- onWasmWarmup={onWasmWarmup}
499
- />,
500
- );
501
-
502
- await waitFor(() => {
503
- expect(mockSetup).toHaveBeenCalled();
504
- });
505
-
506
- updateMockState({
507
- status: 'ready',
508
- currentStep: 'PHONE',
509
- currentStepIndex: 0,
510
- steps: ['PHONE', 'EMAIL'],
511
- config: {},
512
- flow: {
513
- disableLaunchScreen: true,
514
- flowModules: [
515
- { key: 'PHONE', configuration: {} },
516
- { key: 'EMAIL', configuration: {} },
517
- ],
518
- },
519
- });
520
-
521
- // Wait a bit to ensure warmup wasn't called
522
- await new Promise((resolve) => setTimeout(resolve, 100));
523
-
524
- expect(onWasmWarmup).not.toHaveBeenCalled();
525
- expect(mockWarmupWasm).not.toHaveBeenCalled();
526
- });
527
- });
528
-
529
- describe('Email Module Validation', () => {
530
- it('should show error for invalid email configuration', async () => {
531
- render(<IncodeFlow {...defaultProps} />);
532
-
533
- await waitFor(() => {
534
- expect(mockSetup).toHaveBeenCalled();
535
- });
536
-
537
- // Provide invalid config (missing required fields)
538
- updateMockState({
539
- status: 'ready',
540
- currentStep: 'EMAIL',
541
- currentStepIndex: 0,
542
- steps: ['EMAIL'],
543
- config: { invalid: true }, // Missing otpVerification and otpExpirationInMinutes
544
- flow: { disableLaunchScreen: true, flowModules: [] },
545
- });
546
-
547
- await waitFor(() => {
548
- expect(screen.getByText(/Invalid email configuration/)).toBeTruthy();
549
- });
550
- });
551
- });
552
-
553
- describe('Flow Loading After Init', () => {
554
- it('should call flowManager.load after successful initialization', async () => {
555
- render(<IncodeFlow {...defaultProps} />);
556
-
557
- await waitFor(() => {
558
- expect(mockSetup).toHaveBeenCalled();
559
- });
560
-
561
- await waitFor(() => {
562
- expect(mockLoad).toHaveBeenCalled();
563
- });
564
- });
565
- });
566
-
567
- describe('Spinner Customization', () => {
568
- it('should use custom spinner title', () => {
569
- render(
570
- <IncodeFlow
571
- {...defaultProps}
572
- spinnerConfig={{ title: 'Custom Loading' }}
573
- />,
574
- );
575
-
576
- const spinner = screen.getByTestId('spinner');
577
- expect(spinner.getAttribute('data-title')).toBe('Custom Loading');
578
- });
579
-
580
- it('should use custom spinner subtitle', () => {
581
- render(
582
- <IncodeFlow
583
- {...defaultProps}
584
- spinnerConfig={{ subtitle: 'Please wait...' }}
585
- />,
586
- );
587
-
588
- const spinner = screen.getByTestId('spinner');
589
- expect(spinner.getAttribute('data-subtitle')).toBe('Please wait...');
590
- });
591
-
592
- it('should use custom spinner size', () => {
593
- render(
594
- <IncodeFlow {...defaultProps} spinnerConfig={{ size: 'large' }} />,
595
- );
596
-
597
- const spinner = screen.getByTestId('spinner');
598
- expect(spinner.getAttribute('data-size')).toBe('large');
599
- });
600
-
601
- it('should show spinner when loading module', async () => {
602
- render(<IncodeFlow {...defaultProps} />);
603
-
604
- await waitFor(() => {
605
- expect(mockSetup).toHaveBeenCalled();
606
- });
607
-
608
- updateMockState({
609
- status: 'ready',
610
- currentStep: 'PHONE',
611
- currentStepIndex: 0,
612
- steps: ['PHONE'],
613
- config: { otpVerification: true, otpExpirationInMinutes: 5 },
614
- flow: { disableLaunchScreen: true, flowModules: [] },
615
- });
616
-
617
- // Spinner shows during module loading with i18n defaults
618
- // The actual title/subtitle come from i18n keys (loadingCircle.hangOn, loadingCircle.validating)
619
- await waitFor(() => {
620
- expect(screen.getByTestId('spinner')).toBeTruthy();
621
- });
622
- });
623
- });
624
-
625
- describe('Module Error Handling', () => {
626
- it('should handle Selfie module errors', async () => {
627
- const onError = vi.fn();
628
- render(<IncodeFlow {...defaultProps} onError={onError} />);
629
-
630
- await waitFor(() => {
631
- expect(mockSetup).toHaveBeenCalled();
632
- });
633
-
634
- updateMockState({
635
- status: 'ready',
636
- currentStep: 'SELFIE',
637
- currentStepIndex: 0,
638
- steps: ['SELFIE'],
639
- config: { showTutorial: true },
640
- flow: { disableLaunchScreen: true, flowModules: [] },
641
- });
642
-
643
- await waitFor(() => {
644
- expect(screen.getByTestId('selfie-component')).toBeTruthy();
645
- });
646
-
647
- if (mockSelfieOnError) {
648
- mockSelfieOnError('Selfie error');
649
- expect(onError).toHaveBeenCalledWith('Selfie error');
650
- }
651
- });
652
-
653
- it('should handle Selfie module errors with undefined error', async () => {
654
- const onError = vi.fn();
655
- render(<IncodeFlow {...defaultProps} onError={onError} />);
656
-
657
- await waitFor(() => {
658
- expect(mockSetup).toHaveBeenCalled();
659
- });
660
-
661
- updateMockState({
662
- status: 'ready',
663
- currentStep: 'SELFIE',
664
- currentStepIndex: 0,
665
- steps: ['SELFIE'],
666
- config: { showTutorial: true },
667
- flow: { disableLaunchScreen: true, flowModules: [] },
668
- });
669
-
670
- await waitFor(() => {
671
- expect(screen.getByTestId('selfie-component')).toBeTruthy();
672
- });
673
-
674
- if (mockSelfieOnError) {
675
- mockSelfieOnError(undefined);
676
- expect(onError).toHaveBeenCalledWith('Selfie verification error');
677
- }
678
- });
679
-
680
- it('should handle Phone module errors', async () => {
681
- const onError = vi.fn();
682
- render(<IncodeFlow {...defaultProps} onError={onError} />);
683
-
684
- await waitFor(() => {
685
- expect(mockSetup).toHaveBeenCalled();
686
- });
687
-
688
- updateMockState({
689
- status: 'ready',
690
- currentStep: 'PHONE',
691
- currentStepIndex: 0,
692
- steps: ['PHONE'],
693
- config: { otpVerification: true, otpExpirationInMinutes: 5 },
694
- flow: { disableLaunchScreen: true, flowModules: [] },
695
- });
696
-
697
- await waitFor(() => {
698
- expect(screen.getByTestId('phone-component')).toBeTruthy();
699
- });
700
-
701
- if (mockPhoneOnError) {
702
- mockPhoneOnError('Phone error');
703
- expect(onError).toHaveBeenCalledWith('Phone error');
704
- }
705
- });
706
-
707
- it('should handle Phone module errors with undefined error', async () => {
708
- const onError = vi.fn();
709
- render(<IncodeFlow {...defaultProps} onError={onError} />);
710
-
711
- await waitFor(() => {
712
- expect(mockSetup).toHaveBeenCalled();
713
- });
714
-
715
- updateMockState({
716
- status: 'ready',
717
- currentStep: 'PHONE',
718
- currentStepIndex: 0,
719
- steps: ['PHONE'],
720
- config: { otpVerification: true, otpExpirationInMinutes: 5 },
721
- flow: { disableLaunchScreen: true, flowModules: [] },
722
- });
723
-
724
- await waitFor(() => {
725
- expect(screen.getByTestId('phone-component')).toBeTruthy();
726
- });
727
-
728
- if (mockPhoneOnError) {
729
- mockPhoneOnError(undefined);
730
- expect(onError).toHaveBeenCalledWith('Phone verification error');
731
- }
732
- });
733
-
734
- it('should handle Email module errors', async () => {
735
- const onError = vi.fn();
736
- render(<IncodeFlow {...defaultProps} onError={onError} />);
737
-
738
- await waitFor(() => {
739
- expect(mockSetup).toHaveBeenCalled();
740
- });
741
-
742
- updateMockState({
743
- status: 'ready',
744
- currentStep: 'EMAIL',
745
- currentStepIndex: 0,
746
- steps: ['EMAIL'],
747
- config: {
748
- otpVerification: true,
749
- otpExpirationInMinutes: 5,
750
- prefill: false,
751
- },
752
- flow: { disableLaunchScreen: true, flowModules: [] },
753
- });
754
-
755
- await waitFor(() => {
756
- expect(screen.getByTestId('email-component')).toBeTruthy();
757
- });
758
-
759
- if (mockEmailOnError) {
760
- mockEmailOnError('Email error');
761
- expect(onError).toHaveBeenCalledWith('Email error');
762
- }
763
- });
764
-
765
- it('should handle Email module errors with undefined error', async () => {
766
- const onError = vi.fn();
767
- render(<IncodeFlow {...defaultProps} onError={onError} />);
768
-
769
- await waitFor(() => {
770
- expect(mockSetup).toHaveBeenCalled();
771
- });
772
-
773
- updateMockState({
774
- status: 'ready',
775
- currentStep: 'EMAIL',
776
- currentStepIndex: 0,
777
- steps: ['EMAIL'],
778
- config: {
779
- otpVerification: true,
780
- otpExpirationInMinutes: 5,
781
- prefill: false,
782
- },
783
- flow: { disableLaunchScreen: true, flowModules: [] },
784
- });
785
-
786
- await waitFor(() => {
787
- expect(screen.getByTestId('email-component')).toBeTruthy();
788
- });
789
-
790
- if (mockEmailOnError) {
791
- mockEmailOnError(undefined);
792
- expect(onError).toHaveBeenCalledWith('Email verification error');
793
- }
794
- });
795
- });
796
- });