-
Notifications
You must be signed in to change notification settings - Fork 206
/
base-visit-type.test.tsx
93 lines (82 loc) · 2.51 KB
/
base-visit-type.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
import React from 'react';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useVisitTypes } from '@openmrs/esm-framework';
import { mockVisitTypes } from '__mocks__';
import BaseVisitType from './base-visit-type.component';
jest.mock('lodash-es/debounce', () => jest.fn((fn) => fn));
const mockUseVisitTypes = useVisitTypes as jest.Mock;
const mockGoToPage = jest.fn();
jest.mock('@openmrs/esm-framework', () => ({
...(jest.requireActual('@openmrs/esm-framework') as any),
useVisitTypes: jest.fn(),
}));
jest.mock('react-hook-form', () => ({
...jest.requireActual('react-hook-form'),
useFormContext: jest.fn().mockImplementation(() => ({
handleSubmit: () => jest.fn(),
control: {
register: jest.fn(),
unregister: jest.fn(),
getFieldState: jest.fn(),
_names: {
array: new Set('test'),
mount: new Set('test'),
unMount: new Set('test'),
watch: new Set('test'),
focus: 'test',
watchAll: false,
},
_subjects: {
watch: jest.fn(),
array: jest.fn(),
state: jest.fn(),
},
_getWatch: jest.fn(),
_formValues: [],
_defaultValues: [],
},
getValues: () => {
return [];
},
setValue: () => jest.fn(),
formState: () => jest.fn(),
watch: () => jest.fn(),
})),
Controller: ({ render }) =>
render({
field: {
onChange: jest.fn(),
onBlur: jest.fn(),
value: '',
ref: jest.fn(),
},
formState: {
isSubmitted: false,
},
fieldState: {
isTouched: false,
},
}),
useSubscribe: () => ({
r: { current: { subject: { subscribe: () => jest.fn() } } },
}),
}));
describe('VisitTypeOverview', () => {
const renderVisitTypeOverview = () => {
mockUseVisitTypes.mockReturnValue(mockVisitTypes);
render(<BaseVisitType visitTypes={mockVisitTypes} />);
};
it('should be able to search for a visit type', async () => {
const user = userEvent.setup();
renderVisitTypeOverview();
const hivVisit = screen.getByRole('radio', { name: /HIV Return Visit/i });
const outpatientVisit = screen.getByRole('radio', { name: /Outpatient Visit/i });
expect(outpatientVisit).toBeInTheDocument();
expect(hivVisit).toBeInTheDocument();
const searchInput = screen.getByRole('searchbox');
await user.type(searchInput, 'HIV');
expect(outpatientVisit).toBeEmptyDOMElement();
expect(hivVisit).toBeInTheDocument();
});
});