import { render, screen } from "@testing-library/react";
import type { ComponentProps } from "react";

import { StatusBadge } from "@/components/ui/status-badge";

// @ts-expect-error "running" is a step status, not a review decision.
const invalidReviewDecisionProps: ComponentProps<typeof StatusBadge> = {
  variant: "reviewDecision",
  status: "running",
};

test("renders the waiting review label", () => {
  render(<StatusBadge status="waiting_review" />);

  expect(screen.getByText("待审核")).toBeInTheDocument();
});

test("uses order status metadata for the rendered tone", () => {
  render(<StatusBadge status="failed" />);

  expect(screen.getByText("失败")).toHaveAttribute("data-tone", "danger");
});

test("uses compact dense-console badge sizing", () => {
  render(<StatusBadge status="waiting_review" />);

  expect(screen.getByText("待审核").className).toContain("px-2");
  expect(screen.getByText("待审核").className).toContain("py-0.5");
});

test("can render review decision metadata when a variant is provided", () => {
  render(<StatusBadge status="reject" variant="reviewDecision" />);

  expect(screen.getByText("驳回")).toHaveAttribute("data-tone", "danger");
});

test("renders step status metadata for the stepStatus variant", () => {
  render(<StatusBadge status="running" variant="stepStatus" />);

  expect(screen.getByText("执行中")).toHaveAttribute("data-tone", "info");
});

test("renders workflow step metadata for the workflowStep variant", () => {
  render(<StatusBadge status="review" variant="workflowStep" />);

  expect(screen.getByText("人工审核")).toHaveAttribute("data-tone", "warning");
});

test("throws a descriptive error for invalid runtime status and variant pairings", () => {
  expect(() =>
    render(<StatusBadge status={"reject" as never} variant="order" />),
  ).toThrow('Invalid status "reject" for variant "order".');

  expect(invalidReviewDecisionProps.variant).toBe("reviewDecision");
});
