Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding value length check for full name field #1242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/register/RegistrationFields/NameField/NameField.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ describe('NameField', () => {
);
});

it('should check for long full name error', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should check for long full name error', () => {
it('should validate for full name length', () => {

const longName = `
5cnx16mn7qTSbtiha1W473ZtV5prGBCEtNrfLkqizJirf
v5kbzBpLRbdh7FY5qujb8viQ9zPziE1fWnbFu5tj4FXaY5GDESvVwjQkE
txUPE3r9mk4HYcSfXVJPWAWRuK2LJZycZWDm0BMFLZ63YdyQAZhjyvjn7
SCqKjSHDx7mgwFp35PF4CxwtwNLxY11eqf5F88wQ9k2JQ9U8uKSFyTKCM
A456CGA5KjUugYdT1qKdvvnXtaQr8WA87m9jpe16
`;
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
const nameInput = container.querySelector('input#name');
fireEvent.blur(nameInput, { target: { value: longName, name: 'name' } });

expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
expect(props.handleErrorChange).toHaveBeenCalledWith(
'name',
'Full name can not be longer than 255 symbols',
);
});

it('should clear error on focus', () => {
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));

Expand Down
2 changes: 2 additions & 0 deletions src/register/RegistrationFields/NameField/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const validateName = (value, formatMessage) => {
fieldError = formatMessage(messages['empty.name.field.error']);
} else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) {
fieldError = formatMessage(messages['name.validation.message']);
} else if (value && value.length > 255) {
fieldError = formatMessage(messages['name.validation.length.message']);
}
return fieldError;
};
Expand Down
5 changes: 5 additions & 0 deletions src/register/messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ const messages = defineMessages({
defaultMessage: 'Enter a valid name',
description: 'Validation message that appears when fullname contain URL',
},
'name.validation.length.message': {
id: 'name.validation.message',
defaultMessage: 'Full name can not be longer than 255 symbols',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need product approval on this message copy? If we don't, then maybe we can have an error message as for username field.
Full name must be between 1 and 255 characters?

Not sure but please let me know if my comment makes sense

description: 'Validation message that appears when fullname contain URL',
},
'password.validation.message': {
id: 'password.validation.message',
defaultMessage: 'Password criteria has not been met',
Expand Down
Loading