import React from "react";
import { render, fireEvent } from "@testing-library/react";
import ChipList from "../ChipList";

describe("ChipList Component Tests", () => {
  it("renders without crashing", () => {
    const { container } = render(<ChipList data={["Chip 1", "Chip 2"]} />);
    expect(container).toBeTruthy();
  });

  it("displays the correct number of chips", () => {
    const { getAllByRole } = render(<ChipList data={["Chip 1", "Chip 2"]} />);
    expect(getAllByRole("option")).toHaveLength(2);
  });

  it("handles click events", () => {
    const handleClick = jest.fn();
    const { getAllByRole } = render(
      <ChipList data={["Clickable Chip"]} onClick={handleClick} />
    );
    fireEvent.click(getAllByRole("option")[0]);
    expect(handleClick).toHaveBeenCalled();
  });

  it("matches snapshot", () => {
    const { asFragment } = render(<ChipList data={["Chip 1", "Chip 2"]} />);
    expect(asFragment()).toMatchSnapshot();
  });
});
