/**
 * Tests for RefinementModeBadge Component
 *
 * Story 2.3: Refinement Loop (Regeneration)
 */

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

describe('RefinementModeBadge', () => {
  it('should render badge with text', () => {
    const mockCancel = vi.fn();
    render(<RefinementModeBadge onCancel={mockCancel} />);

    expect(screen.getByText('Refining your draft...')).toBeInTheDocument();
  });

  it('should render cancel button', () => {
    const mockCancel = vi.fn();
    render(<RefinementModeBadge onCancel={mockCancel} />);

    const cancelButton = screen.getByRole('button', { name: /cancel refinement/i });
    expect(cancelButton).toBeInTheDocument();
  });

  it('should call onCancel when cancel button is clicked', () => {
    const mockCancel = vi.fn();
    render(<RefinementModeBadge onCancel={mockCancel} />);

    const cancelButton = screen.getByRole('button', { name: /cancel refinement/i });
    fireEvent.click(cancelButton);

    expect(mockCancel).toHaveBeenCalledTimes(1);
  });

  it('should have proper accessibility attributes', () => {
    const mockCancel = vi.fn();
    const { container } = render(<RefinementModeBadge onCancel={mockCancel} />);

    const badge = container.querySelector('[role="status"]');
    expect(badge).toBeInTheDocument();
    expect(badge).toHaveAttribute('aria-live', 'polite');
    expect(badge).toHaveAttribute('aria-label', 'Refinement mode active');
  });

  it('should have amber color scheme for visual indication', () => {
    const mockCancel = vi.fn();
    const { container } = render(<RefinementModeBadge onCancel={mockCancel} />);

    const badge = container.querySelector('[role="status"]');
    expect(badge).toHaveClass('bg-amber-50');
    expect(badge).toHaveClass('border-amber-200');
    expect(badge).toHaveClass('text-amber-800');
  });

  it('should have keyboard accessible cancel button', () => {
    const mockCancel = vi.fn();
    render(<RefinementModeBadge onCancel={mockCancel} />);

    const cancelButton = screen.getByRole('button', { name: /cancel refinement/i });
    expect(cancelButton).toHaveAttribute('type', 'button');
  });
});
