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(patients): adds functionality to save patient
- Loading branch information
1 parent
66c1f00
commit c6159af
Showing
2 changed files
with
65 additions
and
1 deletion.
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
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 { MemoryRouter } from 'react-router' | ||
import { Provider } from 'react-redux' | ||
import NewPatient from '../../../patients/new/NewPatient' | ||
import NewPatientForm from '../../../patients/new/NewPatientForm' | ||
import store from '../../../store' | ||
import Patient from '../../../model/Patient' | ||
import Name from '../../../model/Name' | ||
import * as patientSlice from '../../../patients/patients-slice' | ||
import * as titleUtil from '../../../util/useTitle' | ||
|
||
describe('New Patient', () => { | ||
it('should render a new patient form', () => { | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<NewPatient /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(wrapper.find(NewPatientForm)).toHaveLength(1) | ||
}) | ||
|
||
it('should use "New Patient" as the header', () => { | ||
jest.spyOn(titleUtil, 'default') | ||
mount( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<NewPatient /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
expect(titleUtil.default).toHaveBeenCalledWith('patients.newPatient') | ||
}) | ||
|
||
it('should call create patient when save button is clicked', async () => { | ||
jest.spyOn(patientSlice, 'createPatient') | ||
const expectedName = new Name('prefix', 'given', 'family', 'suffix') | ||
const expectedPatient = { | ||
name: expectedName, | ||
} as Patient | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<NewPatient /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
|
||
const newPatientForm = wrapper.find(NewPatientForm) | ||
|
||
await newPatientForm.prop('onSave')(expectedPatient) | ||
|
||
expect(patientSlice.createPatient).toHaveBeenCalledWith(expectedPatient, expect.anything()) | ||
}) | ||
}) |
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