Skip to content

Commit

Permalink
Merge 35120d0 into 245ab88
Browse files Browse the repository at this point in the history
  • Loading branch information
katherine95 committed Jun 17, 2019
2 parents 245ab88 + 35120d0 commit e6a05dc
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/components/auth/PasswordConfirmForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class PasswordConfirmForm extends Component {

return (
<div className="box">
<Form onSubmit={onSubmit}>
<Form onSubmit={onSubmit} id="form">
<Form.Group>
<p id="error" />
<Form.Label>Enter new password:</Form.Label>
Expand Down
File renamed without changes.
73 changes: 73 additions & 0 deletions tests/PasswordConfirmReducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import expect from 'expect';
import passwordConfirmReducer from '../src/redux/reducers/passwordConfirmReducer';
import { PASSWORD_CONFIRM } from '../src/redux/constants';

/*
* Defines the password confirm reducer tests:
*/

const mockData = {
passwordConfirmData: {
password: '12345678',
},
response: {
data: {
user: {
message: 'Your account password has been changed successfully.',
},
},
status: 200,
},
error: {
error: 'Password must be alphanumeric with a minimum of 8 characters.',
},
};
describe.only('test password confirm reducer', () => {
it('should handle search get request start', () => {
const startAction = {
type: PASSWORD_CONFIRM,
};
const state = passwordConfirmReducer({}, startAction);
expect(state).toEqual({
isLoading: true,
});
});

it('should handle password confirm post request success', () => {
const successAction = {
type: `${PASSWORD_CONFIRM}_SUCCESS`,
response: mockData.response.data.user.message,
};
const state = passwordConfirmReducer({}, successAction);
expect(state).toEqual({
isLoading: false,
message: mockData.response.data.user.message,
});
});

it('should handle password confirm post request failure', () => {
const state = passwordConfirmReducer(
{},
{
type: `${PASSWORD_CONFIRM}_FAILURE`,
error: {
response: {
data: {
message:
'A password should be only Aplhanumeric characters and a minimum of 8 characters',
},
},
},
},
);
expect(state).toEqual({
error: {
data: {
message:
'A password should be only Aplhanumeric characters and a minimum of 8 characters',
},
},
isLoading: false,
});
});
});
41 changes: 41 additions & 0 deletions tests/PasswordConfirmView.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { shallow } from 'enzyme';
import { PasswordConfirmView } from '../src/views/PasswordConfirmView';
import { PasswordConfirmForm } from '../src/components/auth/PasswordConfirmForm';

/*
* Defines the password confirm view tests.
*/
describe('test renders reset password forms', () => {
const props = {
onSubmit: jest.fn(),
onChange: jest.fn(),
handleSubmit: jest.fn(),
passwordConfirm: jest.fn(),
handleConfirmPassword: jest.fn(),
};
const wrapper = shallow(<PasswordConfirmView {...props} />);
const input = { target: { name: 'password', value: 'testpassword' } };
const event = {
preventDefault: jest.fn(),
target: {
name: 'password',
value: '12345678',
},
};

it('should change state value of password', () => {
wrapper.find('PasswordConfirmForm').prop('onChange')(input);
expect(wrapper.state('password')).toBe('testpassword');
});

it('should call onSubmit', () => {
wrapper.instance().onSubmit(event);
expect(props.passwordConfirm).toHaveBeenCalled();
});

it('renders reset password form', () => {
const newWrapper = shallow(<PasswordConfirmForm {...props} />);
expect(newWrapper.exists()).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import moxios from 'moxios';
import { resetPassword } from '../src/redux/actions/resetPasswordAction';
import { RESET_PASSWORD } from '../src/redux/constants';

/*
* Defines tests for reset password action:
* Test for successful and unsuccessful dispatch of action
*/
const mockData = {
resetPasswordData: {
email: 'catherinechepkurui95@gmail.com',
email: 'test678@gmail.com',
},
response: {
data: {
Expand Down Expand Up @@ -42,7 +46,7 @@ describe('reset password actions', () => {
});

it('tests for successful password reset action', () => {
const { response } = mockData;
const { response, resetPasswordData } = mockData;
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
Expand All @@ -59,7 +63,7 @@ describe('reset password actions', () => {
const store = mockStore({});

return store
.dispatch(resetPassword())
.dispatch(resetPassword(resetPasswordData.email))
.then(() => {
expect(store.getActions()[1].type).toEqual(expectedActions.type);
})
Expand All @@ -74,11 +78,11 @@ describe('reset password actions', () => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 404,
response: error.response.data,
response: error.response.data.message,
});
});

const expectedActions = { type: `${RESET_PASSWORD}_FAILURE`, error: error.response.data };
const expectedActions = { type: `${RESET_PASSWORD}_FAILURE`, error: error.response.data.message };

const store = mockStore({});

Expand Down
66 changes: 66 additions & 0 deletions tests/ResetPasswordReducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import expect from 'expect';
import resetPasswordReducer from '../src/redux/reducers/resetPasswordReducer';
import { RESET_PASSWORD } from '../src/redux/constants';

/*
* Defines the reset password reducer tests:
* Tests for successful change of state
*/

const mockData = {
resetPasswordData: {
email: 'testwere@gmail.com',
},
response: {
data: {
message:
'Password reset link has been sent to your email, check your email for instructions on how to change password',
uid: 9,
token: '56v-1dfedbe5e7b11ecc2c47',
},
status: 200,
},
};
describe.only('test reset password reducer', () => {
it('should handle search get request start', () => {
const startAction = {
type: RESET_PASSWORD,
};
const state = resetPasswordReducer({}, startAction);
expect(state).toEqual({
isLoading: true,
});
});
it('should handle reset password post request success', () => {
const successAction = {
type: `${RESET_PASSWORD}_SUCCESS`,
response: mockData.response.data.message,
};
const state = resetPasswordReducer({}, successAction);
expect(state).toEqual({
isLoading: false,
message: mockData.response.data.message,
});
});

it('should handle reset password post request failure', () => {
const state = resetPasswordReducer(
{
reset_password: {
isLoading: true,
message: '',
error: {},
},
},
{
type: 'RESET_PASSWORD_FAILURE',
error: { response: { data: { message: 'Account with this email not found.' } } },
},
);
expect(state).toEqual({
reset_password: { isLoading: true, message: '', error: {} },
error: { data: { message: 'Account with this email not found.' } },
isLoading: false,
});
});
});
35 changes: 35 additions & 0 deletions tests/ResetPasswordView.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { shallow } from 'enzyme';
import { ResetPasswordView } from '../src/views/ResetPasswordView';
import { ResetPasswordForm } from '../src/components/auth/ResetPasswordForm';

/*
* Defines the reset password view tests:
*/
describe('test renders reset password forms', () => {
const props = {
onSubmit: jest.fn(),
onChange: jest.fn(),
resetPassword: jest.fn(),
};
const wrapper = shallow(<ResetPasswordView {...props} />);
const input = { target: { name: 'email', value: 'test@gmail.com' } };

it('should change state value of email', () => {
wrapper.find('ResetPasswordForm').prop('onChange')(input);
expect(wrapper.state('email')).toBe('test@gmail.com');
});

it('should call onSubmit', () => {
const event = {
preventDefault: jest.fn(),
};
wrapper.instance().onSubmit(event);
expect(props.resetPassword).toHaveBeenCalled();
});

it('renders reset password form', () => {
const newWrapper = shallow(<ResetPasswordForm {...props} />);
expect(newWrapper.exists()).toEqual(true);
});
});
43 changes: 0 additions & 43 deletions tests/resetPassword_components.test.js

This file was deleted.

0 comments on commit e6a05dc

Please sign in to comment.