import { createRef } from "react";
import { render, screen } from "@testing-library/react";
import { Segment } from "./Segment";
describe("Segment", () => {
it("applies mobius and mobius-segment classes", () => {
render();
const el = screen.getByTestId("segment");
expect(el).toHaveClass("mobius");
expect(el).toHaveClass("mobius-segment");
});
it("forwards custom className", () => {
render();
expect(screen.getByTestId("segment")).toHaveClass("custom");
});
it("applies subtle colour class", () => {
render();
expect(screen.getByTestId("segment")).toHaveClass("subtle");
});
it("applies primary colour class", () => {
render();
expect(screen.getByTestId("segment")).toHaveClass("primary");
});
it("applies secondary colour class", () => {
render();
expect(screen.getByTestId("segment")).toHaveClass("secondary");
});
it("applies inverted class when prop is true", () => {
render();
expect(screen.getByTestId("segment")).toHaveClass("inverted");
});
it("renders heading when provided", () => {
render();
const heading = screen.getByText("My Heading");
expect(heading).toBeInTheDocument();
expect(heading).toHaveClass("mobius-segment__heading");
});
it("does not render heading when not provided", () => {
const { container } = render(Content);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- no role/text to query when heading is absent
expect(container.querySelector(".mobius-segment__heading")).toBeNull();
});
it("renders children", () => {
render(Child content);
expect(screen.getByText("Child content")).toBeInTheDocument();
});
it("forwards ref", () => {
const ref = createRef();
render(With ref);
expect(ref.current).toBeInstanceOf(HTMLDivElement);
});
});