import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, waitFor } from '@testing-library/react'
import { I18nProvider } from '../i18n'
import { ReportCardPage } from './ReportCardPage'
import * as client from '../api/client'

const renderRC = () => render(<I18nProvider initial="en"><ReportCardPage /></I18nProvider>)

describe('ReportCardPage — F1 regression', () => {
  beforeEach(() => vi.restoreAllMocks())
  afterEach(() => vi.restoreAllMocks())

  it('shows "unavailable" when only a non-numeric note is present (null EERs)', async () => {
    vi.spyOn(client, 'apiRequest').mockResolvedValue({
      recognition: { face_LFW_EER: null, fingerprint_SOCOFing_EER: null, note: 'face: CASIA-WebFace->LFW' },
    } as never)
    renderRC()
    await waitFor(() => expect(screen.getByText('Benchmark data unavailable')).toBeInTheDocument())
  })

  it('shows "available" only when a numeric benchmark value exists', async () => {
    vi.spyOn(client, 'apiRequest').mockResolvedValue({
      recognition: { face_LFW_EER: 0.0175, note: 'x' },
    } as never)
    renderRC()
    await waitFor(() => expect(screen.getByText('Available')).toBeInTheDocument())
  })
})
