-
Notifications
You must be signed in to change notification settings - Fork 7
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/ft-request-actions-168049953
#168049953 A manager should get a re-confirmation dialogue for approving or rejecting travel requests [Deliver #168049953, Deliver#168049962 , Deliver #168049969, Deliver #168050023]
- Loading branch information
Showing
24 changed files
with
588 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import initialState from '../redux/store/initialState'; | ||
|
||
export const middleWares = [thunk]; | ||
export const mockStore = configureMockStore(middleWares); | ||
export default mockStore(initialState); |
44 changes: 16 additions & 28 deletions
44
src/__tests__/components/protected-route/ProtectedRoute.test.js
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,37 +1,25 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
/* eslint-disable import/no-named-as-default-member */ | ||
/* eslint-disable quotes */ | ||
/* eslint-disable import/named */ | ||
/* eslint-disable no-undef */ | ||
import React from "react"; | ||
import { mount } from "enzyme"; | ||
import App from "../../../components/App"; | ||
import { setJwtToLocalStorage } from "../../../services/authServices"; | ||
import VerifyEmailPage from "../../../components/register-page/VerifyEmail"; | ||
import NotFound from "../../../components/not-found/NotFound"; | ||
import React from 'react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { mount } from 'enzyme'; | ||
import { ProtectedRoute } from '../../../components/protected-route/ProtectedRoute'; | ||
|
||
describe("<ProtectedRoute />", () => { | ||
it("should mount the protected route with the token", () => { | ||
const token = | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFtaWx5a2Fzc2ltMDEyQGdtYWlsLmNvbSIsImlhdCI6MTU3MzUzODEyNywiZXhwIjoxNTczNjI0NTI3fQ.sEM3HC_fOraqXEZBMcMzf1Olmpv2XrxpnebB0ZRcFSo"; | ||
setJwtToLocalStorage(token); | ||
const wrapper = mount(<App />); | ||
const protectedRoute = wrapper.find("ProtectedRoute"); | ||
expect(wrapper).toHaveLength(1); | ||
// expect(protectedRoute).toHaveLength(1); | ||
}); | ||
const props = { | ||
isAuthenticated: false, | ||
}; | ||
|
||
it("should mount the protected route without the token thus redirecting the user to login page", () => { | ||
setJwtToLocalStorage(null); | ||
const wrapper = mount(<App />); | ||
const loginRoute = wrapper.find('Route[path="/login"]'); | ||
expect(wrapper).toHaveLength(1); | ||
// expect(loginRoute).toHaveLength(1); | ||
}); | ||
describe('Protected Route', () => { | ||
const protectedRoute = mount( | ||
<BrowserRouter> | ||
<ProtectedRoute {...props} /> | ||
</BrowserRouter>, | ||
); | ||
|
||
it("should mount the verify email component", () => { | ||
setJwtToLocalStorage(null); | ||
const wrapper = mount(<VerifyEmailPage />); | ||
const form = wrapper.find('form[className="card"]'); | ||
expect(form).toHaveLength(1); | ||
test('should redirect to login when user is not authenticated', () => { | ||
expect(protectedRoute.instance().history.location.pathname).toEqual('/login'); | ||
}); | ||
}); |
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,67 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import { Modal } from '../../../../components/shared/modal/Modal'; | ||
import mockStore from '../../../../__mocks__/mockStore'; | ||
import { request } from '../../../../__mocks__/fixtures'; | ||
|
||
const props = { | ||
showModal: jest.fn(), | ||
triggerText: 'Trigger text', | ||
buttonRef: jest.fn(), | ||
handleAction: jest.fn(), | ||
data: request | ||
}; | ||
|
||
describe('Modal', () => { | ||
let modal; | ||
let modalProvider; | ||
|
||
modal = mount(<Modal {...props} />); | ||
modalProvider = mount( | ||
<Provider store={mockStore}> | ||
<Modal {...props} /> | ||
</Provider> | ||
); | ||
|
||
test('should have an initial `isShown` state of false', () => { | ||
expect(modal.state().isShown).toBe(false); | ||
}); | ||
|
||
test('should have `ModalTrigger` present', () => { | ||
expect(modal.find('ModalTrigger').exists()).toBe(true); | ||
}); | ||
|
||
describe('when the modal is triggered', () => { | ||
beforeEach(() => { | ||
modalProvider.find('ModalTrigger').simulate('click'); | ||
}); | ||
|
||
test('should have an action button', () => { | ||
expect(modalProvider.find('.action').text()).toEqual(props.triggerText); | ||
}); | ||
|
||
test('should have a cancel action button', () => { | ||
expect(modalProvider.find('.cancel').text()).toEqual('Cancel'); | ||
}); | ||
|
||
describe('and the action button is clicked', () => { | ||
beforeEach(() => { | ||
modalProvider.find('.action').simulate('click'); | ||
}); | ||
|
||
test('should close the modal', () => { | ||
expect(modalProvider.find('Connect(RequestActionModal)').exist).toBe(undefined); | ||
}); | ||
}); | ||
|
||
describe('and the cancel button is clicked', () => { | ||
beforeEach(() => { | ||
modalProvider.find('.modal-footer .cancel').simulate('click') | ||
}); | ||
test('should not have the `RequestActionModal` on clicking the cancel button', () => { | ||
expect(modalProvider.find('Connect(RequestActionModal)').exist).toBe(undefined); | ||
}); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
src/__tests__/components/shared/modal/RequestActinModal.test.js
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,33 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { RequestActionModal } from '../../../../components/shared/modal/RequestActionModal'; | ||
import { request } from '../../../../__mocks__/fixtures'; | ||
|
||
const props = { | ||
data: request, | ||
triggerText: 'TestButton', | ||
handleAction: jest.fn(), | ||
approveReject: jest.fn(), | ||
closeModal: jest.fn(), | ||
}; | ||
|
||
describe('RequestActionModal', () => { | ||
let requestActionModal; | ||
requestActionModal = shallow(<RequestActionModal {...props} />); | ||
|
||
test('should have the confirm action button', () => { | ||
expect(requestActionModal.find('.action').text()).toEqual( | ||
props.triggerText | ||
); | ||
}); | ||
|
||
test('should have the cancle action button', () => { | ||
expect(requestActionModal.find('.cancel').text()).toEqual('Cancel'); | ||
}); | ||
|
||
test('should call the `handleAction` function when the action button click', () => { | ||
const spyAction = jest.spyOn(requestActionModal.instance(), 'handleAction'); | ||
requestActionModal.find('.action').simulate('click'); | ||
expect(spyAction).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.