// frontend/tests/connectors/ConnectorCard.test.tsx — on/off 액션 + 동기화 콜백
import { render, screen, fireEvent } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { ConnectorCard } from "@/components/connectors/ConnectorCard";
import type { ConnectorStatus } from "@/lib/types";

const base: ConnectorStatus = {
  id: "ca-mail-work",
  domain: "mail",
  provider: "google_workspace",
  name: "회사",
  kind: "Lumi Workspace",
  tone: "coral",
  mode: "mock",
  env_mode: "mock",
  state: "connected",
  on: true,
  last: "방금 동기화",
  last_synced_at: null,
  error_detail: "",
};

const noop = () => {};

describe("ConnectorCard", () => {
  it("on 커넥터는 [동기화]+[해제] 노출", () => {
    render(<ConnectorCard connector={base} onSync={noop} onDisconnect={noop} onImport={noop} />);
    expect(screen.getByText("동기화")).toBeInTheDocument();
    expect(screen.getByText("해제")).toBeInTheDocument();
    expect(screen.queryByText("연결")).toBeNull();
  });

  it("off 커넥터는 [연결] 노출", () => {
    render(
      <ConnectorCard
        connector={{
          ...base,
          id: "ca-health-fit",
          name: "Google Fit",
          state: "disconnected",
          on: false,
          last: "연결 안 됨",
        }}
        onSync={noop}
        onDisconnect={noop}
        onImport={noop}
      />,
    );
    expect(screen.getByText("연결")).toBeInTheDocument();
    expect(screen.queryByText("동기화")).toBeNull();
    expect(screen.queryByText("해제")).toBeNull();
  });

  it("동기화 클릭 시 onSync(id) 호출", () => {
    const onSync = vi.fn();
    render(<ConnectorCard connector={base} onSync={onSync} onDisconnect={noop} onImport={noop} />);
    fireEvent.click(screen.getByText("동기화"));
    expect(onSync).toHaveBeenCalledWith("ca-mail-work");
  });
});
