Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(patient): change newAppointment button label and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oizuldan committed Apr 6, 2020
1 parent ec5d655 commit 1704ccb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
64 changes: 64 additions & 0 deletions 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(
<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')
})
})
})
6 changes: 3 additions & 3 deletions src/patients/appointments/AppointmentsList.tsx
Expand Up @@ -57,13 +57,13 @@ const AppointmentsList = (props: Props) => {
<div className="row">
<div className="col-md-12 d-flex justify-content-end">
<Button
key="newAppointmentButton"
outlined
color="success"
icon="add"
iconLocation="left"
icon="appointment-add"
onClick={() => history.push('/appointments/new')}
>
{t('patient.appointments.new')}
{t('scheduling.appointments.new')}
</Button>
</div>
</div>
Expand Down

0 comments on commit 1704ccb

Please sign in to comment.