@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.
- package/dist/asset-manifest.json +18 -0
- package/dist/browser-ponyfill-B6W6hHVY.js +344 -0
- package/dist/button-DeMZ_34N.js +266 -0
- package/dist/button.css +335 -0
- package/dist/email/email.es.js +145 -0
- package/dist/email/styles.css +123 -0
- package/dist/flow/flow.es.js +9 -0
- package/dist/flow/styles.css +204 -0
- package/dist/flow-ZK6OBsa3.js +568 -0
- package/dist/incodeModule-BF5MX9GT.js +243 -0
- package/dist/incodeModule.css +119 -0
- package/dist/index.es.js +101 -0
- package/dist/otpInput-BUrV4IAF.js +151 -0
- package/dist/otpInput.css +167 -0
- package/dist/phone/phone.es.js +3442 -0
- package/dist/phone/styles.css +305 -0
- package/dist/selfie/selfie.es.js +893 -0
- package/dist/selfie/styles.css +1163 -0
- package/dist/selfieTutorial-C-u5GufD.js +29 -0
- package/dist/styles/core.css +1013 -0
- package/dist/styles/tokens.css +543 -0
- package/dist/successIcon.css +4 -0
- package/dist/title-ng7q7YDh.js +2161 -0
- package/dist/title.css +38 -0
- package/dist/types/core.d.ts +1 -0
- package/dist/types/email/email.d.ts +2 -0
- package/dist/types/email.d.ts +50 -0
- package/dist/types/flow/flow.d.ts +2 -0
- package/dist/types/flow.d.ts +46 -0
- package/dist/types/index.d.ts +223 -0
- package/dist/types/phone/phone.d.ts +2 -0
- package/dist/types/phone.d.ts +51 -0
- package/dist/types/selfie/selfie.d.ts +2 -0
- package/dist/types/selfie.d.ts +24 -0
- package/dist/types/styles/core.d.ts +1 -0
- package/dist/vendor-preact-CK0WeTOR.js +584 -0
- package/package.json +20 -17
- package/dev/README.md +0 -163
- package/dev/getToken.ts +0 -36
- package/dev/headless.html +0 -875
- package/dev/index.html +0 -366
- package/dev/main-headless.tsx +0 -1332
- package/dev/main-orchestrated-flow.tsx +0 -1158
- package/dev/main-preact.tsx +0 -323
- package/dev/main-simplified.tsx +0 -123
- package/dev/main-web-component.tsx +0 -256
- package/dev/main.tsx +0 -332
- package/dev/manual.html +0 -27
- package/dev/orchestrated-flow.html +0 -64
- package/dev/simplified.html +0 -64
- package/dev/tiktok-logo.svg +0 -7
- package/src/defineCustomElement.tsx +0 -30
- package/src/email/email.test.tsx +0 -368
- package/src/email/email.tsx +0 -255
- package/src/email/emailInput.test.tsx +0 -264
- package/src/email/emailInput.tsx +0 -85
- package/src/email/styles.css +0 -59
- package/src/flow/flow.test.tsx +0 -796
- package/src/flow/flow.tsx +0 -292
- package/src/flow/flowCompleted.css +0 -30
- package/src/flow/flowCompleted.test.tsx +0 -331
- package/src/flow/flowCompleted.tsx +0 -121
- package/src/flow/flowInit.test.ts +0 -264
- package/src/flow/flowInit.ts +0 -94
- package/src/flow/flowStart.css +0 -58
- package/src/flow/flowStart.test.tsx +0 -49
- package/src/flow/flowStart.tsx +0 -41
- package/src/flow/incode-logo.svg +0 -8
- package/src/flow/index.ts +0 -7
- package/src/flow/preloadFlow.test.ts +0 -421
- package/src/flow/preloadFlow.ts +0 -171
- package/src/flow/styles.css +0 -9
- package/src/flow/unsupportedModule.css +0 -21
- package/src/flow/unsupportedModule.tsx +0 -39
- package/src/flow/useFlowInitialization.test.tsx +0 -292
- package/src/flow/useFlowInitialization.ts +0 -128
- package/src/flow/useModuleLoader.test.tsx +0 -212
- package/src/flow/useModuleLoader.ts +0 -92
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useManager.test.ts +0 -91
- package/src/hooks/useManager.ts +0 -40
- package/src/i18n/index.ts +0 -3
- package/src/i18n/instance.ts +0 -16
- package/src/i18n/setup.ts +0 -184
- package/src/i18n/useTranslation.ts +0 -42
- package/src/index.ts +0 -27
- package/src/permissions/assets/android-dots-icon.svg +0 -7
- package/src/permissions/assets/android-settings-icon.svg +0 -16
- package/src/permissions/assets/android-toggle-icon.svg +0 -20
- package/src/permissions/assets/bank-card-icon.svg +0 -14
- package/src/permissions/assets/camera-icon.svg +0 -12
- package/src/permissions/assets/camera-ios.svg +0 -53
- package/src/permissions/assets/check-icon.svg +0 -8
- package/src/permissions/assets/chrome-icon.svg +0 -43
- package/src/permissions/assets/password-icon.svg +0 -11
- package/src/permissions/assets/permissions-img.svg +0 -51
- package/src/permissions/assets/safari-icon.svg +0 -37
- package/src/permissions/assets/settings-icon.svg +0 -33
- package/src/permissions/assets/toggle-icon.svg +0 -19
- package/src/permissions/assets/warning-icon.svg +0 -6
- package/src/permissions/boldWithArrow.css +0 -9
- package/src/permissions/boldWithArrow.tsx +0 -41
- package/src/permissions/denied.css +0 -37
- package/src/permissions/denied.tsx +0 -29
- package/src/permissions/deniedAndroid.tsx +0 -56
- package/src/permissions/deniedDesktop.css +0 -9
- package/src/permissions/deniedDesktop.tsx +0 -64
- package/src/permissions/deniedIOS.tsx +0 -73
- package/src/permissions/deniedInstructions.tsx +0 -19
- package/src/permissions/iconWrapper.css +0 -9
- package/src/permissions/iconWrapper.tsx +0 -15
- package/src/permissions/learnMore.css +0 -37
- package/src/permissions/learnMore.tsx +0 -85
- package/src/permissions/numberedStep.css +0 -13
- package/src/permissions/numberedStep.tsx +0 -14
- package/src/permissions/permissions.css +0 -13
- package/src/permissions/permissions.tsx +0 -68
- package/src/phone/phone.tsx +0 -246
- package/src/phone/phoneInput.test.tsx +0 -275
- package/src/phone/phoneInput.tsx +0 -249
- package/src/phone/styles.css +0 -158
- package/src/selfie/cameraButton.css +0 -13
- package/src/selfie/cameraButton.tsx +0 -35
- package/src/selfie/capture.css +0 -57
- package/src/selfie/capture.tsx +0 -232
- package/src/selfie/errorModal.tsx +0 -218
- package/src/selfie/errorModalContent.css +0 -33
- package/src/selfie/errorModalContent.tsx +0 -44
- package/src/selfie/faceOutline.css +0 -5
- package/src/selfie/faceOutline.tsx +0 -22
- package/src/selfie/loadingBorder.css +0 -12
- package/src/selfie/loadingBorder.tsx +0 -77
- package/src/selfie/manualCaptureButton.css +0 -13
- package/src/selfie/manualCaptureButton.tsx +0 -35
- package/src/selfie/noMoreAttemptsModal.tsx +0 -44
- package/src/selfie/notification.css +0 -9
- package/src/selfie/notification.tsx +0 -36
- package/src/selfie/retryErrorModal.tsx +0 -56
- package/src/selfie/selfie.test.tsx +0 -458
- package/src/selfie/selfie.tsx +0 -83
- package/src/selfie/selfieTutorial.json +0 -2626
- package/src/selfie/styles.css +0 -1
- package/src/selfie/tutorial.test.tsx +0 -200
- package/src/selfie/tutorial.tsx +0 -43
- package/src/setup.ts +0 -33
- package/src/shared/baseTutorial/baseTutorial.css +0 -21
- package/src/shared/baseTutorial/baseTutorial.test.tsx +0 -184
- package/src/shared/baseTutorial/baseTutorial.tsx +0 -55
- package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +0 -267
- package/src/shared/baseTutorial/replaceBaseTutorial.ts +0 -68
- package/src/shared/button/button.css +0 -55
- package/src/shared/button/button.test.tsx +0 -101
- package/src/shared/button/button.tsx +0 -47
- package/src/shared/componentRoot/incodeComponent.tsx +0 -12
- package/src/shared/countries/countries.test.ts +0 -75
- package/src/shared/countries/countries.ts +0 -139
- package/src/shared/countries/index.ts +0 -6
- package/src/shared/icons/chevronDown.tsx +0 -22
- package/src/shared/icons/index.ts +0 -2
- package/src/shared/icons/successIcon.css +0 -5
- package/src/shared/icons/successIcon.test.tsx +0 -40
- package/src/shared/icons/successIcon.tsx +0 -26
- package/src/shared/loader/loadingIcon.css +0 -28
- package/src/shared/loader/loadingIcon.tsx +0 -67
- package/src/shared/lottie/lottie.tsx +0 -108
- package/src/shared/otpInput/otpInput.css +0 -85
- package/src/shared/otpInput/otpInput.test.tsx +0 -356
- package/src/shared/otpInput/otpInput.tsx +0 -241
- package/src/shared/page/incode-logo.svg +0 -3
- package/src/shared/page/page.css +0 -47
- package/src/shared/page/page.test.tsx +0 -97
- package/src/shared/page/page.tsx +0 -91
- package/src/shared/page/pageUiConfig.test.ts +0 -112
- package/src/shared/page/pageUiConfig.ts +0 -64
- package/src/shared/page/verifiedByIncode.css +0 -5
- package/src/shared/page/verifiedByIncode.tsx +0 -75
- package/src/shared/spacer/spacer.css +0 -149
- package/src/shared/spacer/spacer.test.tsx +0 -143
- package/src/shared/spacer/spacer.tsx +0 -88
- package/src/shared/spinner/index.ts +0 -2
- package/src/shared/spinner/spinner.css +0 -28
- package/src/shared/spinner/spinner.test.tsx +0 -82
- package/src/shared/spinner/spinner.tsx +0 -65
- package/src/shared/title/title.css +0 -7
- package/src/shared/title/title.tsx +0 -12
- package/src/shared/uiConfig/uiConfig.ts +0 -36
- package/src/shared/webComponent/incodeModule.ts +0 -29
- package/src/shared/webComponent/registerIncodeElement.ts +0 -15
- package/src/styles/__mocks__/fetchTheme.ts +0 -19
- package/src/styles/applyTheme.ts +0 -37
- package/src/styles/cn.test.tsx +0 -57
- package/src/styles/cn.tsx +0 -21
- package/src/styles/core.css +0 -12
- package/src/styles/fetchTheme.test.ts +0 -390
- package/src/styles/fetchTheme.ts +0 -88
- package/src/styles/generatePalette.ts +0 -111
- package/src/styles/reset.css +0 -65
- package/src/styles/resolveCssVariableToHex.ts +0 -28
- package/src/styles/tailwind.css +0 -291
- package/src/styles/themeTypes.ts +0 -18
- package/src/styles/tokens/colors.css +0 -190
- package/src/styles/tokens/components.css +0 -174
- package/src/styles/tokens/index.css +0 -4
- package/src/styles/tokens/primitives.css +0 -129
- package/src/styles/tokens/semantic.css +0 -51
- package/src/svg.d.ts +0 -4
- package/src/types/assets.d.ts +0 -1
- package/src/types/custom-elements.d.ts +0 -104
- package/tsconfig.json +0 -22
- package/vite.config.ts +0 -260
- package/vitest.config.ts +0 -40
- package/vitest.setup.ts +0 -16
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { act, renderHook, waitFor } from '@testing-library/preact';
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
const mockFlowManager = {
|
|
5
|
-
load: vi.fn(),
|
|
6
|
-
getState: vi.fn(() => ({ status: 'idle' })),
|
|
7
|
-
subscribe: vi.fn(() => vi.fn()),
|
|
8
|
-
stop: vi.fn(),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const mockSetupSDK = vi.fn().mockResolvedValue(undefined);
|
|
12
|
-
const mockFetchTheme = vi.fn().mockResolvedValue({
|
|
13
|
-
theme: { logo: 'logo.png' },
|
|
14
|
-
uiConfig: { logoSrc: 'logo.png' },
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
vi.mock('./flowInit', () => ({
|
|
18
|
-
createFlowManager: vi.fn(() => mockFlowManager),
|
|
19
|
-
setupSDK: (...args: unknown[]) => mockSetupSDK(...args),
|
|
20
|
-
fetchTheme: () => mockFetchTheme(),
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
const mockGetPreloadedData = vi.fn();
|
|
24
|
-
const mockConsumePreloadedData = vi.fn();
|
|
25
|
-
|
|
26
|
-
vi.mock('./preloadFlow', () => ({
|
|
27
|
-
getPreloadedData: (...args: unknown[]) => mockGetPreloadedData(...args),
|
|
28
|
-
consumePreloadedData: (...args: unknown[]) =>
|
|
29
|
-
mockConsumePreloadedData(...args),
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
const mockSetUiConfig = vi.fn();
|
|
33
|
-
vi.mock('../shared/uiConfig/uiConfig', () => ({
|
|
34
|
-
setUiConfig: (...args: unknown[]) => mockSetUiConfig(...args),
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
import { useFlowInitialization } from './useFlowInitialization';
|
|
38
|
-
|
|
39
|
-
describe('useFlowInitialization', () => {
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
vi.clearAllMocks();
|
|
42
|
-
mockGetPreloadedData.mockReturnValue(null);
|
|
43
|
-
mockConsumePreloadedData.mockReturnValue(null);
|
|
44
|
-
mockSetupSDK.mockResolvedValue(undefined);
|
|
45
|
-
mockFetchTheme.mockResolvedValue({
|
|
46
|
-
theme: { logo: 'logo.png' },
|
|
47
|
-
uiConfig: { logoSrc: 'logo.png' },
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
afterEach(() => {
|
|
52
|
-
vi.resetAllMocks();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should start in initializing state when no preload', () => {
|
|
56
|
-
const { result } = renderHook(() =>
|
|
57
|
-
useFlowInitialization({
|
|
58
|
-
apiURL: 'https://api.example.com',
|
|
59
|
-
token: 'test-token',
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expect(result.current.status).toBe('initializing');
|
|
64
|
-
expect(result.current.flowManager).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should use preloaded data when available and ready', () => {
|
|
68
|
-
const preloadedFlowManager = {
|
|
69
|
-
...mockFlowManager,
|
|
70
|
-
preloaded: true,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
mockGetPreloadedData.mockReturnValue({
|
|
74
|
-
status: 'ready',
|
|
75
|
-
flowManager: preloadedFlowManager,
|
|
76
|
-
uiConfig: { logoSrc: 'preloaded-logo.png' },
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
mockConsumePreloadedData.mockReturnValue({
|
|
80
|
-
status: 'ready',
|
|
81
|
-
flowManager: preloadedFlowManager,
|
|
82
|
-
uiConfig: { logoSrc: 'preloaded-logo.png' },
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const { result } = renderHook(() =>
|
|
86
|
-
useFlowInitialization({
|
|
87
|
-
apiURL: 'https://api.example.com',
|
|
88
|
-
token: 'preloaded-token',
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(result.current.status).toBe('ready');
|
|
93
|
-
expect(result.current.flowManager).toBe(preloadedFlowManager);
|
|
94
|
-
expect(mockSetUiConfig).toHaveBeenCalledWith({
|
|
95
|
-
logoSrc: 'preloaded-logo.png',
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should show error when preload failed', () => {
|
|
100
|
-
mockGetPreloadedData.mockReturnValue({
|
|
101
|
-
status: 'error',
|
|
102
|
-
error: 'Preload failed',
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const { result } = renderHook(() =>
|
|
106
|
-
useFlowInitialization({
|
|
107
|
-
apiURL: 'https://api.example.com',
|
|
108
|
-
token: 'error-token',
|
|
109
|
-
}),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
expect(result.current.status).toBe('error');
|
|
113
|
-
if (result.current.status === 'error') {
|
|
114
|
-
expect(result.current.error).toBe('Preload failed');
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should wait for preload when loading', async () => {
|
|
119
|
-
let resolvePreload: (value: unknown) => void;
|
|
120
|
-
const readyPromise = new Promise((resolve) => {
|
|
121
|
-
resolvePreload = resolve;
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const preloadedFlowManager = {
|
|
125
|
-
...mockFlowManager,
|
|
126
|
-
preloaded: true,
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
mockGetPreloadedData.mockReturnValue({
|
|
130
|
-
status: 'loading',
|
|
131
|
-
readyPromise,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
const { result } = renderHook(() =>
|
|
135
|
-
useFlowInitialization({
|
|
136
|
-
apiURL: 'https://api.example.com',
|
|
137
|
-
token: 'loading-token',
|
|
138
|
-
}),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
expect(result.current.status).toBe('initializing');
|
|
142
|
-
|
|
143
|
-
mockConsumePreloadedData.mockReturnValue({
|
|
144
|
-
status: 'ready',
|
|
145
|
-
flowManager: preloadedFlowManager,
|
|
146
|
-
uiConfig: { logoSrc: 'loaded-logo.png' },
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
await act(async () => {
|
|
150
|
-
resolvePreload?.(undefined);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
await waitFor(() => {
|
|
154
|
-
expect(result.current.status).toBe('ready');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
expect(result.current.flowManager).toBe(preloadedFlowManager);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should initialize SDK and become ready', async () => {
|
|
161
|
-
const { result } = renderHook(() =>
|
|
162
|
-
useFlowInitialization({
|
|
163
|
-
apiURL: 'https://api.example.com',
|
|
164
|
-
token: 'init-token',
|
|
165
|
-
lang: 'es',
|
|
166
|
-
}),
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
expect(result.current.status).toBe('initializing');
|
|
170
|
-
|
|
171
|
-
await waitFor(() => {
|
|
172
|
-
expect(result.current.status).toBe('ready');
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
expect(mockSetupSDK).toHaveBeenCalledWith({
|
|
176
|
-
apiURL: 'https://api.example.com',
|
|
177
|
-
token: 'init-token',
|
|
178
|
-
lang: 'es',
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
expect(mockFlowManager.load).toHaveBeenCalled();
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should fetch theme during initialization', async () => {
|
|
185
|
-
const { result } = renderHook(() =>
|
|
186
|
-
useFlowInitialization({
|
|
187
|
-
apiURL: 'https://api.example.com',
|
|
188
|
-
token: 'theme-token',
|
|
189
|
-
disableDashboardTheme: false,
|
|
190
|
-
}),
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
await waitFor(() => {
|
|
194
|
-
expect(result.current.status).toBe('ready');
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
expect(mockFetchTheme).toHaveBeenCalled();
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('should skip theme fetch when disabled', async () => {
|
|
201
|
-
const { result } = renderHook(() =>
|
|
202
|
-
useFlowInitialization({
|
|
203
|
-
apiURL: 'https://api.example.com',
|
|
204
|
-
token: 'no-theme-token',
|
|
205
|
-
disableDashboardTheme: true,
|
|
206
|
-
}),
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
await waitFor(() => {
|
|
210
|
-
expect(result.current.status).toBe('ready');
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
expect(mockFetchTheme).not.toHaveBeenCalled();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('should call onError when SDK setup fails', async () => {
|
|
217
|
-
mockSetupSDK.mockRejectedValueOnce(new Error('SDK error'));
|
|
218
|
-
|
|
219
|
-
const onError = vi.fn();
|
|
220
|
-
|
|
221
|
-
const { result } = renderHook(() =>
|
|
222
|
-
useFlowInitialization({
|
|
223
|
-
apiURL: 'https://api.example.com',
|
|
224
|
-
token: 'sdk-error-token',
|
|
225
|
-
onError,
|
|
226
|
-
}),
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
await waitFor(() => {
|
|
230
|
-
expect(result.current.status).toBe('error');
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
if (result.current.status === 'error') {
|
|
234
|
-
expect(result.current.error).toBe('SDK error');
|
|
235
|
-
}
|
|
236
|
-
expect(onError).toHaveBeenCalledWith('SDK error');
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('should handle preload promise rejection', async () => {
|
|
240
|
-
const readyPromise = Promise.reject(new Error('Preload rejected'));
|
|
241
|
-
|
|
242
|
-
mockGetPreloadedData.mockReturnValue({
|
|
243
|
-
status: 'loading',
|
|
244
|
-
readyPromise,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
const onError = vi.fn();
|
|
248
|
-
|
|
249
|
-
const { result } = renderHook(() =>
|
|
250
|
-
useFlowInitialization({
|
|
251
|
-
apiURL: 'https://api.example.com',
|
|
252
|
-
token: 'reject-token',
|
|
253
|
-
onError,
|
|
254
|
-
}),
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
await waitFor(() => {
|
|
258
|
-
expect(result.current.status).toBe('error');
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
if (result.current.status === 'error') {
|
|
262
|
-
expect(result.current.error).toBe('Preload rejected');
|
|
263
|
-
}
|
|
264
|
-
expect(onError).toHaveBeenCalledWith('Preload rejected');
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('should not re-initialize when options change after ready', async () => {
|
|
268
|
-
const { result, rerender } = renderHook<
|
|
269
|
-
ReturnType<typeof useFlowInitialization>,
|
|
270
|
-
{ apiURL: string; token: string; lang?: string }
|
|
271
|
-
>((props) => useFlowInitialization(props), {
|
|
272
|
-
initialProps: {
|
|
273
|
-
apiURL: 'https://api.example.com',
|
|
274
|
-
token: 'stable-token',
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
await waitFor(() => {
|
|
279
|
-
expect(result.current.status).toBe('ready');
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
expect(mockSetupSDK).toHaveBeenCalledTimes(1);
|
|
283
|
-
|
|
284
|
-
rerender({
|
|
285
|
-
apiURL: 'https://api.example.com',
|
|
286
|
-
token: 'stable-token',
|
|
287
|
-
lang: 'fr',
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
expect(mockSetupSDK).toHaveBeenCalledTimes(1);
|
|
291
|
-
});
|
|
292
|
-
});
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
2
|
-
import { setUiConfig } from '../shared/uiConfig/uiConfig';
|
|
3
|
-
import { createFlowManager, fetchTheme, setupSDK } from './flowInit';
|
|
4
|
-
import { consumePreloadedData, getPreloadedData } from './preloadFlow';
|
|
5
|
-
|
|
6
|
-
type FlowManager = ReturnType<typeof createFlowManager>;
|
|
7
|
-
|
|
8
|
-
type FlowInitializationOptions = {
|
|
9
|
-
apiURL: string;
|
|
10
|
-
token: string;
|
|
11
|
-
lang?: string;
|
|
12
|
-
disableDashboardTheme?: boolean;
|
|
13
|
-
onError?: (error: string) => void;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type FlowInitializationState =
|
|
17
|
-
| { status: 'initializing'; flowManager: FlowManager }
|
|
18
|
-
| { status: 'ready'; flowManager: FlowManager }
|
|
19
|
-
| { status: 'error'; error: string; flowManager: FlowManager };
|
|
20
|
-
|
|
21
|
-
export function useFlowInitialization(
|
|
22
|
-
options: FlowInitializationOptions,
|
|
23
|
-
): FlowInitializationState {
|
|
24
|
-
const { apiURL, token, lang, disableDashboardTheme, onError } = options;
|
|
25
|
-
|
|
26
|
-
const flowManagerRef = useRef<FlowManager | null>(null);
|
|
27
|
-
|
|
28
|
-
const [state, setState] = useState<FlowInitializationState>(() => {
|
|
29
|
-
const preloaded = getPreloadedData(token);
|
|
30
|
-
|
|
31
|
-
if (preloaded?.status === 'ready') {
|
|
32
|
-
const consumed = consumePreloadedData(token);
|
|
33
|
-
if (consumed) {
|
|
34
|
-
flowManagerRef.current = consumed.flowManager;
|
|
35
|
-
if (consumed.uiConfig) {
|
|
36
|
-
setUiConfig(consumed.uiConfig);
|
|
37
|
-
}
|
|
38
|
-
return { status: 'ready', flowManager: consumed.flowManager };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const flowManager = createFlowManager();
|
|
43
|
-
flowManagerRef.current = flowManager;
|
|
44
|
-
|
|
45
|
-
if (preloaded?.status === 'error') {
|
|
46
|
-
return {
|
|
47
|
-
status: 'error',
|
|
48
|
-
error: preloaded.error ?? 'Preload failed',
|
|
49
|
-
flowManager,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return { status: 'initializing', flowManager };
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const initStartedRef = useRef(false);
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (state.status !== 'initializing') {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const preloaded = getPreloadedData(token);
|
|
64
|
-
|
|
65
|
-
if (preloaded?.status === 'loading') {
|
|
66
|
-
preloaded.readyPromise
|
|
67
|
-
.then(() => {
|
|
68
|
-
const consumed = consumePreloadedData(token);
|
|
69
|
-
if (consumed) {
|
|
70
|
-
flowManagerRef.current = consumed.flowManager;
|
|
71
|
-
if (consumed.uiConfig) {
|
|
72
|
-
setUiConfig(consumed.uiConfig);
|
|
73
|
-
}
|
|
74
|
-
setState({ status: 'ready', flowManager: consumed.flowManager });
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
.catch((error) => {
|
|
78
|
-
const errorMessage =
|
|
79
|
-
error instanceof Error ? error.message : 'Preload failed';
|
|
80
|
-
setState({
|
|
81
|
-
status: 'error',
|
|
82
|
-
error: errorMessage,
|
|
83
|
-
flowManager: state.flowManager,
|
|
84
|
-
});
|
|
85
|
-
onError?.(errorMessage);
|
|
86
|
-
});
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (initStartedRef.current) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
initStartedRef.current = true;
|
|
94
|
-
|
|
95
|
-
const initialize = async () => {
|
|
96
|
-
try {
|
|
97
|
-
await setupSDK({ apiURL, token, lang });
|
|
98
|
-
|
|
99
|
-
const themePromise = disableDashboardTheme
|
|
100
|
-
? Promise.resolve()
|
|
101
|
-
: fetchTheme().then((result) => {
|
|
102
|
-
if (result.uiConfig) {
|
|
103
|
-
setUiConfig(result.uiConfig);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
state.flowManager.load();
|
|
108
|
-
|
|
109
|
-
await themePromise;
|
|
110
|
-
|
|
111
|
-
setState({ status: 'ready', flowManager: state.flowManager });
|
|
112
|
-
} catch (error) {
|
|
113
|
-
const errorMessage =
|
|
114
|
-
error instanceof Error ? error.message : 'Failed to initialize SDK';
|
|
115
|
-
setState({
|
|
116
|
-
status: 'error',
|
|
117
|
-
error: errorMessage,
|
|
118
|
-
flowManager: state.flowManager,
|
|
119
|
-
});
|
|
120
|
-
onError?.(errorMessage);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
initialize();
|
|
125
|
-
}, [apiURL, token, lang, disableDashboardTheme, onError, state]);
|
|
126
|
-
|
|
127
|
-
return state;
|
|
128
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { renderHook, waitFor } from '@testing-library/preact';
|
|
2
|
-
import type { FC } from 'preact/compat';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
const MockPhoneComponent: FC = () => <div>Phone</div>;
|
|
6
|
-
const MockEmailComponent: FC = () => <div>Email</div>;
|
|
7
|
-
const MockSelfieComponent: FC = () => <div>Selfie</div>;
|
|
8
|
-
|
|
9
|
-
vi.mock('./flowInit', () => ({
|
|
10
|
-
LAZY_UI_MODULES: {
|
|
11
|
-
PHONE: vi.fn(() => Promise.resolve(MockPhoneComponent)),
|
|
12
|
-
EMAIL: vi.fn(() => Promise.resolve(MockEmailComponent)),
|
|
13
|
-
SELFIE: vi.fn(() => Promise.resolve(MockSelfieComponent)),
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
import { LAZY_UI_MODULES } from './flowInit';
|
|
18
|
-
import { useModuleLoader, usePrefetchNextModule } from './useModuleLoader';
|
|
19
|
-
|
|
20
|
-
describe('useModuleLoader', () => {
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
vi.clearAllMocks();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
vi.resetAllMocks();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should return idle state when moduleKey is undefined', () => {
|
|
30
|
-
const { result } = renderHook(() =>
|
|
31
|
-
useModuleLoader({ moduleKey: undefined }),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
expect(result.current.status).toBe('idle');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should return unsupported state for unknown module', () => {
|
|
38
|
-
const { result } = renderHook(() =>
|
|
39
|
-
useModuleLoader({ moduleKey: 'UNKNOWN_MODULE' }),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
expect(result.current.status).toBe('unsupported');
|
|
43
|
-
if (result.current.status === 'unsupported') {
|
|
44
|
-
expect(result.current.moduleKey).toBe('UNKNOWN_MODULE');
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should load PHONE module successfully', async () => {
|
|
49
|
-
const onModuleLoading = vi.fn();
|
|
50
|
-
const onModuleLoaded = vi.fn();
|
|
51
|
-
|
|
52
|
-
const { result } = renderHook(() =>
|
|
53
|
-
useModuleLoader({
|
|
54
|
-
moduleKey: 'PHONE',
|
|
55
|
-
onModuleLoading,
|
|
56
|
-
onModuleLoaded,
|
|
57
|
-
}),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
expect(onModuleLoading).toHaveBeenCalledWith('PHONE');
|
|
61
|
-
|
|
62
|
-
await waitFor(() => {
|
|
63
|
-
expect(result.current.status).toBe('loaded');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (result.current.status === 'loaded') {
|
|
67
|
-
expect(result.current.moduleKey).toBe('PHONE');
|
|
68
|
-
expect(result.current.Component).toBe(MockPhoneComponent);
|
|
69
|
-
}
|
|
70
|
-
expect(onModuleLoaded).toHaveBeenCalledWith('PHONE');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should handle module load error', async () => {
|
|
74
|
-
const loadError = new Error('Failed to load');
|
|
75
|
-
vi.mocked(LAZY_UI_MODULES.EMAIL).mockRejectedValueOnce(loadError);
|
|
76
|
-
|
|
77
|
-
const onError = vi.fn();
|
|
78
|
-
|
|
79
|
-
const { result } = renderHook(() =>
|
|
80
|
-
useModuleLoader({
|
|
81
|
-
moduleKey: 'EMAIL',
|
|
82
|
-
onError,
|
|
83
|
-
}),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
await waitFor(() => {
|
|
87
|
-
expect(result.current.status).toBe('error');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
if (result.current.status === 'error') {
|
|
91
|
-
expect(result.current.error).toBe('Failed to load');
|
|
92
|
-
}
|
|
93
|
-
expect(onError).toHaveBeenCalledWith(
|
|
94
|
-
'Failed to load EMAIL: Failed to load',
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should cancel loading when moduleKey changes', async () => {
|
|
99
|
-
const onModuleLoaded = vi.fn();
|
|
100
|
-
|
|
101
|
-
let resolvePhone: ((value: unknown) => void) | undefined;
|
|
102
|
-
const phonePromise = new Promise((resolve) => {
|
|
103
|
-
resolvePhone = resolve;
|
|
104
|
-
});
|
|
105
|
-
vi.mocked(LAZY_UI_MODULES.PHONE).mockReturnValueOnce(phonePromise as never);
|
|
106
|
-
|
|
107
|
-
const { rerender } = renderHook(
|
|
108
|
-
({ moduleKey }) =>
|
|
109
|
-
useModuleLoader({
|
|
110
|
-
moduleKey,
|
|
111
|
-
onModuleLoaded,
|
|
112
|
-
}),
|
|
113
|
-
{ initialProps: { moduleKey: 'PHONE' } },
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
rerender({ moduleKey: 'EMAIL' });
|
|
117
|
-
|
|
118
|
-
resolvePhone?.(MockPhoneComponent);
|
|
119
|
-
|
|
120
|
-
await waitFor(() => {
|
|
121
|
-
expect(onModuleLoaded).toHaveBeenCalledWith('EMAIL');
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
expect(onModuleLoaded).not.toHaveBeenCalledWith('PHONE');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should reset to idle when moduleKey becomes undefined', async () => {
|
|
128
|
-
const { result, rerender } = renderHook(
|
|
129
|
-
({ moduleKey }) => useModuleLoader({ moduleKey }),
|
|
130
|
-
{ initialProps: { moduleKey: 'PHONE' as string | undefined } },
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
await waitFor(() => {
|
|
134
|
-
expect(result.current.status).toBe('loaded');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
rerender({ moduleKey: undefined });
|
|
138
|
-
|
|
139
|
-
expect(result.current.status).toBe('idle');
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe('usePrefetchNextModule', () => {
|
|
144
|
-
beforeEach(() => {
|
|
145
|
-
vi.clearAllMocks();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should prefetch next module when available', () => {
|
|
149
|
-
const steps = ['PHONE', 'EMAIL', 'SELFIE'];
|
|
150
|
-
|
|
151
|
-
renderHook(() => usePrefetchNextModule(steps, 0));
|
|
152
|
-
|
|
153
|
-
expect(LAZY_UI_MODULES.EMAIL).toHaveBeenCalled();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should not prefetch when at last step', () => {
|
|
157
|
-
const steps = ['PHONE', 'EMAIL', 'SELFIE'];
|
|
158
|
-
|
|
159
|
-
renderHook(() => usePrefetchNextModule(steps, 2));
|
|
160
|
-
|
|
161
|
-
expect(LAZY_UI_MODULES.PHONE).not.toHaveBeenCalled();
|
|
162
|
-
expect(LAZY_UI_MODULES.EMAIL).not.toHaveBeenCalled();
|
|
163
|
-
expect(LAZY_UI_MODULES.SELFIE).not.toHaveBeenCalled();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should not prefetch same module twice', () => {
|
|
167
|
-
const steps = ['PHONE', 'EMAIL', 'SELFIE'];
|
|
168
|
-
|
|
169
|
-
const { rerender } = renderHook(
|
|
170
|
-
({ index }) => usePrefetchNextModule(steps, index),
|
|
171
|
-
{ initialProps: { index: 0 } },
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
expect(LAZY_UI_MODULES.EMAIL).toHaveBeenCalledTimes(1);
|
|
175
|
-
|
|
176
|
-
rerender({ index: 0 });
|
|
177
|
-
|
|
178
|
-
expect(LAZY_UI_MODULES.EMAIL).toHaveBeenCalledTimes(1);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should handle empty steps array', () => {
|
|
182
|
-
expect(() => {
|
|
183
|
-
renderHook(() => usePrefetchNextModule([], 0));
|
|
184
|
-
}).not.toThrow();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('should handle prefetch failure gracefully', async () => {
|
|
188
|
-
vi.mocked(LAZY_UI_MODULES.EMAIL).mockRejectedValueOnce(
|
|
189
|
-
new Error('Prefetch failed'),
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const steps = ['PHONE', 'EMAIL', 'SELFIE'];
|
|
193
|
-
|
|
194
|
-
expect(() => {
|
|
195
|
-
renderHook(() => usePrefetchNextModule(steps, 0));
|
|
196
|
-
}).not.toThrow();
|
|
197
|
-
|
|
198
|
-
expect(LAZY_UI_MODULES.EMAIL).toHaveBeenCalledTimes(1);
|
|
199
|
-
|
|
200
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it('should skip prefetch for unsupported modules', () => {
|
|
204
|
-
const steps = ['PHONE', 'UNKNOWN_MODULE', 'SELFIE'];
|
|
205
|
-
|
|
206
|
-
renderHook(() => usePrefetchNextModule(steps, 0));
|
|
207
|
-
|
|
208
|
-
expect(LAZY_UI_MODULES.PHONE).not.toHaveBeenCalled();
|
|
209
|
-
expect(LAZY_UI_MODULES.EMAIL).not.toHaveBeenCalled();
|
|
210
|
-
expect(LAZY_UI_MODULES.SELFIE).not.toHaveBeenCalled();
|
|
211
|
-
});
|
|
212
|
-
});
|