// frontend/tests/inbox/RouteChips.test.tsx
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import RouteChips from "@/components/inbox/RouteChips";
import type { Classification } from "@/lib/types";

const base: Classification = {
  id: "c1",
  inbox_item_id: "s1",
  type: "task",
  sphere: "life",
  project_id: "p",
  proj_label: "개인 › 여행 — 한국",
  tone: "coral",
  due_text: "출발 전",
  when_text: "오늘 21:00",
  extra: "가격 추적 알림 켜둠",
  reason: "r",
  confidence: 0.9,
  model: "heuristic",
  created_at: "",
};

describe("RouteChips", () => {
  it("task 칩: 작업 + sphere(개인) + proj + extra", () => {
    render(<RouteChips r={{ ...base, type: "task" }} editable onReType={() => {}} />);
    expect(screen.getByText("작업")).toBeInTheDocument();
    expect(screen.getByText("개인")).toBeInTheDocument();
    expect(screen.getByText("개인 › 여행 — 한국")).toBeInTheDocument();
    expect(screen.getByText("가격 추적 알림 켜둠")).toBeInTheDocument();
  });

  it("event 칩: type 클래스에 event 포함", () => {
    const { container } = render(
      <RouteChips r={{ ...base, type: "event" }} editable onReType={() => {}} />,
    );
    expect(container.querySelector(".r-chip.type.event")).toBeTruthy();
    expect(screen.getByText("일정")).toBeInTheDocument();
  });

  it("due/when/extra 없으면 칩 미표시", () => {
    render(
      <RouteChips
        r={{ ...base, type: "idea", due_text: null, when_text: null, extra: null }}
        editable
        onReType={() => {}}
      />,
    );
    expect(screen.queryByText("출발 전")).toBeNull();
    expect(screen.getByText("아이디어")).toBeInTheDocument();
  });

  it("editable=false면 타입 칩 disabled", () => {
    render(<RouteChips r={{ ...base, type: "task" }} editable={false} onReType={() => {}} />);
    expect(screen.getByRole("button", { name: /타입: 작업/ })).toBeDisabled();
  });
});
