This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(incidents): add incident related routing
- Loading branch information
1 parent
91a1a5c
commit 2e9e985
Showing
16 changed files
with
603 additions
and
0 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
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,102 @@ | ||
import '../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { MemoryRouter } from 'react-router' | ||
import { Provider } from 'react-redux' | ||
import thunk from 'redux-thunk' | ||
import configureMockStore from 'redux-mock-store' | ||
import { act } from '@testing-library/react' | ||
import Permissions from 'model/Permissions' | ||
import ViewIncident from '../../incidents/view/ViewIncident' | ||
import Incidents from '../../incidents/Incidents' | ||
import ReportIncident from '../../incidents/report/ReportIncident' | ||
|
||
const mockStore = configureMockStore([thunk]) | ||
|
||
describe('Incidents', () => { | ||
describe('routing', () => { | ||
describe('/incidents/new', () => { | ||
it('should render the new lab request screen when /incidents/new is accessed', () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [Permissions.ReportIncident] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
}) | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/incidents/new']}> | ||
<Incidents /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(ReportIncident)).toHaveLength(1) | ||
}) | ||
|
||
it('should not navigate to /incidents/new if the user does not have RequestLab permissions', () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
}) | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/incidents/new']}> | ||
<Incidents /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(ReportIncident)).toHaveLength(0) | ||
}) | ||
}) | ||
|
||
describe('/incidents/:id', () => { | ||
it('should render the view lab screen when /incidents/:id is accessed', async () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [Permissions.ViewIncident] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
}) | ||
|
||
let wrapper: any | ||
|
||
await act(async () => { | ||
wrapper = await mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/incidents/1234']}> | ||
<Incidents /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(ViewIncident)).toHaveLength(1) | ||
}) | ||
}) | ||
|
||
it('should not navigate to /incidents/:id if the user does not have ViewIncident permissions', async () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
}) | ||
|
||
const wrapper = await mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/incidents/1234']}> | ||
<Incidents /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(ViewIncident)).toHaveLength(0) | ||
}) | ||
}) | ||
}) | ||
}) |
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,61 @@ | ||
import '../../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import { act } from '@testing-library/react' | ||
import { Provider } from 'react-redux' | ||
import { Route, Router } from 'react-router' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
import Permissions from '../../../model/Permissions' | ||
import * as titleUtil from '../../../page-header/useTitle' | ||
import * as ButtonBarProvider from '../../../page-header/ButtonBarProvider' | ||
import * as breadcrumbUtil from '../../../breadcrumbs/useAddBreadcrumbs' | ||
import ViewIncidents from '../../../incidents/list/ViewIncidents' | ||
|
||
const mockStore = createMockStore([thunk]) | ||
|
||
describe('View Incidents', () => { | ||
let history: any | ||
|
||
let setButtonToolBarSpy: any | ||
const setup = async (permissions: Permissions[]) => { | ||
jest.resetAllMocks() | ||
jest.spyOn(breadcrumbUtil, 'default') | ||
setButtonToolBarSpy = jest.fn() | ||
jest.spyOn(titleUtil, 'default') | ||
jest.spyOn(ButtonBarProvider, 'useButtonToolbarSetter').mockReturnValue(setButtonToolBarSpy) | ||
|
||
history = createMemoryHistory() | ||
history.push(`/incidents`) | ||
const store = mockStore({ | ||
title: '', | ||
user: { | ||
permissions, | ||
}, | ||
}) | ||
|
||
let wrapper: any | ||
await act(async () => { | ||
wrapper = await mount( | ||
<ButtonBarProvider.ButtonBarProvider> | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Route path="/incidents"> | ||
<ViewIncidents /> | ||
</Route> | ||
</Router> | ||
</Provider> | ||
</ButtonBarProvider.ButtonBarProvider>, | ||
) | ||
}) | ||
wrapper.update() | ||
return wrapper | ||
} | ||
|
||
it('should set the title', async () => { | ||
await setup([Permissions.ViewIncidents]) | ||
|
||
expect(titleUtil.default).toHaveBeenCalledWith('incidents.reports.label') | ||
}) | ||
}) |
Oops, something went wrong.