Merge pull request #849 from openedx/ahtesham/VAN-1368/test-coverage-registation

fix: registration test coverage
This commit is contained in:
Blue
2023-04-17 15:46:20 +05:00
committed by GitHub
2 changed files with 167 additions and 2 deletions

View File

@@ -1,12 +1,13 @@
import { getConfig } from '@edx/frontend-platform';
import { DEFAULT_STATE } from '../../../data/constants';
import { DEFAULT_REDIRECT_URL, DEFAULT_STATE, PENDING_STATE } from '../../../data/constants';
import {
BACKUP_REGISTRATION_DATA,
REGISTER_CLEAR_USERNAME_SUGGESTIONS,
REGISTER_FORM_VALIDATIONS,
REGISTER_NEW_USER,
REGISTER_SET_COUNTRY_CODE,
REGISTER_SET_USER_PIPELINE_DATA_LOADED,
REGISTERATION_CLEAR_BACKEND_ERROR,
} from '../actions';
import reducer from '../reducers';
@@ -63,6 +64,42 @@ describe('Registration Reducer Tests', () => {
},
);
});
it('should set redirect url dashboard on registration success action', () => {
const payload = {
redirectUrl: `${getConfig().BASE_URL}${DEFAULT_REDIRECT_URL}`,
success: true,
};
const action = {
type: REGISTER_NEW_USER.SUCCESS,
payload,
};
expect(reducer(defaultState, action)).toEqual(
{
...defaultState,
registrationResult: payload,
},
);
});
it('should set the registration call and set the registration error object empty', () => {
const action = {
type: REGISTER_NEW_USER.BEGIN,
};
expect(reducer({
...defaultState,
registrationError: {
email: 'This email already exist.',
},
}, action)).toEqual(
{
...defaultState,
submitState: PENDING_STATE,
registrationError: {},
},
);
});
it('should show username suggestions returned by registration error', () => {
const payload = { usernameSuggestions: ['test12'] };
@@ -79,7 +116,68 @@ describe('Registration Reducer Tests', () => {
},
);
});
it('should set the register user when SSO pipline data is loaded', () => {
const payload = { value: true };
const action = {
type: REGISTER_SET_USER_PIPELINE_DATA_LOADED,
payload,
};
expect(reducer(defaultState, action)).toEqual(
{
...defaultState,
userPipelineDataLoaded: true,
},
);
});
it('should set country code on blur', () => {
const action = {
type: REGISTER_SET_COUNTRY_CODE,
payload: { countryCode: 'PK' },
};
expect(reducer({
...defaultState,
registrationFormData: {
...defaultState.registrationFormData,
configurableFormFields: {
...defaultState.registrationFormData.configurableFormFields,
country: {
name: 'Pakistan',
code: 'PK',
},
},
},
}, action)).toEqual(
{
...defaultState,
registrationFormData: {
...defaultState.registrationFormData,
configurableFormFields: {
...defaultState.registrationFormData.configurableFormFields,
country: {
name: 'Pakistan',
code: 'PK',
},
},
},
},
);
});
it(' registration api failure when api rate limit hits', () => {
const action = {
type: REGISTER_FORM_VALIDATIONS.FAILURE,
};
expect(reducer(defaultState, action)).toEqual(
{
...defaultState,
validationApiRateLimited: true,
validations: null,
},
);
});
it('should clear username suggestions', () => {
const state = {
...defaultState,
@@ -92,6 +190,21 @@ describe('Registration Reducer Tests', () => {
expect(reducer(state, action)).toEqual({ ...defaultState });
});
it('should take back data during form reset', () => {
const state = {
...defaultState,
shouldBackupState: true,
};
const action = {
type: BACKUP_REGISTRATION_DATA.BASE,
};
expect(reducer(state, action)).toEqual({
...defaultState,
shouldBackupState: true,
});
});
it('should not reset username suggestions and fields data during form reset', () => {
const state = {
...defaultState,

View File

@@ -346,6 +346,15 @@ describe('RegistrationPage', () => {
expect(registrationPage.find('#email-warning').text()).toEqual('Did you mean: john@hotmail.com?');
});
it('should click on email suggestions for common service provider domain typos', () => {
store.dispatch = jest.fn(store.dispatch);
const registrationPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
registrationPage.find('input#email').simulate('change', { target: { value: 'john@yopmail.com', name: 'email' } });
registrationPage.find('input#email').simulate('blur');
registrationPage.find('.email-warning-alert-link').first().simulate('click');
expect(registrationPage.find('input#email').props().value).toEqual('john@hotmail.com');
});
it('should give error for common top level domain mistakes', () => {
store.dispatch = jest.fn(store.dispatch);
@@ -384,7 +393,32 @@ describe('RegistrationPage', () => {
expect(registrationPage.find('input#username').prop('value')).toEqual('test-user');
});
it('should remove extra character if username is more than 30 character long', () => {
const registrationPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
registrationPage.find('input#username').simulate('change', { target: { value: 'why_this_is_not_valid_username_', name: 'username' } });
expect(registrationPage.find('input#username').prop('value')).toEqual('');
});
it('should give error with suggestion for common top level domain mistakes', () => {
const registrationPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
registrationPage.find('input#email').simulate('change', { target: { value: 'ahtesham@hotmail', name: 'email' } });
registrationPage.find('input#email').simulate('blur');
const receievedMessage = 'Did you mean ahtesham@hotmail.com?';
expect(registrationPage.find('.alert-text').text()).toEqual(receievedMessage);
});
it('should call backend validation api for password validation', () => {
store.dispatch = jest.fn(store.dispatch);
const registrationPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
registrationPage.find('input#password').simulate('change', { target: { value: 'aziz194@', name: 'password' } });
registrationPage.find('input#password').simulate('blur');
expect(store.dispatch).toHaveBeenCalledWith(fetchRealtimeValidations({
form_field_key: 'password', email: '', name: '', username: '', password: 'aziz194@',
}));
});
// ******** test field focus in functionality ********
it('should clear field related error messages on input field Focus', () => {
@@ -644,6 +678,25 @@ describe('RegistrationPage', () => {
expect(registrationPage.find('button.username-suggestion').length).toEqual(3);
});
it('should click on username suggestions when full name is populated', () => {
store = mockStore({
...initialState,
register: {
...initialState.register,
usernameSuggestions: ['test_1', 'test_12', 'test_123'],
registrationFormData: {
...registrationFormData,
username: ' ',
},
},
});
const registrationPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
registrationPage.find('input#name').simulate('change', { target: { value: 'test name', name: 'name' } });
registrationPage.find('.username-suggestion').first().simulate('click');
expect(registrationPage.find('input#username').props().value).toEqual('test_1');
});
it('should clear username suggestions when close icon is clicked', () => {
store = mockStore({
...initialState,
@@ -1110,7 +1163,6 @@ describe('RegistrationPage', () => {
const registrationPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
registrationPage.find('input#email').simulate('change', { target: { value: 'test1@gmail.com', name: 'email' } });
registrationPage.find('input#confirm_email').simulate('blur', { target: { value: 'test2@gmail.com', name: 'confirm_email' } });
expect(registrationPage.find('div#confirm_email-error').text()).toEqual('The email addresses do not match.');
});