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

Commit

Permalink
fix(viewpatients): call PatientRepository.findAll() only once (#2044)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed May 5, 2020
1 parent 2daf54e commit 9084411
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/__tests__/patients/list/ViewPatients.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ describe('Patients', () => {
mockedPatientRepository.findAll.mockResolvedValue([])
})

describe('initalLoad', () => {
afterEach(() => {
jest.restoreAllMocks()
})

it('should call fetchPatients only once', () => {
setup()
const findAllPagedSpy = jest.spyOn(PatientRepository, 'findAll')
expect(findAllPagedSpy).toHaveBeenCalledTimes(1)
})
})

describe('layout', () => {
afterEach(() => {
jest.restoreAllMocks()
Expand Down
4 changes: 1 addition & 3 deletions src/patients/list/ViewPatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Spinner, Button, Container, Row, TextInput, Column } from '@hospitalrun
import { useButtonToolbarSetter } from 'page-header/ButtonBarProvider'
import format from 'date-fns/format'
import { RootState } from '../../store'
import { fetchPatients, searchPatients } from '../patients-slice'
import { searchPatients } from '../patients-slice'
import useTitle from '../../page-header/useTitle'
import useAddBreadcrumbs from '../../breadcrumbs/useAddBreadcrumbs'
import useDebounce from '../../hooks/debounce'
Expand All @@ -32,8 +32,6 @@ const ViewPatients = () => {
}, [dispatch, debouncedSearchText])

useEffect(() => {
dispatch(fetchPatients())

setButtonToolBar([
<Button
key="newPatientButton"
Expand Down

1 comment on commit 9084411

@vercel
Copy link

@vercel vercel bot commented on 9084411 May 5, 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.