From b5e4c387ed43d1373c43bc5a2a66893c090bad27 Mon Sep 17 00:00:00 2001 From: oliv37 Date: Mon, 17 Feb 2020 21:55:31 +0100 Subject: [PATCH] feat(breadcrumb): test the dispatch of addBreadcrumbs action --- src/__tests__/HospitalRun.test.tsx | 85 +++++++++++++------- src/scheduling/appointments/Appointments.tsx | 2 +- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/src/__tests__/HospitalRun.test.tsx b/src/__tests__/HospitalRun.test.tsx index bbfec06db1..bdf1cd4bc4 100644 --- a/src/__tests__/HospitalRun.test.tsx +++ b/src/__tests__/HospitalRun.test.tsx @@ -27,14 +27,14 @@ describe('HospitalRun', () => { describe('routing', () => { describe('/patients/new', () => { it('should render the new patient screen when /patients/new is accessed', () => { + const store = mockStore({ + title: 'test', + user: { permissions: [Permissions.WritePatients] }, + breadcrumbs: { breadcrumbs: [] }, + }) + const wrapper = mount( - + @@ -42,6 +42,13 @@ describe('HospitalRun', () => { ) expect(wrapper.find(NewPatient)).toHaveLength(1) + + expect(store.getActions()).toContainEqual( + addBreadcrumbs([ + { i18nKey: 'patients.label', location: '/patients' }, + { i18nKey: 'patients.newPatient', location: '/patients/new' }, + ]), + ) }) it('should render the Dashboard if the user does not have write patient privileges', () => { @@ -156,15 +163,15 @@ describe('HospitalRun', () => { mockedPatientRepository.find.mockResolvedValue(patient) + const store = mockStore({ + title: 'test', + user: { permissions: [Permissions.ReadPatients] }, + patient: { patient }, + breadcrumbs: { breadcrumbs: [] }, + }) + const wrapper = mount( - + @@ -172,6 +179,13 @@ describe('HospitalRun', () => { ) expect(wrapper.find(ViewPatient)).toHaveLength(1) + + expect(store.getActions()).toContainEqual( + addBreadcrumbs([ + { i18nKey: 'patients.label', location: '/patients' }, + { text: 'test test test', location: `/patients/${patient.id}` }, + ]), + ) }) it('should render the Dashboard when the user does not have read patient privileges', () => { @@ -195,15 +209,15 @@ describe('HospitalRun', () => { describe('/appointments', () => { it('should render the appointments screen when /appointments is accessed', async () => { + const store = mockStore({ + title: 'test', + user: { permissions: [Permissions.ReadAppointments] }, + appointments: { appointments: [] }, + breadcrumbs: { breadcrumbs: [] }, + }) + const wrapper = mount( - + @@ -215,6 +229,10 @@ describe('HospitalRun', () => { }) expect(wrapper.find(Appointments)).toHaveLength(1) + + expect(store.getActions()).toContainEqual( + addBreadcrumbs([{ i18nKey: 'scheduling.appointments.label', location: '/appointments' }]), + ) }) it('should render the Dashboard when the user does not have read appointment privileges', () => { @@ -239,14 +257,14 @@ describe('HospitalRun', () => { describe('/appointments/new', () => { it('should render the new appointment screen when /appointments/new is accessed', async () => { + const store = mockStore({ + title: 'test', + user: { permissions: [Permissions.WriteAppointments] }, + breadcrumbs: { breadcrumbs: [] }, + }) + const wrapper = mount( - + @@ -254,6 +272,13 @@ describe('HospitalRun', () => { ) expect(wrapper.find(NewAppointment)).toHaveLength(1) + + expect(store.getActions()).toContainEqual( + addBreadcrumbs([ + { i18nKey: 'scheduling.appointments.label', location: '/appointments' }, + { i18nKey: 'scheduling.appointments.new', location: '/appointments/new' }, + ]), + ) }) it('should render the Dashboard when the user does not have read appointment privileges', () => { diff --git a/src/scheduling/appointments/Appointments.tsx b/src/scheduling/appointments/Appointments.tsx index b52194b922..28fdb48f1f 100644 --- a/src/scheduling/appointments/Appointments.tsx +++ b/src/scheduling/appointments/Appointments.tsx @@ -17,7 +17,7 @@ interface Event { allDay: boolean } -const breadcrumbs = [{ i18nKey: 'scheduling.appointments.label', location: '/patients' }] +const breadcrumbs = [{ i18nKey: 'scheduling.appointments.label', location: '/appointments' }] const Appointments = () => { const { t } = useTranslation()