/**
 * #343 — Stars 컴포넌트 렌더 테스트.
 */
import { render, screen } from "@testing-library/react";
import Stars from "@/components/Stars";

describe("Stars", () => {
  it("renders 5 star slots", () => {
    const { container } = render(<Stars rating={3} />);
    // 빈 별 5개 (text-gray-300 클래스 갖는 span)
    const emptyStars = container.querySelectorAll("span.text-gray-300");
    expect(emptyStars.length).toBe(5);
  });

  it("shows aria-label with rating", () => {
    render(<Stars rating={4.5} />);
    expect(screen.getByLabelText("4.5점")).toBeInTheDocument();
  });

  it("clamps rating to 0~5", () => {
    render(<Stars rating={-1} />);
    expect(screen.getByLabelText("0점")).toBeInTheDocument();
    render(<Stars rating={10} />);
    expect(screen.getByLabelText("5점")).toBeInTheDocument();
  });

  it("shows number when showNumber + rating > 0", () => {
    const { container } = render(<Stars rating={3.5} showNumber />);
    expect(container.textContent).toContain("3.5");
  });

  it("does not show number when rating is 0 even with showNumber", () => {
    const { container } = render(<Stars rating={0} showNumber />);
    expect(container.textContent).not.toContain("0");
  });
});
