2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
|
|
|
import { mount, shallow } from "enzyme";
|
|
|
|
import DropDownItem from ".";
|
2019-09-07 10:31:22 +00:00
|
|
|
|
2019-11-01 06:21:59 +00:00
|
|
|
const baseProps = {
|
|
|
|
isSeparator: false,
|
|
|
|
isHeader: false,
|
|
|
|
tabIndex: -1,
|
2020-10-16 13:16:01 +00:00
|
|
|
label: "test",
|
2019-11-01 06:21:59 +00:00
|
|
|
disabled: false,
|
2021-02-20 08:46:32 +00:00
|
|
|
icon: "static/images/nav.logo.react.svg",
|
2019-11-01 06:21:59 +00:00
|
|
|
noHover: false,
|
2020-10-16 13:16:01 +00:00
|
|
|
onClick: jest.fn(),
|
|
|
|
};
|
2019-11-01 06:21:59 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
describe("<DropDownItem />", () => {
|
|
|
|
it("renders without error", () => {
|
|
|
|
const wrapper = mount(<DropDownItem {...baseProps} />);
|
2019-09-07 10:31:22 +00:00
|
|
|
|
|
|
|
expect(wrapper).toExist();
|
|
|
|
});
|
2019-11-01 06:21:59 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("check disabled props", () => {
|
|
|
|
const wrapper = mount(<DropDownItem {...baseProps} disabled={true} />);
|
2019-11-01 06:21:59 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("disabled")).toEqual(true);
|
2019-11-01 06:21:59 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("check isSeparator props", () => {
|
|
|
|
const wrapper = mount(<DropDownItem {...baseProps} isSeparator={true} />);
|
2019-11-01 06:21:59 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("isSeparator")).toEqual(true);
|
2019-11-01 06:21:59 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("check isHeader props", () => {
|
|
|
|
const wrapper = mount(<DropDownItem {...baseProps} isHeader={true} />);
|
2019-11-01 06:21:59 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("isHeader")).toEqual(true);
|
2019-11-01 06:21:59 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("check noHover props", () => {
|
|
|
|
const wrapper = mount(<DropDownItem {...baseProps} noHover={true} />);
|
2019-11-01 06:21:59 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("noHover")).toEqual(true);
|
2019-11-01 06:21:59 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("causes function onClick()", () => {
|
2019-11-01 06:21:59 +00:00
|
|
|
const onClick = jest.fn();
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
const wrapper = shallow(
|
|
|
|
<DropDownItem id="test" {...baseProps} onClick={onClick} />
|
|
|
|
);
|
2019-11-01 06:21:59 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
wrapper.find("#test").simulate("click");
|
2019-11-01 06:21:59 +00:00
|
|
|
|
|
|
|
expect(onClick).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("render without child", () => {
|
|
|
|
const wrapper = shallow(<DropDownItem>test</DropDownItem>);
|
2019-11-01 06:21:59 +00:00
|
|
|
|
|
|
|
expect(wrapper.props.children).toEqual(undefined);
|
|
|
|
});
|
2019-11-27 13:39:21 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts id", () => {
|
|
|
|
const wrapper = mount(<DropDownItem {...baseProps} id="testId" />);
|
2019-11-27 13:39:21 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("id")).toEqual("testId");
|
2019-11-27 13:39:21 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts className", () => {
|
|
|
|
const wrapper = mount(<DropDownItem {...baseProps} className="test" />);
|
2019-11-27 13:39:21 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("className")).toEqual("test");
|
2019-11-27 13:39:21 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts style", () => {
|
2019-11-27 13:39:21 +00:00
|
|
|
const wrapper = mount(
|
2020-10-16 13:16:01 +00:00
|
|
|
<DropDownItem {...baseProps} style={{ color: "red" }} />
|
2019-11-27 13:39:21 +00:00
|
|
|
);
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.getDOMNode().style).toHaveProperty("color", "red");
|
2019-11-27 13:39:21 +00:00
|
|
|
});
|
2019-09-07 10:31:22 +00:00
|
|
|
});
|