@incodetech/web 2.0.0-alpha.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 (176) hide show
  1. package/dev/README.md +163 -0
  2. package/dev/getToken.ts +36 -0
  3. package/dev/headless.html +875 -0
  4. package/dev/index.html +366 -0
  5. package/dev/main-headless.tsx +1332 -0
  6. package/dev/main-orchestrated-flow.tsx +1158 -0
  7. package/dev/main-preact.tsx +323 -0
  8. package/dev/main-simplified.tsx +123 -0
  9. package/dev/main-web-component.tsx +256 -0
  10. package/dev/main.tsx +332 -0
  11. package/dev/manual.html +27 -0
  12. package/dev/orchestrated-flow.html +64 -0
  13. package/dev/simplified.html +64 -0
  14. package/dev/tiktok-logo.svg +7 -0
  15. package/package.json +85 -0
  16. package/src/defineCustomElement.tsx +30 -0
  17. package/src/email/email.test.tsx +368 -0
  18. package/src/email/email.tsx +255 -0
  19. package/src/email/emailInput.test.tsx +264 -0
  20. package/src/email/emailInput.tsx +85 -0
  21. package/src/email/styles.css +59 -0
  22. package/src/flow/flow.test.tsx +796 -0
  23. package/src/flow/flow.tsx +292 -0
  24. package/src/flow/flowCompleted.css +30 -0
  25. package/src/flow/flowCompleted.test.tsx +331 -0
  26. package/src/flow/flowCompleted.tsx +121 -0
  27. package/src/flow/flowInit.test.ts +264 -0
  28. package/src/flow/flowInit.ts +94 -0
  29. package/src/flow/flowStart.css +58 -0
  30. package/src/flow/flowStart.test.tsx +49 -0
  31. package/src/flow/flowStart.tsx +41 -0
  32. package/src/flow/incode-logo.svg +8 -0
  33. package/src/flow/index.ts +7 -0
  34. package/src/flow/preloadFlow.test.ts +421 -0
  35. package/src/flow/preloadFlow.ts +171 -0
  36. package/src/flow/styles.css +9 -0
  37. package/src/flow/unsupportedModule.css +21 -0
  38. package/src/flow/unsupportedModule.tsx +39 -0
  39. package/src/flow/useFlowInitialization.test.tsx +292 -0
  40. package/src/flow/useFlowInitialization.ts +128 -0
  41. package/src/flow/useModuleLoader.test.tsx +212 -0
  42. package/src/flow/useModuleLoader.ts +92 -0
  43. package/src/hooks/index.ts +1 -0
  44. package/src/hooks/useManager.test.ts +91 -0
  45. package/src/hooks/useManager.ts +40 -0
  46. package/src/i18n/index.ts +3 -0
  47. package/src/i18n/instance.ts +16 -0
  48. package/src/i18n/setup.ts +184 -0
  49. package/src/i18n/useTranslation.ts +42 -0
  50. package/src/index.ts +27 -0
  51. package/src/permissions/assets/android-dots-icon.svg +7 -0
  52. package/src/permissions/assets/android-settings-icon.svg +16 -0
  53. package/src/permissions/assets/android-toggle-icon.svg +20 -0
  54. package/src/permissions/assets/bank-card-icon.svg +14 -0
  55. package/src/permissions/assets/camera-icon.svg +12 -0
  56. package/src/permissions/assets/camera-ios.svg +53 -0
  57. package/src/permissions/assets/check-icon.svg +8 -0
  58. package/src/permissions/assets/chrome-icon.svg +43 -0
  59. package/src/permissions/assets/password-icon.svg +11 -0
  60. package/src/permissions/assets/permissions-img.svg +51 -0
  61. package/src/permissions/assets/safari-icon.svg +37 -0
  62. package/src/permissions/assets/settings-icon.svg +33 -0
  63. package/src/permissions/assets/toggle-icon.svg +19 -0
  64. package/src/permissions/assets/warning-icon.svg +6 -0
  65. package/src/permissions/boldWithArrow.css +9 -0
  66. package/src/permissions/boldWithArrow.tsx +41 -0
  67. package/src/permissions/denied.css +37 -0
  68. package/src/permissions/denied.tsx +29 -0
  69. package/src/permissions/deniedAndroid.tsx +56 -0
  70. package/src/permissions/deniedDesktop.css +9 -0
  71. package/src/permissions/deniedDesktop.tsx +64 -0
  72. package/src/permissions/deniedIOS.tsx +73 -0
  73. package/src/permissions/deniedInstructions.tsx +19 -0
  74. package/src/permissions/iconWrapper.css +9 -0
  75. package/src/permissions/iconWrapper.tsx +15 -0
  76. package/src/permissions/learnMore.css +37 -0
  77. package/src/permissions/learnMore.tsx +85 -0
  78. package/src/permissions/numberedStep.css +13 -0
  79. package/src/permissions/numberedStep.tsx +14 -0
  80. package/src/permissions/permissions.css +13 -0
  81. package/src/permissions/permissions.tsx +68 -0
  82. package/src/phone/phone.tsx +246 -0
  83. package/src/phone/phoneInput.test.tsx +275 -0
  84. package/src/phone/phoneInput.tsx +249 -0
  85. package/src/phone/styles.css +158 -0
  86. package/src/selfie/cameraButton.css +13 -0
  87. package/src/selfie/cameraButton.tsx +35 -0
  88. package/src/selfie/capture.css +57 -0
  89. package/src/selfie/capture.tsx +232 -0
  90. package/src/selfie/errorModal.tsx +218 -0
  91. package/src/selfie/errorModalContent.css +33 -0
  92. package/src/selfie/errorModalContent.tsx +44 -0
  93. package/src/selfie/faceOutline.css +5 -0
  94. package/src/selfie/faceOutline.tsx +22 -0
  95. package/src/selfie/loadingBorder.css +12 -0
  96. package/src/selfie/loadingBorder.tsx +77 -0
  97. package/src/selfie/manualCaptureButton.css +13 -0
  98. package/src/selfie/manualCaptureButton.tsx +35 -0
  99. package/src/selfie/noMoreAttemptsModal.tsx +44 -0
  100. package/src/selfie/notification.css +9 -0
  101. package/src/selfie/notification.tsx +36 -0
  102. package/src/selfie/retryErrorModal.tsx +56 -0
  103. package/src/selfie/selfie.test.tsx +458 -0
  104. package/src/selfie/selfie.tsx +83 -0
  105. package/src/selfie/selfieTutorial.json +2626 -0
  106. package/src/selfie/styles.css +1 -0
  107. package/src/selfie/tutorial.test.tsx +200 -0
  108. package/src/selfie/tutorial.tsx +43 -0
  109. package/src/setup.ts +33 -0
  110. package/src/shared/baseTutorial/baseTutorial.css +21 -0
  111. package/src/shared/baseTutorial/baseTutorial.test.tsx +184 -0
  112. package/src/shared/baseTutorial/baseTutorial.tsx +55 -0
  113. package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +267 -0
  114. package/src/shared/baseTutorial/replaceBaseTutorial.ts +68 -0
  115. package/src/shared/button/button.css +55 -0
  116. package/src/shared/button/button.test.tsx +101 -0
  117. package/src/shared/button/button.tsx +47 -0
  118. package/src/shared/componentRoot/incodeComponent.tsx +12 -0
  119. package/src/shared/countries/countries.test.ts +75 -0
  120. package/src/shared/countries/countries.ts +139 -0
  121. package/src/shared/countries/index.ts +6 -0
  122. package/src/shared/icons/chevronDown.tsx +22 -0
  123. package/src/shared/icons/index.ts +2 -0
  124. package/src/shared/icons/successIcon.css +5 -0
  125. package/src/shared/icons/successIcon.test.tsx +40 -0
  126. package/src/shared/icons/successIcon.tsx +26 -0
  127. package/src/shared/loader/loadingIcon.css +28 -0
  128. package/src/shared/loader/loadingIcon.tsx +67 -0
  129. package/src/shared/lottie/lottie.tsx +108 -0
  130. package/src/shared/otpInput/otpInput.css +85 -0
  131. package/src/shared/otpInput/otpInput.test.tsx +356 -0
  132. package/src/shared/otpInput/otpInput.tsx +241 -0
  133. package/src/shared/page/incode-logo.svg +3 -0
  134. package/src/shared/page/page.css +47 -0
  135. package/src/shared/page/page.test.tsx +97 -0
  136. package/src/shared/page/page.tsx +91 -0
  137. package/src/shared/page/pageUiConfig.test.ts +112 -0
  138. package/src/shared/page/pageUiConfig.ts +64 -0
  139. package/src/shared/page/verifiedByIncode.css +5 -0
  140. package/src/shared/page/verifiedByIncode.tsx +75 -0
  141. package/src/shared/spacer/spacer.css +149 -0
  142. package/src/shared/spacer/spacer.test.tsx +143 -0
  143. package/src/shared/spacer/spacer.tsx +88 -0
  144. package/src/shared/spinner/index.ts +2 -0
  145. package/src/shared/spinner/spinner.css +28 -0
  146. package/src/shared/spinner/spinner.test.tsx +82 -0
  147. package/src/shared/spinner/spinner.tsx +65 -0
  148. package/src/shared/title/title.css +7 -0
  149. package/src/shared/title/title.tsx +12 -0
  150. package/src/shared/uiConfig/uiConfig.ts +36 -0
  151. package/src/shared/webComponent/incodeModule.ts +29 -0
  152. package/src/shared/webComponent/registerIncodeElement.ts +15 -0
  153. package/src/styles/__mocks__/fetchTheme.ts +19 -0
  154. package/src/styles/applyTheme.ts +37 -0
  155. package/src/styles/cn.test.tsx +57 -0
  156. package/src/styles/cn.tsx +21 -0
  157. package/src/styles/core.css +12 -0
  158. package/src/styles/fetchTheme.test.ts +390 -0
  159. package/src/styles/fetchTheme.ts +88 -0
  160. package/src/styles/generatePalette.ts +111 -0
  161. package/src/styles/reset.css +65 -0
  162. package/src/styles/resolveCssVariableToHex.ts +28 -0
  163. package/src/styles/tailwind.css +291 -0
  164. package/src/styles/themeTypes.ts +18 -0
  165. package/src/styles/tokens/colors.css +190 -0
  166. package/src/styles/tokens/components.css +174 -0
  167. package/src/styles/tokens/index.css +4 -0
  168. package/src/styles/tokens/primitives.css +129 -0
  169. package/src/styles/tokens/semantic.css +51 -0
  170. package/src/svg.d.ts +4 -0
  171. package/src/types/assets.d.ts +1 -0
  172. package/src/types/custom-elements.d.ts +104 -0
  173. package/tsconfig.json +22 -0
  174. package/vite.config.ts +260 -0
  175. package/vitest.config.ts +40 -0
  176. package/vitest.setup.ts +16 -0
@@ -0,0 +1,796 @@
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
+ });