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(medications): implement basic medication module (#2249)
Co-authored-by: Matteo Vivona <[email protected]> Co-authored-by: Maksim Sinik <[email protected]> Co-authored-by: morrme <[email protected]>
- Loading branch information
1 parent
1ccd2f6
commit ab1bd5c
Showing
27 changed files
with
2,666 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { act } from '@testing-library/react' | ||
import { mount, ReactWrapper } from 'enzyme' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { MemoryRouter } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import Medications from '../../medications/Medications' | ||
import NewMedicationRequest from '../../medications/requests/NewMedicationRequest' | ||
import ViewMedication from '../../medications/ViewMedication' | ||
import MedicationRepository from '../../shared/db/MedicationRepository' | ||
import PatientRepository from '../../shared/db/PatientRepository' | ||
import Medication from '../../shared/model/Medication' | ||
import Patient from '../../shared/model/Patient' | ||
import Permissions from '../../shared/model/Permissions' | ||
import { RootState } from '../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('Medications', () => { | ||
const setup = (route: string, permissions: Array<string>) => { | ||
jest.resetAllMocks() | ||
jest.spyOn(MedicationRepository, 'findAll').mockResolvedValue([]) | ||
jest | ||
.spyOn(MedicationRepository, 'find') | ||
.mockResolvedValue({ id: '1234', requestedOn: new Date().toISOString() } as Medication) | ||
jest | ||
.spyOn(PatientRepository, 'find') | ||
.mockResolvedValue({ id: '12345', fullName: 'test test' } as Patient) | ||
|
||
const store = mockStore({ | ||
title: 'test', | ||
user: { permissions }, | ||
breadcrumbs: { breadcrumbs: [] }, | ||
components: { sidebarCollapsed: false }, | ||
medication: { | ||
medication: ({ | ||
id: 'medicationId', | ||
patientId: 'patientId', | ||
requestedOn: new Date().toISOString(), | ||
medication: 'medication', | ||
status: 'draft', | ||
intent: 'order', | ||
priority: 'routine', | ||
quantity: { value: 1, unit: 'unit' }, | ||
notes: 'medication notes', | ||
} as unknown) as Medication, | ||
patient: { id: 'patientId', fullName: 'some name' }, | ||
error: {}, | ||
}, | ||
} as any) | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={[route]}> | ||
<Medications /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
return wrapper as ReactWrapper | ||
} | ||
|
||
describe('routing', () => { | ||
describe('/medications/new', () => { | ||
it('should render the new medication request screen when /medications/new is accessed', () => { | ||
const route = '/medications/new' | ||
const permissions = [Permissions.RequestMedication] | ||
const wrapper = setup(route, permissions) | ||
expect(wrapper.find(NewMedicationRequest)).toHaveLength(1) | ||
}) | ||
|
||
it('should not navigate to /medications/new if the user does not have RequestMedication permissions', () => { | ||
const route = '/medications/new' | ||
const permissions: never[] = [] | ||
const wrapper = setup(route, permissions) | ||
expect(wrapper.find(NewMedicationRequest)).toHaveLength(0) | ||
}) | ||
}) | ||
|
||
describe('/medications/:id', () => { | ||
it('should render the view medication screen when /medications/:id is accessed', async () => { | ||
const route = '/medications/1234' | ||
const permissions = [Permissions.ViewMedication] | ||
let wrapper: any | ||
await act(async () => { | ||
wrapper = setup(route, permissions) | ||
|
||
expect(wrapper.find(ViewMedication)).toHaveLength(1) | ||
}) | ||
}) | ||
|
||
it('should not navigate to /medications/:id if the user does not have ViewMedication permissions', async () => { | ||
const route = '/medications/1234' | ||
const permissions: never[] = [] | ||
const wrapper = setup(route, permissions) | ||
|
||
expect(wrapper.find(ViewMedication)).toHaveLength(0) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
ab1bd5c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: