fix: reset-password code coverage (#855)

Improve the code coverage of reset-password component

VAN-1369
This commit is contained in:
Blue
2023-04-18 13:24:59 +05:00
committed by GitHub
parent 9ab23cf485
commit 46f8217e1a
2 changed files with 63 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ export const TOKEN_STATE = {
// password reset error codes
export const FORM_SUBMISSION_ERROR = 'form-submission-error';
export const PASSWORD_RESET_ERROR = 'password-reset-error';
export const SUCCESS = 'success';
export const PASSWORD_VALIDATION_ERROR = 'password-validation-failure';
export const PASSWORD_RESET = {

View File

@@ -10,8 +10,10 @@ import { MemoryRouter, Router } from 'react-router-dom';
import configureStore from 'redux-mock-store';
import { LOGIN_PAGE } from '../../data/constants';
import { resetPassword } from '../data/actions';
import { PASSWORD_RESET, TOKEN_STATE } from '../data/constants';
import { resetPassword, validateToken } from '../data/actions';
import {
PASSWORD_RESET, PASSWORD_RESET_ERROR, SUCCESS, TOKEN_STATE,
} from '../data/constants';
import ResetPasswordPage from '../ResetPasswordPage';
jest.mock('@edx/frontend-platform/auth');
@@ -158,6 +160,64 @@ describe('ResetPasswordPage', () => {
// ******** miscellaneous tests ********
it('should call validation on password field when blur event fires', () => {
const resetPasswordPage = mount(reduxWrapper(<IntlResetPasswordPage {...props} />));
const expectedText = 'Password criteria has not been metPassword must contain at least 8 characters, at least one letter, and at least one number';
resetPasswordPage.find('input#newPassword').simulate('change', { target: { value: 'aziz156', name: 'newPassword' } });
resetPasswordPage.find('input#newPassword').simulate('blur', { target: { value: 'aziz156', name: 'newPassword' } });
expect(resetPasswordPage.find('div[feedback-for="newPassword"]').text()).toEqual(expectedText);
});
it('should not call validation when typing and click on show icon button', () => {
const resetPasswordPage = mount(reduxWrapper(<IntlResetPasswordPage {...props} />));
resetPasswordPage.find('input#newPassword').simulate('change', { target: { value: 'aziz156@', name: 'newPassword' } });
resetPasswordPage.find('button[aria-label="Show password"]').at(0).simulate('click');
resetPasswordPage.find('button[aria-label="Hide password"]').at(0).simulate('blur');
expect(resetPasswordPage.find('div[feedback-for="newPassword"]').exists()).toBe(false);
});
it('should call validation click on show icon button and then focus out', () => {
const resetPasswordPage = mount(reduxWrapper(<IntlResetPasswordPage {...props} />));
resetPasswordPage.find('input#newPassword').simulate('focus', { target: { value: 'aziz156@', name: 'newPassword' } });
resetPasswordPage.find('input#newPassword').simulate('blur', { relatedTarget: { name: 'password' } });
resetPasswordPage.find('button[aria-label="Show password"]').at(0).simulate('click');
expect(resetPasswordPage.find('div[feedback-for="newPassword"]').exists()).toBe(false);
});
it('show spinner when api call is pending', () => {
store.dispatch = jest.fn(store.dispatch);
props = {
status:
TOKEN_STATE.PENDING,
match: {
params: { token: '1c-bmjdkc-5e60e084cf8113048ca7' },
},
};
mount(reduxWrapper(<IntlResetPasswordPage {...props} />));
expect(store.dispatch).toHaveBeenCalledWith(validateToken(props.match.params.token));
});
it('should redirect the user to Reset password email screen ', async () => {
props = {
status:
PASSWORD_RESET_ERROR,
};
mount(reduxWrapper(
<Router history={history}>
<IntlResetPasswordPage {...props} />
</Router>,
));
expect(history.location.pathname).toEqual('/reset');
});
it('should redirect the user to root url of the application ', async () => {
props = {
status: SUCCESS,
};
mount(reduxWrapper(
<Router history={history}>
<IntlResetPasswordPage {...props} />
</Router>,
));
expect(history.location.pathname).toEqual('/login');
});
it('check cookie rendered', () => {
const resetPasswordPage = mount(reduxWrapper(<IntlResetPasswordPage {...props} />));
expect(resetPasswordPage.find(<CookiePolicyBanner />)).toBeTruthy();