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(labs): adds test for lab related routes
- Loading branch information
1 parent
691572b
commit f354c94
Showing
7 changed files
with
205 additions
and
219 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 |
---|---|---|
@@ -1,3 +1,115 @@ | ||
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 'react-dom/test-utils' | ||
import Labs from 'labs/Labs' | ||
import NewLabRequest from 'labs/requests/NewLabRequest' | ||
import Permissions from 'model/Permissions' | ||
import ViewLab from 'labs/ViewLab' | ||
import LabRepository from 'clients/db/LabRepository' | ||
import Lab from 'model/Lab' | ||
import Patient from 'model/Patient' | ||
import PatientRepository from 'clients/db/PatientRepository' | ||
|
||
const mockStore = configureMockStore([thunk]) | ||
|
||
describe('Labs', () => { | ||
it('should render the routes', () => {}) | ||
jest.spyOn(LabRepository, 'findAll').mockResolvedValue([]) | ||
jest | ||
.spyOn(LabRepository, 'find') | ||
.mockResolvedValue({ id: '1234', requestedOn: new Date().toISOString() } as Lab) | ||
jest | ||
.spyOn(PatientRepository, 'find') | ||
.mockResolvedValue({ id: '12345', fullName: 'test test' } as Patient) | ||
|
||
describe('routing', () => { | ||
describe('/labs/new', () => { | ||
it('should render the new lab request screen when /labs/new is accessed', () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [Permissions.RequestLab] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
}) | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/labs/new']}> | ||
<Labs /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(NewLabRequest)).toHaveLength(1) | ||
}) | ||
|
||
it('should not navigate to /labs/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={['/labs/new']}> | ||
<Labs /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(NewLabRequest)).toHaveLength(0) | ||
}) | ||
}) | ||
|
||
describe('/labs/:id', () => { | ||
it('should render the view lab screen when /labs/:id is accessed', async () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [Permissions.ViewLab] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
}) | ||
|
||
let wrapper: any | ||
|
||
await act(async () => { | ||
wrapper = await mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/labs/1234']}> | ||
<Labs /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(ViewLab)).toHaveLength(1) | ||
}) | ||
}) | ||
|
||
it('should not navigate to /labs/:id if the user does not have ViewLab permissions', async () => { | ||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions: [] }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
}) | ||
|
||
const wrapper = await mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={['/labs/1234']}> | ||
<Labs /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(ViewLab)).toHaveLength(0) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.