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 #126 from codyarose/codyarose_ViewCareGoals
Convert ViewCareGoals.test.tsx to RTL
- Loading branch information
Showing
1 changed file
with
21 additions
and
22 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,42 +1,41 @@ | ||
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 CareGoalTable from '../../../patients/care-goals/CareGoalTable' | ||
import ViewCareGoals from '../../../patients/care-goals/ViewCareGoals' | ||
import PatientRepository from '../../../shared/db/PatientRepository' | ||
import CareGoal from '../../../shared/model/CareGoal' | ||
import Patient from '../../../shared/model/Patient' | ||
|
||
describe('View Care Goals', () => { | ||
const patient = { id: '123', careGoals: [] as CareGoal[] } as Patient | ||
const careGoal = { | ||
id: 'abc', | ||
status: 'accepted', | ||
startDate: new Date().toISOString(), | ||
dueDate: new Date().toISOString(), | ||
} as CareGoal | ||
const patient = { id: '123', careGoals: [careGoal] as CareGoal[] } as Patient | ||
const setup = async () => { | ||
jest.resetAllMocks() | ||
jest.spyOn(PatientRepository, 'find').mockResolvedValue(patient) | ||
|
||
const history = createMemoryHistory() | ||
history.push(`/patients/${patient.id}/care-goals`) | ||
let wrapper: any | ||
|
||
await act(async () => { | ||
wrapper = await mount( | ||
<Router history={history}> | ||
<Route path="/patients/:id/care-goals"> | ||
<ViewCareGoals /> | ||
</Route> | ||
</Router>, | ||
) | ||
}) | ||
|
||
return { wrapper: wrapper as ReactWrapper } | ||
return render( | ||
<Router history={history}> | ||
<Route path="/patients/:id/care-goals"> | ||
<ViewCareGoals /> | ||
</Route> | ||
</Router>, | ||
) | ||
} | ||
|
||
it('should render a care goals table with the patient id', async () => { | ||
const { wrapper } = await setup() | ||
|
||
expect(wrapper.exists(CareGoalTable)).toBeTruthy() | ||
const careGoalTable = wrapper.find(CareGoalTable) | ||
expect(careGoalTable.prop('patientId')).toEqual(patient.id) | ||
it('should render a care goals table', async () => { | ||
const { container } = await setup() | ||
await waitFor(() => { | ||
expect(container.querySelector('table')).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |