From 3c2b2ae978a856037d66e3d32fda4b3c3e0f5836 Mon Sep 17 00:00:00 2001 From: Jack Meyer Date: Sun, 5 Jan 2020 20:37:35 -0600 Subject: [PATCH 1/2] feat(patients): add success message when patient is created successfully fix #1701 --- public/locales/en/translation.json | 6 +++- src/__tests__/containers/HospitalRun.test.tsx | 20 +++++++++++ src/__tests__/patients/patients-slice.test.ts | 33 +++++++++++++++++++ src/containers/HospitalRun.tsx | 2 ++ src/patients/patients-slice.ts | 9 +++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 67bc044bfb..73872b2c8f 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -6,7 +6,8 @@ "label": "Patients", "viewPatients": "View Patients", "viewPatient": "View Patient", - "newPatient": "New Patient" + "newPatient": "New Patient", + "successfullyCreated": "Successfully created patient " }, "patient": { "suffix": "Suffix", @@ -47,5 +48,8 @@ "new": "New", "list": "List", "search": "Search" + }, + "states": { + "success": "Success!" } } diff --git a/src/__tests__/containers/HospitalRun.test.tsx b/src/__tests__/containers/HospitalRun.test.tsx index 606409eb61..5e288419a6 100644 --- a/src/__tests__/containers/HospitalRun.test.tsx +++ b/src/__tests__/containers/HospitalRun.test.tsx @@ -6,6 +6,7 @@ import { Provider } from 'react-redux' import { mocked } from 'ts-jest/utils' import thunk from 'redux-thunk' import configureMockStore from 'redux-mock-store' +import { Toaster } from '@hospitalrun/components' import NewPatient from '../../patients/new/NewPatient' import ViewPatient from '../../patients/view/ViewPatient' import PatientRepository from '../../clients/db/PatientRepository' @@ -64,4 +65,23 @@ describe('HospitalRun', () => { expect(wrapper.find(ViewPatient)).toHaveLength(1) }) }) + + describe('layout', () => { + it('should render a Toaster', () => { + const wrapper = mount( + + + + + , + ) + + expect(wrapper.find(Toaster)).toHaveLength(1) + }) + }) }) diff --git a/src/__tests__/patients/patients-slice.test.ts b/src/__tests__/patients/patients-slice.test.ts index a8950369e6..c13dad058d 100644 --- a/src/__tests__/patients/patients-slice.test.ts +++ b/src/__tests__/patients/patients-slice.test.ts @@ -1,10 +1,15 @@ +import '../../__mocks__/matchMediaMock' import { AnyAction } from 'redux' import { createMemoryHistory } from 'history' import { mocked } from 'ts-jest/utils' +import * as components from '@hospitalrun/components' +import { useTranslation } from 'react-i18next' import * as patientsSlice from '../../patients/patients-slice' import Patient from '../../model/Patient' import PatientRepository from '../../clients/db/PatientRepository' +const { t } = useTranslation() + describe('patients slice', () => { beforeEach(() => { jest.resetAllMocks() @@ -100,5 +105,33 @@ describe('patients slice', () => { expect(history.entries[1].pathname).toEqual(`/patients/${expectedPatientId}`) }) + + it('should call the Toaster function with the correct data', async () => { + jest.spyOn(components, 'Toast') + const expectedPatientId = '12345' + const expectedGivenName = 'given' + const expectedFamilyName = 'family' + const expectedSuffix = 'suffix' + const expectedPatient = { + id: expectedPatientId, + givenName: expectedGivenName, + familyName: expectedFamilyName, + suffix: expectedSuffix, + } as Patient + const mockedPatientRepository = mocked(PatientRepository, true) + mockedPatientRepository.save.mockResolvedValue(expectedPatient) + const mockedComponents = mocked(components, true) + const history = createMemoryHistory() + const dispatch = jest.fn() + const getState = jest.fn() + + await patientsSlice.createPatient(expectedPatient, history)(dispatch, getState, null) + + expect(mockedComponents.Toast).toHaveBeenCalledWith( + 'success', + 'Success!', + `patients.successfullyCreated ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`, + ) + }) }) }) diff --git a/src/containers/HospitalRun.tsx b/src/containers/HospitalRun.tsx index dbc20d736b..621ff14544 100644 --- a/src/containers/HospitalRun.tsx +++ b/src/containers/HospitalRun.tsx @@ -1,6 +1,7 @@ import React from 'react' import { Switch, Route } from 'react-router-dom' import { useSelector } from 'react-redux' +import { Toaster } from '@hospitalrun/components' import Sidebar from '../components/Sidebar' import Permissions from '../util/Permissions' import Dashboard from './Dashboard' @@ -47,6 +48,7 @@ const HospitalRun = () => { /> + diff --git a/src/patients/patients-slice.ts b/src/patients/patients-slice.ts index 76a381880d..358929e640 100644 --- a/src/patients/patients-slice.ts +++ b/src/patients/patients-slice.ts @@ -1,7 +1,9 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' +import { Toast } from '@hospitalrun/components' import Patient from '../model/Patient' import PatientRepository from '../clients/db/PatientRepository' import { AppThunk } from '../store' +import il8n from '../i18n' interface PatientsState { isLoading: boolean @@ -45,6 +47,13 @@ export const createPatient = (patient: Patient, history: any): AppThunk => async const newPatient = await PatientRepository.save(patient) dispatch(createPatientSuccess()) history.push(`/patients/${newPatient.id}`) + Toast( + 'success', + il8n.t('Success!'), + `${il8n.t('patients.successfullyCreated')} ${patient.givenName} ${patient.familyName} ${ + patient.suffix + }`, + ) } catch (error) { console.log(error) } From b014a2ca19cb5a4777aa2d50bf17274286598073 Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Fri, 10 Jan 2020 09:29:23 +0100 Subject: [PATCH 2/2] updates components --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36c1c383ae..ef82cc4abe 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "private": false, "license": "MIT", "dependencies": { - "@hospitalrun/components": "^0.27.2", + "@hospitalrun/components": "^0.28.0", "@reduxjs/toolkit": "~1.2.1", "@semantic-release/changelog": "~3.0.4", "@semantic-release/git": "~7.0.16",