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
/
NotesTab.test.tsx
99 lines (80 loc) · 2.93 KB
/
NotesTab.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import '../../../__mocks__/matchMediaMock'
import React from 'react'
import PatientRepository from 'clients/db/PatientRepository'
import Note from 'model/Note'
import { createMemoryHistory } from 'history'
import configureMockStore from 'redux-mock-store'
import Patient from 'model/Patient'
import thunk from 'redux-thunk'
import { mount } from 'enzyme'
import { Router } from 'react-router-dom'
import { Provider } from 'react-redux'
import NoteTab from 'patients/notes/NoteTab'
import * as components from '@hospitalrun/components'
import { act } from 'react-dom/test-utils'
import Permissions from '../../../model/Permissions'
const expectedPatient = {
id: '123',
notes: [{ date: new Date().toISOString(), text: 'notes1' } as Note],
} as Patient
const mockStore = configureMockStore([thunk])
const history = createMemoryHistory()
let user: any
let store: any
const setup = (patient = expectedPatient, permissions = [Permissions.WritePatients]) => {
user = { permissions }
store = mockStore({ patient, user })
const wrapper = mount(
<Router history={history}>
<Provider store={store}>
<NoteTab patient={patient} />
</Provider>
</Router>,
)
return wrapper
}
describe('Notes Tab', () => {
describe('Add New Note', () => {
beforeEach(() => {
jest.resetAllMocks()
jest.spyOn(PatientRepository, 'saveOrUpdate')
})
it('should render a add notes button', () => {
const wrapper = setup()
const addNoteButton = wrapper.find(components.Button)
expect(addNoteButton).toHaveLength(1)
expect(addNoteButton.text().trim()).toEqual('patient.notes.new')
})
it('should not render a add notes button if the user does not have permissions', () => {
const wrapper = setup(expectedPatient, [])
const addNotesButton = wrapper.find(components.Button)
expect(addNotesButton).toHaveLength(0)
})
it('should open the Add Notes Modal', () => {
const wrapper = setup()
act(() => {
const onClick = wrapper.find(components.Button).prop('onClick') as any
onClick()
})
wrapper.update()
expect(wrapper.find(components.Modal).prop('show')).toBeTruthy()
})
})
describe('notes list', () => {
it('should list the patients diagnoses', () => {
const notes = expectedPatient.notes as Note[]
const wrapper = setup()
const list = wrapper.find(components.List)
const listItems = wrapper.find(components.ListItem)
expect(list).toHaveLength(1)
expect(listItems).toHaveLength(notes.length)
})
it('should render a warning message if the patient does not have any diagnoses', () => {
const wrapper = setup({ ...expectedPatient, notes: [] })
const alert = wrapper.find(components.Alert)
expect(alert).toHaveLength(1)
expect(alert.prop('title')).toEqual('patient.notes.warning.noNotes')
expect(alert.prop('message')).toEqual('patient.notes.addNoteAbove')
})
})
})