@incodetech/web 2.0.0-alpha.2 → 2.0.0-alpha.4

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 (273) hide show
  1. package/dist/{styles/core.css → base.css} +53 -57
  2. package/dist/email/email.es.js +1 -1
  3. package/dist/email/styles.css +11 -11
  4. package/dist/flow/styles.css +688 -1
  5. package/dist/{incodeModule-BF5MX9GT.js → incodeModule-Ct9jp5k6.js} +22 -19
  6. package/dist/index.es.js +18 -18
  7. package/dist/phone/phone.es.js +1 -1
  8. package/dist/phone/styles.css +31 -31
  9. package/dist/selfie/selfie.es.js +16 -16
  10. package/dist/selfie/styles.css +0 -51
  11. package/dist/themes/dark.css +652 -0
  12. package/dist/types/dark.d.ts +1 -0
  13. package/dist/types/light.d.ts +1 -0
  14. package/dist/types/themes/light.d.ts +1 -0
  15. package/package.json +12 -6
  16. package/.turbo/turbo-build.log +0 -58
  17. package/.turbo/turbo-coverage.log +0 -23
  18. package/.turbo/turbo-format.log +0 -6
  19. package/.turbo/turbo-lint$colon$fix.log +0 -6
  20. package/.turbo/turbo-lint.log +0 -6
  21. package/.turbo/turbo-test.log +0 -1033
  22. package/.turbo/turbo-typecheck.log +0 -5
  23. package/coverage/base.css +0 -224
  24. package/coverage/block-navigation.js +0 -87
  25. package/coverage/email/email.tsx.html +0 -850
  26. package/coverage/email/emailInput.tsx.html +0 -340
  27. package/coverage/email/index.html +0 -131
  28. package/coverage/favicon.png +0 -0
  29. package/coverage/flow/flow.tsx.html +0 -961
  30. package/coverage/flow/flowCompleted.tsx.html +0 -448
  31. package/coverage/flow/flowInit.ts.html +0 -367
  32. package/coverage/flow/flowStart.tsx.html +0 -208
  33. package/coverage/flow/index.html +0 -221
  34. package/coverage/flow/preloadFlow.ts.html +0 -598
  35. package/coverage/flow/unsupportedModule.tsx.html +0 -202
  36. package/coverage/flow/useFlowInitialization.ts.html +0 -469
  37. package/coverage/flow/useModuleLoader.ts.html +0 -361
  38. package/coverage/hooks/index.html +0 -116
  39. package/coverage/hooks/useManager.ts.html +0 -205
  40. package/coverage/index.html +0 -401
  41. package/coverage/permissions/boldWithArrow.tsx.html +0 -208
  42. package/coverage/permissions/denied.tsx.html +0 -172
  43. package/coverage/permissions/deniedAndroid.tsx.html +0 -253
  44. package/coverage/permissions/deniedDesktop.tsx.html +0 -277
  45. package/coverage/permissions/deniedIOS.tsx.html +0 -304
  46. package/coverage/permissions/deniedInstructions.tsx.html +0 -142
  47. package/coverage/permissions/iconWrapper.tsx.html +0 -130
  48. package/coverage/permissions/index.html +0 -251
  49. package/coverage/permissions/learnMore.tsx.html +0 -340
  50. package/coverage/permissions/numberedStep.tsx.html +0 -127
  51. package/coverage/permissions/permissions.tsx.html +0 -289
  52. package/coverage/phone/index.html +0 -116
  53. package/coverage/phone/phoneInput.tsx.html +0 -832
  54. package/coverage/prettify.css +0 -1
  55. package/coverage/prettify.js +0 -2
  56. package/coverage/selfie/index.html +0 -131
  57. package/coverage/selfie/selfie.tsx.html +0 -334
  58. package/coverage/selfie/tutorial.tsx.html +0 -214
  59. package/coverage/shared/baseTutorial/baseTutorial.tsx.html +0 -250
  60. package/coverage/shared/baseTutorial/index.html +0 -131
  61. package/coverage/shared/baseTutorial/replaceBaseTutorial.ts.html +0 -289
  62. package/coverage/shared/button/button.tsx.html +0 -226
  63. package/coverage/shared/button/index.html +0 -116
  64. package/coverage/shared/componentRoot/incodeComponent.tsx.html +0 -121
  65. package/coverage/shared/componentRoot/index.html +0 -116
  66. package/coverage/shared/countries/countries.ts.html +0 -502
  67. package/coverage/shared/countries/index.html +0 -116
  68. package/coverage/shared/icons/chevronDown.tsx.html +0 -151
  69. package/coverage/shared/icons/index.html +0 -131
  70. package/coverage/shared/icons/successIcon.tsx.html +0 -163
  71. package/coverage/shared/loader/index.html +0 -116
  72. package/coverage/shared/loader/loadingIcon.tsx.html +0 -286
  73. package/coverage/shared/otpInput/index.html +0 -116
  74. package/coverage/shared/otpInput/otpInput.tsx.html +0 -808
  75. package/coverage/shared/page/index.html +0 -146
  76. package/coverage/shared/page/page.tsx.html +0 -358
  77. package/coverage/shared/page/pageUiConfig.ts.html +0 -277
  78. package/coverage/shared/page/verifiedByIncode.tsx.html +0 -310
  79. package/coverage/shared/spacer/index.html +0 -116
  80. package/coverage/shared/spacer/spacer.tsx.html +0 -349
  81. package/coverage/shared/spinner/index.html +0 -116
  82. package/coverage/shared/spinner/spinner.tsx.html +0 -280
  83. package/coverage/shared/title/index.html +0 -116
  84. package/coverage/shared/title/title.tsx.html +0 -121
  85. package/coverage/shared/uiConfig/index.html +0 -116
  86. package/coverage/shared/uiConfig/uiConfig.ts.html +0 -193
  87. package/coverage/shared/webComponent/incodeModule.ts.html +0 -172
  88. package/coverage/shared/webComponent/index.html +0 -131
  89. package/coverage/shared/webComponent/registerIncodeElement.ts.html +0 -130
  90. package/coverage/sort-arrow-sprite.png +0 -0
  91. package/coverage/sorter.js +0 -210
  92. package/coverage/styles/cn.tsx.html +0 -148
  93. package/coverage/styles/fetchTheme.ts.html +0 -349
  94. package/coverage/styles/index.html +0 -131
  95. package/dev/README.md +0 -163
  96. package/dev/getToken.ts +0 -36
  97. package/dev/headless.html +0 -875
  98. package/dev/index.html +0 -366
  99. package/dev/main-headless.tsx +0 -1332
  100. package/dev/main-orchestrated-flow.tsx +0 -1158
  101. package/dev/main-preact.tsx +0 -323
  102. package/dev/main-simplified.tsx +0 -123
  103. package/dev/main-web-component.tsx +0 -256
  104. package/dev/main.tsx +0 -332
  105. package/dev/manual.html +0 -27
  106. package/dev/orchestrated-flow.html +0 -64
  107. package/dev/simplified.html +0 -64
  108. package/dev/tiktok-logo.svg +0 -7
  109. package/dist/asset-manifest.json +0 -18
  110. package/src/defineCustomElement.tsx +0 -30
  111. package/src/email/email.test.tsx +0 -368
  112. package/src/email/email.tsx +0 -255
  113. package/src/email/emailInput.test.tsx +0 -264
  114. package/src/email/emailInput.tsx +0 -85
  115. package/src/email/styles.css +0 -59
  116. package/src/flow/flow.test.tsx +0 -796
  117. package/src/flow/flow.tsx +0 -292
  118. package/src/flow/flowCompleted.css +0 -30
  119. package/src/flow/flowCompleted.test.tsx +0 -331
  120. package/src/flow/flowCompleted.tsx +0 -121
  121. package/src/flow/flowInit.test.ts +0 -264
  122. package/src/flow/flowInit.ts +0 -94
  123. package/src/flow/flowStart.css +0 -58
  124. package/src/flow/flowStart.test.tsx +0 -49
  125. package/src/flow/flowStart.tsx +0 -41
  126. package/src/flow/incode-logo.svg +0 -8
  127. package/src/flow/index.ts +0 -7
  128. package/src/flow/preloadFlow.test.ts +0 -421
  129. package/src/flow/preloadFlow.ts +0 -171
  130. package/src/flow/styles.css +0 -9
  131. package/src/flow/unsupportedModule.css +0 -21
  132. package/src/flow/unsupportedModule.tsx +0 -39
  133. package/src/flow/useFlowInitialization.test.tsx +0 -292
  134. package/src/flow/useFlowInitialization.ts +0 -128
  135. package/src/flow/useModuleLoader.test.tsx +0 -212
  136. package/src/flow/useModuleLoader.ts +0 -92
  137. package/src/hooks/index.ts +0 -1
  138. package/src/hooks/useManager.test.ts +0 -91
  139. package/src/hooks/useManager.ts +0 -40
  140. package/src/i18n/index.ts +0 -3
  141. package/src/i18n/instance.ts +0 -16
  142. package/src/i18n/setup.ts +0 -184
  143. package/src/i18n/useTranslation.ts +0 -42
  144. package/src/index.ts +0 -27
  145. package/src/permissions/assets/android-dots-icon.svg +0 -7
  146. package/src/permissions/assets/android-settings-icon.svg +0 -16
  147. package/src/permissions/assets/android-toggle-icon.svg +0 -20
  148. package/src/permissions/assets/bank-card-icon.svg +0 -14
  149. package/src/permissions/assets/camera-icon.svg +0 -12
  150. package/src/permissions/assets/camera-ios.svg +0 -53
  151. package/src/permissions/assets/check-icon.svg +0 -8
  152. package/src/permissions/assets/chrome-icon.svg +0 -43
  153. package/src/permissions/assets/password-icon.svg +0 -11
  154. package/src/permissions/assets/permissions-img.svg +0 -51
  155. package/src/permissions/assets/safari-icon.svg +0 -37
  156. package/src/permissions/assets/settings-icon.svg +0 -33
  157. package/src/permissions/assets/toggle-icon.svg +0 -19
  158. package/src/permissions/assets/warning-icon.svg +0 -6
  159. package/src/permissions/boldWithArrow.css +0 -9
  160. package/src/permissions/boldWithArrow.tsx +0 -41
  161. package/src/permissions/denied.css +0 -37
  162. package/src/permissions/denied.tsx +0 -29
  163. package/src/permissions/deniedAndroid.tsx +0 -56
  164. package/src/permissions/deniedDesktop.css +0 -9
  165. package/src/permissions/deniedDesktop.tsx +0 -64
  166. package/src/permissions/deniedIOS.tsx +0 -73
  167. package/src/permissions/deniedInstructions.tsx +0 -19
  168. package/src/permissions/iconWrapper.css +0 -9
  169. package/src/permissions/iconWrapper.tsx +0 -15
  170. package/src/permissions/learnMore.css +0 -37
  171. package/src/permissions/learnMore.tsx +0 -85
  172. package/src/permissions/numberedStep.css +0 -13
  173. package/src/permissions/numberedStep.tsx +0 -14
  174. package/src/permissions/permissions.css +0 -13
  175. package/src/permissions/permissions.tsx +0 -68
  176. package/src/phone/phone.tsx +0 -246
  177. package/src/phone/phoneInput.test.tsx +0 -275
  178. package/src/phone/phoneInput.tsx +0 -249
  179. package/src/phone/styles.css +0 -158
  180. package/src/selfie/cameraButton.css +0 -13
  181. package/src/selfie/cameraButton.tsx +0 -35
  182. package/src/selfie/capture.css +0 -57
  183. package/src/selfie/capture.tsx +0 -232
  184. package/src/selfie/errorModal.tsx +0 -218
  185. package/src/selfie/errorModalContent.css +0 -33
  186. package/src/selfie/errorModalContent.tsx +0 -44
  187. package/src/selfie/faceOutline.css +0 -5
  188. package/src/selfie/faceOutline.tsx +0 -22
  189. package/src/selfie/loadingBorder.css +0 -12
  190. package/src/selfie/loadingBorder.tsx +0 -77
  191. package/src/selfie/manualCaptureButton.css +0 -13
  192. package/src/selfie/manualCaptureButton.tsx +0 -35
  193. package/src/selfie/noMoreAttemptsModal.tsx +0 -44
  194. package/src/selfie/notification.css +0 -9
  195. package/src/selfie/notification.tsx +0 -36
  196. package/src/selfie/retryErrorModal.tsx +0 -56
  197. package/src/selfie/selfie.test.tsx +0 -458
  198. package/src/selfie/selfie.tsx +0 -83
  199. package/src/selfie/selfieTutorial.json +0 -2626
  200. package/src/selfie/styles.css +0 -1
  201. package/src/selfie/tutorial.test.tsx +0 -200
  202. package/src/selfie/tutorial.tsx +0 -43
  203. package/src/setup.ts +0 -33
  204. package/src/shared/baseTutorial/baseTutorial.css +0 -21
  205. package/src/shared/baseTutorial/baseTutorial.test.tsx +0 -184
  206. package/src/shared/baseTutorial/baseTutorial.tsx +0 -55
  207. package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +0 -267
  208. package/src/shared/baseTutorial/replaceBaseTutorial.ts +0 -68
  209. package/src/shared/button/button.css +0 -55
  210. package/src/shared/button/button.test.tsx +0 -101
  211. package/src/shared/button/button.tsx +0 -47
  212. package/src/shared/componentRoot/incodeComponent.tsx +0 -12
  213. package/src/shared/countries/countries.test.ts +0 -75
  214. package/src/shared/countries/countries.ts +0 -139
  215. package/src/shared/countries/index.ts +0 -6
  216. package/src/shared/icons/chevronDown.tsx +0 -22
  217. package/src/shared/icons/index.ts +0 -2
  218. package/src/shared/icons/successIcon.css +0 -5
  219. package/src/shared/icons/successIcon.test.tsx +0 -40
  220. package/src/shared/icons/successIcon.tsx +0 -26
  221. package/src/shared/loader/loadingIcon.css +0 -28
  222. package/src/shared/loader/loadingIcon.tsx +0 -67
  223. package/src/shared/lottie/lottie.tsx +0 -108
  224. package/src/shared/otpInput/otpInput.css +0 -85
  225. package/src/shared/otpInput/otpInput.test.tsx +0 -356
  226. package/src/shared/otpInput/otpInput.tsx +0 -241
  227. package/src/shared/page/incode-logo.svg +0 -3
  228. package/src/shared/page/page.css +0 -47
  229. package/src/shared/page/page.test.tsx +0 -97
  230. package/src/shared/page/page.tsx +0 -91
  231. package/src/shared/page/pageUiConfig.test.ts +0 -112
  232. package/src/shared/page/pageUiConfig.ts +0 -64
  233. package/src/shared/page/verifiedByIncode.css +0 -5
  234. package/src/shared/page/verifiedByIncode.tsx +0 -75
  235. package/src/shared/spacer/spacer.css +0 -149
  236. package/src/shared/spacer/spacer.test.tsx +0 -143
  237. package/src/shared/spacer/spacer.tsx +0 -88
  238. package/src/shared/spinner/index.ts +0 -2
  239. package/src/shared/spinner/spinner.css +0 -28
  240. package/src/shared/spinner/spinner.test.tsx +0 -82
  241. package/src/shared/spinner/spinner.tsx +0 -65
  242. package/src/shared/title/title.css +0 -7
  243. package/src/shared/title/title.tsx +0 -12
  244. package/src/shared/uiConfig/uiConfig.ts +0 -36
  245. package/src/shared/webComponent/incodeModule.ts +0 -29
  246. package/src/shared/webComponent/registerIncodeElement.ts +0 -15
  247. package/src/styles/__mocks__/fetchTheme.ts +0 -19
  248. package/src/styles/applyTheme.ts +0 -37
  249. package/src/styles/cn.test.tsx +0 -57
  250. package/src/styles/cn.tsx +0 -21
  251. package/src/styles/core.css +0 -12
  252. package/src/styles/fetchTheme.test.ts +0 -390
  253. package/src/styles/fetchTheme.ts +0 -88
  254. package/src/styles/generatePalette.ts +0 -111
  255. package/src/styles/reset.css +0 -65
  256. package/src/styles/resolveCssVariableToHex.ts +0 -28
  257. package/src/styles/tailwind.css +0 -291
  258. package/src/styles/themeTypes.ts +0 -18
  259. package/src/styles/tokens/colors.css +0 -190
  260. package/src/styles/tokens/components.css +0 -174
  261. package/src/styles/tokens/index.css +0 -4
  262. package/src/styles/tokens/primitives.css +0 -129
  263. package/src/styles/tokens/semantic.css +0 -51
  264. package/src/svg.d.ts +0 -4
  265. package/src/types/assets.d.ts +0 -1
  266. package/src/types/custom-elements.d.ts +0 -104
  267. package/tsconfig.json +0 -22
  268. package/vite.config.ts +0 -260
  269. package/vitest.config.ts +0 -40
  270. package/vitest.setup.ts +0 -16
  271. /package/dist/{styles/tokens.css → themes/light.css} +0 -0
  272. /package/dist/types/{core.d.ts → base.d.ts} +0 -0
  273. /package/dist/types/{styles/core.d.ts → themes/dark.d.ts} +0 -0
@@ -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
- });