@incodetech/web 2.0.0-alpha.2 → 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 (256) hide show
  1. package/dist/asset-manifest.json +16 -16
  2. package/package.json +5 -2
  3. package/.turbo/turbo-build.log +0 -58
  4. package/.turbo/turbo-coverage.log +0 -23
  5. package/.turbo/turbo-format.log +0 -6
  6. package/.turbo/turbo-lint$colon$fix.log +0 -6
  7. package/.turbo/turbo-lint.log +0 -6
  8. package/.turbo/turbo-test.log +0 -1033
  9. package/.turbo/turbo-typecheck.log +0 -5
  10. package/coverage/base.css +0 -224
  11. package/coverage/block-navigation.js +0 -87
  12. package/coverage/email/email.tsx.html +0 -850
  13. package/coverage/email/emailInput.tsx.html +0 -340
  14. package/coverage/email/index.html +0 -131
  15. package/coverage/favicon.png +0 -0
  16. package/coverage/flow/flow.tsx.html +0 -961
  17. package/coverage/flow/flowCompleted.tsx.html +0 -448
  18. package/coverage/flow/flowInit.ts.html +0 -367
  19. package/coverage/flow/flowStart.tsx.html +0 -208
  20. package/coverage/flow/index.html +0 -221
  21. package/coverage/flow/preloadFlow.ts.html +0 -598
  22. package/coverage/flow/unsupportedModule.tsx.html +0 -202
  23. package/coverage/flow/useFlowInitialization.ts.html +0 -469
  24. package/coverage/flow/useModuleLoader.ts.html +0 -361
  25. package/coverage/hooks/index.html +0 -116
  26. package/coverage/hooks/useManager.ts.html +0 -205
  27. package/coverage/index.html +0 -401
  28. package/coverage/permissions/boldWithArrow.tsx.html +0 -208
  29. package/coverage/permissions/denied.tsx.html +0 -172
  30. package/coverage/permissions/deniedAndroid.tsx.html +0 -253
  31. package/coverage/permissions/deniedDesktop.tsx.html +0 -277
  32. package/coverage/permissions/deniedIOS.tsx.html +0 -304
  33. package/coverage/permissions/deniedInstructions.tsx.html +0 -142
  34. package/coverage/permissions/iconWrapper.tsx.html +0 -130
  35. package/coverage/permissions/index.html +0 -251
  36. package/coverage/permissions/learnMore.tsx.html +0 -340
  37. package/coverage/permissions/numberedStep.tsx.html +0 -127
  38. package/coverage/permissions/permissions.tsx.html +0 -289
  39. package/coverage/phone/index.html +0 -116
  40. package/coverage/phone/phoneInput.tsx.html +0 -832
  41. package/coverage/prettify.css +0 -1
  42. package/coverage/prettify.js +0 -2
  43. package/coverage/selfie/index.html +0 -131
  44. package/coverage/selfie/selfie.tsx.html +0 -334
  45. package/coverage/selfie/tutorial.tsx.html +0 -214
  46. package/coverage/shared/baseTutorial/baseTutorial.tsx.html +0 -250
  47. package/coverage/shared/baseTutorial/index.html +0 -131
  48. package/coverage/shared/baseTutorial/replaceBaseTutorial.ts.html +0 -289
  49. package/coverage/shared/button/button.tsx.html +0 -226
  50. package/coverage/shared/button/index.html +0 -116
  51. package/coverage/shared/componentRoot/incodeComponent.tsx.html +0 -121
  52. package/coverage/shared/componentRoot/index.html +0 -116
  53. package/coverage/shared/countries/countries.ts.html +0 -502
  54. package/coverage/shared/countries/index.html +0 -116
  55. package/coverage/shared/icons/chevronDown.tsx.html +0 -151
  56. package/coverage/shared/icons/index.html +0 -131
  57. package/coverage/shared/icons/successIcon.tsx.html +0 -163
  58. package/coverage/shared/loader/index.html +0 -116
  59. package/coverage/shared/loader/loadingIcon.tsx.html +0 -286
  60. package/coverage/shared/otpInput/index.html +0 -116
  61. package/coverage/shared/otpInput/otpInput.tsx.html +0 -808
  62. package/coverage/shared/page/index.html +0 -146
  63. package/coverage/shared/page/page.tsx.html +0 -358
  64. package/coverage/shared/page/pageUiConfig.ts.html +0 -277
  65. package/coverage/shared/page/verifiedByIncode.tsx.html +0 -310
  66. package/coverage/shared/spacer/index.html +0 -116
  67. package/coverage/shared/spacer/spacer.tsx.html +0 -349
  68. package/coverage/shared/spinner/index.html +0 -116
  69. package/coverage/shared/spinner/spinner.tsx.html +0 -280
  70. package/coverage/shared/title/index.html +0 -116
  71. package/coverage/shared/title/title.tsx.html +0 -121
  72. package/coverage/shared/uiConfig/index.html +0 -116
  73. package/coverage/shared/uiConfig/uiConfig.ts.html +0 -193
  74. package/coverage/shared/webComponent/incodeModule.ts.html +0 -172
  75. package/coverage/shared/webComponent/index.html +0 -131
  76. package/coverage/shared/webComponent/registerIncodeElement.ts.html +0 -130
  77. package/coverage/sort-arrow-sprite.png +0 -0
  78. package/coverage/sorter.js +0 -210
  79. package/coverage/styles/cn.tsx.html +0 -148
  80. package/coverage/styles/fetchTheme.ts.html +0 -349
  81. package/coverage/styles/index.html +0 -131
  82. package/dev/README.md +0 -163
  83. package/dev/getToken.ts +0 -36
  84. package/dev/headless.html +0 -875
  85. package/dev/index.html +0 -366
  86. package/dev/main-headless.tsx +0 -1332
  87. package/dev/main-orchestrated-flow.tsx +0 -1158
  88. package/dev/main-preact.tsx +0 -323
  89. package/dev/main-simplified.tsx +0 -123
  90. package/dev/main-web-component.tsx +0 -256
  91. package/dev/main.tsx +0 -332
  92. package/dev/manual.html +0 -27
  93. package/dev/orchestrated-flow.html +0 -64
  94. package/dev/simplified.html +0 -64
  95. package/dev/tiktok-logo.svg +0 -7
  96. package/src/defineCustomElement.tsx +0 -30
  97. package/src/email/email.test.tsx +0 -368
  98. package/src/email/email.tsx +0 -255
  99. package/src/email/emailInput.test.tsx +0 -264
  100. package/src/email/emailInput.tsx +0 -85
  101. package/src/email/styles.css +0 -59
  102. package/src/flow/flow.test.tsx +0 -796
  103. package/src/flow/flow.tsx +0 -292
  104. package/src/flow/flowCompleted.css +0 -30
  105. package/src/flow/flowCompleted.test.tsx +0 -331
  106. package/src/flow/flowCompleted.tsx +0 -121
  107. package/src/flow/flowInit.test.ts +0 -264
  108. package/src/flow/flowInit.ts +0 -94
  109. package/src/flow/flowStart.css +0 -58
  110. package/src/flow/flowStart.test.tsx +0 -49
  111. package/src/flow/flowStart.tsx +0 -41
  112. package/src/flow/incode-logo.svg +0 -8
  113. package/src/flow/index.ts +0 -7
  114. package/src/flow/preloadFlow.test.ts +0 -421
  115. package/src/flow/preloadFlow.ts +0 -171
  116. package/src/flow/styles.css +0 -9
  117. package/src/flow/unsupportedModule.css +0 -21
  118. package/src/flow/unsupportedModule.tsx +0 -39
  119. package/src/flow/useFlowInitialization.test.tsx +0 -292
  120. package/src/flow/useFlowInitialization.ts +0 -128
  121. package/src/flow/useModuleLoader.test.tsx +0 -212
  122. package/src/flow/useModuleLoader.ts +0 -92
  123. package/src/hooks/index.ts +0 -1
  124. package/src/hooks/useManager.test.ts +0 -91
  125. package/src/hooks/useManager.ts +0 -40
  126. package/src/i18n/index.ts +0 -3
  127. package/src/i18n/instance.ts +0 -16
  128. package/src/i18n/setup.ts +0 -184
  129. package/src/i18n/useTranslation.ts +0 -42
  130. package/src/index.ts +0 -27
  131. package/src/permissions/assets/android-dots-icon.svg +0 -7
  132. package/src/permissions/assets/android-settings-icon.svg +0 -16
  133. package/src/permissions/assets/android-toggle-icon.svg +0 -20
  134. package/src/permissions/assets/bank-card-icon.svg +0 -14
  135. package/src/permissions/assets/camera-icon.svg +0 -12
  136. package/src/permissions/assets/camera-ios.svg +0 -53
  137. package/src/permissions/assets/check-icon.svg +0 -8
  138. package/src/permissions/assets/chrome-icon.svg +0 -43
  139. package/src/permissions/assets/password-icon.svg +0 -11
  140. package/src/permissions/assets/permissions-img.svg +0 -51
  141. package/src/permissions/assets/safari-icon.svg +0 -37
  142. package/src/permissions/assets/settings-icon.svg +0 -33
  143. package/src/permissions/assets/toggle-icon.svg +0 -19
  144. package/src/permissions/assets/warning-icon.svg +0 -6
  145. package/src/permissions/boldWithArrow.css +0 -9
  146. package/src/permissions/boldWithArrow.tsx +0 -41
  147. package/src/permissions/denied.css +0 -37
  148. package/src/permissions/denied.tsx +0 -29
  149. package/src/permissions/deniedAndroid.tsx +0 -56
  150. package/src/permissions/deniedDesktop.css +0 -9
  151. package/src/permissions/deniedDesktop.tsx +0 -64
  152. package/src/permissions/deniedIOS.tsx +0 -73
  153. package/src/permissions/deniedInstructions.tsx +0 -19
  154. package/src/permissions/iconWrapper.css +0 -9
  155. package/src/permissions/iconWrapper.tsx +0 -15
  156. package/src/permissions/learnMore.css +0 -37
  157. package/src/permissions/learnMore.tsx +0 -85
  158. package/src/permissions/numberedStep.css +0 -13
  159. package/src/permissions/numberedStep.tsx +0 -14
  160. package/src/permissions/permissions.css +0 -13
  161. package/src/permissions/permissions.tsx +0 -68
  162. package/src/phone/phone.tsx +0 -246
  163. package/src/phone/phoneInput.test.tsx +0 -275
  164. package/src/phone/phoneInput.tsx +0 -249
  165. package/src/phone/styles.css +0 -158
  166. package/src/selfie/cameraButton.css +0 -13
  167. package/src/selfie/cameraButton.tsx +0 -35
  168. package/src/selfie/capture.css +0 -57
  169. package/src/selfie/capture.tsx +0 -232
  170. package/src/selfie/errorModal.tsx +0 -218
  171. package/src/selfie/errorModalContent.css +0 -33
  172. package/src/selfie/errorModalContent.tsx +0 -44
  173. package/src/selfie/faceOutline.css +0 -5
  174. package/src/selfie/faceOutline.tsx +0 -22
  175. package/src/selfie/loadingBorder.css +0 -12
  176. package/src/selfie/loadingBorder.tsx +0 -77
  177. package/src/selfie/manualCaptureButton.css +0 -13
  178. package/src/selfie/manualCaptureButton.tsx +0 -35
  179. package/src/selfie/noMoreAttemptsModal.tsx +0 -44
  180. package/src/selfie/notification.css +0 -9
  181. package/src/selfie/notification.tsx +0 -36
  182. package/src/selfie/retryErrorModal.tsx +0 -56
  183. package/src/selfie/selfie.test.tsx +0 -458
  184. package/src/selfie/selfie.tsx +0 -83
  185. package/src/selfie/selfieTutorial.json +0 -2626
  186. package/src/selfie/styles.css +0 -1
  187. package/src/selfie/tutorial.test.tsx +0 -200
  188. package/src/selfie/tutorial.tsx +0 -43
  189. package/src/setup.ts +0 -33
  190. package/src/shared/baseTutorial/baseTutorial.css +0 -21
  191. package/src/shared/baseTutorial/baseTutorial.test.tsx +0 -184
  192. package/src/shared/baseTutorial/baseTutorial.tsx +0 -55
  193. package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +0 -267
  194. package/src/shared/baseTutorial/replaceBaseTutorial.ts +0 -68
  195. package/src/shared/button/button.css +0 -55
  196. package/src/shared/button/button.test.tsx +0 -101
  197. package/src/shared/button/button.tsx +0 -47
  198. package/src/shared/componentRoot/incodeComponent.tsx +0 -12
  199. package/src/shared/countries/countries.test.ts +0 -75
  200. package/src/shared/countries/countries.ts +0 -139
  201. package/src/shared/countries/index.ts +0 -6
  202. package/src/shared/icons/chevronDown.tsx +0 -22
  203. package/src/shared/icons/index.ts +0 -2
  204. package/src/shared/icons/successIcon.css +0 -5
  205. package/src/shared/icons/successIcon.test.tsx +0 -40
  206. package/src/shared/icons/successIcon.tsx +0 -26
  207. package/src/shared/loader/loadingIcon.css +0 -28
  208. package/src/shared/loader/loadingIcon.tsx +0 -67
  209. package/src/shared/lottie/lottie.tsx +0 -108
  210. package/src/shared/otpInput/otpInput.css +0 -85
  211. package/src/shared/otpInput/otpInput.test.tsx +0 -356
  212. package/src/shared/otpInput/otpInput.tsx +0 -241
  213. package/src/shared/page/incode-logo.svg +0 -3
  214. package/src/shared/page/page.css +0 -47
  215. package/src/shared/page/page.test.tsx +0 -97
  216. package/src/shared/page/page.tsx +0 -91
  217. package/src/shared/page/pageUiConfig.test.ts +0 -112
  218. package/src/shared/page/pageUiConfig.ts +0 -64
  219. package/src/shared/page/verifiedByIncode.css +0 -5
  220. package/src/shared/page/verifiedByIncode.tsx +0 -75
  221. package/src/shared/spacer/spacer.css +0 -149
  222. package/src/shared/spacer/spacer.test.tsx +0 -143
  223. package/src/shared/spacer/spacer.tsx +0 -88
  224. package/src/shared/spinner/index.ts +0 -2
  225. package/src/shared/spinner/spinner.css +0 -28
  226. package/src/shared/spinner/spinner.test.tsx +0 -82
  227. package/src/shared/spinner/spinner.tsx +0 -65
  228. package/src/shared/title/title.css +0 -7
  229. package/src/shared/title/title.tsx +0 -12
  230. package/src/shared/uiConfig/uiConfig.ts +0 -36
  231. package/src/shared/webComponent/incodeModule.ts +0 -29
  232. package/src/shared/webComponent/registerIncodeElement.ts +0 -15
  233. package/src/styles/__mocks__/fetchTheme.ts +0 -19
  234. package/src/styles/applyTheme.ts +0 -37
  235. package/src/styles/cn.test.tsx +0 -57
  236. package/src/styles/cn.tsx +0 -21
  237. package/src/styles/core.css +0 -12
  238. package/src/styles/fetchTheme.test.ts +0 -390
  239. package/src/styles/fetchTheme.ts +0 -88
  240. package/src/styles/generatePalette.ts +0 -111
  241. package/src/styles/reset.css +0 -65
  242. package/src/styles/resolveCssVariableToHex.ts +0 -28
  243. package/src/styles/tailwind.css +0 -291
  244. package/src/styles/themeTypes.ts +0 -18
  245. package/src/styles/tokens/colors.css +0 -190
  246. package/src/styles/tokens/components.css +0 -174
  247. package/src/styles/tokens/index.css +0 -4
  248. package/src/styles/tokens/primitives.css +0 -129
  249. package/src/styles/tokens/semantic.css +0 -51
  250. package/src/svg.d.ts +0 -4
  251. package/src/types/assets.d.ts +0 -1
  252. package/src/types/custom-elements.d.ts +0 -104
  253. package/tsconfig.json +0 -22
  254. package/vite.config.ts +0 -260
  255. package/vitest.config.ts +0 -40
  256. package/vitest.setup.ts +0 -16
@@ -1,458 +0,0 @@
1
- import type { SelfieState } from '@incodetech/core/selfie';
2
- import { render, waitFor } from '@testing-library/preact';
3
- import { beforeEach, describe, expect, it, vi } from 'vitest';
4
-
5
- const mockRegister = vi.fn();
6
- const mockNextStep = vi.fn();
7
- const mockRequestPermission = vi.fn();
8
- const mockGoToLearnMore = vi.fn();
9
- const mockBack = vi.fn();
10
- const mockQuitProcess = vi.fn();
11
- const mockRetryCapture = vi.fn();
12
- const mockReset = vi.fn();
13
- const mockLoad = vi.fn();
14
-
15
- const createMockManager = () => ({
16
- nextStep: mockNextStep,
17
- requestPermission: mockRequestPermission,
18
- goToLearnMore: mockGoToLearnMore,
19
- back: mockBack,
20
- close: mockQuitProcess,
21
- retryCapture: mockRetryCapture,
22
- reset: mockReset,
23
- load: mockLoad,
24
- });
25
-
26
- let currentMockState: SelfieState = { status: 'idle' };
27
-
28
- vi.mock('@incodetech/core', () => ({
29
- api: {
30
- get: vi.fn().mockResolvedValue({
31
- data: {
32
- theme: 'https://example.com/theme.json',
33
- 'logo.png': 'https://example.com/logo.png',
34
- },
35
- }),
36
- },
37
- getDeviceClass: vi.fn(() => 'desktop'),
38
- getBrowser: vi.fn(() => 'chrome'),
39
- }));
40
-
41
- vi.mock('preact-custom-element', () => ({
42
- default: mockRegister,
43
- }));
44
-
45
- vi.mock('../hooks', () => ({
46
- useManager: () => [currentMockState, createMockManager()],
47
- }));
48
-
49
- vi.mock('./tutorial', async () => {
50
- const actual =
51
- await vi.importActual<typeof import('./tutorial')>('./tutorial');
52
- return {
53
- ...actual,
54
- Tutorial: ({ manager }: { manager: { nextStep: () => void } }) => (
55
- <div data-testid="tutorial">
56
- <button
57
- type="button"
58
- data-testid="tutorial-continue"
59
- onClick={() => manager.nextStep()}
60
- >
61
- Continue
62
- </button>
63
- </div>
64
- ),
65
- };
66
- });
67
-
68
- vi.mock('./permissions/permissions', () => ({
69
- Permissions: ({ permissionStatus }: { permissionStatus: string }) => (
70
- <div data-testid="permissions" data-permission-status={permissionStatus}>
71
- Permissions Component
72
- </div>
73
- ),
74
- }));
75
-
76
- vi.mock('./capture', () => ({
77
- Capture: ({ onFinish }: { onFinish: () => void }) => (
78
- <div data-testid="capture">
79
- <button type="button" data-testid="capture-finish" onClick={onFinish}>
80
- Finish
81
- </button>
82
- </div>
83
- ),
84
- }));
85
-
86
- const mockConfig = {
87
- showTutorial: true,
88
- showPreview: false,
89
- assistedOnboarding: false,
90
- enableFaceRecording: false,
91
- autoCaptureTimeout: 30,
92
- captureAttempts: 3,
93
- validateLenses: false,
94
- validateFaceMask: false,
95
- validateHeadCover: false,
96
- validateClosedEyes: false,
97
- validateBrightness: false,
98
- deepsightLiveness: 'SINGLE_FRAME' as const,
99
- };
100
-
101
- describe('Selfie', () => {
102
- beforeEach(() => {
103
- vi.clearAllMocks();
104
- currentMockState = { status: 'idle' };
105
- });
106
-
107
- describe('custom element registration', () => {
108
- it('registers with correct tag name and props', async () => {
109
- vi.resetModules();
110
- mockRegister.mockClear();
111
- const module = await import('./selfie');
112
- expect(module).toBeDefined();
113
- await new Promise((resolve) => setTimeout(resolve, 0));
114
- expect(mockRegister).toHaveBeenCalledWith(
115
- expect.any(Function),
116
- 'incode-selfie',
117
- ['config', 'onFinish', 'onError'],
118
- { shadow: false },
119
- );
120
- }, 10000);
121
- });
122
-
123
- describe('container rendering', () => {
124
- it('renders with IncodeComponent class', async () => {
125
- const { Selfie } = await import('./selfie');
126
- const { container } = render(
127
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
128
- );
129
- expect(container.querySelector('.IncodeComponent')).toBeTruthy();
130
- });
131
-
132
- it('renders nothing when config is undefined', async () => {
133
- const { Selfie } = await import('./selfie');
134
- const { container } = render(
135
- <Selfie
136
- config={undefined as unknown as typeof mockConfig}
137
- onFinish={() => {}}
138
- onError={() => {}}
139
- />,
140
- );
141
- const incodeComponent = container.querySelector('.IncodeComponent');
142
- expect(incodeComponent?.children.length).toBe(0);
143
- });
144
- });
145
-
146
- describe('state-based rendering', () => {
147
- it('renders nothing when status is idle', async () => {
148
- currentMockState = { status: 'idle' };
149
- vi.resetModules();
150
- const { Selfie } = await import('./selfie');
151
- const { queryByTestId } = render(
152
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
153
- );
154
- expect(queryByTestId('tutorial')).toBeNull();
155
- expect(queryByTestId('permissions')).toBeNull();
156
- expect(queryByTestId('capture')).toBeNull();
157
- });
158
-
159
- it('renders nothing when status is loading', async () => {
160
- currentMockState = { status: 'loading' };
161
- vi.resetModules();
162
- const { Selfie } = await import('./selfie');
163
- const { queryByTestId } = render(
164
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
165
- );
166
- expect(queryByTestId('tutorial')).toBeNull();
167
- expect(queryByTestId('permissions')).toBeNull();
168
- expect(queryByTestId('capture')).toBeNull();
169
- });
170
-
171
- it('renders Tutorial when tutorial is loading', async () => {
172
- currentMockState = { status: 'tutorial' };
173
- vi.resetModules();
174
- const { Selfie } = await import('./selfie');
175
- const { getByTestId, queryByTestId } = render(
176
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
177
- );
178
- await waitFor(() => {
179
- expect(getByTestId('tutorial')).toBeTruthy();
180
- });
181
- expect(queryByTestId('permissions')).toBeNull();
182
- expect(queryByTestId('capture')).toBeNull();
183
- });
184
-
185
- it('renders Tutorial when status is tutorial', async () => {
186
- currentMockState = { status: 'tutorial' };
187
- vi.resetModules();
188
- const { Selfie } = await import('./selfie');
189
- const { getByTestId, queryByTestId } = render(
190
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
191
- );
192
- await waitFor(() => {
193
- expect(getByTestId('tutorial')).toBeTruthy();
194
- });
195
- expect(queryByTestId('permissions')).toBeNull();
196
- expect(queryByTestId('capture')).toBeNull();
197
- });
198
-
199
- it('renders Permissions when status is permissions', async () => {
200
- currentMockState = {
201
- status: 'permissions',
202
- permissionStatus: 'idle',
203
- };
204
- vi.resetModules();
205
- const { Selfie } = await import('./selfie');
206
- const { container, queryByTestId } = render(
207
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
208
- );
209
- expect(container.querySelector('.IncodePermissionsPage')).toBeTruthy();
210
- expect(queryByTestId('tutorial')).toBeNull();
211
- expect(queryByTestId('capture')).toBeNull();
212
- });
213
-
214
- it('passes permissionStatus to Permissions component', async () => {
215
- currentMockState = {
216
- status: 'permissions',
217
- permissionStatus: 'denied',
218
- };
219
- vi.resetModules();
220
- const { Selfie } = await import('./selfie');
221
- const { container } = render(
222
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
223
- );
224
- expect(container.querySelector('.IncodeDeniedPage')).toBeTruthy();
225
- });
226
-
227
- it('renders Capture when status is capture', async () => {
228
- currentMockState = {
229
- status: 'capture',
230
- captureStatus: 'detecting',
231
- stream: undefined,
232
- detectionStatus: 'detecting',
233
- debugFrame: undefined,
234
- attemptsRemaining: 3,
235
- uploadError: undefined,
236
- };
237
- vi.resetModules();
238
- const { Selfie } = await import('./selfie');
239
- const { getByTestId, queryByTestId } = render(
240
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
241
- );
242
- expect(getByTestId('capture')).toBeTruthy();
243
- expect(queryByTestId('tutorial')).toBeNull();
244
- expect(queryByTestId('permissions')).toBeNull();
245
- });
246
-
247
- it('renders nothing when status is finished', async () => {
248
- currentMockState = { status: 'finished' };
249
- vi.resetModules();
250
- const { Selfie } = await import('./selfie');
251
- const { queryByTestId } = render(
252
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
253
- );
254
- expect(queryByTestId('tutorial')).toBeNull();
255
- expect(queryByTestId('permissions')).toBeNull();
256
- expect(queryByTestId('capture')).toBeNull();
257
- });
258
-
259
- it('renders nothing when status is closed', async () => {
260
- currentMockState = { status: 'closed' };
261
- vi.resetModules();
262
- const { Selfie } = await import('./selfie');
263
- const { queryByTestId } = render(
264
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
265
- );
266
- expect(queryByTestId('tutorial')).toBeNull();
267
- expect(queryByTestId('permissions')).toBeNull();
268
- expect(queryByTestId('capture')).toBeNull();
269
- });
270
-
271
- it('renders nothing when status is error', async () => {
272
- currentMockState = { status: 'error', error: 'Some error' };
273
- vi.resetModules();
274
- const { Selfie } = await import('./selfie');
275
- const { queryByTestId } = render(
276
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
277
- );
278
- expect(queryByTestId('tutorial')).toBeNull();
279
- expect(queryByTestId('permissions')).toBeNull();
280
- expect(queryByTestId('capture')).toBeNull();
281
- });
282
-
283
- it('renders nothing for unknown state', async () => {
284
- currentMockState = { status: 'unknown' } as unknown as SelfieState;
285
- vi.resetModules();
286
- const { Selfie } = await import('./selfie');
287
- const { queryByTestId } = render(
288
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
289
- );
290
- expect(queryByTestId('tutorial')).toBeNull();
291
- expect(queryByTestId('permissions')).toBeNull();
292
- expect(queryByTestId('capture')).toBeNull();
293
- });
294
- });
295
-
296
- describe('callbacks', () => {
297
- it('calls onFinish when status is finished', async () => {
298
- currentMockState = { status: 'finished' };
299
- vi.resetModules();
300
- const { Selfie } = await import('./selfie');
301
- const onFinish = vi.fn();
302
- render(
303
- <Selfie config={mockConfig} onFinish={onFinish} onError={() => {}} />,
304
- );
305
- await waitFor(() => {
306
- expect(onFinish).toHaveBeenCalledTimes(1);
307
- });
308
- });
309
-
310
- it('calls onError with undefined when status is closed', async () => {
311
- currentMockState = { status: 'closed' };
312
- vi.resetModules();
313
- const { Selfie } = await import('./selfie');
314
- const onError = vi.fn();
315
- render(
316
- <Selfie config={mockConfig} onFinish={() => {}} onError={onError} />,
317
- );
318
- await waitFor(() => {
319
- expect(onError).toHaveBeenCalledWith(undefined);
320
- });
321
- });
322
-
323
- it('calls onError with error message when status is error', async () => {
324
- currentMockState = { status: 'error', error: 'Permission denied' };
325
- vi.resetModules();
326
- const { Selfie } = await import('./selfie');
327
- const onError = vi.fn();
328
- render(
329
- <Selfie config={mockConfig} onFinish={() => {}} onError={onError} />,
330
- );
331
- await waitFor(() => {
332
- expect(onError).toHaveBeenCalledWith('Permission denied');
333
- });
334
- });
335
-
336
- it('does not throw when onFinish is undefined and status is finished', async () => {
337
- currentMockState = { status: 'finished' };
338
- vi.resetModules();
339
- const { Selfie } = await import('./selfie');
340
- expect(() => {
341
- render(
342
- <Selfie
343
- config={mockConfig}
344
- onFinish={undefined}
345
- onError={undefined}
346
- />,
347
- );
348
- }).not.toThrow();
349
- });
350
-
351
- it('does not throw when onError is undefined and status is closed', async () => {
352
- currentMockState = { status: 'closed' };
353
- vi.resetModules();
354
- const { Selfie } = await import('./selfie');
355
- expect(() => {
356
- render(
357
- <Selfie
358
- config={mockConfig}
359
- onFinish={undefined}
360
- onError={undefined}
361
- />,
362
- );
363
- }).not.toThrow();
364
- });
365
- });
366
-
367
- describe('manager interactions', () => {
368
- it('calls manager.nextStep when Tutorial onContinue is triggered', async () => {
369
- currentMockState = { status: 'tutorial' };
370
- vi.resetModules();
371
- const { Selfie } = await import('./selfie');
372
- const { getByTestId } = render(
373
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
374
- );
375
- await waitFor(() => {
376
- expect(getByTestId('tutorial-continue')).toBeTruthy();
377
- });
378
- getByTestId('tutorial-continue').click();
379
- expect(mockNextStep).toHaveBeenCalledTimes(1);
380
- });
381
-
382
- it('calls onFinish prop when Capture onFinish is triggered', async () => {
383
- currentMockState = {
384
- status: 'capture',
385
- captureStatus: 'detecting',
386
- stream: undefined,
387
- detectionStatus: 'detecting',
388
- debugFrame: undefined,
389
- attemptsRemaining: 3,
390
- uploadError: undefined,
391
- };
392
- vi.resetModules();
393
- const { Selfie } = await import('./selfie');
394
- const onFinish = vi.fn();
395
- const { getByTestId } = render(
396
- <Selfie config={mockConfig} onFinish={onFinish} onError={() => {}} />,
397
- );
398
- getByTestId('capture-finish').click();
399
- expect(onFinish).toHaveBeenCalledTimes(1);
400
- });
401
- });
402
-
403
- describe('permissions substates', () => {
404
- it('renders Permissions with permissionStatus=idle', async () => {
405
- currentMockState = {
406
- status: 'permissions',
407
- permissionStatus: 'idle',
408
- };
409
- vi.resetModules();
410
- const { Selfie } = await import('./selfie');
411
- const { container } = render(
412
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
413
- );
414
- expect(container.querySelector('.IncodePermissionsPage')).toBeTruthy();
415
- });
416
-
417
- it('renders Permissions with permissionStatus=requesting', async () => {
418
- currentMockState = {
419
- status: 'permissions',
420
- permissionStatus: 'requesting',
421
- };
422
- vi.resetModules();
423
- const { Selfie } = await import('./selfie');
424
- const { container } = render(
425
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
426
- );
427
- expect(
428
- container.querySelector('.IncodePermissionsRequestingPage'),
429
- ).toBeTruthy();
430
- });
431
-
432
- it('renders Permissions with permissionStatus=denied', async () => {
433
- currentMockState = {
434
- status: 'permissions',
435
- permissionStatus: 'denied',
436
- };
437
- vi.resetModules();
438
- const { Selfie } = await import('./selfie');
439
- const { container } = render(
440
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
441
- );
442
- expect(container.querySelector('.IncodeDeniedPage')).toBeTruthy();
443
- });
444
-
445
- it('renders Permissions with permissionStatus=learnMore', async () => {
446
- currentMockState = {
447
- status: 'permissions',
448
- permissionStatus: 'learnMore',
449
- };
450
- vi.resetModules();
451
- const { Selfie } = await import('./selfie');
452
- const { container } = render(
453
- <Selfie config={mockConfig} onFinish={() => {}} onError={() => {}} />,
454
- );
455
- expect(container.querySelector('.IncodeLearnMorePage')).toBeTruthy();
456
- });
457
- });
458
- });
@@ -1,83 +0,0 @@
1
- import './styles.css';
2
- import {
3
- createSelfieManager,
4
- type SelfieConfig,
5
- } from '@incodetech/core/selfie';
6
- import type { FC } from 'preact/compat';
7
- import { useManager } from '@/hooks';
8
- import { Permissions } from '../permissions/permissions';
9
- import { IncodeComponent } from '../shared/componentRoot/incodeComponent';
10
- import {
11
- type IncodeModuleProps,
12
- registerIncodeModuleElement,
13
- } from '../shared/webComponent/incodeModule';
14
- import { Capture } from './capture';
15
- import { Tutorial } from './tutorial';
16
-
17
- type SelfieContentProps = {
18
- config: SelfieConfig;
19
- onFinish?: () => void;
20
- onError?: (error: string | undefined) => void;
21
- };
22
-
23
- const SelfieContent: FC<SelfieContentProps> = ({
24
- config,
25
- onFinish,
26
- onError,
27
- }) => {
28
- const [state, manager] = useManager(() => createSelfieManager({ config }));
29
-
30
- if (state.status === 'idle' || state.status === 'loading') {
31
- return null;
32
- }
33
-
34
- if (state.status === 'tutorial') {
35
- return <Tutorial manager={manager} />;
36
- }
37
-
38
- if (state.status === 'permissions') {
39
- return (
40
- <Permissions
41
- manager={manager}
42
- permissionStatus={state.permissionStatus}
43
- />
44
- );
45
- }
46
-
47
- if (state.status === 'capture') {
48
- return (
49
- <Capture manager={manager} state={state} onFinish={() => onFinish?.()} />
50
- );
51
- }
52
-
53
- if (state.status === 'finished') {
54
- onFinish?.();
55
- return null;
56
- }
57
-
58
- if (state.status === 'closed') {
59
- onError?.(undefined);
60
- return null;
61
- }
62
-
63
- if (state.status === 'error') {
64
- onError?.(state.error);
65
- return null;
66
- }
67
-
68
- return null;
69
- };
70
-
71
- type SelfieProps = IncodeModuleProps<SelfieConfig>;
72
-
73
- export const Selfie: FC<SelfieProps> = ({ config, onFinish, onError }) => {
74
- return (
75
- <IncodeComponent>
76
- {config ? (
77
- <SelfieContent config={config} onFinish={onFinish} onError={onError} />
78
- ) : null}
79
- </IncodeComponent>
80
- );
81
- };
82
-
83
- registerIncodeModuleElement(Selfie, 'incode-selfie');