-
Notifications
You must be signed in to change notification settings - Fork 210
/
stop-visit.test.tsx
45 lines (34 loc) · 1.6 KB
/
stop-visit.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
import React from 'react';
import StopVisitOverflowMenuItem from './stop-visit.component';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { showModal, useVisit } from '@openmrs/esm-framework';
import { mockCurrentVisit } from '__mocks__';
import { mockPatient } from 'tools';
const mockUseVisit = jest.mocked(useVisit);
const mockShowModal = jest.mocked(showModal);
jest.mock('@openmrs/esm-framework', () => ({
useVisit: jest.fn(),
showModal: jest.fn(),
useConfig: jest.fn(),
}));
describe('StopVisitOverflowMenuItem', () => {
it('should be able to stop current visit', async () => {
const user = userEvent.setup();
mockUseVisit.mockReturnValue({ currentVisit: mockCurrentVisit } as ReturnType<typeof useVisit>);
render(<StopVisitOverflowMenuItem patientUuid={mockPatient.id} />);
const endVisitButton = screen.getByRole('menuitem', { name: /End Visit/i });
expect(endVisitButton).toBeInTheDocument();
await user.click(endVisitButton);
expect(mockShowModal).toHaveBeenCalledTimes(1);
});
it('should be able to show configured label in button to stop current visit', async () => {
const user = userEvent.setup();
mockUseVisit.mockReturnValue({ currentVisit: mockCurrentVisit } as ReturnType<typeof useVisit>);
render(<StopVisitOverflowMenuItem patientUuid={mockPatient.id} />);
const endVisitButton = screen.getByRole('menuitem', { name: /End visit/ });
expect(endVisitButton).toBeInTheDocument();
await user.click(endVisitButton);
expect(mockShowModal).toHaveBeenCalledTimes(1);
});
});