/**
 * Tests for ContentFilter component
 */
import { render, screen, fireEvent } from '@testing-library/react';
import { ContentFilter } from '../ContentFilter';

describe('ContentFilter', () => {
  const mockOnFilterChange = vi.fn();

  beforeEach(() => {
    mockOnFilterChange.mockClear();
  });

  it('renders search input', () => {
    render(<ContentFilter onFilterChange={mockOnFilterChange} />);
    expect(screen.getByPlaceholderText('Search content...')).toBeInTheDocument();
  });

  it('calls onFilterChange when search input changes', () => {
    render(<ContentFilter onFilterChange={mockOnFilterChange} />);
    const searchInput = screen.getByPlaceholderText('Search content...');
    
    fireEvent.change(searchInput, { target: { value: 'test search' } });
    
    expect(mockOnFilterChange).toHaveBeenCalledWith(
      expect.objectContaining({ search: 'test search' })
    );
  });

  it('renders source filter buttons', () => {
    render(<ContentFilter onFilterChange={mockOnFilterChange} />);
    expect(screen.getByText('All')).toBeInTheDocument();
    expect(screen.getByText('IGNY8')).toBeInTheDocument();
    expect(screen.getByText('WordPress')).toBeInTheDocument();
  });

  it('calls onFilterChange when source filter is clicked', () => {
    render(<ContentFilter onFilterChange={mockOnFilterChange} />);
    const wordpressButton = screen.getByText('WordPress').closest('button');
    
    if (wordpressButton) {
      fireEvent.click(wordpressButton);
      expect(mockOnFilterChange).toHaveBeenCalledWith(
        expect.objectContaining({ source: 'wordpress' })
      );
    }
  });

  it('renders sync status filter buttons', () => {
    render(<ContentFilter onFilterChange={mockOnFilterChange} />);
    expect(screen.getByText('Native')).toBeInTheDocument();
    expect(screen.getByText('Imported')).toBeInTheDocument();
    expect(screen.getByText('Synced')).toBeInTheDocument();
  });

  it('calls onFilterChange when sync status filter is clicked', () => {
    render(<ContentFilter onFilterChange={mockOnFilterChange} />);
    const syncedButton = screen.getByText('Synced').closest('button');
    
    if (syncedButton) {
      fireEvent.click(syncedButton);
      expect(mockOnFilterChange).toHaveBeenCalledWith(
        expect.objectContaining({ syncStatus: 'synced' })
      );
    }
  });
});

