fleet/frontend/components/buttons/DropdownButton/DropdownButton.tests.jsx

25 lines
710 B
React
Raw Normal View History

import React from "react";
import { fireEvent, render, screen } from "@testing-library/react";
import { noop } from "lodash";
2017-01-05 15:26:10 +00:00
import { DropdownButton } from "./DropdownButton";
2017-01-05 15:26:10 +00:00
describe("DropdownButton - component", () => {
2017-01-05 15:26:10 +00:00
it("calls the clicked item's onClick attribute", () => {
const optionSpy = jest.fn();
const dropdownOptions = [
{ label: "btn1", onClick: noop },
{ label: "btn2", onClick: optionSpy },
];
render(
<DropdownButton options={dropdownOptions}>New Button</DropdownButton>
2017-01-05 15:26:10 +00:00
);
fireEvent.click(screen.getByText("New Button"));
2017-01-05 15:26:10 +00:00
fireEvent.click(screen.getByRole("button", { name: "btn2" }));
2017-01-05 15:26:10 +00:00
expect(optionSpy).toHaveBeenCalled();
});
});