@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,264 +0,0 @@
|
|
|
1
|
-
import { fireEvent, render, screen } from '@testing-library/preact';
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { EmailInput } from './emailInput';
|
|
4
|
-
|
|
5
|
-
describe('EmailInput', () => {
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
onEmailChange: vi.fn(),
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
vi.clearAllMocks();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('Rendering', () => {
|
|
15
|
-
it('renders email input field', () => {
|
|
16
|
-
render(<EmailInput {...defaultProps} />);
|
|
17
|
-
|
|
18
|
-
const input = screen.getByTestId('email-input');
|
|
19
|
-
expect(input).toBeTruthy();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('renders with placeholder text', () => {
|
|
23
|
-
render(<EmailInput {...defaultProps} />);
|
|
24
|
-
|
|
25
|
-
const input = screen.getByTestId('email-input') as HTMLInputElement;
|
|
26
|
-
expect(input.placeholder).toBe('Email');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('renders label for accessibility', () => {
|
|
30
|
-
render(<EmailInput {...defaultProps} />);
|
|
31
|
-
|
|
32
|
-
const label = screen.getByText('Email');
|
|
33
|
-
expect(label).toBeTruthy();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('input has correct type', () => {
|
|
37
|
-
render(<EmailInput {...defaultProps} />);
|
|
38
|
-
|
|
39
|
-
const input = screen.getByTestId('email-input') as HTMLInputElement;
|
|
40
|
-
expect(input.type).toBe('email');
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('Email input behavior', () => {
|
|
45
|
-
it('calls onEmailChange when input changes', () => {
|
|
46
|
-
const onEmailChange = vi.fn();
|
|
47
|
-
render(<EmailInput {...defaultProps} onEmailChange={onEmailChange} />);
|
|
48
|
-
|
|
49
|
-
const input = screen.getByTestId('email-input');
|
|
50
|
-
fireEvent.input(input, { target: { value: 'user@example.com' } });
|
|
51
|
-
|
|
52
|
-
expect(onEmailChange).toHaveBeenCalled();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('validates valid email and reports isValid as true', () => {
|
|
56
|
-
const onEmailChange = vi.fn();
|
|
57
|
-
render(<EmailInput {...defaultProps} onEmailChange={onEmailChange} />);
|
|
58
|
-
|
|
59
|
-
const input = screen.getByTestId('email-input');
|
|
60
|
-
fireEvent.input(input, { target: { value: 'user@example.com' } });
|
|
61
|
-
|
|
62
|
-
expect(onEmailChange).toHaveBeenCalledWith('user@example.com', true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('validates invalid email and reports isValid as false', () => {
|
|
66
|
-
const onEmailChange = vi.fn();
|
|
67
|
-
render(<EmailInput {...defaultProps} onEmailChange={onEmailChange} />);
|
|
68
|
-
|
|
69
|
-
const input = screen.getByTestId('email-input');
|
|
70
|
-
fireEvent.input(input, { target: { value: 'invalid-email' } });
|
|
71
|
-
|
|
72
|
-
expect(onEmailChange).toHaveBeenCalledWith('invalid-email', false);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('validates email without @ as invalid', () => {
|
|
76
|
-
const onEmailChange = vi.fn();
|
|
77
|
-
render(<EmailInput {...defaultProps} onEmailChange={onEmailChange} />);
|
|
78
|
-
|
|
79
|
-
const input = screen.getByTestId('email-input');
|
|
80
|
-
fireEvent.input(input, { target: { value: 'userexample.com' } });
|
|
81
|
-
|
|
82
|
-
expect(onEmailChange).toHaveBeenCalledWith('userexample.com', false);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('validates email without domain as invalid', () => {
|
|
86
|
-
const onEmailChange = vi.fn();
|
|
87
|
-
render(<EmailInput {...defaultProps} onEmailChange={onEmailChange} />);
|
|
88
|
-
|
|
89
|
-
const input = screen.getByTestId('email-input');
|
|
90
|
-
fireEvent.input(input, { target: { value: 'user@' } });
|
|
91
|
-
|
|
92
|
-
expect(onEmailChange).toHaveBeenCalledWith('user@', false);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('trims whitespace from email', () => {
|
|
96
|
-
const onEmailChange = vi.fn();
|
|
97
|
-
render(<EmailInput {...defaultProps} onEmailChange={onEmailChange} />);
|
|
98
|
-
|
|
99
|
-
const input = screen.getByTestId('email-input');
|
|
100
|
-
fireEvent.input(input, { target: { value: ' user@example.com ' } });
|
|
101
|
-
|
|
102
|
-
expect(onEmailChange).toHaveBeenCalledWith('user@example.com', true);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('empty email is invalid', () => {
|
|
106
|
-
const onEmailChange = vi.fn();
|
|
107
|
-
render(<EmailInput {...defaultProps} onEmailChange={onEmailChange} />);
|
|
108
|
-
|
|
109
|
-
const input = screen.getByTestId('email-input');
|
|
110
|
-
fireEvent.input(input, { target: { value: '' } });
|
|
111
|
-
|
|
112
|
-
expect(onEmailChange).toHaveBeenCalledWith('', false);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('Prefilled email', () => {
|
|
117
|
-
it('populates input with prefilled email', () => {
|
|
118
|
-
render(
|
|
119
|
-
<EmailInput {...defaultProps} prefilledEmail="prefilled@example.com" />,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const input = screen.getByTestId('email-input') as HTMLInputElement;
|
|
123
|
-
expect(input.value).toBe('prefilled@example.com');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('calls onEmailChange with prefilled email on mount', () => {
|
|
127
|
-
const onEmailChange = vi.fn();
|
|
128
|
-
render(
|
|
129
|
-
<EmailInput
|
|
130
|
-
{...defaultProps}
|
|
131
|
-
prefilledEmail="prefilled@example.com"
|
|
132
|
-
onEmailChange={onEmailChange}
|
|
133
|
-
/>,
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
expect(onEmailChange).toHaveBeenCalledWith('prefilled@example.com', true);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('validates prefilled email', () => {
|
|
140
|
-
const onEmailChange = vi.fn();
|
|
141
|
-
render(
|
|
142
|
-
<EmailInput
|
|
143
|
-
{...defaultProps}
|
|
144
|
-
prefilledEmail="invalid-prefilled"
|
|
145
|
-
onEmailChange={onEmailChange}
|
|
146
|
-
/>,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
expect(onEmailChange).toHaveBeenCalledWith('invalid-prefilled', false);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('Error state', () => {
|
|
154
|
-
it('displays error message when emailError is set', () => {
|
|
155
|
-
render(
|
|
156
|
-
<EmailInput {...defaultProps} emailError="Invalid email address" />,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
expect(screen.getByTestId('email-error')).toBeTruthy();
|
|
160
|
-
expect(screen.getByText('Invalid email address')).toBeTruthy();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('shows error styling on input wrapper', () => {
|
|
164
|
-
const { container } = render(
|
|
165
|
-
<EmailInput {...defaultProps} emailError="Error" />,
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
const wrapper = container.querySelector('.IncodeEmailInputWrapperError');
|
|
169
|
-
expect(wrapper).toBeTruthy();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('does not show error element when no error', () => {
|
|
173
|
-
render(<EmailInput {...defaultProps} />);
|
|
174
|
-
|
|
175
|
-
expect(screen.queryByTestId('email-error')).toBeNull();
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('sets aria-invalid to true when error is present', () => {
|
|
179
|
-
render(<EmailInput {...defaultProps} emailError="Error" />);
|
|
180
|
-
|
|
181
|
-
const input = screen.getByTestId('email-input');
|
|
182
|
-
expect(input.getAttribute('aria-invalid')).toBe('true');
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('sets aria-invalid to false when no error', () => {
|
|
186
|
-
render(<EmailInput {...defaultProps} />);
|
|
187
|
-
|
|
188
|
-
const input = screen.getByTestId('email-input');
|
|
189
|
-
expect(input.getAttribute('aria-invalid')).toBe('false');
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('Disabled state', () => {
|
|
194
|
-
it('disables input when disabled prop is true', () => {
|
|
195
|
-
render(<EmailInput {...defaultProps} disabled />);
|
|
196
|
-
|
|
197
|
-
const input = screen.getByTestId('email-input') as HTMLInputElement;
|
|
198
|
-
expect(input.disabled).toBe(true);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('shows disabled styling', () => {
|
|
202
|
-
const { container } = render(<EmailInput {...defaultProps} disabled />);
|
|
203
|
-
|
|
204
|
-
const wrapper = container.querySelector(
|
|
205
|
-
'.IncodeEmailInputWrapperDisabled',
|
|
206
|
-
);
|
|
207
|
-
expect(wrapper).toBeTruthy();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('does not disable input by default', () => {
|
|
211
|
-
render(<EmailInput {...defaultProps} />);
|
|
212
|
-
|
|
213
|
-
const input = screen.getByTestId('email-input') as HTMLInputElement;
|
|
214
|
-
expect(input.disabled).toBe(false);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
describe('Accessibility', () => {
|
|
219
|
-
it('has aria-label for screen readers', () => {
|
|
220
|
-
render(<EmailInput {...defaultProps} />);
|
|
221
|
-
|
|
222
|
-
const input = screen.getByTestId('email-input');
|
|
223
|
-
expect(input.getAttribute('aria-label')).toBe('Email address');
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('has aria-describedby when error is present', () => {
|
|
227
|
-
render(<EmailInput {...defaultProps} emailError="Error message" />);
|
|
228
|
-
|
|
229
|
-
const input = screen.getByTestId('email-input');
|
|
230
|
-
expect(input.getAttribute('aria-describedby')).toBe('email-error');
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('does not have aria-describedby when no error', () => {
|
|
234
|
-
render(<EmailInput {...defaultProps} />);
|
|
235
|
-
|
|
236
|
-
const input = screen.getByTestId('email-input');
|
|
237
|
-
expect(input.getAttribute('aria-describedby')).toBeNull();
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('error message has role="alert"', () => {
|
|
241
|
-
render(<EmailInput {...defaultProps} emailError="Error" />);
|
|
242
|
-
|
|
243
|
-
const error = screen.getByTestId('email-error');
|
|
244
|
-
expect(error.getAttribute('role')).toBe('alert');
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('has autocomplete attribute for email', () => {
|
|
248
|
-
render(<EmailInput {...defaultProps} />);
|
|
249
|
-
|
|
250
|
-
const input = screen.getByTestId('email-input');
|
|
251
|
-
expect(input.getAttribute('autocomplete')).toBe('email');
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('label is associated with input', () => {
|
|
255
|
-
render(<EmailInput {...defaultProps} />);
|
|
256
|
-
|
|
257
|
-
const input = screen.getByTestId('email-input');
|
|
258
|
-
expect(input.getAttribute('id')).toBe('email-input');
|
|
259
|
-
|
|
260
|
-
const label = document.querySelector('label[for="email-input"]');
|
|
261
|
-
expect(label).toBeTruthy();
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
});
|
package/src/email/emailInput.tsx
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { FC } from 'preact/compat';
|
|
2
|
-
import { useEffect, useState } from 'preact/hooks';
|
|
3
|
-
import { Spacer } from '../shared/spacer/spacer';
|
|
4
|
-
import './styles.css';
|
|
5
|
-
|
|
6
|
-
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
7
|
-
|
|
8
|
-
export type EmailInputProps = {
|
|
9
|
-
prefilledEmail?: string;
|
|
10
|
-
emailError?: string;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
onEmailChange: (email: string, isValid: boolean) => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const EmailInput: FC<EmailInputProps> = ({
|
|
16
|
-
prefilledEmail,
|
|
17
|
-
emailError,
|
|
18
|
-
disabled = false,
|
|
19
|
-
onEmailChange,
|
|
20
|
-
}) => {
|
|
21
|
-
const [email, setEmail] = useState('');
|
|
22
|
-
|
|
23
|
-
// Handle prefilled email
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (prefilledEmail) {
|
|
26
|
-
setEmail(prefilledEmail);
|
|
27
|
-
const isValid = EMAIL_REGEX.test(prefilledEmail.trim());
|
|
28
|
-
onEmailChange(prefilledEmail.trim(), isValid);
|
|
29
|
-
}
|
|
30
|
-
}, [prefilledEmail, onEmailChange]);
|
|
31
|
-
|
|
32
|
-
const handleEmailChange = (e: Event) => {
|
|
33
|
-
const target = e.target as HTMLInputElement;
|
|
34
|
-
const value = target.value;
|
|
35
|
-
setEmail(value);
|
|
36
|
-
|
|
37
|
-
const trimmedValue = value.trim();
|
|
38
|
-
const isValid = trimmedValue.length > 0 && EMAIL_REGEX.test(trimmedValue);
|
|
39
|
-
onEmailChange(trimmedValue, isValid);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const errorId = emailError ? 'email-error' : undefined;
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<div class="IncodeEmailInput">
|
|
46
|
-
<div class="IncodeEmailInputContainer">
|
|
47
|
-
<div
|
|
48
|
-
class={`IncodeEmailInputWrapper ${emailError ? 'IncodeEmailInputWrapperError' : ''} ${disabled ? 'IncodeEmailInputWrapperDisabled' : ''}`}
|
|
49
|
-
>
|
|
50
|
-
<label for="email-input" class="IncodeEmailInputLabel">
|
|
51
|
-
Email
|
|
52
|
-
</label>
|
|
53
|
-
<input
|
|
54
|
-
id="email-input"
|
|
55
|
-
type="email"
|
|
56
|
-
value={email}
|
|
57
|
-
onInput={handleEmailChange}
|
|
58
|
-
placeholder="Email"
|
|
59
|
-
disabled={disabled}
|
|
60
|
-
class="IncodeEmailInputField"
|
|
61
|
-
data-testid="email-input"
|
|
62
|
-
aria-label="Email address"
|
|
63
|
-
aria-invalid={emailError ? 'true' : 'false'}
|
|
64
|
-
aria-describedby={errorId}
|
|
65
|
-
autocomplete="email"
|
|
66
|
-
/>
|
|
67
|
-
</div>
|
|
68
|
-
|
|
69
|
-
{emailError && (
|
|
70
|
-
<>
|
|
71
|
-
<Spacer size={8} />
|
|
72
|
-
<p
|
|
73
|
-
id={errorId}
|
|
74
|
-
class="IncodeEmailInputError"
|
|
75
|
-
data-testid="email-error"
|
|
76
|
-
role="alert"
|
|
77
|
-
>
|
|
78
|
-
{emailError}
|
|
79
|
-
</p>
|
|
80
|
-
</>
|
|
81
|
-
)}
|
|
82
|
-
</div>
|
|
83
|
-
</div>
|
|
84
|
-
);
|
|
85
|
-
};
|
package/src/email/styles.css
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
@reference "../styles/tailwind.css";
|
|
2
|
-
|
|
3
|
-
/* Email Page Layout */
|
|
4
|
-
.IncodeEmailPage .IncodePageContent {
|
|
5
|
-
@apply pt-32 pb-16;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.IncodeEmailInput {
|
|
9
|
-
@apply flex flex-col items-center w-full;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.IncodeEmailInputContainer {
|
|
13
|
-
@apply flex flex-col items-center w-full;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/* Email Input Wrapper */
|
|
17
|
-
.IncodeEmailInputWrapper {
|
|
18
|
-
@apply flex flex-col w-full max-w-[340px];
|
|
19
|
-
@apply border border-input-border-default rounded-small bg-input-surface-default transition-colors duration-200;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.IncodeEmailInputWrapper:focus-within {
|
|
23
|
-
@apply border-input-border-active;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.IncodeEmailInputWrapper.IncodeEmailInputWrapperError {
|
|
27
|
-
@apply border-input-border-negative;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.IncodeEmailInputWrapper.IncodeEmailInputWrapperDisabled {
|
|
31
|
-
@apply border-input-border-disabled bg-input-surface-disabled;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/* Email Input Label */
|
|
35
|
-
.IncodeEmailInputLabel {
|
|
36
|
-
@apply sr-only;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/* Email Input Field */
|
|
40
|
-
.IncodeEmailInputField {
|
|
41
|
-
@apply w-full py-16 px-16 text-18 font-medium border-none outline-none bg-transparent text-input-text-field-default;
|
|
42
|
-
@apply rounded-small;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.IncodeEmailInputField::placeholder {
|
|
46
|
-
@apply text-input-text-field-placeholder font-medium;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.IncodeEmailInputField:disabled {
|
|
50
|
-
@apply cursor-not-allowed text-input-text-field-disabled;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.IncodeEmailInputField:focus {
|
|
54
|
-
@apply outline-none;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.IncodeEmailInputError {
|
|
58
|
-
@apply text-input-text-helper-negative text-14 text-center m-0 font-medium;
|
|
59
|
-
}
|