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

afterEach(cleanup)

describe("Button", () => {
  it("renders", () => {
    render(<Button>Button</Button>)

    expect(screen.getByText("Button")).toBeInTheDocument()
  })

  it("has cursor-pointer when enabled", () => {
    render(<Button disabled={false}>Button</Button>)

    const button = screen.getByText("Button")
    fireEvent.mouseOver(button)
    expect(button).toHaveClass("cursor-pointer")
  })

  it("has cursor-default when disabled", () => {
    render(<Button disabled={true}>Button</Button>)

    const button = screen.getByText("Button")
    fireEvent.mouseOver(button)
    expect(button).toHaveClass("cursor-default")
  })

  it("has cursor-default when disabled is added but not explicitly set", () => {
    render(<Button disabled>Button</Button>)

    const button = screen.getByText("Button")
    fireEvent.mouseOver(button)
    expect(button).toHaveClass("cursor-default")
  })
})
