// frontend/tests/dashboard/CommandInput.test.tsx
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";

const push = vi.fn();
vi.mock("next/navigation", () => ({ useRouter: () => ({ push }) }));

const capture = vi.fn().mockResolvedValue({ item: {}, classification: {} });
vi.mock("@/lib/dashboard/api", () => ({ captureCommand: (r: string) => capture(r) }));

import { CommandInput } from "@/components/dashboard/CommandInput";

describe("CommandInput", () => {
  it("전송 시 캡처 호출 후 /inbox로 이동", async () => {
    render(<CommandInput />);
    const input = screen.getByLabelText("아리에게 명령 입력");
    fireEvent.change(input, { target: { value: "다음 주 한국 비행기 티켓 사기" } });
    fireEvent.click(screen.getByLabelText("보내기"));
    await waitFor(() => expect(capture).toHaveBeenCalledWith("다음 주 한국 비행기 티켓 사기"));
    await waitFor(() => expect(push).toHaveBeenCalledWith("/inbox"));
  });

  it("빈 입력이면 send 비활성", () => {
    render(<CommandInput />);
    expect(screen.getByLabelText("보내기")).toBeDisabled();
  });
});
