import { render } from "@testing-library/react"; import { expect, it, describe } from "vitest"; import { ScrollArea } from "."; describe("ScrollArea", () => { describe("Snapshots", () => { it("should match snapshot with basic structure", () => { const res = render(

Content that overflows both directions

); expect(res).toMatchSnapshot(); }); it("should match snapshot with vertical scrollbar", () => { const res = render(

Content that overflows vertically

); expect(res).toMatchSnapshot(); }); it("should match snapshot with horizontal scrollbar", () => { const res = render(

Content that overflows horizontally

); expect(res).toMatchSnapshot(); }); it("should match snapshot with both scrollbars", () => { const res = render(

Content that overflows in both directions

); expect(res).toMatchSnapshot(); }); it("should match snapshot with scrollbar props", () => { const res = render(

Content with scrollbar props

); expect(res).toMatchSnapshot(); }); it("should match snapshot with custom root props", () => { const res = render(

Content with custom root props

); expect(res).toMatchSnapshot(); }); }); describe("Rendering", () => { it("should render ScrollArea", () => { const { container } = render(); expect(container.firstChild).toBeInTheDocument(); }); it("should render ScrollArea.Viewport", () => { const { getByText } = render(
Test content
); expect(getByText("Test content")).toBeInTheDocument(); }); it("should apply custom className to root", () => { const { container } = render(
Content
); expect(container.firstChild).toHaveClass("custom-class"); }); it("should apply custom styles to viewport", () => { const customStyle = { backgroundColor: "red", height: "300px" }; const { container } = render(
Content
); const viewport = container.querySelector(".aje-scrollarea__viewport"); expect(viewport).toHaveStyle("height: 300px"); }); }); describe("Scrollbar visibility", () => { it("should hide scrollbar when show='auto' and content does not overflow", () => { const { container } = render(
Small content
); const scrollbarTrack = container.querySelector( '[data-orientation="vertical"]' ); expect(scrollbarTrack).not.toBeInTheDocument(); }); it("should reserve space when reserveSpace=true even if not scrollable", () => { const { container } = render(
Small content
); const scrollbar = container.querySelector(".aje-scrollarea__scrollbar"); expect(scrollbar).toBeInTheDocument(); expect(scrollbar).toHaveStyle("visibility: hidden"); }); }); });