forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopover.spec.js
More file actions
98 lines (95 loc) · 2.45 KB
/
Copy pathPopover.spec.js
File metadata and controls
98 lines (95 loc) · 2.45 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
/* 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/>. */
import React from "react";
import { mount, shallow } from "enzyme";
import Popover from "../Popover";
describe("Popover", () => {
const onMouseLeave = jest.fn();
const editorRef = {
getBoundingClientRect() {
return {
x: 0,
y: 0,
width: 100,
height: 100,
top: 250,
right: 0,
bottom: 0,
left: 20
};
}
};
const targetPosition = {
x: 100,
y: 200,
width: 300,
height: 300,
top: 50,
right: 0,
bottom: 0,
left: 200
};
const popover = shallow(
<Popover
onMouseLeave={onMouseLeave}
editorRef={editorRef}
targetPosition={targetPosition}
>
<h1>Poppy!</h1>
</Popover>
);
const tooltip = shallow(
<Popover
type="tooltip"
onMouseLeave={onMouseLeave}
editorRef={editorRef}
targetPosition={targetPosition}
>
<h1>Toolie!</h1>
</Popover>
);
const div = document.createElement("div");
const event = { currentTarget: div };
beforeEach(() => onMouseLeave.mockClear());
it("render", () => expect(popover).toMatchSnapshot());
it("render (tooltip)", () => expect(tooltip).toMatchSnapshot());
it("calls mouseLeave", () => {
popover.find(".popover").simulate("mouseleave", event);
expect(onMouseLeave).toHaveBeenCalled();
});
it("calls mouseLeave (tooltip)", () => {
tooltip.find(".tooltip").simulate("mouseleave", event);
expect(onMouseLeave).toHaveBeenCalled();
});
it("no mouse leave on bracket or gap", () => {
div.className = "bracket-arrow";
popover.find(".popover").simulate("mouseleave", event);
expect(onMouseLeave).not.toHaveBeenCalled();
});
it("mount popover", () => {
const mountedPopover = mount(
<Popover
onMouseLeave={onMouseLeave}
editorRef={editorRef}
targetPosition={targetPosition}
>
<h1>Poppy!</h1>
</Popover>
);
expect(mountedPopover).toMatchSnapshot();
});
it("mount tooltip", () => {
const mountedTooltip = mount(
<Popover
type="tooltip"
onMouseLeave={onMouseLeave}
editorRef={editorRef}
targetPosition={targetPosition}
>
<h1>Toolie!</h1>
</Popover>
);
expect(mountedTooltip).toMatchSnapshot();
});
});