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

Commit

Permalink
test(imaging-request-tablet): convert to rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerabrodi committed Dec 23, 2020
1 parent a97f002 commit db49a0b
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions src/__tests__/imagings/search/ImagingRequestTable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Table } from '@hospitalrun/components'
import { mount, ReactWrapper } from 'enzyme'
import { render as rtlRender, screen } from '@testing-library/react'
import React from 'react'
import { act } from 'react-dom/test-utils'

import ImagingSearchRequest from '../../../imagings/model/ImagingSearchRequest'
import ImagingRequestTable from '../../../imagings/search/ImagingRequestTable'
Expand Down Expand Up @@ -31,52 +29,40 @@ describe('Imaging Request Table', () => {
} as Imaging
const expectedImagings = [expectedImaging]

const setup = async (searchRequest: ImagingSearchRequest) => {
const render = (searchRequest: ImagingSearchRequest) => {
jest.resetAllMocks()
jest.spyOn(ImagingRepository, 'search').mockResolvedValue(expectedImagings)
let wrapper: any

await act(async () => {
wrapper = await mount(<ImagingRequestTable searchRequest={searchRequest} />)
})
wrapper.update()
const results = rtlRender(<ImagingRequestTable searchRequest={searchRequest} />)

return { wrapper: wrapper as ReactWrapper }
return results
}

it('should search for imaging requests ', async () => {
it('should search for imaging requests ', () => {
const expectedSearch: ImagingSearchRequest = { status: 'all', text: 'text' }
await setup(expectedSearch)
render(expectedSearch)

expect(ImagingRepository.search).toHaveBeenCalledTimes(1)
expect(ImagingRepository.search).toHaveBeenCalledWith({ ...expectedSearch, defaultSortRequest })
})

it('should render a table of imaging requests', async () => {
it('should render a table of imaging requests', () => {
const expectedSearch: ImagingSearchRequest = { status: 'all', text: 'text' }
const { wrapper } = await setup(expectedSearch)
render(expectedSearch)
const headers = screen.getAllByRole('columnheader')
const cells = screen.getAllByRole('cell')
expect(headers[0]).toHaveTextContent(/imagings.imaging.code/i)
expect(headers[1]).toHaveTextContent(/imagings.imaging.type/i)
expect(headers[2]).toHaveTextContent(/imagings.imaging.requestedOn/i)
expect(headers[3]).toHaveTextContent(/imagings.imaging.patient/i)
expect(headers[4]).toHaveTextContent(/imagings.imaging.requestedBy/i)
expect(headers[5]).toHaveTextContent(/imagings.imaging.status/i)
screen.debug(undefined, Infinity)

const table = wrapper.find(Table)
const columns = table.prop('columns')
expect(columns[0]).toEqual(
expect.objectContaining({ label: 'imagings.imaging.code', key: 'code' }),
)
expect(columns[1]).toEqual(
expect.objectContaining({ label: 'imagings.imaging.type', key: 'type' }),
)
expect(columns[2]).toEqual(
expect.objectContaining({ label: 'imagings.imaging.requestedOn', key: 'requestedOn' }),
)
expect(columns[3]).toEqual(
expect.objectContaining({ label: 'imagings.imaging.patient', key: 'fullName' }),
)
expect(columns[4]).toEqual(
expect.objectContaining({ label: 'imagings.imaging.requestedBy', key: 'requestedBy' }),
)
expect(columns[5]).toEqual(
expect.objectContaining({ label: 'imagings.imaging.status', key: 'status' }),
)

expect(table.prop('data')).toEqual([expectedImaging])
expect(cells[0]).toHaveTextContent('I-1234')
expect(cells[1]).toHaveTextContent('imaging type')
expect(cells[3]).toHaveTextContent('full name')
expect(cells[4]).toHaveTextContent('some user')
expect(cells[5]).toHaveTextContent('requested')
})
})

0 comments on commit db49a0b

Please sign in to comment.