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

import { CookieDeclarationDiff } from '../CookieDeclarationDiff'

const DATA = {
  coverage: { total: 761, checked: 244, discrepant: 1 },
  rows: [{
    cookie: '_ga', vendor: 'Google Analytics', severity: 'HIGH',
    diffs: [
      { field: 'Kategorie', declared: 'notwendig', expected: 'Marketing', severe: true },
      { field: 'Laufzeit', declared: 'Session', expected: '2 Jahre' },
    ],
    measures: ['Als einwilligungspflichtig (§ 25) einstufen.'],
  }],
}

describe('CookieDeclarationDiff', () => {
  it('zeigt den Funnel + Feld-Diffs deklariert→Library', () => {
    render(<CookieDeclarationDiff data={DATA} />)
    expect(screen.getByText('761')).toBeInTheDocument()       // gesamt
    expect(screen.getByText('244')).toBeInTheDocument()       // geprüft
    expect(screen.getByText('_ga')).toBeInTheDocument()
    expect(screen.getByText('Kategorie')).toBeInTheDocument()
    expect(screen.getByText('Marketing')).toBeInTheDocument() // Soll-Wert
    expect(screen.getByText(/2 Abweichungen/)).toBeInTheDocument()
    expect(screen.getByText(/Als einwilligungspflichtig/)).toBeInTheDocument()
  })

  it('rendert nichts ohne Daten', () => {
    const { container } = render(<CookieDeclarationDiff data={undefined} />)
    expect(container.firstChild).toBeNull()
  })
})
