Skip to content

Commit 2590956

Browse files
attiyaIshaquezainab-amir
authored andcommitted
fix: TPA data not auto-populated (#1156)
1 parent 94e8236 commit 2590956

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
@@ -120,10 +120,10 @@ const RegistrationPage = (props) => {
120120
}
121121
if (pipelineUserDetails && Object.keys(pipelineUserDetails).length !== 0) {
122122
const {
123-
firstname = '', lastname = '', username = '', email = '',
123+
firstName = '', lastName = '', username = '', email = '',
124124
} = pipelineUserDetails;
125125
setFormFields(prevState => ({
126-
...prevState, firstname, lastname, username, email,
126+
...prevState, firstName, lastName, username, email,
127127
}));
128128
dispatch(setUserPipelineDataLoaded(true));
129129
}
@@ -312,22 +312,22 @@ const RegistrationPage = (props) => {
312312
/>
313313
<Form id="registration-form" name="registration-form">
314314
<NameField
315-
name="firstname"
316-
value={formFields.firstname}
315+
name="firstName"
316+
value={formFields.firstName}
317317
handleChange={handleOnChange}
318318
handleErrorChange={handleErrorChange}
319-
errorMessage={errors.firstname}
320-
floatingLabel={formatMessage(messages['registration.firstname.label'])}
319+
errorMessage={errors.firstName}
320+
floatingLabel={formatMessage(messages['registration.firstName.label'])}
321321
/>
322322
<NameField
323-
name="lastname"
324-
value={formFields.lastname}
323+
name="lastName"
324+
value={formFields.lastName}
325325
shouldFetchUsernameSuggestions={!formFields.username.trim()}
326-
fullName={`${formFields.firstname} ${formFields.lastname}`}
326+
fullName={`${formFields.firstName} ${formFields.lastName}`}
327327
handleChange={handleOnChange}
328328
handleErrorChange={handleErrorChange}
329-
errorMessage={errors.lastname}
330-
floatingLabel={formatMessage(messages['registration.lastname.label'])}
329+
errorMessage={errors.lastName}
330+
floatingLabel={formatMessage(messages['registration.lastName.label'])}
331331
/>
332332
<EmailField
333333
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',
@@ -584,8 +584,8 @@ describe('RegistrationPage', () => {
584584
registrationFormData: {
585585
...registrationFormData,
586586
formFields: {
587-
firstname: 'John',
588-
lastname: 'Doe',
587+
firstName: 'John',
588+
lastName: 'Doe',
589589
username: 'john_doe',
590590
591591
password: 'password1',
@@ -599,8 +599,8 @@ describe('RegistrationPage', () => {
599599

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

602-
const firstNameInput = container.querySelector('input#firstname');
603-
const lastNameInput = container.querySelector('input#lastname');
602+
const firstNameInput = container.querySelector('input#firstName');
603+
const lastNameInput = container.querySelector('input#lastName');
604604
const usernameInput = container.querySelector('input#username');
605605
const emailInput = container.querySelector('input#email');
606606
const passwordInput = container.querySelector('input#password');
@@ -728,8 +728,8 @@ describe('RegistrationPage', () => {
728728
thirdPartyAuthContext: {
729729
...initialState.commonComponents.thirdPartyAuthContext,
730730
pipelineUserDetails: {
731-
firstname: 'John',
732-
lastname: 'Doe',
731+
firstName: 'John',
732+
lastName: 'Doe',
733733
username: 'john_doe',
734734
735735
},
@@ -760,8 +760,8 @@ describe('RegistrationPage', () => {
760760
registrationFormData: {
761761
...registrationFormData,
762762
formFields: {
763-
firstname: 'John',
764-
lastname: 'Doe',
763+
firstName: 'John',
764+
lastName: 'Doe',
765765
username: 'john_doe',
766766
767767
},
@@ -781,8 +781,8 @@ describe('RegistrationPage', () => {
781781
...initialState.commonComponents.thirdPartyAuthContext,
782782
currentProvider: 'Apple',
783783
pipelineUserDetails: {
784-
firstname: 'John',
785-
lastname: 'Doe',
784+
firstName: 'John',
785+
lastName: 'Doe',
786786
username: 'john_doe',
787787
788788
},
@@ -794,8 +794,8 @@ describe('RegistrationPage', () => {
794794

795795
render(routerWrapper(reduxWrapper(<IntlRegistrationPage {...props} />)));
796796
expect(store.dispatch).toHaveBeenCalledWith(registerNewUser({
797-
firstname: 'John',
798-
lastname: 'Doe',
797+
first_name: 'John',
798+
last_name: 'Doe',
799799
username: 'john_doe',
800800
801801
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
@@ -22,13 +22,13 @@ export const defaultState = {
2222
marketingEmailsOptIn: true,
2323
},
2424
formFields: {
25-
firstname: '', lastname: '', email: '', username: '', password: '',
25+
firstName: '', lastName: '', email: '', username: '', password: '',
2626
},
2727
emailSuggestion: {
2828
suggestion: '', type: '',
2929
},
3030
errors: {
31-
firstname: '', lastname: '', email: '', username: '', password: '',
31+
firstName: '', lastName: '', email: '', username: '', password: '',
3232
},
3333
},
3434
validations: null,

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

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

0 commit comments

Comments
 (0)