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 #237 from kcdraidgroup/juhanakristian-viewpatients…
Browse files Browse the repository at this point in the history
…table-test-improvements

ViewPatientsTable.test.tsx improvements
  • Loading branch information
JacobMGEvans authored Jan 7, 2021
2 parents 05d2e17 + 94f5b9f commit 67c29c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/patients/search/ViewPatients.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Patients', () => {
jest.spyOn(PatientRepository, 'search').mockResolvedValue([])
})

it('should render the search patients component', async () => {
it('should render the search patients component', () => {
setup()
userEvent.type(screen.getByRole('textbox'), 'Jean Luc Picard')
expect(screen.getByRole('textbox')).toHaveValue('Jean Luc Picard')
Expand Down
19 changes: 6 additions & 13 deletions src/__tests__/patients/search/ViewPatientsTable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
render as rtlRender,
screen,
waitFor,
waitForElementToBeRemoved,
} from '@testing-library/react'
import { screen, render, waitFor, waitForElementToBeRemoved } from '@testing-library/react'
import format from 'date-fns/format'
import React from 'react'

Expand All @@ -13,13 +8,11 @@ import PatientRepository from '../../../shared/db/PatientRepository'
import Patient from '../../../shared/model/Patient'

describe('View Patients Table', () => {
const render = (expectedSearchRequest: PatientSearchRequest, expectedPatients: Patient[]) => {
const setup = (expectedSearchRequest: PatientSearchRequest, expectedPatients: Patient[]) => {
jest.spyOn(PatientRepository, 'search').mockResolvedValueOnce(expectedPatients)
jest.spyOn(PatientRepository, 'count').mockResolvedValueOnce(expectedPatients.length)

const results = rtlRender(<ViewPatientsTable searchRequest={expectedSearchRequest} />)

return results
return render(<ViewPatientsTable searchRequest={expectedSearchRequest} />)
}

beforeEach(() => {
Expand All @@ -28,14 +21,14 @@ describe('View Patients Table', () => {

it('should search for patients given a search request', () => {
const expectedSearchRequest = { queryString: 'someQueryString' }
render(expectedSearchRequest, [])
setup(expectedSearchRequest, [])

expect(PatientRepository.search).toHaveBeenCalledTimes(1)
expect(PatientRepository.search).toHaveBeenCalledWith(expectedSearchRequest.queryString)
})

it('should display no patients exist if total patient count is 0', async () => {
const { container } = render({ queryString: '' }, [])
const { container } = setup({ queryString: '' }, [])
await waitForElementToBeRemoved(container.querySelector('.css-0'))
expect(screen.getByRole('heading', { name: /patients.noPatients/i })).toBeInTheDocument()
})
Expand All @@ -51,7 +44,7 @@ describe('View Patients Table', () => {
} as Patient
const expectedPatients = [expectedPatient]

render({ queryString: '' }, expectedPatients)
setup({ queryString: '' }, expectedPatients)

await waitFor(() => screen.getByText('familyName'))
const cells = screen.getAllByRole('cell')
Expand Down
20 changes: 10 additions & 10 deletions src/__tests__/patients/view/ImportantPatientInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Important Patient Info Panel', () => {
],
} as Patient

const setup = async (patient = expectedPatient, permissions: Permissions[]) => {
const setup = (patient = expectedPatient, permissions: Permissions[]) => {
jest.resetAllMocks()
jest.spyOn(PatientRepository, 'find').mockResolvedValue(patient)
history = createMemoryHistory()
Expand All @@ -76,24 +76,24 @@ describe('Important Patient Info Panel', () => {
}
})

it("should render patient's code", async () => {
it("should render patient's code", () => {
setup(expectedPatient, [])
expect(screen.getByText(expectedPatient.code)).toBeInTheDocument()
})

it("should render patient's sex", async () => {
it("should render patient's sex", () => {
setup(expectedPatient, [])
expect(screen.getByText(expectedPatient.sex)).toBeInTheDocument()
})

it("should render patient's dateOfDate", async () => {
it("should render patient's dateOfDate", () => {
setup(expectedPatient, [])
expect(screen.getAllByText(expectedPatient.dateOfBirth)[0]).toBeInTheDocument()
})
})

describe('add new visit button', () => {
it('should render an add visit button if user has correct permissions', async () => {
it('should render an add visit button if user has correct permissions', () => {
setup(expectedPatient, [Permissions.AddVisit])
expect(screen.getByRole('button', { name: /patient.visits.new/i })).toBeInTheDocument()
})
Expand All @@ -115,14 +115,14 @@ describe('Important Patient Info Panel', () => {
expect(await screen.findByRole('dialog')).not.toBeInTheDocument()
})

it('should not render new visit button if user does not have permissions', async () => {
it('should not render new visit button if user does not have permissions', () => {
setup(expectedPatient, [])
expect(screen.queryByRole('button', { name: /patient.visits.new/i })).not.toBeInTheDocument()
})
})

describe('add new allergy button', () => {
it('should render an add allergy button if user has correct permissions', async () => {
it('should render an add allergy button if user has correct permissions', () => {
setup(expectedPatient, [Permissions.AddAllergy])
expect(screen.getByRole('button', { name: /patient.allergies.new/i })).toBeInTheDocument()
})
Expand All @@ -144,7 +144,7 @@ describe('Important Patient Info Panel', () => {
expect(await screen.findByRole('dialog')).not.toBeInTheDocument()
})

it('should not render new allergy button if user does not have permissions', async () => {
it('should not render new allergy button if user does not have permissions', () => {
setup(expectedPatient, [])
expect(
screen.queryByRole('button', { name: /patient.allergies.new/i }),
Expand All @@ -153,7 +153,7 @@ describe('Important Patient Info Panel', () => {
})

describe('add diagnoses button', () => {
it('should render an add diagnosis button if user has correct permissions', async () => {
it('should render an add diagnosis button if user has correct permissions', () => {
setup(expectedPatient, [Permissions.AddDiagnosis])
expect(screen.getByRole('button', { name: /patient.diagnoses.new/i })).toBeInTheDocument()
})
Expand All @@ -175,7 +175,7 @@ describe('Important Patient Info Panel', () => {
expect(await screen.findByRole('dialog')).not.toBeInTheDocument()
})

it('should not render new diagnosis button if user does not have permissions', async () => {
it('should not render new diagnosis button if user does not have permissions', () => {
setup(expectedPatient, [])
expect(
screen.queryByRole('button', { name: /patient.diagnoses.new/i }),
Expand Down

0 comments on commit 67c29c7

Please sign in to comment.