import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render, fireEvent } from "@testing-library/react";
import Button from "../button";

test("click on button", () => {
  const onClick = jest.fn();
  const { queryByTestId } = render(
    <Button data-testid="btn" onClick={onClick}>
      Test Button
    </Button>
  );
  expect(queryByTestId("btn")).toBeTruthy();
  fireEvent.click(queryByTestId("btn"));
  expect(onClick).toHaveBeenCalled();
});

test("does not call click on disabled button", () => {
  const onClick = jest.fn();
  const { queryByTestId } = render(
    <Button data-testid="btn" disabled={true} variant="info" onClick={onClick}>
      Test Button
    </Button>
  );

  expect(queryByTestId("btn")).toBeTruthy();
  expect(queryByTestId("btn")).toHaveClass("disabled");
  fireEvent.click(queryByTestId("btn"));
  expect(onClick).toHaveBeenCalledTimes(0);
});
