import { SeeMore } from "./index";
import { fireEvent, render, screen } from "@testing-library/react";
describe("SeeMore", () => {
const defaultList = ["Item 1", "Item 2", "Item 3"];
it("renders with default text when no text prop is provided", () => {
render();
expect(screen.getByText("See details")).toBeInTheDocument();
});
it("renders with custom text when text prop is provided", () => {
render();
expect(screen.getByText("Show more info")).toBeInTheDocument();
});
it("renders the checklist items", () => {
render();
defaultList.forEach(item => {
expect(screen.getByText(item)).toBeInTheDocument();
});
});
it("starts with details expanded (showDetails is true)", () => {
render();
const button = screen.getByRole("button");
expect(button).toHaveAttribute("aria-expanded", "true");
});
it("shows keyboard_arrow_down icon when expanded", () => {
render();
expect(screen.getByText("keyboard_arrow_down")).toBeInTheDocument();
});
it("collapses details when button is clicked", () => {
render();
const button = screen.getByRole("button");
fireEvent.click(button);
expect(button).toHaveAttribute("aria-expanded", "false");
});
it("shows keyboard_arrow_up icon when collapsed", () => {
render();
const button = screen.getByRole("button");
fireEvent.click(button);
expect(screen.getByText("keyboard_arrow_up")).toBeInTheDocument();
});
it("expands details again on second click", () => {
render();
const button = screen.getByRole("button");
fireEvent.click(button);
fireEvent.click(button);
expect(button).toHaveAttribute("aria-expanded", "true");
expect(screen.getByText("keyboard_arrow_down")).toBeInTheDocument();
});
it("stops event propagation on click", () => {
const parentClickHandler = jest.fn();
render(
);
const button = screen.getByRole("button");
fireEvent.click(button);
expect(parentClickHandler).not.toHaveBeenCalled();
});
it("passes list items to Checklist", () => {
const items = ["Feature A", "Feature B"];
render();
items.forEach(item => {
expect(screen.getByText(item)).toBeInTheDocument();
});
});
it("renders with an empty list without crashing", () => {
render();
expect(screen.getByRole("button")).toBeInTheDocument();
});
it("has the correct displayName", () => {
expect(SeeMore.displayName).toBe("SeeMore");
});
});