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 #70 from kcdraidgroup/tigerabrodi-viewnote-to-rtl
Browse files Browse the repository at this point in the history
test(view-note): convert to rtl
  • Loading branch information
tigerabrodi authored Dec 23, 2020
2 parents 8ecbca7 + 4a3b435 commit 34b31b7
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/__tests__/patients/notes/ViewNote.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { mount, ReactWrapper } from 'enzyme'
import { render, screen } 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 ViewNote from '../../../patients/notes/ViewNote'
import TextInputWithLabelFormGroup from '../../../shared/components/input/TextInputWithLabelFormGroup'
import PatientRepository from '../../../shared/db/PatientRepository'
import Patient from '../../../shared/model/Patient'

Expand All @@ -15,32 +13,21 @@ describe('View Note', () => {
notes: [{ id: '123', text: 'some name', date: '1947-09-09T14:48:00.000Z' }],
} as Patient

const setup = async () => {
it('should render a note input with the correct data', async () => {
jest.spyOn(PatientRepository, 'find').mockResolvedValue(patient)
const history = createMemoryHistory()
history.push(`/patients/${patient.id}/notes/${patient.notes![0].id}`)
let wrapper: any

await act(async () => {
wrapper = await mount(
<Router history={history}>
<Route path="/patients/:id/notes/:noteId">
<ViewNote />
</Route>
</Router>,
)
const history = createMemoryHistory({
initialEntries: [`/patients/${patient.id}/notes/${patient.notes![0].id}`],
})

wrapper.update()

return { wrapper: wrapper as ReactWrapper }
}

it('should render a note input with the correct data', async () => {
const { wrapper } = await setup()
render(
<Router history={history}>
<Route path="/patients/:id/notes/:noteId">
<ViewNote />
</Route>
</Router>,
)

const noteText = wrapper.find(TextInputWithLabelFormGroup)
expect(noteText).toHaveLength(1)
expect(noteText.prop('value')).toEqual(patient.notes![0].text)
const input = await screen.findByLabelText(/patient.note/i)
expect(input).toHaveValue(patient.notes![0].text)
})
})

0 comments on commit 34b31b7

Please sign in to comment.