import { fireEvent, render, screen } from "@solidjs/testing-library";
import { describe, expect, it, vi } from "vitest";
import { Button } from "../../../src/components/button/index";

describe("Button", () => {
	it("renders as button element", () => {
		render(() => <Button>Click</Button>);
		expect(screen.getByRole("button")).toBeTruthy();
	});
	it("has type=button by default", () => {
		render(() => <Button>Click</Button>);
		expect(screen.getByRole("button").getAttribute("type")).toBe("button");
	});
	it("disabled button", () => {
		render(() => <Button disabled>Click</Button>);
		expect(screen.getByRole("button")).toBeDisabled();
	});
	it("fires onClick", () => {
		const onClick = vi.fn();
		render(() => <Button onClick={onClick}>Click</Button>);
		fireEvent.click(screen.getByRole("button"));
		expect(onClick).toHaveBeenCalled();
	});
	it("does not fire onClick when disabled", () => {
		const onClick = vi.fn();
		render(() => (
			<Button disabled onClick={onClick}>
				Click
			</Button>
		));
		fireEvent.click(screen.getByRole("button"));
		expect(onClick).not.toHaveBeenCalled();
	});
});
