-
Notifications
You must be signed in to change notification settings - Fork 4
/
ToolTip-test.tsx
65 lines (50 loc) · 1.87 KB
/
ToolTip-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
import { expect } from "chai";
import * as React from "react";
import { shallow } from "enzyme";
import { spy } from "sinon";
import ToolTip from "../ToolTip";
describe("ToolTip", () => {
let wrapper;
let trigger;
beforeEach(() => {
trigger = <h1>Hover</h1>;
wrapper = shallow(<ToolTip trigger={trigger} text="ToolTip Content" />);
});
it("renders the trigger element", () => {
const trigger = wrapper.find("h1");
expect(trigger.length).to.equal(1);
expect(trigger.text()).to.equal("Hover");
});
it("renders the tooltip", () => {
const tooltip = wrapper.find(".tool-tip");
expect(tooltip.length).to.equal(1);
expect(tooltip.prop("dangerouslySetInnerHTML")["__html"]).to.equal(
"ToolTip Content"
);
expect(tooltip.html()).to.include("ToolTip Content");
});
it("initially hides the tooltip", () => {
expect(wrapper.state()["show"]).to.be.false;
expect(wrapper.find(".tool-tip").hasClass("hide")).to.be.true;
});
it("shows the tooltip on mouseEnter", () => {
const spyShowToolTip = spy(wrapper.instance(), "showToolTip");
wrapper.setProps({ show: spyShowToolTip });
wrapper.simulate("mouseEnter");
expect(spyShowToolTip.callCount).to.equal(1);
expect(wrapper.find(".tool-tip").hasClass("hide")).to.be.false;
expect(wrapper.state()["show"]).to.be.true;
spyShowToolTip.restore();
});
it("hides the tooltip on mouseLeave", () => {
wrapper.setState({ show: true });
expect(wrapper.find(".tool-tip").hasClass("hide")).to.be.false;
const spyHideToolTip = spy(wrapper.instance(), "hideToolTip");
wrapper.setProps({ hide: spyHideToolTip });
wrapper.simulate("mouseLeave");
expect(spyHideToolTip.callCount).to.equal(1);
expect(wrapper.find(".tool-tip").hasClass("hide")).to.be.true;
expect(wrapper.state()["show"]).to.be.false;
spyHideToolTip.restore();
});
});