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.
Merge pull request #148 from emma-r-slight/emma-AddDiagnosisModal
test(adddiagnosismodal.test): update test file to use RTL
- Loading branch information
Showing
3 changed files
with
55 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,45 @@ | ||
import { mount } from 'enzyme' | ||
import { render, screen, waitFor } from '@testing-library/react' | ||
import { createMemoryHistory } from 'history' | ||
import React from 'react' | ||
import { act } from 'react-dom/test-utils' | ||
import { Route, Router } from 'react-router-dom' | ||
|
||
import CarePlanForm from '../../../patients/care-plans/CarePlanForm' | ||
import ViewCarePlan from '../../../patients/care-plans/ViewCarePlan' | ||
import PatientRepository from '../../../shared/db/PatientRepository' | ||
import CarePlan from '../../../shared/model/CarePlan' | ||
import Patient from '../../../shared/model/Patient' | ||
|
||
describe('View Care Plan', () => { | ||
const carePlan = { | ||
id: '123', | ||
title: 'Feed Harry Potter', | ||
} as CarePlan | ||
const patient = { | ||
id: 'patientId', | ||
id: '023', | ||
diagnoses: [{ id: '123', name: 'some name', diagnosisDate: new Date().toISOString() }], | ||
carePlans: [{ id: '123', title: 'some title' }], | ||
carePlans: [carePlan], | ||
} as Patient | ||
|
||
const setup = async () => { | ||
jest.resetAllMocks() | ||
jest.spyOn(PatientRepository, 'find').mockResolvedValue(patient) | ||
const history = createMemoryHistory() | ||
history.push(`/patients/${patient.id}/care-plans/${patient.carePlans[0].id}`) | ||
let wrapper: any | ||
|
||
await act(async () => { | ||
wrapper = await mount( | ||
<Router history={history}> | ||
<Route path="/patients/:id/care-plans/:carePlanId"> | ||
<ViewCarePlan /> | ||
</Route> | ||
</Router>, | ||
) | ||
}) | ||
wrapper.update() | ||
|
||
return { wrapper } | ||
return render( | ||
<Router history={history}> | ||
<Route path="/patients/:id/care-plans/:carePlanId"> | ||
<ViewCarePlan /> | ||
</Route> | ||
</Router>, | ||
) | ||
} | ||
|
||
it('should render the care plan title', async () => { | ||
const { wrapper } = await setup() | ||
|
||
expect(wrapper.find('h2').text()).toEqual(patient.carePlans[0].title) | ||
}) | ||
|
||
it('should render a care plan form with the correct data', async () => { | ||
const { wrapper } = await setup() | ||
const { container } = await setup() | ||
|
||
const carePlanForm = wrapper.find(CarePlanForm) | ||
expect(carePlanForm).toHaveLength(1) | ||
expect(carePlanForm.prop('carePlan')).toEqual(patient.carePlans[0]) | ||
expect(carePlanForm.prop('patient')).toEqual(patient) | ||
await waitFor(() => { | ||
screen.logTestingPlaygroundURL() | ||
expect(container.querySelectorAll('div').length).toBe(4) | ||
}) | ||
}) | ||
}) |
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