@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,292 @@
1
+ import type { WasmConfig } from '@incodetech/core';
2
+ import type {
3
+ FinishStatus,
4
+ FlowModuleConfig,
5
+ OrchestratedFlowReadyState,
6
+ } from '@incodetech/core/flow';
7
+ import { getRequiredWasmPipelines } from '@incodetech/core/flow';
8
+ import type { FC } from 'preact/compat';
9
+ import { useEffect } from 'preact/hooks';
10
+ import register from 'preact-custom-element';
11
+ import { useManager } from '@/hooks';
12
+ import { useTranslation } from '@/i18n';
13
+ import { Spinner, type SpinnerSize } from '../shared/spinner';
14
+ import { warmupWasmIfNeeded } from './flowInit';
15
+ import { UnsupportedModule } from './unsupportedModule';
16
+ import { useFlowInitialization } from './useFlowInitialization';
17
+ import { useModuleLoader, usePrefetchNextModule } from './useModuleLoader';
18
+ import './styles.css';
19
+ import './flowStart.css';
20
+ import './flowCompleted.css';
21
+
22
+ export type SpinnerConfig = {
23
+ title?: string;
24
+ subtitle?: string;
25
+ size?: SpinnerSize;
26
+ };
27
+
28
+ export type IncodeFlowProps = {
29
+ apiURL: string;
30
+ token: string;
31
+ wasmConfig?: WasmConfig;
32
+ lang?: string;
33
+ disableDashboardTheme?: boolean;
34
+ onComplete: (result: FinishStatus) => void;
35
+ onError?: (error: string) => void;
36
+ onModuleLoading?: (moduleKey: string) => void;
37
+ onModuleLoaded?: (moduleKey: string) => void;
38
+ onWasmWarmup?: (pipelines: string[]) => void;
39
+ spinnerConfig?: SpinnerConfig;
40
+ };
41
+
42
+ const IncodeFlowContent: FC<IncodeFlowProps> = ({
43
+ apiURL,
44
+ token,
45
+ wasmConfig,
46
+ lang,
47
+ disableDashboardTheme,
48
+ onComplete,
49
+ onError,
50
+ onModuleLoading,
51
+ onModuleLoaded,
52
+ onWasmWarmup,
53
+ spinnerConfig,
54
+ }) => {
55
+ const { t } = useTranslation();
56
+
57
+ const initState = useFlowInitialization({
58
+ apiURL,
59
+ token,
60
+ lang,
61
+ disableDashboardTheme,
62
+ onError,
63
+ });
64
+
65
+ const [flowState, flowManager] = useManager(() => initState.flowManager, {
66
+ autoLoad: false,
67
+ });
68
+
69
+ const moduleLoaderState = useModuleLoader({
70
+ moduleKey:
71
+ flowState?.status === 'ready' ? flowState.currentStep : undefined,
72
+ onModuleLoading,
73
+ onModuleLoaded,
74
+ onError,
75
+ });
76
+
77
+ usePrefetchNextModule(
78
+ flowState?.status === 'ready' ? flowState.steps : [],
79
+ flowState?.status === 'ready' ? flowState.currentStepIndex : -1,
80
+ );
81
+
82
+ useEffect(() => {
83
+ if (flowState?.status === 'ready' && wasmConfig) {
84
+ const readyState = flowState as OrchestratedFlowReadyState;
85
+ const requiredPipelines = getRequiredWasmPipelines(readyState.flow);
86
+ if (requiredPipelines.length > 0) {
87
+ onWasmWarmup?.(requiredPipelines);
88
+ warmupWasmIfNeeded(readyState, wasmConfig);
89
+ }
90
+ }
91
+ }, [flowState?.status, wasmConfig, flowState, onWasmWarmup]);
92
+
93
+ useEffect(() => {
94
+ if (flowState?.status === 'finished') {
95
+ onComplete(flowState.finishStatus);
96
+ }
97
+ }, [flowState?.status, onComplete, flowState]);
98
+
99
+ useEffect(() => {
100
+ if (flowState?.status === 'error' && onError) {
101
+ onError(flowState.error);
102
+ }
103
+ }, [flowState?.status, onError, flowState]);
104
+
105
+ if (initState.status === 'error') {
106
+ return (
107
+ <div class="IncodeFlow">
108
+ <div>Error: {initState.error}</div>
109
+ </div>
110
+ );
111
+ }
112
+
113
+ if (initState.status === 'initializing') {
114
+ return (
115
+ <div class="IncodeFlow">
116
+ <Spinner
117
+ title={spinnerConfig?.title ?? t('home.settingUp')}
118
+ subtitle={spinnerConfig?.subtitle}
119
+ size={spinnerConfig?.size}
120
+ fullScreen
121
+ />
122
+ </div>
123
+ );
124
+ }
125
+
126
+ if (
127
+ !flowState ||
128
+ flowState.status === 'idle' ||
129
+ flowState.status === 'loading'
130
+ ) {
131
+ return (
132
+ <div class="IncodeFlow">
133
+ <Spinner
134
+ title={spinnerConfig?.title ?? t('home.settingUp')}
135
+ subtitle={spinnerConfig?.subtitle}
136
+ size={spinnerConfig?.size}
137
+ fullScreen
138
+ />
139
+ </div>
140
+ );
141
+ }
142
+
143
+ if (flowState.status === 'error') {
144
+ return (
145
+ <div class="IncodeFlow">
146
+ <div>Error: {flowState.error}</div>
147
+ </div>
148
+ );
149
+ }
150
+
151
+ if (flowState.status === 'finished') {
152
+ return null;
153
+ }
154
+
155
+ if (flowState.status === 'ready') {
156
+ const { currentStep, config } = flowState;
157
+
158
+ if (!currentStep || !config) {
159
+ return (
160
+ <div class="IncodeFlow">
161
+ <Spinner
162
+ title={spinnerConfig?.title ?? t('loadingCircle.hangOn')}
163
+ subtitle={spinnerConfig?.subtitle ?? t('loadingCircle.validating')}
164
+ size={spinnerConfig?.size}
165
+ fullScreen
166
+ />
167
+ </div>
168
+ );
169
+ }
170
+
171
+ if (moduleLoaderState.status === 'unsupported') {
172
+ return (
173
+ <div class="IncodeFlow">
174
+ <UnsupportedModule
175
+ moduleKey={currentStep}
176
+ onNext={() => flowManager.completeModule()}
177
+ />
178
+ </div>
179
+ );
180
+ }
181
+
182
+ if (
183
+ moduleLoaderState.status === 'idle' ||
184
+ moduleLoaderState.status === 'loading' ||
185
+ moduleLoaderState.status === 'error'
186
+ ) {
187
+ return (
188
+ <div class="IncodeFlow">
189
+ <Spinner
190
+ title={spinnerConfig?.title ?? t('loadingCircle.hangOn')}
191
+ subtitle={spinnerConfig?.subtitle ?? t('loadingCircle.validating')}
192
+ size={spinnerConfig?.size}
193
+ fullScreen
194
+ />
195
+ </div>
196
+ );
197
+ }
198
+
199
+ const { Component } = moduleLoaderState;
200
+
201
+ if (currentStep === 'SELFIE') {
202
+ const selfieConfig = config as FlowModuleConfig['SELFIE'];
203
+ return (
204
+ <div class="IncodeFlow">
205
+ <Component
206
+ key={`selfie-${flowState.currentStepIndex}`}
207
+ config={selfieConfig}
208
+ onFinish={() => flowManager.completeModule()}
209
+ onError={(error: string | undefined) => {
210
+ onError?.(error ?? 'Selfie verification error');
211
+ }}
212
+ />
213
+ </div>
214
+ );
215
+ }
216
+
217
+ if (currentStep === 'PHONE') {
218
+ const phoneConfig = config as FlowModuleConfig['PHONE'];
219
+ return (
220
+ <div class="IncodeFlow">
221
+ <Component
222
+ key={`phone-${flowState.currentStepIndex}`}
223
+ config={phoneConfig}
224
+ onFinish={() => flowManager.completeModule()}
225
+ onError={(error: string | undefined) => {
226
+ onError?.(error ?? 'Phone verification error');
227
+ }}
228
+ />
229
+ </div>
230
+ );
231
+ }
232
+
233
+ if (currentStep === 'EMAIL') {
234
+ const emailConfig = config as FlowModuleConfig['EMAIL'];
235
+ if (
236
+ !emailConfig ||
237
+ typeof emailConfig.otpVerification !== 'boolean' ||
238
+ typeof emailConfig.otpExpirationInMinutes !== 'number'
239
+ ) {
240
+ return (
241
+ <div class="IncodeFlow">
242
+ <div>Error: Invalid email configuration</div>
243
+ </div>
244
+ );
245
+ }
246
+ return (
247
+ <div class="IncodeFlow">
248
+ <Component
249
+ key={`email-${flowState.currentStepIndex}`}
250
+ config={{
251
+ ...emailConfig,
252
+ prefill: emailConfig.prefill ?? false,
253
+ }}
254
+ onFinish={() => flowManager.completeModule()}
255
+ onError={(error: string | undefined) => {
256
+ onError?.(error ?? 'Email verification error');
257
+ }}
258
+ />
259
+ </div>
260
+ );
261
+ }
262
+ }
263
+
264
+ return null;
265
+ };
266
+
267
+ export const IncodeFlow: FC<IncodeFlowProps> = (props) => (
268
+ <div class="IncodeComponent">
269
+ <IncodeFlowContent {...props} />
270
+ </div>
271
+ );
272
+
273
+ register(
274
+ IncodeFlow,
275
+ 'incode-flow',
276
+ [
277
+ 'apiURL',
278
+ 'token',
279
+ 'wasmConfig',
280
+ 'lang',
281
+ 'disableDashboardTheme',
282
+ 'spinnerConfig',
283
+ 'onComplete',
284
+ 'onError',
285
+ ],
286
+ {
287
+ shadow: false,
288
+ },
289
+ );
290
+
291
+ export type { PreloadHandle } from './preloadFlow';
292
+ export { preloadIncodeFlow } from './preloadFlow';
@@ -0,0 +1,30 @@
1
+ @reference "../styles/tailwind.css";
2
+
3
+ .IncodeFlowCompleted {
4
+ @apply flex flex-col items-center justify-center h-full w-full p-20;
5
+ }
6
+
7
+ .IncodeComponent .IncodeFlowCompleted h1.IncodeFlowCompletedTitle {
8
+ font-size: 2rem;
9
+ margin: 20px 0;
10
+ font-weight: 700;
11
+ color: #20263d;
12
+ text-align: left;
13
+ width: 100%;
14
+ }
15
+
16
+ .IncodeComponent .IncodeFlowCompleted p.IncodeFlowCompletedSubtitle {
17
+ font-size: 1rem;
18
+ margin: 20px 0;
19
+ font-weight: 700;
20
+ color: #20263d;
21
+ text-align: left;
22
+ width: 100%;
23
+ }
24
+
25
+ @media screen and (min-width: 992px) {
26
+ .IncodeComponent .IncodeFlowCompleted h1.IncodeFlowCompletedTitle,
27
+ .IncodeComponent .IncodeFlowCompleted p.IncodeFlowCompletedSubtitle {
28
+ text-align: center;
29
+ }
30
+ }
@@ -0,0 +1,331 @@
1
+ import { render, screen } from '@testing-library/preact';
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { FlowCompleted } from './flowCompleted';
4
+
5
+ describe('FlowCompleted', () => {
6
+ const originalLocation = window.location;
7
+ const mockLocation = {
8
+ ...originalLocation,
9
+ href: '',
10
+ origin: 'https://example.com',
11
+ search: '',
12
+ };
13
+
14
+ beforeEach(() => {
15
+ vi.clearAllMocks();
16
+ vi.useFakeTimers();
17
+ Object.defineProperty(window, 'location', {
18
+ writable: true,
19
+ value: mockLocation,
20
+ });
21
+ mockLocation.href = '';
22
+ mockLocation.search = '';
23
+ });
24
+
25
+ afterEach(() => {
26
+ vi.useRealTimers();
27
+ Object.defineProperty(window, 'location', {
28
+ writable: true,
29
+ value: originalLocation,
30
+ });
31
+ });
32
+
33
+ describe('Rendering', () => {
34
+ it('renders with default i18n title and message', () => {
35
+ render(<FlowCompleted />);
36
+
37
+ expect(screen.getByText('verificationComplete.title')).toBeTruthy();
38
+ expect(screen.getByText('verificationComplete.message')).toBeTruthy();
39
+ });
40
+
41
+ it('renders with custom title', () => {
42
+ render(<FlowCompleted title="Custom Title" />);
43
+
44
+ expect(screen.getByText('Custom Title')).toBeTruthy();
45
+ expect(screen.getByText('verificationComplete.message')).toBeTruthy();
46
+ });
47
+
48
+ it('renders with custom message', () => {
49
+ render(<FlowCompleted message="Custom Message" />);
50
+
51
+ expect(screen.getByText('verificationComplete.title')).toBeTruthy();
52
+ expect(screen.getByText('Custom Message')).toBeTruthy();
53
+ });
54
+
55
+ it('renders with both custom title and message', () => {
56
+ render(<FlowCompleted title="Custom Title" message="Custom Message" />);
57
+
58
+ expect(screen.getByText('Custom Title')).toBeTruthy();
59
+ expect(screen.getByText('Custom Message')).toBeTruthy();
60
+ });
61
+
62
+ it('renders with section element and correct structure', () => {
63
+ const { container } = render(
64
+ <FlowCompleted title="Test Title" message="Test Message" />,
65
+ );
66
+
67
+ const section = container.querySelector('section.IncodeFlowCompleted');
68
+ expect(section).toBeTruthy();
69
+ expect(section?.getAttribute('aria-live')).toBe('assertive');
70
+ expect(screen.getByText('Test Title')).toBeTruthy();
71
+ expect(screen.getByText('Test Message')).toBeTruthy();
72
+ });
73
+
74
+ it('renders with IncodeFlowCompleted wrapper class', () => {
75
+ const { container } = render(<FlowCompleted />);
76
+
77
+ const wrapper = container.querySelector('.IncodeFlowCompleted');
78
+ expect(wrapper).toBeTruthy();
79
+ });
80
+ });
81
+
82
+ describe('Redirect functionality', () => {
83
+ it('redirects after default delay (3000ms)', async () => {
84
+ render(<FlowCompleted redirectionUrl="https://example.com/redirect" />);
85
+
86
+ expect(mockLocation.href).toBe('');
87
+
88
+ await vi.runAllTimersAsync();
89
+
90
+ expect(mockLocation.href).toBe('https://example.com/redirect');
91
+ });
92
+
93
+ it('redirects after custom delay', async () => {
94
+ render(
95
+ <FlowCompleted
96
+ redirectionUrl="https://example.com/redirect"
97
+ redirectDelay={5000}
98
+ />,
99
+ );
100
+
101
+ expect(mockLocation.href).toBe('');
102
+
103
+ vi.advanceTimersByTime(4999);
104
+ expect(mockLocation.href).toBe('');
105
+
106
+ await vi.runAllTimersAsync();
107
+
108
+ expect(mockLocation.href).toBe('https://example.com/redirect');
109
+ });
110
+
111
+ it('does not redirect when disableRedirect is true', async () => {
112
+ render(
113
+ <FlowCompleted
114
+ redirectionUrl="https://example.com/redirect"
115
+ disableRedirect
116
+ />,
117
+ );
118
+
119
+ await vi.runAllTimersAsync();
120
+
121
+ expect(mockLocation.href).toBe('');
122
+ });
123
+
124
+ it('does not redirect when redirectionUrl is not provided', async () => {
125
+ render(<FlowCompleted />);
126
+
127
+ await vi.runAllTimersAsync();
128
+
129
+ expect(mockLocation.href).toBe('');
130
+ });
131
+
132
+ it('does not redirect when redirectOriginOnly is true and isRedirect query param is present', async () => {
133
+ mockLocation.search = '?isRedirect=true';
134
+ render(
135
+ <FlowCompleted
136
+ redirectionUrl="https://example.com/redirect"
137
+ redirectOriginOnly
138
+ />,
139
+ );
140
+
141
+ await vi.runAllTimersAsync();
142
+
143
+ expect(mockLocation.href).toBe('');
144
+ });
145
+
146
+ it('redirects when redirectOriginOnly is true but isRedirect query param is not present', async () => {
147
+ mockLocation.search = '';
148
+ render(
149
+ <FlowCompleted
150
+ redirectionUrl="https://example.com/redirect"
151
+ redirectOriginOnly
152
+ />,
153
+ );
154
+
155
+ await vi.runAllTimersAsync();
156
+
157
+ expect(mockLocation.href).toBe('https://example.com/redirect');
158
+ });
159
+ });
160
+
161
+ describe('URL query parameter handling', () => {
162
+ it('adds flowId to redirect URL', async () => {
163
+ render(
164
+ <FlowCompleted
165
+ redirectionUrl="https://example.com/redirect"
166
+ flowId="test-flow-id"
167
+ />,
168
+ );
169
+
170
+ await vi.runAllTimersAsync();
171
+
172
+ expect(mockLocation.href).toBe(
173
+ 'https://example.com/redirect?flowId=test-flow-id',
174
+ );
175
+ });
176
+
177
+ it('adds interviewId to redirect URL when origins differ', async () => {
178
+ mockLocation.origin = 'https://example.com';
179
+ render(
180
+ <FlowCompleted
181
+ redirectionUrl="https://other-domain.com/redirect"
182
+ flowId="test-flow-id"
183
+ interviewId="test-interview-id"
184
+ />,
185
+ );
186
+
187
+ await vi.runAllTimersAsync();
188
+
189
+ const url = new URL(mockLocation.href);
190
+ expect(url.searchParams.get('flowId')).toBe('test-flow-id');
191
+ expect(url.searchParams.get('interviewId')).toBe('test-interview-id');
192
+ });
193
+
194
+ it('does not add interviewId when origins match', async () => {
195
+ mockLocation.origin = 'https://example.com';
196
+ render(
197
+ <FlowCompleted
198
+ redirectionUrl="https://example.com/redirect"
199
+ flowId="test-flow-id"
200
+ interviewId="test-interview-id"
201
+ />,
202
+ );
203
+
204
+ await vi.runAllTimersAsync();
205
+
206
+ const url = new URL(mockLocation.href);
207
+ expect(url.searchParams.get('flowId')).toBe('test-flow-id');
208
+ expect(url.searchParams.get('interviewId')).toBeNull();
209
+ });
210
+
211
+ it('handles invalid URL gracefully', async () => {
212
+ render(
213
+ <FlowCompleted
214
+ redirectionUrl="not-a-valid-url"
215
+ flowId="test-flow-id"
216
+ interviewId="test-interview-id"
217
+ />,
218
+ );
219
+
220
+ await vi.runAllTimersAsync();
221
+
222
+ expect(mockLocation.href).toContain('not-a-valid-url');
223
+ expect(mockLocation.href).toContain('flowId=test-flow-id');
224
+ expect(mockLocation.href).toContain('interviewId=test-interview-id');
225
+ });
226
+
227
+ it('handles URL with existing query parameters', async () => {
228
+ render(
229
+ <FlowCompleted
230
+ redirectionUrl="https://example.com/redirect?existing=param"
231
+ flowId="test-flow-id"
232
+ />,
233
+ );
234
+
235
+ await vi.runAllTimersAsync();
236
+
237
+ const url = new URL(mockLocation.href);
238
+ expect(url.searchParams.get('existing')).toBe('param');
239
+ expect(url.searchParams.get('flowId')).toBe('test-flow-id');
240
+ });
241
+ });
242
+
243
+ describe('Props handling', () => {
244
+ it('accepts action prop without affecting rendering', () => {
245
+ const { container } = render(
246
+ <FlowCompleted action="approved" title="Test" />,
247
+ );
248
+
249
+ expect(container.querySelector('.IncodeFlowCompleted')).toBeTruthy();
250
+ expect(screen.getByText('Test')).toBeTruthy();
251
+ });
252
+
253
+ it('accepts scoreStatus prop without affecting rendering', () => {
254
+ const { container } = render(
255
+ <FlowCompleted scoreStatus="OK" title="Test" />,
256
+ );
257
+
258
+ expect(container.querySelector('.IncodeFlowCompleted')).toBeTruthy();
259
+ expect(screen.getByText('Test')).toBeTruthy();
260
+ });
261
+
262
+ it('handles all scoreStatus values', () => {
263
+ const statuses = [
264
+ 'OK',
265
+ 'WARN',
266
+ 'MANUAL_OK',
267
+ 'FAIL',
268
+ 'UNKNOWN',
269
+ 'MANUAL_FAIL',
270
+ ] as const;
271
+
272
+ statuses.forEach((status) => {
273
+ const { unmount } = render(
274
+ <FlowCompleted scoreStatus={status} title="Test" />,
275
+ );
276
+ expect(screen.getByText('Test')).toBeTruthy();
277
+ unmount();
278
+ });
279
+ });
280
+
281
+ it('handles all action values', () => {
282
+ const actions = ['approved', 'rejected', 'none'] as const;
283
+
284
+ actions.forEach((action) => {
285
+ const { unmount } = render(
286
+ <FlowCompleted action={action} title="Test" />,
287
+ );
288
+ expect(screen.getByText('Test')).toBeTruthy();
289
+ unmount();
290
+ });
291
+ });
292
+ });
293
+
294
+ describe('Edge cases', () => {
295
+ it('handles empty strings for title and message', () => {
296
+ render(<FlowCompleted title="" message="" />);
297
+
298
+ expect(screen.getByText('verificationComplete.title')).toBeTruthy();
299
+ expect(screen.getByText('verificationComplete.message')).toBeTruthy();
300
+ });
301
+
302
+ it('handles very long redirect delay', async () => {
303
+ render(
304
+ <FlowCompleted
305
+ redirectionUrl="https://example.com/redirect"
306
+ redirectDelay={100000}
307
+ />,
308
+ );
309
+
310
+ vi.advanceTimersByTime(99999);
311
+ expect(mockLocation.href).toBe('');
312
+
313
+ await vi.runAllTimersAsync();
314
+
315
+ expect(mockLocation.href).toBe('https://example.com/redirect');
316
+ });
317
+
318
+ it('handles zero redirect delay', async () => {
319
+ render(
320
+ <FlowCompleted
321
+ redirectionUrl="https://example.com/redirect"
322
+ redirectDelay={0}
323
+ />,
324
+ );
325
+
326
+ await vi.runAllTimersAsync();
327
+
328
+ expect(mockLocation.href).toBe('https://example.com/redirect');
329
+ });
330
+ });
331
+ });