2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { mount } from "enzyme";
|
|
|
|
|
import { noop } from "lodash";
|
2017-01-05 15:26:10 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import { DropdownButton } from "./DropdownButton";
|
2017-01-05 15:26:10 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("DropdownButton - component", () => {
|
2017-01-05 15:26:10 +00:00
|
|
|
it("calls the clicked item's onClick attribute", () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const optionSpy = jest.fn();
|
2021-04-12 13:32:25 +00:00
|
|
|
const dropdownOptions = [
|
|
|
|
|
{ label: "btn1", onClick: noop },
|
|
|
|
|
{ label: "btn2", onClick: optionSpy },
|
|
|
|
|
];
|
2017-01-05 15:26:10 +00:00
|
|
|
const component = mount(
|
2021-04-12 13:32:25 +00:00
|
|
|
<DropdownButton options={dropdownOptions}>New Button</DropdownButton>
|
2017-01-05 15:26:10 +00:00
|
|
|
);
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
component.find("button.dropdown-button").simulate("click");
|
2017-01-05 15:26:10 +00:00
|
|
|
expect(component.state().isOpen).toEqual(true);
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
component
|
|
|
|
|
.find("li.dropdown-button__option")
|
|
|
|
|
.last()
|
|
|
|
|
.find("Button")
|
|
|
|
|
.simulate("click");
|
2017-01-05 15:26:10 +00:00
|
|
|
expect(optionSpy).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|