From 9084411bc459abfd5e7003460ff2f1574cbbc243 Mon Sep 17 00:00:00 2001 From: Akshay Patel Date: Tue, 5 May 2020 05:40:58 +0530 Subject: [PATCH] fix(viewpatients): call PatientRepository.findAll() only once (#2044) --- src/__tests__/patients/list/ViewPatients.test.tsx | 12 ++++++++++++ src/patients/list/ViewPatients.tsx | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/__tests__/patients/list/ViewPatients.test.tsx b/src/__tests__/patients/list/ViewPatients.test.tsx index 4d13c1f516..a250d28a1d 100644 --- a/src/__tests__/patients/list/ViewPatients.test.tsx +++ b/src/__tests__/patients/list/ViewPatients.test.tsx @@ -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() diff --git a/src/patients/list/ViewPatients.tsx b/src/patients/list/ViewPatients.tsx index 7682463e46..ba2c470013 100644 --- a/src/patients/list/ViewPatients.tsx +++ b/src/patients/list/ViewPatients.tsx @@ -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' @@ -32,8 +32,6 @@ const ViewPatients = () => { }, [dispatch, debouncedSearchText]) useEffect(() => { - dispatch(fetchPatients()) - setButtonToolBar([