forked from patternfly/react-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialConsole.test.tsx
More file actions
72 lines (64 loc) · 1.92 KB
/
SerialConsole.test.tsx
File metadata and controls
72 lines (64 loc) · 1.92 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
import { render } from '@testing-library/react';
import { SerialConsole } from './SerialConsole';
import { constants } from '../common/constants';
const { CONNECTED, DISCONNECTED, LOADING } = constants;
describe('SerialConsole', () => {
beforeAll(() => {
window.HTMLCanvasElement.prototype.getContext = () => ({ canvas: {} } as any);
});
test('in the LOADING state', () => {
const { asFragment } = render(
<SerialConsole
onData={jest.fn()}
onConnect={jest.fn()}
onDisconnect={jest.fn()}
status={LOADING}
textLoading="My text for Loading"
/>
);
expect(asFragment()).toMatchSnapshot();
});
test('in the DISCONNECTED state', () => {
const { asFragment } = render(
<SerialConsole
onData={jest.fn()}
onConnect={jest.fn()}
onDisconnect={jest.fn()}
status={DISCONNECTED}
textDisconnected="My text for Disconnected"
textConnect="My text for Connect"
/>
);
expect(asFragment()).toMatchSnapshot();
});
describe('with CONNECTED state', () => {
beforeAll(() => {
window.HTMLCanvasElement.prototype.getContext = () =>
({ canvas: {}, createLinearGradient: jest.fn(), fillRect: jest.fn() } as any);
global.window.matchMedia = () => ({
addListener: jest.fn(),
removeListener: jest.fn(),
matches: true,
media: undefined,
onchange: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn()
});
});
test('renders', () => {
const { asFragment } = render(
<SerialConsole
cols={33}
rows={44}
status={CONNECTED}
onData={jest.fn()}
onConnect={jest.fn()}
onDisconnect={jest.fn()}
textDisconnect="My text for Disconnect"
/>
);
expect(asFragment()).toMatchSnapshot();
});
});
});