From 1704ccb0ecdf0678038aa7e6c06c222f60ed501f Mon Sep 17 00:00:00 2001 From: aisultankassenov Date: Mon, 6 Apr 2020 15:19:02 +0600 Subject: [PATCH] feat(patient): change newAppointment button label and add tests --- .../appointments/NewAppointment.test.tsx | 64 +++++++++++++++++++ .../appointments/AppointmentsList.tsx | 6 +- 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/__tests__/patients/appointments/NewAppointment.test.tsx diff --git a/src/__tests__/patients/appointments/NewAppointment.test.tsx b/src/__tests__/patients/appointments/NewAppointment.test.tsx new file mode 100644 index 0000000000..1d7dcfaa56 --- /dev/null +++ b/src/__tests__/patients/appointments/NewAppointment.test.tsx @@ -0,0 +1,64 @@ +import '../../../__mocks__/matchMediaMock' +import React from 'react' +import { mount } from 'enzyme' +import { createMemoryHistory } from 'history' +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import Patient from 'model/Patient' +import Permissions from 'model/Permissions' +import { Router } from 'react-router' +import { Provider } from 'react-redux' +import AppointmentsList from 'patients/appointments/AppointmentsList' +import * as components from '@hospitalrun/components' +import { act } from 'react-dom/test-utils' +import PatientRepository from 'clients/db/PatientRepository' + +const expectedPatient = { + id: '123', +} as Patient + +const mockStore = configureMockStore([thunk]) +const history = createMemoryHistory() + +let store: any + +const setup = (patient = expectedPatient) => { + store = mockStore({ patient }) + const wrapper = mount( + + + + + , + ) + + return wrapper +} + +describe('AppointmentsList', () => { + describe('add new appointment button', () => { + beforeEach(() => { + jest.resetAllMocks() + jest.spyOn(PatientRepository, 'saveOrUpdate') + }) + + it('should render a new appointment button', () => { + const wrapper = setup() + + const addNewAppointmentButton = wrapper.find(components.Button) + expect(addNewAppointmentButton).toHaveLength(1) + expect(addNewAppointmentButton.text().trim()).toEqual('scheduling.appointments.new') + }) + + it('should navigate to new appointment page', () => { + const wrapper = setup() + + act(() => { + wrapper.find(components.Button).prop('onClick')() + }) + wrapper.update() + + expect(history.location.pathname).toEqual('/appointments/new') + }) + }) +}) diff --git a/src/patients/appointments/AppointmentsList.tsx b/src/patients/appointments/AppointmentsList.tsx index 15355cd924..68152d2eaf 100644 --- a/src/patients/appointments/AppointmentsList.tsx +++ b/src/patients/appointments/AppointmentsList.tsx @@ -57,13 +57,13 @@ const AppointmentsList = (props: Props) => {