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 #120 from emma-r-slight/emma.S-AddCareModal
test(addcareplanmodal.test.tsx): update tests to use RTL
- Loading branch information
Showing
3 changed files
with
87 additions
and
93 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 |
---|---|---|
@@ -1,42 +1,45 @@ | ||
import { mount, ReactWrapper } from 'enzyme' | ||
import { render, 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 CarePlanTable from '../../../patients/care-plans/CarePlanTable' | ||
import ViewCarePlans from '../../../patients/care-plans/ViewCarePlans' | ||
import PatientRepository from '../../../shared/db/PatientRepository' | ||
import CarePlan from '../../../shared/model/CarePlan' | ||
import CarePlan, { CarePlanIntent, CarePlanStatus } from '../../../shared/model/CarePlan' | ||
import Patient from '../../../shared/model/Patient' | ||
|
||
describe('View Care Plans', () => { | ||
const patient = { id: '123', carePlans: [] as CarePlan[] } as Patient | ||
const carePlan = { | ||
id: '123', | ||
title: 'Feed Harry Potter', | ||
description: 'Get Dobby to feed Harry Food', | ||
diagnosisId: '123', | ||
startDate: new Date().toISOString(), | ||
endDate: new Date().toISOString(), | ||
status: CarePlanStatus.Active, | ||
intent: CarePlanIntent.Proposal, | ||
} as CarePlan | ||
const patient = { id: '123', carePlans: [carePlan] as CarePlan[] } as Patient | ||
const setup = async () => { | ||
jest.resetAllMocks() | ||
jest.spyOn(PatientRepository, 'find').mockResolvedValue(patient) | ||
|
||
const history = createMemoryHistory() | ||
history.push(`/patients/${patient.id}/careplans`) | ||
let wrapper: any | ||
|
||
await act(async () => { | ||
wrapper = await mount( | ||
<Router history={history}> | ||
<Route path="/patients/:id/careplans"> | ||
<ViewCarePlans /> | ||
</Route> | ||
</Router>, | ||
) | ||
}) | ||
|
||
return { wrapper: wrapper as ReactWrapper } | ||
return render( | ||
<Router history={history}> | ||
<Route path="/patients/:id/careplans"> | ||
<ViewCarePlans /> | ||
</Route> | ||
</Router>, | ||
) | ||
} | ||
|
||
it('should render a care plans table with the patient id', async () => { | ||
const { wrapper } = await setup() | ||
|
||
expect(wrapper.exists(CarePlanTable)).toBeTruthy() | ||
const carePlanTable = wrapper.find(CarePlanTable) | ||
expect(carePlanTable.prop('patientId')).toEqual(patient.id) | ||
const { container } = await setup() | ||
await waitFor(() => { | ||
expect(container.querySelector('table')).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |