-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
858 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/src/.eslintrc.js | ||
/src/serviceWorker.js | ||
/coverage | ||
/src/__tests__ |
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 |
---|---|---|
@@ -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, | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -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); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -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); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -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":[], | ||
}, | ||
); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -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":"" | ||
}, | ||
); | ||
}); | ||
|
||
}); |
Oops, something went wrong.