-
Notifications
You must be signed in to change notification settings - Fork 227
/
workspace-window.test.tsx
91 lines (68 loc) · 3.02 KB
/
workspace-window.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
import React from 'react';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { isDesktop } from '@openmrs/esm-framework';
import { launchPatientWorkspace, registerWorkspace } from '@openmrs/esm-patient-common-lib';
import { mockPatient } from 'tools';
import WorkspaceWindow from './workspace-window.component';
const mockExtensionRegistry = {};
const mockedIsDesktop = isDesktop as jest.Mock;
jest.mock('./workspace-renderer.component', () => ({
WorkspaceRenderer: jest.fn().mockImplementation(() => <div>Workspace-Renderer</div>),
}));
jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
...originalModule,
isDesktop: jest.fn(),
getExtensionRegistration: (name) => mockExtensionRegistry[name],
registerExtension: (ext) => {
mockExtensionRegistry[ext.name] = ext;
},
translateFrom: (module, key, defaultValue, options) => defaultValue,
useBodyScrollLock: jest.fn(),
};
});
const path = `/patient/:patientUuid/chart`;
// const sampleMatchProp: match<{ patientUuid: string }> = {
// isExact: false,
// path,
// url: path.replace(':patientUuid', '1'),
// params: { patientUuid: '1' },
// };
// const mockRoute: RouteComponentProps<{ patientUuid: string }> = {
// history: '' as any,
// location: '' as any,
// match: sampleMatchProp,
// };
xdescribe('WorkspaceWindow', () => {
test('should reopen hidden workspace window when user relaunches the same workspace window', async () => {
const user = userEvent.setup();
registerWorkspace({ name: 'Clinical Form', title: 'Clinical Form', load: jest.fn() });
launchPatientWorkspace('Clinical Form', { workspaceTitle: 'POC Triage' });
mockedIsDesktop.mockReturnValue(true);
renderWorkspaceWindow();
expect(screen.getByRole('banner', { name: 'Workspace Title' })).toBeInTheDocument();
expect(screen.getByText('POC Triage')).toBeInTheDocument();
const workspaceContainer = screen.getByRole('complementary');
expect(workspaceContainer).toHaveClass('show');
const hideButton = screen.getByRole('button', { name: 'Hide' });
user.click(hideButton);
expect(workspaceContainer).toHaveClass('hide');
await launchPatientWorkspace('Clinical Form', { workspaceTitle: 'POC Triage' });
expect(await screen.findByRole('complementary')).toHaveClass('show');
});
test('should toggle between maximized and normal screen size', async () => {
const user = userEvent.setup();
renderWorkspaceWindow();
const maximizeButton = await screen.findByRole('button', { name: 'Maximize' });
user.click(maximizeButton);
expect(screen.getByRole('complementary')).toHaveClass('maximized');
const minimizeButton = await screen.findByRole('button', { name: 'Minimize' });
user.click(minimizeButton);
expect(screen.getByRole('complementary')).not.toHaveClass('maximized');
});
});
function renderWorkspaceWindow() {
render(<WorkspaceWindow patientUuid={mockPatient.id} />);
}