import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; import Tooltip from "./Tooltip"; describe("Tooltip", () => { test("renders the children", () => { render( , ); expect(screen.getByRole("button", { name: "Save" })).toBeInTheDocument(); }); test("tooltip element is always present in the DOM", () => { render( , ); expect(screen.getByRole("tooltip")).toBeInTheDocument(); }); test("tooltip has the correct text content", () => { render( , ); expect(screen.getByRole("tooltip")).toHaveTextContent("Helpful hint"); }); test("applies the correct position class", () => { render( , ); expect(screen.getByRole("tooltip")).toHaveClass("tooltip-bottom"); }); test("defaults to the top position", () => { render( , ); expect(screen.getByRole("tooltip")).toHaveClass("tooltip-top"); }); test("applies an additional className to the tooltip", () => { render( , ); expect(screen.getByRole("tooltip")).toHaveClass("tooltip", "custom-tip"); }); test.each(["top", "bottom", "left", "right"])( "renders the %s position without error", (position) => { render( , ); expect(screen.getByRole("tooltip")).toHaveClass(`tooltip-${position}`); }, ); test("renders rich content in the tooltip", () => { render( Bold hint}> , ); expect(screen.getByText("Bold hint")).toBeInTheDocument(); }); test("wrapper has the tooltip-wrapper class", () => { const { container } = render( , ); expect(container.querySelector(".tooltip-wrapper")).toBeInTheDocument(); }); });