-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from andela/ch-test-for-auth-module-161115790
#161115790 Add test for Auth module
- Loading branch information
Showing
6 changed files
with
3,700 additions
and
3,478 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
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 |
---|---|---|
@@ -1,11 +1,92 @@ | ||
|
||
/* eslint-disable no-undef */ | ||
|
||
const props = { | ||
handleForm: jest.fn(), | ||
handleChange: jest.fn(), | ||
slackId: 'abndh234456', | ||
githubId: '234535' | ||
extraFormProps: { | ||
handleForm: jest.fn(), | ||
handleChange: jest.fn(), | ||
slackId: 'abndh234456', | ||
githubId: '234535' | ||
}, | ||
|
||
googleButtonProps: { | ||
handleFailure: jest.fn(), | ||
handleSuccess: jest.fn() | ||
}, | ||
containerProps: { | ||
auth: { | ||
auth: {} | ||
}, | ||
history: { | ||
push: jest.fn() | ||
}, | ||
signUp: jest.fn(), | ||
signIn: jest.fn() | ||
}, | ||
|
||
containerPropsErrors: { | ||
auth: { | ||
auth: { | ||
errors: 'Not an andela email' | ||
} | ||
} | ||
}, | ||
containerPropsMessage: { | ||
auth: { | ||
auth: { | ||
message: 'Login successful' | ||
} | ||
} | ||
}, | ||
containerPropsData: { | ||
auth: { | ||
auth: { | ||
data: 'Login successful' | ||
} | ||
}, | ||
history: { | ||
push: jest.fn() | ||
} | ||
} | ||
}; | ||
|
||
|
||
const responses = { | ||
success: { | ||
profileObj: { | ||
givenName: 'victor', | ||
email: 'test@andela.com', | ||
googleId: '123456', | ||
imageUrl: 'http://wwww.photo.com' | ||
} | ||
}, | ||
error: { | ||
profileObj: { | ||
givenName: 'victor', | ||
email: 'test@google.com', | ||
googleId: '123456', | ||
imageUrl: 'http://wwww.photo.com' | ||
} | ||
} | ||
}; | ||
|
||
const expected = { | ||
notSuccessful: { | ||
showForm: true, | ||
data: null, | ||
slackId: '', | ||
githubId: '' | ||
}, | ||
withMessage: { | ||
showForm: false, | ||
data: null, | ||
slackId: '', | ||
githubId: '' | ||
} | ||
}; | ||
export default props; | ||
|
||
|
||
export { | ||
responses, | ||
props, | ||
expected | ||
}; |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Extraform from '../../../../modules/Auth/components/ExtraForm'; | ||
import props from '../authMockData'; | ||
import { props } from '../authMockData'; | ||
|
||
describe('<Test Component />', () => { | ||
it('should mount without crashing', () => { | ||
const wrapper = shallow(<Extraform {...props} />); | ||
const wrapper = shallow(<Extraform {...props.extraFormProps} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
client/src/tests/modules/auth/components/GoogleButton.test.jsx
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,11 @@ | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
import GoogleButton from "../../../../modules/Auth/components/GoogleButton"; | ||
import { props } from "../authMockData"; | ||
|
||
describe("<Google Button Component test />", () => { | ||
it("should mount without crashing", () => { | ||
const wrapper = shallow(<GoogleButton {...props.googleButtonProps} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
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,89 @@ | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
import { SignIn, mapStateToProps } from "../../../../modules/Auth/container"; | ||
import { props, responses, expected } from "../authMockData"; | ||
|
||
describe("<Testing the redux container />", () => { | ||
it("should mount without crashing", () => { | ||
const wrapper = shallow(<SignIn {...props.containerProps} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
it("should test for returned errors on authentication ", () => { | ||
const wrapper = shallow(<SignIn {...props.containerProps} />); | ||
wrapper.instance().componentWillReceiveProps(props.containerPropsErrors); | ||
const actual = wrapper.instance().state; | ||
expect(actual).toEqual(expected.notSuccessful); | ||
}); | ||
|
||
|
||
it("should test for returned messages on authentication ", () => { | ||
const wrapper = shallow(<SignIn {...props.containerProps} />); | ||
wrapper.instance().componentWillReceiveProps(props.containerPropsMessage); | ||
const actual = wrapper.instance().state; | ||
expect(actual).toEqual(expected.withMessage); | ||
}); | ||
|
||
|
||
it("should test for successful authentication ", () => { | ||
const wrapper = shallow(<SignIn {...props.containerProps} />); | ||
wrapper.instance().componentWillReceiveProps(props.containerPropsData); | ||
const actual = props.containerPropsData.history.push; | ||
expect(actual).toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
it("should call the complete signUp method", () => { | ||
const spy = jest.fn(); | ||
const propsNew = { signUp: spy }; | ||
const mockWrapper = shallow(<SignIn | ||
{...props.containerProps} | ||
{...propsNew} />); | ||
mockWrapper.instance().completeSignUp({ preventDefault: jest.fn() }); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
it('Should call the onChange method', () => { | ||
const wrapper = shallow(<SignIn {...props.containerProps} />); | ||
wrapper.instance().handleChange({ target: { name: 'name', value: 'victor' } }); | ||
const actual = wrapper.instance().state.name; | ||
expect(actual).toEqual('victor'); | ||
}); | ||
|
||
|
||
it('Should call the handleSuccess method', () => { | ||
const spy = jest.fn(); | ||
const propsNew = { signIn: spy }; | ||
const mockWrapper = shallow(<SignIn | ||
{...props.containerProps} | ||
{...propsNew} />); | ||
mockWrapper.instance().handleSuccess(responses.success); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
it('Should call the handleSuccess method', () => { | ||
const wrapper = shallow(<SignIn {...props.containerProps} />); | ||
wrapper.instance().handleSuccess(responses.error); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
it('Should call the handleFailure method', () => { | ||
const wrapper = shallow(<SignIn {...props.containerProps} />); | ||
wrapper.instance().handleFailure(responses.error); | ||
const actual = wrapper.instance().state.showForm; | ||
expect(actual).toEqual(false); | ||
}); | ||
|
||
|
||
it('testing map state To Props', () => { | ||
const storeState = mapStateToProps({ | ||
auth: true | ||
}); | ||
const { auth } = storeState; | ||
expect(auth).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.