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

Commit

Permalink
fix(test): add typing delay so search gets called correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nobrayner committed Dec 31, 2020
1 parent f12f344 commit 0638d44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { act, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import React from 'react'
import { ReactQueryConfigProvider } from 'react-query'

import AddRelatedPersonModal from '../../../patients/related-persons/AddRelatedPersonModal'
import PatientRepository from '../../../shared/db/PatientRepository'
import Patient from '../../../shared/model/Patient'
import { expectOneConsoleError } from '../../test-utils/console.utils'

const noRetryConfig = {
queries: {
retry: false,
},
}

describe('Add Related Person Modal', () => {
const patients = [
{
Expand All @@ -22,19 +29,20 @@ describe('Add Related Person Modal', () => {
] as Patient[]

const setup = () => {
jest.resetAllMocks()
jest.spyOn(PatientRepository, 'find').mockResolvedValue(patients[0])
jest.spyOn(PatientRepository, 'search').mockResolvedValue(patients)
jest.spyOn(PatientRepository, 'saveOrUpdate').mockResolvedValue(patients[1])
jest.spyOn(PatientRepository, 'count').mockResolvedValue(2)

return render(
<AddRelatedPersonModal
show
patientId={patients[0].id}
onCloseButtonClick={jest.fn()}
toggle={jest.fn()}
/>,
<ReactQueryConfigProvider config={noRetryConfig}>
<AddRelatedPersonModal
show
patientId={patients[0].id}
onCloseButtonClick={jest.fn()}
toggle={jest.fn()}
/>
</ReactQueryConfigProvider>,
)
}

Expand Down Expand Up @@ -102,11 +110,12 @@ describe('Add Related Person Modal', () => {
it('should call the save function with the correct data', async () => {
setup()

userEvent.type(
await userEvent.type(
screen.getByPlaceholderText(/^patient.relatedPerson$/i),
patients[1].fullName as string,
{ delay: 50 },
)
userEvent.click(await screen.findByText(/fullName2/i))
userEvent.click(await screen.findByText(/^fullname2/i))

userEvent.type(
screen.getByLabelText(/^patient.relatedPersons.relationshipType$/i),
Expand All @@ -127,6 +136,6 @@ describe('Add Related Person Modal', () => {
],
}),
)
}, 20000)
}, 40000)
})
})
1 change: 1 addition & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ configure({ defaultHidden: true })
jest.setTimeout(10000)

afterEach(() => {
jest.resetAllMocks()
jest.restoreAllMocks()
queryCache.clear()
})
Expand Down

0 comments on commit 0638d44

Please sign in to comment.