import { describe, expect, it } from 'vitest'
import { renderToStaticMarkup } from 'react-dom/server'
import { ProcessingFileRow } from '@/components/app/document-drop-zone'

describe('permit processing row', () => {
  it('shows Cancel during normal processing', () => {
    const html = renderToStaticMarkup(<ProcessingFileRow name="permit.pdf" label="Being read" onCancel={() => {}} />)
    expect(html).toContain('Cancel')
    expect(html).toContain('animate-spin')
  })

  it('stops the spinner when processing is stale but keeps Cancel available', () => {
    const html = renderToStaticMarkup(<ProcessingFileRow name="permit.pdf" label="Taking longer" stalled onCancel={() => {}} />)
    expect(html).toContain('Cancel')
    expect(html).not.toContain('animate-spin')
  })

  it('shows a dismissible upload failure without a spinner', () => {
    const html = renderToStaticMarkup(<ProcessingFileRow name="permit.pdf" label="Upload failed" failed onDismiss={() => {}} />)
    expect(html).toContain('Dismiss')
    expect(html).not.toContain('animate-spin')
  })

  it('offers Retry for a saved permit whose reading failed', () => {
    const html = renderToStaticMarkup(<ProcessingFileRow name="permit.pdf" label="Reading failed" failed onRetry={() => {}} />)
    expect(html).toContain('Retry')
    expect(html).not.toContain('animate-spin')
  })
})
