diff --git a/src/__tests__/imagings/search/ImagingRequestTable.test.tsx b/src/__tests__/imagings/search/ImagingRequestTable.test.tsx index 1daf557e24..aa3cefbd51 100644 --- a/src/__tests__/imagings/search/ImagingRequestTable.test.tsx +++ b/src/__tests__/imagings/search/ImagingRequestTable.test.tsx @@ -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', @@ -27,31 +18,20 @@ 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() + jest.spyOn(ImagingRepository, 'search').mockResolvedValue([expectedImaging]) - return results + return rtlRender() } - 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) @@ -59,10 +39,13 @@ describe('Imaging Request Table', () => { 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) }) })