/**
 * @ai-summary Tests for SelectionToolbar component
 */

import { render, screen, fireEvent } from '@testing-library/react';
import { SelectionToolbar } from '../../components/SelectionToolbar';

describe('SelectionToolbar', () => {
  it('should not render when selectedCount is 0', () => {
    const { container } = render(
      <SelectionToolbar selectedCount={0} onClear={jest.fn()} />
    );

    expect(container.firstChild).toBeNull();
  });

  it('should render when items are selected', () => {
    const { container } = render(
      <SelectionToolbar selectedCount={3} onClear={jest.fn()} />
    );

    expect(container).toMatchSnapshot();
    expect(screen.getByText('Selected: 3')).toBeInTheDocument();
  });

  it('should call onClear when Clear button clicked', () => {
    const handleClear = jest.fn();

    render(<SelectionToolbar selectedCount={2} onClear={handleClear} />);

    fireEvent.click(screen.getByText('Clear'));
    expect(handleClear).toHaveBeenCalledTimes(1);
  });

  it('should call onSelectAll when Select All button clicked', () => {
    const handleSelectAll = jest.fn();

    render(
      <SelectionToolbar
        selectedCount={2}
        onSelectAll={handleSelectAll}
        onClear={jest.fn()}
      />
    );

    fireEvent.click(screen.getByText('Select All'));
    expect(handleSelectAll).toHaveBeenCalledTimes(1);
  });

  it('should render custom action buttons', () => {
    const { container } = render(
      <SelectionToolbar selectedCount={3} onClear={jest.fn()}>
        <button>Delete</button>
        <button>Export</button>
      </SelectionToolbar>
    );

    expect(container).toMatchSnapshot();
    expect(screen.getByText('Delete')).toBeInTheDocument();
    expect(screen.getByText('Export')).toBeInTheDocument();
  });
});
