Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #126 from codyarose/codyarose_ViewCareGoals
Browse files Browse the repository at this point in the history
Convert ViewCareGoals.test.tsx to RTL
  • Loading branch information
nobrayner authored Dec 28, 2020
2 parents b7f2d2f + 617067f commit 6f5c496
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/__tests__/patients/care-goals/ViewCareGoals.test.tsx
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()
})
})
})

0 comments on commit 6f5c496

Please sign in to comment.