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

describe('AgentMetaSidebar', () => {
  it('renders recorded metadata and not-recorded account fallback', () => {
    render(
      <AgentMetaSidebar
        seat="Coder"
        model="composer-2.5"
        attempt={2}
        branch="agent/t4-a2"
        taskId="t4"
        taskHref="/plans/run-28#task-t4"
        account={null}
      />,
    )

    expect(screen.getByText('Coder')).toBeInTheDocument()
    expect(screen.getByText('composer-2.5')).toBeInTheDocument()
    expect(screen.getByText('not recorded')).toHaveAttribute(
      'data-tips',
      'No executing account on dispatch.attempt for this task.',
    )
    expect(screen.getByRole('link', { name: 't4' })).toHaveAttribute(
      'href',
      '/plans/run-28#task-t4',
    )
    expect(screen.queryByText('Cost')).not.toBeInTheDocument()
  })

  it('renders the journaled executing account when present', () => {
    render(
      <AgentMetaSidebar
        seat="coder"
        model="gpt-test"
        attempt={1}
        taskId="t1"
        taskHref="/plans/run-1"
        account="zync"
      />,
    )

    expect(screen.getByText('zync')).toBeInTheDocument()
    expect(screen.queryByText('not recorded')).not.toBeInTheDocument()
  })
})
