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

Commit

Permalink
feat(viewlabs): sort Labs by requestedOn field (#2004)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap authored Apr 22, 2020
1 parent d1dce48 commit 88ec61c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/__tests__/labs/ViewLabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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(
<Provider store={store}>
<Router history={createMemoryHistory()}>
<ViewLabs />
</Router>
</Provider>,
)
})
})

it('should have called findAll with sort request', () => {
const sortRequest: SortRequest = {
sorts: [
{
field: 'requestedOn',
direction: 'desc',
},
],
}
expect(findAllSpy).toHaveBeenCalledWith(sortRequest)
})
})
})
11 changes: 10 additions & 1 deletion src/labs/ViewLabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}

Expand Down

1 comment on commit 88ec61c

@vercel
Copy link

@vercel vercel bot commented on 88ec61c Apr 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.