allow spaces in username with trim

This commit is contained in:
Pavel Mineev
2021-05-02 18:55:07 +03:00
parent a4f2542924
commit b748771fed
2 changed files with 43 additions and 1 deletions
@@ -211,4 +211,42 @@ describe('<Auth/>', () => {
expect(getByRole('presentation')).toHaveAttribute('aria-label', 'Loading...');
await waitFor(() => expect(api.anonymousSignin).toBeCalled());
});
it.each`
value | expected
${'username '} | ${'username'}
${' username'} | ${'username'}
${' username '} | ${'username'}
`('should remove spaces in the first/last postion in username', async ({ value, expected }) => {
StaticStore.config.auth_providers = ['email'];
const { getByText, getByPlaceholderText } = render(<Auth />);
fireEvent.click(getByText('Sign In'));
const input = getByPlaceholderText('Username');
fireEvent.change(input, { target: { value } });
fireEvent.blur(input);
expect(input).toHaveValue(expected);
});
it.each`
value | expected
${'user name '} | ${'user name'}
${' user name'} | ${'user name'}
${' user name '} | ${'user name'}
`('should leave spaces in the middle of username', ({ value, expected }) => {
StaticStore.config.auth_providers = ['email'];
const { getByText, getByPlaceholderText } = render(<Auth />);
fireEvent.click(getByText('Sign In'));
const input = getByPlaceholderText('Username');
fireEvent.change(input, { target: { value } });
fireEvent.blur(input);
expect(input).toHaveValue(expected);
});
});
+5 -1
View File
@@ -233,10 +233,14 @@ export default function Auth() {
required
name="username"
minLength={3}
pattern="^[\p{L}\d_]+$"
pattern="[\p{L}\d\s_]+"
title={intl.formatMessage(messages.usernameRestriction)}
placeholder={intl.formatMessage(messages.username)}
disabled={isLoading}
onBlur={(evt) => {
const element = evt.target as HTMLInputElement;
element.value = element.value.trim();
}}
/>
</div>
{view === 'email' && (