Skip to content

Commit

Permalink
Merge 93770b7 into 4dd298e
Browse files Browse the repository at this point in the history
  • Loading branch information
winniekariuki committed Apr 17, 2019
2 parents 4dd298e + 93770b7 commit d4f6be9
Show file tree
Hide file tree
Showing 26 changed files with 858 additions and 73 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src/.eslintrc.js
/src/serviceWorker.js
/coverage
/src/__tests__
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.9.1",
"enzyme-to-json": "^3.3.5",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"mdbreact": "^4.12.0",
"moxios": "^0.4.0",
"node-sass": "^4.11.0",
"npm-run-all": "^4.1.5",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.6",
Expand All @@ -22,6 +27,7 @@
"react-scripts": "2.1.8",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8",
"redux-mock-store": "^1.5.3",
"redux-thunk": "^2.3.0",
"semantic-ui-react": "^0.86.0",
"watch": "^1.0.2"
Expand Down Expand Up @@ -64,6 +70,7 @@
"npm-run-all": "^4.1.5",
"redux-mock-store": "^1.5.3",
"prettier": "^1.16.4",
"sinon": "^7.3.1"
"sinon": "^7.3.1",
"redux-promise-middleware": "^6.1.0"
}
}
14 changes: 2 additions & 12 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/logo.png" />
Expand All @@ -17,16 +16,7 @@
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div class="root-content" id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->

</body>

</html>
</html>
66 changes: 66 additions & 0 deletions src/__tests__/RequestPassword.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import {
RequestResetForm,
mapDispatchToProps,
mapStateToProps,
} from '../components/ResetPassword/requestReset';


describe('Requestreset form elements tests', () => {
let wrapper;
const props = {
requestPasswordDetails: {
message: 'This is testing',
},
};

beforeEach(() => {
wrapper = mount(<RequestResetForm {...props} />);
});

it('should render the RequestResetForm without crashing', () => {
expect(wrapper).toMatchSnapshot();
});

it(
'should change email state to the passed email when handleChange ' +
'is called with an email parameter',
() => {
const email = 'test.email@andela.com';
wrapper.setProps({
message: 'Lalalalala',
});
wrapper.instance().handleChange({ target: { value: email } });
expect(wrapper.state().email).toEqual(email);
},
);

it('should return an object when mapStateToProps is called', () => {
const state = {
requestPassword: {
message: 'this is testing',
},
};
const stateToProps = mapStateToProps(state);
expect(stateToProps.requestPasswordDetails).toEqual(state.requestPassword);
});

it('should return an object when mapDispatchToProps is called', () => {
const dispatch = jest.fn();
const dispatchToProps = mapDispatchToProps(dispatch);
expect(typeof dispatchToProps).toEqual('object');
});

it('should actually work', () => {
const nextProps = {
requestPasswordDetails: {
errors: 'This is testing an error',
},
};
wrapper.setProps(nextProps);
expect(wrapper.state().errors).toEqual(
nextProps.requestPasswordDetails.errors,
);
});
});
52 changes: 52 additions & 0 deletions src/__tests__/Reset.actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
resetPasswordAction,
success,
failure,
} from '../actions/resetPassword';

import {
RESET_SUCCESSFUL,
RESET_FAILURE,
RESET_REQUEST,
} from '../actions/types';

import configureMockStore from 'redux-mock-store';

import resetPassword from '../actions/resetPassword';

const mockStore = configureMockStore();
const store = mockStore([]);
const payload = { password: 'Password123' };


describe('when password is reset successful', () => {
beforeEach(() => {
store.clearActions();
});
it('Should create an action for reset password success', () => {
const expectedActions = [
{
type: RESET_SUCCESSFUL,
payload,
},
];
store.dispatch(success(payload));
const dispatchedActions = store.getActions();
const actionTypes = dispatchedActions.map(action => action.type);
expect(dispatchedActions).toEqual(expectedActions);
});

it('Should create an action for reset password failure', () => {
const expectedActions = [
{
type: RESET_FAILURE,
payload,
},
];
store.dispatch(failure(payload));
const dispatchedActions = store.getActions();
const actionTypes = dispatchedActions.map(action => action.type);
expect(dispatchedActions).toEqual(expectedActions);
});

});
124 changes: 124 additions & 0 deletions src/__tests__/ResetPassword.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import React from 'react';
import { shallow } from 'enzyme';
import {
ResetPassword,
mapStateToProps,
} from '../components/ResetPassword/resetPassword';

describe('Request password form elements tests', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<ResetPassword />);
});

it('should render the ResetPassword without crashing', () => {
expect(wrapper).toMatchSnapshot();
});

it(
'should change password state to the passed password when handleChange ' +
'is called with a password parameter',
() => {
const password = 'Example1';
wrapper
.instance()
.handleChange({ target: { id: 'password', value: password } });
expect(wrapper.state().password).toEqual(password);
},
),
it(
'should change message state to an error message when handleChange ' +
' is called with a blank password',
() => {
const message = 'Password cannot be empty';
wrapper
.instance()
.handleChange({ target: { id: 'password', value: '' } });
expect(wrapper.state().message).toEqual(message);
},
);

it(
'should change message state to a message when handleChange ' +
'is called with a password that does not meet requiremts of a password',
() => {
const message =
'Password should be atleast 8 characters with a capital letter, a small letter and a number';
wrapper
.instance()
.handleChange({ target: { id: 'password', value: 'rgy' } });
expect(wrapper.state().message).toEqual(message);
},
);

it(
'should return message to null when handleChange ' +
'is called with a password parameter and confirm password',
() => {
const password = 'Testing4';
wrapper
.instance()
.handleChange({ target: { id: 'password', value: password } });
wrapper
.instance()
.handleChange({ target: { id: 'confirmPassword', value: password } });
expect(wrapper.state().message).toEqual(null);
},
);

it(
'should change state to a message when handleChange ' +
'is called with a password parameter',
() => {
const password = 'Testing4';
const message = 'Passwords do not match';
wrapper.instance().handleChange({
target: { id: 'password', value: password },
});
wrapper.instance().handleChange({
target: { id: 'confirmPassword', value: 'wrongPassword4' },
});
expect(wrapper.state().message).toEqual(message);
},
);

it('should call spy when a wrapper is instanciated', () => {
const event = { preventDefault: jest.fn() };
wrapper.setProps({
resetPassword: () => Promise.resolve(),
});
const spy = jest.spyOn(wrapper.instance(), 'handleSubmit');

wrapper.instance().handleSubmit(event);
expect(spy).toHaveBeenCalled();
});

it('should return a message on submit of a password that does not match the confirm password', () => {
const message = "Passwords didn't match";
const event = { preventDefault: jest.fn() };
wrapper.setProps({
resetPassword: () => Promise.resolve(),
});
wrapper.setState({
password: 'Testing4',
confirmPassword: 'WrongPassword4',
});
const spy = jest.spyOn(wrapper.instance(), 'handleSubmit');
wrapper.instance().handleSubmit(event);
expect(spy).toHaveBeenCalled();
expect(wrapper.state().message).toEqual(message);
});

it('blah blah kul', () => {
const state = {
resetPassword: 'NewPassword',
};
const passwordReset = mapStateToProps(state);
expect(passwordReset).toEqual(
expect.objectContaining({
passwordReset: expect.any(String),
}),
);
expect(passwordReset.passwordReset).toEqual(state.resetPassword);
});
});
44 changes: 44 additions & 0 deletions src/__tests__/ResetReducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { resetPassword, initialState } from '../reducers/resetPassword';
import * as types from '../actions/types';

describe('Resetpassword reducers', () => {
it('should provide the initial state', () => {
expect(resetPassword(undefined, {})).toEqual(initialState);
});
it('should change state on action type reset request', () => {
expect(
resetPassword({}, {
type: types.RESET_REQUEST,
payload: [],
}),
).toEqual(
{
},
);
});
it('should change state on action type reset successful', () => {
expect(
resetPassword({}, {
type: types.RESET_SUCCESSFUL,
payload: [],
}),
).toEqual(
{
"message": []
},
);
});
it('should change state on action type reset failure', () => {
expect(
resetPassword({}, {
type: types.RESET_FAILURE,
payload: [],
}),
).toEqual(
{
"message":[],
},
);
});

});
35 changes: 35 additions & 0 deletions src/__tests__/requestReset.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { requestPassword, initialState } from '../reducers/requestPasswordReset';
import * as types from '../actions/types';

describe('requestPassword reducers', () => {
it('should provide the initial state', () => {
expect(requestPassword(undefined, {})).toEqual(initialState);
});
it('should change state on action type email send', () => {
expect(
requestPassword({}, {
type: types.EMAIL_SEND,
payload: [],
}),
).toEqual(
{
"errors": null,
"message":[]
},
);
});
it('should change state on action type fail send', () => {
expect(
requestPassword({}, {
type: types.FAIL_SEND,
payload: [],
}),
).toEqual(
{
"errors": [],
"message":""
},
);
});

});
Loading

0 comments on commit d4f6be9

Please sign in to comment.