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

fix(viewpatients): call PatientRepository.findAll() only once #2044

Merged
merged 3 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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