generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Attiya Ishaque <[email protected]>
- Loading branch information
1 parent
3ddaf79
commit 73e8913
Showing
4 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,9 +134,16 @@ describe('RegistrationPage', () => { | |
jest.clearAllMocks(); | ||
}); | ||
|
||
const populateRequiredFields = (getByLabelText, payload, isThirdPartyAuth = false) => { | ||
const populateRequiredFields = ( | ||
getByLabelText, | ||
payload, | ||
isThirdPartyAuth = false, | ||
autoGeneratedUsernameEnabled = false, | ||
) => { | ||
fireEvent.change(getByLabelText('Full name'), { target: { value: payload.name, name: 'name' } }); | ||
fireEvent.change(getByLabelText('Public username'), { target: { value: payload.username, name: 'username' } }); | ||
if (!autoGeneratedUsernameEnabled) { | ||
fireEvent.change(getByLabelText('Public username'), { target: { value: payload.username, name: 'username' } }); | ||
} | ||
fireEvent.change(getByLabelText('Email'), { target: { value: payload.email, name: 'email' } }); | ||
|
||
fireEvent.change(getByLabelText('Country/Region'), { target: { value: payload.country, name: 'country' } }); | ||
|
@@ -299,6 +306,44 @@ describe('RegistrationPage', () => { | |
}); | ||
}); | ||
|
||
it('should submit form without UsernameField when autoGeneratedUsernameEnabled is true', () => { | ||
mergeConfig({ | ||
ENABLE_AUTO_GENERATED_USERNAME: true, | ||
}); | ||
jest.spyOn(global.Date, 'now').mockImplementation(() => 0); | ||
const payload = { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
password: 'password1', | ||
country: 'Pakistan', | ||
honor_code: true, | ||
totalRegistrationTime: 0, | ||
}; | ||
|
||
store.dispatch = jest.fn(store.dispatch); | ||
const { getByLabelText, container } = render(routerWrapper(reduxWrapper(<IntlRegistrationPage {...props} />))); | ||
populateRequiredFields(getByLabelText, payload, false, true); | ||
const button = container.querySelector('button.btn-brand'); | ||
fireEvent.click(button); | ||
expect(store.dispatch).toHaveBeenCalledWith(registerNewUser({ ...payload, country: 'PK' })); | ||
mergeConfig({ | ||
ENABLE_AUTO_GENERATED_USERNAME: false, | ||
}); | ||
}); | ||
|
||
it('should not display UsernameField when ENABLE_AUTO_GENERATED_USERNAME is true', () => { | ||
mergeConfig({ | ||
ENABLE_AUTO_GENERATED_USERNAME: true, | ||
}); | ||
|
||
const { queryByLabelText } = render(routerWrapper(reduxWrapper(<IntlRegistrationPage {...props} />))); | ||
expect(queryByLabelText('Username')).toBeNull(); | ||
|
||
mergeConfig({ | ||
ENABLE_AUTO_GENERATED_USERNAME: false, | ||
}); | ||
}); | ||
|
||
it('should not dispatch registerNewUser on empty form Submission', () => { | ||
store.dispatch = jest.fn(store.dispatch); | ||
|
||
|