-
Notifications
You must be signed in to change notification settings - Fork 227
/
form-view.test.tsx
94 lines (76 loc) · 2.69 KB
/
form-view.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
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { showModal, useConfig } from '@openmrs/esm-framework';
import { launchFormEntryOrHtmlForms, useVisitOrOfflineVisit } from '@openmrs/esm-patient-common-lib';
import { mockCurrentVisit, mockForms } from '__mocks__';
import { mockPatient } from 'tools';
import FormView from './form-view.component';
const mockLaunchFormEntryOrHtmlForms = launchFormEntryOrHtmlForms as jest.Mock;
const mockShowModal = showModal as jest.Mock;
const mockUseConfig = useConfig as jest.Mock;
const mockUseVisitOrOfflineVisit = useVisitOrOfflineVisit as jest.Mock;
jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
...originalModule,
isDesktop: jest.fn(),
showModal: jest.fn(),
useConfig: jest.fn(),
useConnectivity: jest.fn(),
usePagination: jest.fn().mockImplementation((data) => ({
currentPage: 1,
goTo: () => {},
results: data,
})),
};
});
jest.mock('@openmrs/esm-patient-common-lib', () => {
const originalModule = jest.requireActual('@openmrs/esm-patient-common-lib');
return {
...originalModule,
launchFormEntryOrHtmlForms: jest.fn().mockImplementation((data) => {
showModal(data);
}),
useVisitOrOfflineVisit: jest.fn(),
};
});
describe('FormView', () => {
test('should display `start-visit-dialog` when no visit has been started', async () => {
const user = userEvent.setup();
mockUseVisitOrOfflineVisit.mockReturnValueOnce({
currentVisit: null,
});
mockUseConfig.mockReturnValue({ htmlFormEntryForms: [] });
renderFormView();
const pocForm = await screen.findByText('POC COVID 19 Assessment Form v1.1');
expect(pocForm).toBeInTheDocument();
await user.click(pocForm);
expect(mockShowModal).toHaveBeenCalledTimes(1);
});
test('should launch form-entry patient-workspace window when visit is started', async () => {
const user = userEvent.setup();
mockUseConfig.mockReturnValue({ htmlFormEntryForms: [] });
mockUseVisitOrOfflineVisit.mockReturnValue({
currentVisit: mockCurrentVisit,
error: null,
});
renderFormView();
const pocForm = await screen.findByText('POC COVID 19 Assessment Form v1.1');
expect(pocForm).toBeInTheDocument();
await user.click(pocForm);
expect(mockLaunchFormEntryOrHtmlForms).toBeCalled();
});
});
function renderFormView() {
render(
<FormView
patientUuid={mockPatient.id}
forms={mockForms}
pageSize={5}
pageUrl={'/some-url'}
patient={mockPatient}
urlLabel="some-url-label"
/>,
);
}