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 #200 from codyarose/codyarose
Browse files Browse the repository at this point in the history
ImagingRequestTable.test.tsx - Remove redundant test and clean up
  • Loading branch information
JacobMGEvans authored Jan 3, 2021
2 parents 4f154e3 + 4dff109 commit 7a162f2
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions src/__tests__/imagings/search/ImagingRequestTable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { render as rtlRender, screen } from '@testing-library/react'
import format from 'date-fns/format'
import React from 'react'

import ImagingSearchRequest from '../../../imagings/model/ImagingSearchRequest'
import ImagingRequestTable from '../../../imagings/search/ImagingRequestTable'
import ImagingRepository from '../../../shared/db/ImagingRepository'
import SortRequest from '../../../shared/db/SortRequest'
import Imaging from '../../../shared/model/Imaging'

const defaultSortRequest: SortRequest = {
sorts: [
{
field: 'requestedOn',
direction: 'desc',
},
],
}

describe('Imaging Request Table', () => {
const expectedImaging = {
code: 'I-1234',
Expand All @@ -27,42 +18,34 @@ describe('Imaging Request Table', () => {
requestedOn: new Date().toISOString(),
requestedBy: 'some user',
} as Imaging
const expectedImagings = [expectedImaging]

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

const results = rtlRender(<ImagingRequestTable searchRequest={searchRequest} />)
jest.spyOn(ImagingRepository, 'search').mockResolvedValue([expectedImaging])

return results
return rtlRender(<ImagingRequestTable searchRequest={searchRequest} />)
}

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

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

it('should render a table of imaging requests', async () => {
const expectedSearch: ImagingSearchRequest = { status: 'all', text: 'text' }
render(expectedSearch)

const headers = await screen.findAllByRole('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)

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')
expect(cells[0]).toHaveTextContent(expectedImaging.code)
expect(cells[1]).toHaveTextContent(expectedImaging.type)
expect(cells[2]).toHaveTextContent(
format(new Date(expectedImaging.requestedOn), 'yyyy-MM-dd hh:mm a'),
)
expect(cells[3]).toHaveTextContent(expectedImaging.fullName)
expect(cells[4]).toHaveTextContent(expectedImaging.requestedBy)
expect(cells[5]).toHaveTextContent(expectedImaging.status)
})
})

0 comments on commit 7a162f2

Please sign in to comment.