This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(patient): change newAppointment button label and add tests
- Loading branch information
Showing
2 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/__tests__/patients/appointments/NewAppointment.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<Router history={history}> | ||
<Provider store={store}> | ||
<AppointmentsList patientId={patient.id} /> | ||
</Provider> | ||
</Router>, | ||
) | ||
|
||
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') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters