import { jsx as _jsx } from "react/jsx-runtime";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import { Tooltip, TooltipProvider } from "./tooltip.js";
const TooltipTest = ({ content = "Test tooltip", children = "Hover me", ...props }) => (_jsx(TooltipProvider, { children: _jsx(Tooltip, { content: content, ...props, children: children }) }));
describe("Tooltip", () => {
    it("should render trigger element", () => {
        render(_jsx(TooltipTest, {}));
        expect(screen.getByRole("button")).toBeInTheDocument();
    });
    it("should show tooltip on hover", async () => {
        const onOpenChange = vi.fn();
        render(_jsx(TooltipTest, { onOpenChange: onOpenChange }));
        const trigger = screen.getByText("Hover me");
        const user = userEvent.setup();
        await user.hover(trigger);
        // Wait for the tooltip to be visible by role
        const tooltip = await waitFor(() => screen.getAllByText("Test tooltip"));
        expect(tooltip[0]).toBeInTheDocument();
    });
    it("should hide tooltip when mouse leaves", async () => {
        render(_jsx(TooltipTest, {}));
        const trigger = screen.getByRole("button");
        fireEvent.mouseEnter(trigger);
        fireEvent.mouseLeave(trigger);
        await waitFor(() => {
            expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
        });
    });
    it("should render with custom content", () => {
        render(_jsx(TooltipTest, { content: _jsx("div", { children: "Custom tooltip" }), open: true }));
        expect(screen.getByRole("tooltip")).toBeInTheDocument();
    });
    it("should render with custom trigger element", () => {
        render(_jsx(TooltipTest, { children: _jsx("span", { children: "Custom trigger" }) }));
        expect(screen.getByText("Custom trigger")).toBeInTheDocument();
    });
    it("should be controlled with open prop", () => {
        render(_jsx(TooltipTest, { open: true }));
        expect(screen.getByRole("tooltip")).toBeInTheDocument();
    });
    it("should apply custom className to tooltip content", () => {
        // custom class for testing purposes
        render(_jsx(TooltipTest, { className: "custom-class", open: true }));
        const tooltip = screen.getAllByText("Test tooltip");
        expect(tooltip[0]).toHaveClass("custom-class");
    });
    it("should render with different alignments", () => {
        render(_jsx(TooltipTest, { align: "start", open: true }));
        const tooltip = screen.getAllByText("Test tooltip");
        expect(tooltip[0]).toHaveAttribute("data-align", "start");
    });
    it("should render on different sides", () => {
        render(_jsx(TooltipTest, { side: "right", open: true }));
        const tooltip = screen.getAllByText("Test tooltip");
        expect(tooltip[0]).toHaveAttribute("data-side", "right");
    });
});
//# sourceMappingURL=tooltip.test.js.map