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

describe("CaptureComposer", () => {
  it("Enter로 text 제출 후 입력 비움", () => {
    const onSubmit = vi.fn();
    render(<CaptureComposer onSubmit={onSubmit} />);
    const input = screen.getByLabelText("인박스에 빠르게 캡처") as HTMLInputElement;
    fireEvent.change(input, { target: { value: "엄마 생신 선물 알아보기" } });
    fireEvent.keyDown(input, { key: "Enter" });
    expect(onSubmit).toHaveBeenCalledWith("엄마 생신 선물 알아보기", "text");
    expect(input.value).toBe("");
  });

  it("mic 버튼: voice kind + 더미 transcript", () => {
    const onSubmit = vi.fn();
    render(<CaptureComposer onSubmit={onSubmit} />);
    fireEvent.click(screen.getByLabelText(/음성으로 캡처/));
    expect(onSubmit).toHaveBeenCalledWith(expect.stringContaining("음성 메모"), "voice");
  });

  it("image 버튼: image kind", () => {
    const onSubmit = vi.fn();
    render(<CaptureComposer onSubmit={onSubmit} />);
    fireEvent.click(screen.getByLabelText(/이미지로 캡처/));
    expect(onSubmit).toHaveBeenCalledWith(expect.any(String), "image");
  });

  it("빈 입력은 제출 무시", () => {
    const onSubmit = vi.fn();
    render(<CaptureComposer onSubmit={onSubmit} />);
    fireEvent.keyDown(screen.getByLabelText("인박스에 빠르게 캡처"), { key: "Enter" });
    expect(onSubmit).not.toHaveBeenCalled();
  });
});
