diff --git a/src/__tests__/labs/ViewLabs.test.tsx b/src/__tests__/labs/ViewLabs.test.tsx index abc149ad1e..89c2e9f8c4 100644 --- a/src/__tests__/labs/ViewLabs.test.tsx +++ b/src/__tests__/labs/ViewLabs.test.tsx @@ -13,6 +13,7 @@ import LabRepository from 'clients/db/LabRepository' import Lab from 'model/Lab' import format from 'date-fns/format' import * as ButtonBarProvider from 'page-header/ButtonBarProvider' +import SortRequest from 'clients/db/SortRequest' import * as titleUtil from '../../page-header/useTitle' const mockStore = configureMockStore([thunk]) @@ -160,4 +161,37 @@ describe('View Labs', () => { expect(history.location.pathname).toEqual(`/labs/${expectedLab.id}`) }) }) + + describe('sort Request', () => { + let findAllSpy: any + beforeEach(async () => { + const store = mockStore({ + title: '', + user: { permissions: [Permissions.ViewLabs, Permissions.RequestLab] }, + }) + findAllSpy = jest.spyOn(LabRepository, 'findAll') + findAllSpy.mockResolvedValue([]) + await act(async () => { + await mount( + + + + + , + ) + }) + }) + + it('should have called findAll with sort request', () => { + const sortRequest: SortRequest = { + sorts: [ + { + field: 'requestedOn', + direction: 'desc', + }, + ], + } + expect(findAllSpy).toHaveBeenCalledWith(sortRequest) + }) + }) }) diff --git a/src/labs/ViewLabs.tsx b/src/labs/ViewLabs.tsx index af65879f36..d7a42de14d 100644 --- a/src/labs/ViewLabs.tsx +++ b/src/labs/ViewLabs.tsx @@ -6,6 +6,7 @@ import { useButtonToolbarSetter } from 'page-header/ButtonBarProvider' import { Button } from '@hospitalrun/components' import { useHistory } from 'react-router' import LabRepository from 'clients/db/LabRepository' +import SortRequest from 'clients/db/SortRequest' import Lab from 'model/Lab' import { useSelector } from 'react-redux' import Permissions from 'model/Permissions' @@ -38,7 +39,15 @@ const ViewLabs = () => { useEffect(() => { const fetch = async () => { - const fetchedLabs = await LabRepository.findAll() + const sortRequest: SortRequest = { + sorts: [ + { + field: 'requestedOn', + direction: 'desc', + }, + ], + } + const fetchedLabs = await LabRepository.findAll(sortRequest) setLabs(fetchedLabs) }