-
Notifications
You must be signed in to change notification settings - Fork 227
/
allergies-detailed-summary.test.tsx
80 lines (65 loc) · 3.18 KB
/
allergies-detailed-summary.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
import React from 'react';
import { screen } from '@testing-library/react';
import { openmrsFetch } from '@openmrs/esm-framework';
import { mockFhirAllergyIntoleranceResponse } from '__mocks__';
import { mockPatient, renderWithSwr, waitForLoadingToFinish } from 'tools';
import AllergiesDetailedSummary from './allergies-detailed-summary.component';
const testProps = {
patient: mockPatient,
};
const mockOpenmrsFetch = openmrsFetch as jest.Mock;
mockOpenmrsFetch.mockImplementation(jest.fn());
describe('AllergiesDetailedSummary: ', () => {
it('renders an empty state view if allergy data is unavailable', async () => {
mockOpenmrsFetch.mockReturnValueOnce({ data: { entry: [] } });
renderAllergiesDetailedSummary();
await waitForLoadingToFinish();
expect(screen.queryByRole('table')).not.toBeInTheDocument();
expect(screen.getByRole('heading', { name: /allergies/i })).toBeInTheDocument();
expect(screen.getByText(/There are no allergy intolerances to display for this patient/i)).toBeInTheDocument();
expect(screen.getByText(/Record allergy intolerances/i)).toBeInTheDocument();
});
it('renders an error state view if there was a problem fetching allergies data', async () => {
const error = {
message: 'You are not logged in',
response: {
status: 401,
statusText: 'Unauthorized',
},
};
mockOpenmrsFetch.mockRejectedValueOnce(error);
renderAllergiesDetailedSummary();
await waitForLoadingToFinish();
expect(screen.queryByRole('table')).not.toBeInTheDocument();
expect(screen.getByRole('heading', { name: /allergies/i })).toBeInTheDocument();
expect(screen.getByText(/Error 401: Unauthorized/i)).toBeInTheDocument();
expect(
screen.getByText(
/Sorry, there was a problem displaying this information. You can try to reload this page, or contact the site administrator and quote the error code above/i,
),
).toBeInTheDocument();
});
it("renders a detailed summary of the patient's allergic reactions and their manifestations", async () => {
mockOpenmrsFetch.mockReturnValueOnce({ data: mockFhirAllergyIntoleranceResponse });
renderAllergiesDetailedSummary();
await waitForLoadingToFinish();
expect(screen.getByRole('heading', { name: /allergies/i })).toBeInTheDocument();
const expectedColumnHeaders = [/allergen/i, /severity/i, /reaction/i, /onset date and comments/i];
const expectedAllergies = [
/ACE inhibitors moderate Anaphylaxis/i,
/Fish mild Anaphylaxis, Angioedema, Fever, Hives Some Comments/i,
/Penicillins severe Diarrhea, Cough, Musculoskeletal pain, Mental status change, Angioedema Patient allergies have been noted down/i,
/Morphine severe Mental status change Comments/i,
/Aspirin severe Mental status change Comments/i,
];
expectedColumnHeaders.forEach((header) =>
expect(screen.getByRole('columnheader', { name: new RegExp(header) })).toBeInTheDocument(),
);
expectedAllergies.forEach((allergy) =>
expect(screen.getByRole('row', { name: new RegExp(allergy) })).toBeInTheDocument(),
);
});
});
function renderAllergiesDetailedSummary() {
renderWithSwr(<AllergiesDetailedSummary {...testProps} />);
}