-
Notifications
You must be signed in to change notification settings - Fork 207
/
vitals-header.test.tsx
187 lines (145 loc) · 6.24 KB
/
vitals-header.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import React from 'react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {
type WorkspacesInfo,
defineConfigSchema,
getDefaultsFromConfigSchema,
useConfig,
useWorkspaces,
} from '@openmrs/esm-framework';
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib';
import { mockPatient, getByTextWithMarkup, renderWithSwr, waitForLoadingToFinish } from 'tools';
import { mockVitalsConfig, mockCurrentVisit, mockConceptUnits, mockConceptMetadata, formattedVitals } from '__mocks__';
import { configSchema, type ConfigObject } from '../config-schema';
import { patientVitalsBiometricsFormWorkspace } from '../constants';
import { useVitalsAndBiometrics } from '../common';
import VitalsHeader from './vitals-header.component';
defineConfigSchema('@openmrs/esm-patient-vitals-app', configSchema);
const mockedUseConfig = jest.mocked(useConfig);
const mockedLaunchPatientWorkspace = jest.mocked(launchPatientWorkspace);
const mockedUseVitalsAndBiometrics = jest.mocked(useVitalsAndBiometrics);
const mockedUseWorkspaces = jest.mocked(useWorkspaces);
mockedUseWorkspaces.mockReturnValue({ workspaces: [] } as WorkspacesInfo);
jest.mock('@openmrs/esm-patient-common-lib', () => {
const originalModule = jest.requireActual('@openmrs/esm-patient-common-lib');
return {
...originalModule,
launchPatientWorkspace: jest.fn(),
useVisitOrOfflineVisit: jest.fn().mockImplementation(() => ({ currentVisit: mockCurrentVisit })),
};
});
jest.mock('../common', () => {
const originalModule = jest.requireActual('../common');
return {
...originalModule,
useVitalsConceptMetadata: jest.fn().mockImplementation(() => ({
data: mockConceptUnits,
conceptMetadata: mockConceptMetadata,
isLoading: false,
})),
useVitalsAndBiometrics: jest.fn(),
};
});
describe('VitalsHeader: ', () => {
beforeEach(() => {
mockedUseConfig.mockReturnValue({
...(getDefaultsFromConfigSchema(configSchema) as ConfigObject),
mockVitalsConfig,
});
jest.clearAllMocks();
});
it('renders an empty state view when there are no vitals data to show', async () => {
mockedUseVitalsAndBiometrics.mockReturnValue({
data: [],
} as ReturnType<typeof useVitalsAndBiometrics>);
renderVitalsHeader();
await waitForLoadingToFinish();
expect(screen.getByText(/vitals and biometrics/i)).toBeInTheDocument();
expect(screen.getByText(/no data has been recorded for this patient/i)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /record vitals/i })).toBeInTheDocument();
});
it('renders the most recently recorded values in the vitals header', async () => {
mockedUseVitalsAndBiometrics.mockReturnValue({
data: formattedVitals,
} as ReturnType<typeof useVitalsAndBiometrics>);
renderVitalsHeader();
await waitForLoadingToFinish();
expect(screen.getByText(/vitals and biometrics/i)).toBeInTheDocument();
expect(screen.getByText(/19-May-2021/i)).toBeInTheDocument();
expect(screen.getByText(/vitals history/i)).toBeInTheDocument();
expect(screen.getByText(/record vitals/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/BP\s*121 \/ 89\s*mmHg/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/Temp\s*37\s*DEG C/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/Heart rate\s*76\s*beats\/min/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/SpO2\s*-\s*/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/R\. Rate\s*12\s*breaths\/min/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/Height\s*-\s*/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/BMI\s*-\s*/i)).toBeInTheDocument();
expect(getByTextWithMarkup(/Weight\s*-\s*/i)).toBeInTheDocument();
expect(screen.getByText(/overdue/i)).toBeInTheDocument();
});
it('launches the vitals form when the `record vitals` button is clicked', async () => {
const user = userEvent.setup();
renderVitalsHeader();
await waitForLoadingToFinish();
const recordVitalsButton = screen.getByText(/Record vitals/i);
await user.click(recordVitalsButton);
expect(mockedLaunchPatientWorkspace).toHaveBeenCalledTimes(1);
expect(mockedLaunchPatientWorkspace).toHaveBeenCalledWith(patientVitalsBiometricsFormWorkspace);
});
it('does not flag normal values that lie within the provided reference ranges', async () => {
mockedUseVitalsAndBiometrics.mockReturnValue({
data: formattedVitals,
} as ReturnType<typeof useVitalsAndBiometrics>);
renderVitalsHeader();
await waitForLoadingToFinish();
expect(screen.queryByTitle(/abnormal value/i)).not.toBeInTheDocument();
});
it('flags abnormal values that lie outside of the provided reference ranges', async () => {
const abnormalVitals = [
{
id: '6f4ed885-2bc1-4ed4-92e5-3dddb9180f30',
date: '2022-05-19T00:00:00.000Z',
systolic: 165,
diastolic: 150,
bloodPressureRenderInterpretation: 'critically_high',
pulse: 76,
spo2: undefined,
temperature: 37,
respiratoryRate: 12,
},
];
mockedUseVitalsAndBiometrics.mockReturnValue({
data: abnormalVitals,
} as ReturnType<typeof useVitalsAndBiometrics>);
renderVitalsHeader();
await waitForLoadingToFinish();
expect(screen.getByTitle(/abnormal value/i)).toBeInTheDocument();
});
it('should launch Form Entry vitals and biometrics form', async () => {
const user = userEvent.setup();
mockedUseConfig.mockReturnValue({
...(getDefaultsFromConfigSchema(configSchema) as ConfigObject),
vitals: { ...mockVitalsConfig.vitals, useFormEngine: true, formName: 'Triage' },
});
renderVitalsHeader();
await waitForLoadingToFinish();
const recordVitalsButton = screen.getByText(/Record vitals/i);
await user.click(recordVitalsButton);
expect(mockedLaunchPatientWorkspace).toHaveBeenCalledWith('patient-form-entry-workspace', {
formInfo: {
encounterUuid: '',
formUuid: 'a000cb34-9ec1-4344-a1c8-f692232f6edd',
},
workspaceTitle: 'Triage',
});
});
});
function renderVitalsHeader() {
const testProps = {
patientUuid: mockPatient.id,
showRecordVitalsButton: true,
};
renderWithSwr(<VitalsHeader {...testProps} />);
}