2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
|
|
|
import { mount } from "enzyme";
|
|
|
|
import ContextMenu from ".";
|
2019-09-07 09:16:00 +00:00
|
|
|
|
2019-11-11 11:55:39 +00:00
|
|
|
const baseProps = {
|
2020-10-16 13:16:01 +00:00
|
|
|
options: [],
|
|
|
|
};
|
2019-11-11 11:55:39 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
describe("<ContextMenu />", () => {
|
|
|
|
it("renders without error", () => {
|
2019-11-11 11:55:39 +00:00
|
|
|
const wrapper = mount(<ContextMenu {...baseProps} />);
|
2019-09-07 09:16:00 +00:00
|
|
|
|
|
|
|
expect(wrapper).toExist();
|
|
|
|
});
|
2019-11-11 11:55:39 +00:00
|
|
|
|
2021-03-26 13:03:51 +00:00
|
|
|
/* it("componentWillUnmount() test unmount", () => {
|
2019-11-11 11:55:39 +00:00
|
|
|
const wrapper = mount(<ContextMenu {...baseProps} />);
|
|
|
|
|
|
|
|
wrapper.unmount();
|
|
|
|
|
|
|
|
expect(wrapper).toEqual(wrapper);
|
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("simulate handleClick() with change state to close context menu", () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<div id="container">
|
|
|
|
<ContextMenu {...baseProps} id="container" />
|
|
|
|
</div>
|
|
|
|
);
|
2020-01-20 12:32:19 +00:00
|
|
|
const instance = wrapper.find(ContextMenu).instance();
|
2019-11-11 11:55:39 +00:00
|
|
|
|
2020-01-20 12:32:19 +00:00
|
|
|
wrapper.find(ContextMenu).setState({ visible: true });
|
2020-10-16 13:16:01 +00:00
|
|
|
instance.handleClick(new Event("click", { target: null }));
|
2019-11-11 11:55:39 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.find(ContextMenu).state("visible")).toEqual(false);
|
2019-11-11 11:55:39 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("render with options", () => {
|
2019-11-11 11:55:39 +00:00
|
|
|
const options = [
|
2020-10-16 13:16:01 +00:00
|
|
|
{ label: "test" },
|
|
|
|
{ key: 2, label: "test" },
|
2019-11-11 11:55:39 +00:00
|
|
|
false,
|
2020-10-16 13:16:01 +00:00
|
|
|
{ key: 4, label: "test" },
|
2019-11-11 11:55:39 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const wrapper = mount(<ContextMenu options={options} />);
|
|
|
|
wrapper.setState({ visible: true });
|
|
|
|
|
|
|
|
expect(wrapper.props().options).toEqual(options);
|
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("simulate handleContextMenu(e) to close context menu", () => {
|
2019-11-11 11:55:39 +00:00
|
|
|
const wrapper = mount(<ContextMenu {...baseProps} />);
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
instance.handleContextMenu(new Event("click", { target: null }));
|
2019-11-11 11:55:39 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.state("visible")).toEqual(true);
|
2019-11-11 11:55:39 +00:00
|
|
|
});
|
2019-11-27 13:06:48 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts id", () => {
|
2019-11-27 13:06:48 +00:00
|
|
|
const wrapper = mount(<ContextMenu {...baseProps} id="testId" />);
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("id")).toEqual("testId");
|
2019-11-27 13:06:48 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts className", () => {
|
2019-11-27 13:06:48 +00:00
|
|
|
const wrapper = mount(<ContextMenu {...baseProps} className="test" />);
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("className")).toEqual("test");
|
2019-11-27 13:06:48 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts style", () => {
|
|
|
|
const wrapper = mount(
|
2020-12-10 16:42:59 +00:00
|
|
|
<ContextMenu
|
|
|
|
{...baseProps}
|
|
|
|
style={{ color: "red" }}
|
|
|
|
withBackdrop={false}
|
|
|
|
/>
|
2020-10-16 13:16:01 +00:00
|
|
|
);
|
2019-11-27 13:06:48 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
wrapper.setState({ visible: true });
|
2019-11-27 13:06:48 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.getDOMNode().style).toHaveProperty("color", "red");
|
2021-03-26 13:03:51 +00:00
|
|
|
}); */
|
2019-09-07 09:16:00 +00:00
|
|
|
});
|