import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import CommandTab from './CommandTab.jsx';

vi.mock('../../../api', () => ({
  sendAgentCommand: vi.fn(),
  approveAgentTask: vi.fn(),
}));

describe('CommandTab approval card', () => {
  const samplePendingTask = {
    id: 'task-123',
    task_type: 'lotto_briefing',
    input_data: { draw_no: 1234 },
  };

  it('agentState가 waiting_approval이고 pendingTask가 있으면 승인 카드를 표시', () => {
    render(
      <CommandTab
        agentId="lotto"
        agentState="waiting_approval"
        pendingTask={samplePendingTask}
      />
    );
    expect(screen.getByText('Awaiting Approval')).toBeInTheDocument();
    expect(screen.getByRole('button', { name: 'Approve' })).toBeInTheDocument();
    expect(screen.getByRole('button', { name: 'Reject' })).toBeInTheDocument();
  });

  it('agentState가 working이면 승인 카드를 표시하지 않음', () => {
    render(
      <CommandTab
        agentId="lotto"
        agentState="working"
        pendingTask={samplePendingTask}
      />
    );
    expect(screen.queryByText('Awaiting Approval')).toBeNull();
  });

  it('pendingTask가 null이면 waiting_approval이어도 승인 카드를 표시하지 않음', () => {
    render(
      <CommandTab
        agentId="lotto"
        agentState="waiting_approval"
        pendingTask={null}
      />
    );
    expect(screen.queryByText('Awaiting Approval')).toBeNull();
  });
});
