Skip to content

Commit e40c49d

Browse files
fix: TPA data not auto-populated (#1156)
1 parent ba5aece commit e40c49d

File tree

8 files changed

+92
-92
lines changed

8 files changed

+92
-92
lines changed

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,43 @@ describe('NameField', () => {
6767

6868
describe('Test Name Field', () => {
6969
it('should run first name field validation when onBlur is fired', () => {
70-
props.name = 'firstname';
70+
props.name = 'firstName';
7171
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
7272

73-
const firstNameInput = container.querySelector('input#firstname');
74-
fireEvent.blur(firstNameInput, { target: { value: '', name: 'firstname' } });
73+
const firstNameInput = container.querySelector('input#firstName');
74+
fireEvent.blur(firstNameInput, { target: { value: '', name: 'firstName' } });
7575

7676
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
7777
expect(props.handleErrorChange).toHaveBeenCalledWith(
78-
'firstname',
78+
'firstName',
7979
'Enter your first name',
8080
);
8181
});
8282

8383
it('should update first name field error for frontend validations', () => {
84-
props.name = 'firstname';
84+
props.name = 'firstName';
8585
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
8686

87-
const firstNameInput = container.querySelector('input#firstname');
88-
fireEvent.blur(firstNameInput, { target: { value: 'https://invalid-name.com', name: 'firstname' } });
87+
const firstNameInput = container.querySelector('input#firstName');
88+
fireEvent.blur(firstNameInput, { target: { value: 'https://invalid-name.com', name: 'firstName' } });
8989

9090
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
9191
expect(props.handleErrorChange).toHaveBeenCalledWith(
92-
'firstname',
92+
'firstName',
9393
'Enter a valid first name',
9494
);
9595
});
9696

9797
it('should clear first name error on focus', () => {
98-
props.name = 'firstname';
98+
props.name = 'firstName';
9999
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
100100

101-
const firstNameInput = container.querySelector('input#firstname');
102-
fireEvent.focus(firstNameInput, { target: { value: '', name: 'firstname' } });
101+
const firstNameInput = container.querySelector('input#firstName');
102+
fireEvent.focus(firstNameInput, { target: { value: '', name: 'firstName' } });
103103

104104
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
105105
expect(props.handleErrorChange).toHaveBeenCalledWith(
106-
'firstname',
106+
'firstName',
107107
'',
108108
);
109109
});
@@ -115,12 +115,12 @@ describe('NameField', () => {
115115
shouldFetchUsernameSuggestions: true,
116116
fullName: 'test test',
117117
};
118-
props.name = 'lastname';
118+
props.name = 'lastName';
119119
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
120120

121-
const lastNameInput = container.querySelector('input#lastname');
121+
const lastNameInput = container.querySelector('input#lastName');
122122
// Enter a valid name so that frontend validations are passed
123-
fireEvent.blur(lastNameInput, { target: { value: 'test', name: 'lastname' } });
123+
fireEvent.blur(lastNameInput, { target: { value: 'test', name: 'lastName' } });
124124

125125
expect(store.dispatch).toHaveBeenCalledWith(fetchRealtimeValidations({ name: props.fullName }));
126126
});
@@ -137,41 +137,41 @@ describe('NameField', () => {
137137
},
138138
});
139139

140-
props.name = 'lastname';
140+
props.name = 'lastName';
141141
store.dispatch = jest.fn(store.dispatch);
142142
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
143143

144-
const lastNameInput = container.querySelector('input#lastname');
144+
const lastNameInput = container.querySelector('input#lastName');
145145

146-
fireEvent.focus(lastNameInput, { target: { value: 'test', name: 'lastname' } });
146+
fireEvent.focus(lastNameInput, { target: { value: 'test', name: 'lastName' } });
147147

148-
expect(store.dispatch).toHaveBeenCalledWith(clearRegistrationBackendError('lastname'));
148+
expect(store.dispatch).toHaveBeenCalledWith(clearRegistrationBackendError('lastName'));
149149
});
150150

151151
it('should run last name field validation when onBlur is fired', () => {
152-
props.name = 'lastname';
152+
props.name = 'lastName';
153153
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
154154

155-
const lastNameInput = container.querySelector('input#lastname');
156-
fireEvent.blur(lastNameInput, { target: { value: '', name: 'lastname' } });
155+
const lastNameInput = container.querySelector('input#lastName');
156+
fireEvent.blur(lastNameInput, { target: { value: '', name: 'lastName' } });
157157

158158
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
159159
expect(props.handleErrorChange).toHaveBeenCalledWith(
160-
'lastname',
160+
'lastName',
161161
'Enter your last name',
162162
);
163163
});
164164

165165
it('should update last name field error for frontend validation', () => {
166-
props.name = 'lastname';
166+
props.name = 'lastName';
167167
const { container } = render(routerWrapper(reduxWrapper(<IntlNameField {...props} />)));
168168

169-
const lastNameInput = container.querySelector('input#lastname');
170-
fireEvent.blur(lastNameInput, { target: { value: 'https://invalid-name.com', name: 'lastname' } });
169+
const lastNameInput = container.querySelector('input#lastName');
170+
fireEvent.blur(lastNameInput, { target: { value: 'https://invalid-name.com', name: 'lastName' } });
171171

172172
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
173173
expect(props.handleErrorChange).toHaveBeenCalledWith(
174-
'lastname',
174+
'lastName',
175175
'Enter a valid last name',
176176
);
177177
});

src/register/RegistrationFields/NameField/validator.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export const INVALID_NAME_REGEX = /https?:\/\/(?:[-\w.]|(?:%[\da-fA-F]{2}))*/g;
1212
const validateName = (value, fieldName, formatMessage) => {
1313
let fieldError;
1414
if (!value.trim()) {
15-
fieldError = fieldName === 'lastname'
16-
? formatMessage(messages['empty.lastname.field.error'])
17-
: formatMessage(messages['empty.firstname.field.error']);
15+
fieldError = fieldName === 'lastName'
16+
? formatMessage(messages['empty.lastName.field.error'])
17+
: formatMessage(messages['empty.firstName.field.error']);
1818
} else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) {
19-
fieldError = fieldName === 'lastname'
20-
? formatMessage(messages['lastname.validation.message'])
21-
: formatMessage(messages['firstname.validation.message']);
19+
fieldError = fieldName === 'lastName'
20+
? formatMessage(messages['lastName.validation.message'])
21+
: formatMessage(messages['firstName.validation.message']);
2222
}
2323
return fieldError;
2424
};

src/register/RegistrationPage.jsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ const RegistrationPage = (props) => {
121121
}
122122
if (pipelineUserDetails && Object.keys(pipelineUserDetails).length !== 0) {
123123
const {
124-
firstname = '', lastname = '', username = '', email = '',
124+
firstName = '', lastName = '', username = '', email = '',
125125
} = pipelineUserDetails;
126126
setFormFields(prevState => ({
127-
...prevState, firstname, lastname, username, email,
127+
...prevState, firstName, lastName, username, email,
128128
}));
129129
dispatch(setUserPipelineDataLoaded(true));
130130
}
@@ -323,22 +323,22 @@ const RegistrationPage = (props) => {
323323
/>
324324
<Form id="registration-form" name="registration-form">
325325
<NameField
326-
name="firstname"
327-
value={formFields.firstname}
326+
name="firstName"
327+
value={formFields.firstName}
328328
handleChange={handleOnChange}
329329
handleErrorChange={handleErrorChange}
330-
errorMessage={errors.firstname}
331-
floatingLabel={formatMessage(messages['registration.firstname.label'])}
330+
errorMessage={errors.firstName}
331+
floatingLabel={formatMessage(messages['registration.firstName.label'])}
332332
/>
333333
<NameField
334-
name="lastname"
335-
value={formFields.lastname}
334+
name="lastName"
335+
value={formFields.lastName}
336336
shouldFetchUsernameSuggestions={!formFields.username.trim()}
337-
fullName={`${formFields.firstname} ${formFields.lastname}`}
337+
fullName={`${formFields.firstName} ${formFields.lastName}`}
338338
handleChange={handleOnChange}
339339
handleErrorChange={handleErrorChange}
340-
errorMessage={errors.lastname}
341-
floatingLabel={formatMessage(messages['registration.lastname.label'])}
340+
errorMessage={errors.lastName}
341+
floatingLabel={formatMessage(messages['registration.lastName.label'])}
342342
/>
343343
<EmailField
344344
name="email"

src/register/RegistrationPage.test.jsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ describe('RegistrationPage', () => {
6464
marketingEmailsOptIn: true,
6565
},
6666
formFields: {
67-
firstname: '', lastname: '', email: '', username: '', password: '',
67+
firstName: '', lastName: '', email: '', username: '', password: '',
6868
},
6969
emailSuggestion: {
7070
suggestion: '', type: '',
7171
},
7272
errors: {
73-
firstname: '', lastname: '', email: '', username: '', password: '',
73+
firstName: '', lastName: '', email: '', username: '', password: '',
7474
},
7575
};
7676

@@ -134,8 +134,8 @@ describe('RegistrationPage', () => {
134134
});
135135

136136
const populateRequiredFields = (getByLabelText, payload, isThirdPartyAuth = false) => {
137-
fireEvent.change(getByLabelText('First name'), { target: { value: payload.firstname, name: 'firstname' } });
138-
fireEvent.change(getByLabelText('Last name'), { target: { value: payload.lastname, name: 'lastname' } });
137+
fireEvent.change(getByLabelText('First name'), { target: { value: payload.first_name, name: 'firstName' } });
138+
fireEvent.change(getByLabelText('Last name'), { target: { value: payload.last_name, name: 'lastName' } });
139139
fireEvent.change(getByLabelText('Public username'), { target: { value: payload.username, name: 'username' } });
140140
fireEvent.change(getByLabelText('Email'), { target: { value: payload.email, name: 'email' } });
141141

@@ -153,8 +153,8 @@ describe('RegistrationPage', () => {
153153
});
154154

155155
const emptyFieldValidation = {
156-
firstname: 'Enter your first name',
157-
lastname: 'Enter your last name',
156+
firstName: 'Enter your first name',
157+
lastName: 'Enter your last name',
158158
username: 'Username must be between 2 and 30 characters',
159159
email: 'Enter your email',
160160
password: 'Password criteria has not been met',
@@ -171,8 +171,8 @@ describe('RegistrationPage', () => {
171171
window.location = { href: getConfig().BASE_URL, search: '?next=/course/demo-course-url' };
172172

173173
const payload = {
174-
firstname: 'John',
175-
lastname: 'Doe',
174+
first_name: 'John',
175+
last_name: 'Doe',
176176
username: 'john_doe',
177177
178178
password: 'password1',
@@ -195,8 +195,8 @@ describe('RegistrationPage', () => {
195195
jest.spyOn(global.Date, 'now').mockImplementation(() => 0);
196196

197197
const formPayload = {
198-
firstname: 'John',
199-
lastname: 'Doe',
198+
first_name: 'John',
199+
last_name: 'Doe',
200200
username: 'john_doe',
201201
202202
country: 'Pakistan',
@@ -232,8 +232,8 @@ describe('RegistrationPage', () => {
232232
jest.spyOn(global.Date, 'now').mockImplementation(() => 0);
233233

234234
const payload = {
235-
firstname: 'John',
236-
lastname: 'Doe',
235+
first_name: 'John',
236+
last_name: 'Doe',
237237
username: 'john_doe',
238238
239239
password: 'password1',
@@ -616,8 +616,8 @@ describe('RegistrationPage', () => {
616616
registrationFormData: {
617617
...registrationFormData,
618618
formFields: {
619-
firstname: 'John',
620-
lastname: 'Doe',
619+
firstName: 'John',
620+
lastName: 'Doe',
621621
username: 'john_doe',
622622
623623
password: 'password1',
@@ -631,8 +631,8 @@ describe('RegistrationPage', () => {
631631

632632
const { container } = render(routerWrapper(reduxWrapper(<IntlRegistrationPage {...props} />)));
633633

634-
const firstNameInput = container.querySelector('input#firstname');
635-
const lastNameInput = container.querySelector('input#lastname');
634+
const firstNameInput = container.querySelector('input#firstName');
635+
const lastNameInput = container.querySelector('input#lastName');
636636
const usernameInput = container.querySelector('input#username');
637637
const emailInput = container.querySelector('input#email');
638638
const passwordInput = container.querySelector('input#password');
@@ -760,8 +760,8 @@ describe('RegistrationPage', () => {
760760
thirdPartyAuthContext: {
761761
...initialState.commonComponents.thirdPartyAuthContext,
762762
pipelineUserDetails: {
763-
firstname: 'John',
764-
lastname: 'Doe',
763+
firstName: 'John',
764+
lastName: 'Doe',
765765
username: 'john_doe',
766766
767767
},
@@ -792,8 +792,8 @@ describe('RegistrationPage', () => {
792792
registrationFormData: {
793793
...registrationFormData,
794794
formFields: {
795-
firstname: 'John',
796-
lastname: 'Doe',
795+
firstName: 'John',
796+
lastName: 'Doe',
797797
username: 'john_doe',
798798
799799
},
@@ -813,8 +813,8 @@ describe('RegistrationPage', () => {
813813
...initialState.commonComponents.thirdPartyAuthContext,
814814
currentProvider: 'Apple',
815815
pipelineUserDetails: {
816-
firstname: 'John',
817-
lastname: 'Doe',
816+
firstName: 'John',
817+
lastName: 'Doe',
818818
username: 'john_doe',
819819
820820
},
@@ -826,8 +826,8 @@ describe('RegistrationPage', () => {
826826

827827
render(routerWrapper(reduxWrapper(<IntlRegistrationPage {...props} />)));
828828
expect(store.dispatch).toHaveBeenCalledWith(registerNewUser({
829-
firstname: 'John',
830-
lastname: 'Doe',
829+
first_name: 'John',
830+
last_name: 'Doe',
831831
username: 'john_doe',
832832
833833
country: 'PK',

src/register/components/tests/ConfigurableRegistrationForm.test.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ describe('ConfigurableRegistrationForm', () => {
5656
marketingEmailsOptIn: true,
5757
},
5858
formFields: {
59-
firstname: '', lastname: '', email: '', username: '', password: '',
59+
firstName: '', lastName: '', email: '', username: '', password: '',
6060
},
6161
emailSuggestion: {
6262
suggestion: '', type: '',
6363
},
6464
errors: {
65-
firstname: '', lastname: '', email: '', username: '', password: '',
65+
firstName: '', lastName: '', email: '', username: '', password: '',
6666
},
6767
};
6868

@@ -128,8 +128,8 @@ describe('ConfigurableRegistrationForm', () => {
128128
});
129129

130130
const populateRequiredFields = (getByLabelText, payload, isThirdPartyAuth = false) => {
131-
fireEvent.change(getByLabelText('First name'), { target: { value: payload.firstname, name: 'firstname' } });
132-
fireEvent.change(getByLabelText('Last name'), { target: { value: payload.lastname, name: 'lastname' } });
131+
fireEvent.change(getByLabelText('First name'), { target: { value: payload.first_name, name: 'firstName' } });
132+
fireEvent.change(getByLabelText('Last name'), { target: { value: payload.last_name, name: 'lastName' } });
133133
fireEvent.change(getByLabelText('Public username'), { target: { value: payload.username, name: 'username' } });
134134
fireEvent.change(getByLabelText('Email'), { target: { value: payload.email, name: 'email' } });
135135

@@ -239,8 +239,8 @@ describe('ConfigurableRegistrationForm', () => {
239239
});
240240

241241
const payload = {
242-
firstname: 'John',
243-
lastname: 'Doe',
242+
first_name: 'John',
243+
last_name: 'Doe',
244244
username: 'john_doe',
245245
246246
password: 'password1',

src/register/data/reducers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export const defaultState = {
2323
marketingEmailsOptIn: true,
2424
},
2525
formFields: {
26-
firstname: '', lastname: '', email: '', username: '', password: '',
26+
firstName: '', lastName: '', email: '', username: '', password: '',
2727
},
2828
emailSuggestion: {
2929
suggestion: '', type: '',
3030
},
3131
errors: {
32-
firstname: '', lastname: '', email: '', username: '', password: '',
32+
firstName: '', lastName: '', email: '', username: '', password: '',
3333
},
3434
},
3535
validations: null,

src/register/data/tests/reducers.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ describe('Registration Reducer Tests', () => {
2323
marketingEmailsOptIn: true,
2424
},
2525
formFields: {
26-
firstname: '', lastname: '', email: '', username: '', password: '',
26+
firstName: '', lastName: '', email: '', username: '', password: '',
2727
},
2828
emailSuggestion: {
2929
suggestion: '', type: '',
3030
},
3131
errors: {
32-
firstname: '', lastname: '', email: '', username: '', password: '',
32+
firstName: '', lastName: '', email: '', username: '', password: '',
3333
},
3434
},
3535
validations: null,

0 commit comments

Comments
 (0)