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

describe('BulkActions', () => {
  it('should not render when no items selected', () => {
    const { container } = render(
      <BulkActions selectedCount={0} />
    )

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

  it('should render when items are selected', () => {
    render(
      <BulkActions selectedCount={5} />
    )

    expect(screen.getByText('5 selected')).toBeInTheDocument()
  })

  it('should call onBulkDelete when delete button clicked', () => {
    const handleDelete = vi.fn()
    render(
      <BulkActions
        selectedCount={3}
        onBulkDelete={handleDelete}
      />
    )

    const deleteButton = screen.getByText(/delete/i)
    deleteButton.click()

    expect(handleDelete).toHaveBeenCalledTimes(1)
  })

  it('should call onBulkEdit when edit button clicked', () => {
    const handleEdit = vi.fn()
    render(
      <BulkActions
        selectedCount={2}
        onBulkEdit={handleEdit}
      />
    )

    const editButton = screen.getByText(/edit/i)
    editButton.click()

    expect(handleEdit).toHaveBeenCalledTimes(1)
  })

  it('should render custom actions', () => {
    const handleCustom = vi.fn()
    render(
      <BulkActions
        selectedCount={1}
        actions={[
          {
            label: 'Custom Action',
            onClick: handleCustom,
          },
        ]}
      />
    )

    const customButton = screen.getByText('Custom Action')
    customButton.click()

    expect(handleCustom).toHaveBeenCalledTimes(1)
  })
})

