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

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