forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonWithPanel.test.js
94 lines (82 loc) · 2.67 KB
/
ButtonWithPanel.test.js
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import * as React from 'react';
import { render, fireEvent } from 'react-testing-library';
import ButtonWithPanel from '../../components/shared/ButtonWithPanel';
import ArrowPanel from '../../components/shared/ArrowPanel';
import { ensureExists } from '../../utils/flow';
describe('shared/ButtonWithPanel', () => {
// renders the button in its default state
function setup() {
return render(
<ButtonWithPanel
className="button"
label="My Button"
panel={
<ArrowPanel className="panel">
<div>Panel content</div>
</ArrowPanel>
}
/>
);
}
it('renders the ButtonWithPanel with a closed panel', () => {
const { container } = setup();
expect(container.firstChild).toMatchSnapshot();
});
it('renders a button with a panel', () => {
const { container } = render(
<ButtonWithPanel
className="button"
label="My Button"
open={true}
panel={
<ArrowPanel className="panel">
<div>Panel content</div>
</ArrowPanel>
}
/>
);
expect(container.firstChild).toMatchSnapshot();
});
it('renders a disabled button', () => {
const { container } = render(
<ButtonWithPanel
className="button"
label="My Button"
disabled={true}
panel={
<ArrowPanel className="panel">
<div>Panel content</div>
</ArrowPanel>
}
/>
);
expect(container.firstChild).toMatchSnapshot();
});
it('opens the panel when the button is clicked and closes the panel when the escape key is pressed', () => {
const { getByValue, container } = setup();
fireEvent.click(getByValue('My Button'));
expect(container.firstChild).toMatchSnapshot();
//it closes the panel when Esc key is pressed
fireEvent.keyDown(container, {
key: 'Escape',
keyCode: 27,
which: 27,
});
expect(container.firstChild).toMatchSnapshot();
});
it('opens the panel when the button is clicked and closes the panel by clicking outside the panel', () => {
const { getByValue, container } = setup();
fireEvent.click(getByValue('My Button'));
expect(container.firstChild).toMatchSnapshot();
//it closes the panel when clicking outside the panel
const newDiv = ensureExists(document.body).appendChild(
document.createElement('div')
);
fireEvent.mouseDown(newDiv);
expect(container.firstChild).toMatchSnapshot();
});
});