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 #232 from kcdraidgroup/tigerabrodi-medication-requ…
Browse files Browse the repository at this point in the history
…est-table-test-improvements

test(medication-request-table): improvements
  • Loading branch information
JacobMGEvans authored Jan 7, 2021
2 parents 692893c + 386574b commit e94d817
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/__tests__/medications/search/MedicationRequestTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MedicationRepository from '../../../shared/db/MedicationRepository'
import Medication from '../../../shared/model/Medication'

describe('Medication Request Table', () => {
const setup = async (
const setup = (
givenSearchRequest: MedicationSearchRequest = { text: '', status: 'all' },
givenMedications: Medication[] = [],
) => {
Expand All @@ -29,11 +29,12 @@ describe('Medication Request Table', () => {
}

it('should render a table with the correct columns', async () => {
const { container } = await setup()
const { container } = setup()

await waitFor(() => {
expect(container.querySelector('table')).toBeInTheDocument()
})

const columns = container.querySelectorAll('th')

expect(columns[0]).toHaveTextContent(/medications.medication.medication/i)
Expand All @@ -53,7 +54,7 @@ describe('Medication Request Table', () => {
status: expectedSearchRequest.status,
} as Medication,
]
const { container } = await setup(expectedSearchRequest, expectedMedicationRequests)
const { container } = setup(expectedSearchRequest, expectedMedicationRequests)

await waitFor(() => {
expect(container.querySelector('table')).toBeInTheDocument()
Expand All @@ -65,13 +66,13 @@ describe('Medication Request Table', () => {
it('should navigate to the medication when the view button is clicked', async () => {
const expectedSearchRequest: MedicationSearchRequest = { text: 'someText', status: 'draft' }
const expectedMedicationRequests: Medication[] = [{ id: 'someId' } as Medication]
const { container, history } = await setup(expectedSearchRequest, expectedMedicationRequests)
const { container, history } = setup(expectedSearchRequest, expectedMedicationRequests)

await waitFor(() => {
expect(container.querySelector('table')).toBeInTheDocument()
})
userEvent.click(screen.getByRole('button', { name: /actions.view/i }))

expect(history.location.pathname).toEqual(`/medications/${expectedMedicationRequests[0].id}`)
expect(history.location.pathname).toBe(`/medications/${expectedMedicationRequests[0].id}`)
})
})

0 comments on commit e94d817

Please # to comment.