Skip to content

Commit 076b078

Browse files
Dima AlipovDmytroAlipov
Dima Alipov
authored andcommitted
fix: adding value length check for full name field
1 parent 9688bd3 commit 076b078

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/register/RegistrationFields/NameField/NameField.test.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ describe('NameField', () => {
9494
);
9595
});
9696

97+
it('should check for long full name error', () => {
98+
const longName = `
99+
5cnx16mn7qTSbtiha1W473ZtV5prGBCEtNrfLkqizJirf
100+
v5kbzBpLRbdh7FY5qujb8viQ9zPziE1fWnbFu5tj4FXaY5GDESvVwjQkE
101+
txUPE3r9mk4HYcSfXVJPWAWRuK2LJZycZWDm0BMFLZ63YdyQAZhjyvjn7
102+
SCqKjSHDx7mgwFp35PF4CxwtwNLxY11eqf5F88wQ9k2JQ9U8uKSFyTKCM
103+
A456CGA5KjUugYdT1qKdvvnXtaQr8WA87m9jpe16
104+
`;
105+
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
106+
const nameInput = container.querySelector('input#name');
107+
fireEvent.blur(nameInput, { target: { value: longName, name: 'name' } });
108+
109+
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
110+
expect(props.handleErrorChange).toHaveBeenCalledWith(
111+
'name',
112+
'Full name can not be longer than 255 symbols',
113+
);
114+
});
115+
97116
it('should clear error on focus', () => {
98117
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
99118

src/register/RegistrationFields/NameField/validator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const validateName = (value, formatMessage) => {
1515
fieldError = formatMessage(messages['empty.name.field.error']);
1616
} else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) {
1717
fieldError = formatMessage(messages['name.validation.message']);
18+
} else if (value && value.length > 255) {
19+
fieldError = formatMessage(messages['name.validation.length.message']);
1820
}
1921
return fieldError;
2022
};

src/register/messages.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ const messages = defineMessages({
126126
defaultMessage: 'Enter a valid name',
127127
description: 'Validation message that appears when fullname contain URL',
128128
},
129+
'name.validation.length.message': {
130+
id: 'name.validation.message',
131+
defaultMessage: 'Full name can not be longer than 255 symbols',
132+
description: 'Validation message that appears when fullname contain URL',
133+
},
129134
'password.validation.message': {
130135
id: 'password.validation.message',
131136
defaultMessage: 'Password criteria has not been met',

0 commit comments

Comments
 (0)