@proteinjs/user-ui 1.4.1 → 1.5.0
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/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/dist/generated/index.d.ts +0 -9
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +1 -10
- package/dist/generated/index.js.map +1 -1
- package/dist/src/auth/AuthApi.d.ts +12 -0
- package/dist/src/auth/AuthApi.d.ts.map +1 -0
- package/dist/src/auth/AuthApi.js +151 -0
- package/dist/src/auth/AuthApi.js.map +1 -0
- package/dist/src/auth/AuthButton.d.ts +13 -0
- package/dist/src/auth/AuthButton.d.ts.map +1 -0
- package/dist/src/auth/AuthButton.js +21 -0
- package/dist/src/auth/AuthButton.js.map +1 -0
- package/dist/src/auth/AuthFormError.d.ts +6 -0
- package/dist/src/auth/AuthFormError.d.ts.map +1 -0
- package/dist/src/auth/AuthFormError.js +18 -0
- package/dist/src/auth/AuthFormError.js.map +1 -0
- package/dist/src/auth/AuthLayout.d.ts +17 -0
- package/dist/src/auth/AuthLayout.d.ts.map +1 -0
- package/dist/src/auth/AuthLayout.js +52 -0
- package/dist/src/auth/AuthLayout.js.map +1 -0
- package/dist/src/auth/AuthMessagePanel.d.ts +13 -0
- package/dist/src/auth/AuthMessagePanel.d.ts.map +1 -0
- package/dist/src/auth/AuthMessagePanel.js +22 -0
- package/dist/src/auth/AuthMessagePanel.js.map +1 -0
- package/dist/src/auth/AuthTextField.d.ts +21 -0
- package/dist/src/auth/AuthTextField.d.ts.map +1 -0
- package/dist/src/auth/AuthTextField.js +60 -0
- package/dist/src/auth/AuthTextField.js.map +1 -0
- package/dist/src/auth/AuthValidation.d.ts +18 -0
- package/dist/src/auth/AuthValidation.d.ts.map +1 -0
- package/dist/src/auth/AuthValidation.js +38 -0
- package/dist/src/auth/AuthValidation.js.map +1 -0
- package/dist/src/pages/ForgotPassword.d.ts.map +1 -1
- package/dist/src/pages/ForgotPassword.js +77 -75
- package/dist/src/pages/ForgotPassword.js.map +1 -1
- package/dist/src/pages/Login.d.ts.map +1 -1
- package/dist/src/pages/Login.js +79 -97
- package/dist/src/pages/Login.js.map +1 -1
- package/dist/src/pages/PasswordReset.d.ts.map +1 -1
- package/dist/src/pages/PasswordReset.js +86 -134
- package/dist/src/pages/PasswordReset.js.map +1 -1
- package/dist/src/pages/Signup.d.ts.map +1 -1
- package/dist/src/pages/Signup.js +88 -148
- package/dist/src/pages/Signup.js.map +1 -1
- package/dist/test/authApi.test.d.ts +2 -0
- package/dist/test/authApi.test.d.ts.map +1 -0
- package/dist/test/authApi.test.js +188 -0
- package/dist/test/authApi.test.js.map +1 -0
- package/dist/test/authPages.test.d.ts +2 -0
- package/dist/test/authPages.test.d.ts.map +1 -0
- package/dist/test/authPages.test.js +52 -0
- package/dist/test/authPages.test.js.map +1 -0
- package/dist/test/authValidation.test.d.ts +2 -0
- package/dist/test/authValidation.test.d.ts.map +1 -0
- package/dist/test/authValidation.test.js +52 -0
- package/dist/test/authValidation.test.js.map +1 -0
- package/generated/index.ts +8 -20
- package/package.json +4 -3
- package/src/auth/AuthApi.ts +67 -0
- package/src/auth/AuthButton.tsx +38 -0
- package/src/auth/AuthFormError.tsx +15 -0
- package/src/auth/AuthLayout.tsx +69 -0
- package/src/auth/AuthMessagePanel.tsx +28 -0
- package/src/auth/AuthTextField.tsx +75 -0
- package/src/auth/AuthValidation.ts +39 -0
- package/src/pages/ForgotPassword.tsx +77 -56
- package/src/pages/Login.tsx +74 -78
- package/src/pages/PasswordReset.tsx +118 -124
- package/src/pages/Signup.tsx +117 -136
- package/test/authApi.test.ts +92 -0
- package/test/authPages.test.tsx +51 -0
- package/test/authValidation.test.ts +56 -0
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
import { loginPage } from '../src/pages/Login';
|
|
5
|
+
import { forgotPasswordPage } from '../src/pages/ForgotPassword';
|
|
6
|
+
import { passwordResetPage } from '../src/pages/PasswordReset';
|
|
7
|
+
import { signupPage } from '../src/pages/Signup';
|
|
8
|
+
|
|
9
|
+
function render(node: React.ReactElement) {
|
|
10
|
+
return renderToStaticMarkup(<MemoryRouter>{node}</MemoryRouter>);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('auth pages', () => {
|
|
14
|
+
it('login renders email + password fields, the submit action, and the forgot-password link', () => {
|
|
15
|
+
const Login = loginPage.component;
|
|
16
|
+
const html = render(<Login urlParams={{}} />);
|
|
17
|
+
expect(html).toContain('Email');
|
|
18
|
+
expect(html).toContain('Password');
|
|
19
|
+
expect(html).toContain('Log in');
|
|
20
|
+
expect(html).toContain('href="/login/forgot-password"');
|
|
21
|
+
// Real submit semantics: Enter submits the form.
|
|
22
|
+
expect(html).toContain('type="submit"');
|
|
23
|
+
// Mobile keyboards + autofill: proper autocomplete tokens (HTML attribute names are
|
|
24
|
+
// case-insensitive; SSR emits the camelCase form).
|
|
25
|
+
expect(html.toLowerCase()).toContain('autocomplete="email"');
|
|
26
|
+
expect(html.toLowerCase()).toContain('autocomplete="current-password"');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('forgot password renders the email field, the send action, and a way back to login', () => {
|
|
30
|
+
const ForgotPassword = forgotPasswordPage.component;
|
|
31
|
+
const html = render(<ForgotPassword urlParams={{}} />);
|
|
32
|
+
expect(html).toContain('Reset your password');
|
|
33
|
+
expect(html).toContain('Send reset link');
|
|
34
|
+
expect(html).toContain('href="/login"');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('password reset without a token renders the invalid-link state, never the form', () => {
|
|
38
|
+
const PasswordReset = passwordResetPage.component;
|
|
39
|
+
const html = render(<PasswordReset urlParams={{}} />);
|
|
40
|
+
expect(html).toContain('This reset link is invalid');
|
|
41
|
+
expect(html).toContain('href="/login"');
|
|
42
|
+
expect(html).not.toContain('New password');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('signup renders its loading state before initialization resolves (no form flash)', () => {
|
|
46
|
+
const Signup = signupPage.component;
|
|
47
|
+
const html = render(<Signup urlParams={{}} />);
|
|
48
|
+
expect(html).toContain('Create your account');
|
|
49
|
+
expect(html).not.toContain('type="submit"');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AuthValidation } from '../src/auth/AuthValidation';
|
|
2
|
+
|
|
3
|
+
const validSignup = {
|
|
4
|
+
name: 'Ada Lovelace',
|
|
5
|
+
email: 'ada@example.com',
|
|
6
|
+
password: 'hunter22',
|
|
7
|
+
confirmPassword: 'hunter22',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe('AuthValidation.signup', () => {
|
|
11
|
+
it('accepts a complete, matching signup', () => {
|
|
12
|
+
expect(AuthValidation.signup(validSignup, false)).toBeUndefined();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('requires a name', () => {
|
|
16
|
+
expect(AuthValidation.signup({ ...validSignup, name: ' ' }, false)).toBe('Please enter your name.');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('requires a valid email when not invited', () => {
|
|
20
|
+
expect(AuthValidation.signup({ ...validSignup, email: 'not-an-email' }, false)).toBe(
|
|
21
|
+
'Please enter a valid email address.'
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('skips the email check for invited users (the invite token carries the email)', () => {
|
|
26
|
+
expect(AuthValidation.signup({ ...validSignup, email: '' }, true)).toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('requires a password', () => {
|
|
30
|
+
expect(AuthValidation.signup({ ...validSignup, password: '', confirmPassword: '' }, false)).toBe(
|
|
31
|
+
'Please enter a password.'
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('rejects a mismatched password confirmation', () => {
|
|
36
|
+
expect(AuthValidation.signup({ ...validSignup, confirmPassword: 'different' }, false)).toBe(
|
|
37
|
+
'Passwords do not match.'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('AuthValidation.passwordReset', () => {
|
|
43
|
+
it('accepts matching passwords', () => {
|
|
44
|
+
expect(AuthValidation.passwordReset({ newPassword: 'hunter22', confirmPassword: 'hunter22' })).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('requires a new password', () => {
|
|
48
|
+
expect(AuthValidation.passwordReset({ newPassword: '', confirmPassword: '' })).toBe('Please enter a new password.');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('rejects a mismatched confirmation', () => {
|
|
52
|
+
expect(AuthValidation.passwordReset({ newPassword: 'hunter22', confirmPassword: 'hunter23' })).toBe(
|
|
53
|
+
'Passwords do not match.'
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
});
|