import { render, screen } from '@testing-library/react'
import { describe, expect, it } from 'vitest'
import { BotTable } from './BotTable'
import { BOT_ROWS } from './fixtures/bots'

describe('BotTable', () => {
  it('renders one row per bot with its metrics', () => {
    render(<BotTable bots={BOT_ROWS} />)
    expect(screen.getByText('dealbot')).toBeInTheDocument()
    expect(screen.getByText('412')).toBeInTheDocument()
    expect(screen.getByText('$1.9')).toBeInTheDocument()
    expect(screen.getByRole('table', { name: 'Bots' })).toBeInTheDocument()
  })

  it('shows a dash for null cost on a stopped bot', () => {
    render(<BotTable bots={BOT_ROWS} />)
    expect(screen.getByText('stopped')).toBeInTheDocument()
    expect(screen.getAllByText('—')).toHaveLength(1)
  })

  it('renders the exact column headers', () => {
    render(<BotTable bots={BOT_ROWS} />)
    for (const header of ['Bot', 'Status', 'Msgs 24h', 'Errors', 'Cost']) {
      expect(screen.getByText(header)).toBeInTheDocument()
    }
  })

  it('renders full-density columns with search', () => {
    render(<BotTable bots={BOT_ROWS} density="full" />)
    for (const header of ['Total', 'Last active', 'Last message']) {
      expect(screen.getByText(header)).toBeInTheDocument()
    }
    expect(screen.getByRole('searchbox', { name: 'Filter bots' })).toBeInTheDocument()
  })
})
