import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom/vitest'
import { describe, expect, it } from 'vitest'
import { BOTS_PANEL } from '../../../tests/fixtures/collector-fixtures'
import { BotsCard } from './BotsCard'

describe('BotsCard', () => {
  it('renders bot rows from the collector bots panel', () => {
    render(
      <BotsCard
        panels={[BOTS_PANEL]}
        adapters={[{ id: 'botmaster', interval: 30_000, consecutiveErrors: 0, stale: false }]}
      />,
    )

    expect(screen.getByText('dealbot')).toBeInTheDocument()
    expect(screen.getByText('zyncbot')).toBeInTheDocument()
  })

  it('shows an unavailable message when the bots panel is missing', () => {
    render(<BotsCard panels={[]} adapters={[]} />)

    expect(screen.getByText(/botmaster adapter has not returned data yet/i)).toBeInTheDocument()
  })

  it('shows an empty snapshot message when the panel has no bots', () => {
    render(
      <BotsCard
        panels={[{ ...BOTS_PANEL, data: { bots: [], d1LatestAt: null, mirrorLagHours: null } }]}
        adapters={[{ id: 'botmaster', interval: 30_000, consecutiveErrors: 0, stale: false }]}
      />,
    )

    expect(screen.getByText(/no bots in the latest snapshot/i)).toBeInTheDocument()
  })
})
