forked from patternfly/react-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesktopViewer.test.tsx
More file actions
111 lines (89 loc) · 3.7 KB
/
DesktopViewer.test.tsx
File metadata and controls
111 lines (89 loc) · 3.7 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { DesktopViewer } from './DesktopViewer';
import { MoreInformationDefaultContent } from './MoreInformationDefaultContent';
import { generateDescriptorFile } from './consoleDescriptorGenerator';
import { constants } from '../common/constants';
const { SPICE_CONSOLE_TYPE, RDP_CONSOLE_TYPE, DEFAULT_RDP_PORT } = constants;
const spice = {
address: 'my.host.com',
port: 5900,
tlsPort: '5901'
};
const vnc = {
address: 'my.host.com',
port: 5902,
tlsPort: '5903'
};
const rdp = {
address: 'my.host.com',
port: DEFAULT_RDP_PORT
};
const rdp2 = {
address: 'my.differenthost.com',
port: 1234
};
describe('DesktopViewer', () => {
test('empty', () => {
const { asFragment } = render(<DesktopViewer />);
expect(asFragment()).toMatchSnapshot();
});
test('with Spice and VNC', () => {
const { asFragment } = render(<DesktopViewer spice={spice} vnc={vnc} />);
expect(asFragment()).toMatchSnapshot();
});
test('with Spice, VNC and RDP', () => {
const { asFragment } = render(<DesktopViewer spice={spice} vnc={vnc} rdp={rdp} />);
expect(asFragment()).toMatchSnapshot();
});
test('with Spice, VNC and RDP (different hostname)', () => {
const { asFragment } = render(<DesktopViewer spice={spice} vnc={vnc} rdp={rdp2} />);
expect(asFragment()).toMatchSnapshot();
});
test('launch button', async () => {
const onDownload = jest.fn();
const onGenerate = jest.fn().mockReturnValue({ content: 'Foo' });
const user = userEvent.setup();
render(<DesktopViewer spice={spice} vnc={vnc} onDownload={onDownload} onGenerate={onGenerate} />);
await user.click(screen.getByRole('button', { name: 'Launch Remote Viewer' }));
expect(onGenerate).toHaveBeenCalledTimes(1);
expect(onDownload).toHaveBeenCalledTimes(1);
});
test('RDP launch button', async () => {
const onDownload = jest.fn();
const onGenerate = jest.fn().mockReturnValue({ content: 'Foo' });
const user = userEvent.setup();
render(<DesktopViewer rdp={rdp} onDownload={onDownload} onGenerate={onGenerate} />);
await user.click(screen.getByRole('button', { name: 'Launch Remote Desktop' }));
expect(onGenerate).toHaveBeenCalledTimes(1);
expect(onDownload).toHaveBeenCalledTimes(1);
});
test('with custom more-info content', async () => {
const user = userEvent.setup();
render(
<DesktopViewer spice={spice} vnc={vnc}>
<p id="custom-more-info">My more-info content</p>
</DesktopViewer>
);
expect(screen.queryByText('My more-info content')).toBeNull();
await user.click(screen.getByRole('button', { name: 'Remote Viewer Details' }));
// If one of the items is shown in the description list, the rest will be in the document as well.
expect(screen.getByText('RHEL, CentOS')).toBeInTheDocument();
});
test('default MoreInformationContent', () => {
const { asFragment } = render(<MoreInformationDefaultContent />);
expect(asFragment()).toMatchSnapshot();
});
test('default implementation of generateVVFile()', () => {
const output = generateDescriptorFile(spice, SPICE_CONSOLE_TYPE);
expect(output.mimeType).toMatch('application/x-virt-viewer');
expect(output.content).toMatch(
'[virt-viewer]\ntype=spice\nhost=my.host.com\nport=5900\ndelete-this-file=1\nfullscreen=0\n'
);
});
test('default implementation of generateRDPFile()', () => {
const output = generateDescriptorFile(rdp, RDP_CONSOLE_TYPE);
expect(output.mimeType).toMatch('application/rdp');
expect(output.content).toEqual(expect.stringContaining('full address:s:my.host.com:3389\n')); // the rest is a constant so far
});
});