35 lines
1.9 KiB
TypeScript
35 lines
1.9 KiB
TypeScript
import { cleanup, render, screen, within } from '@testing-library/react'
|
|
import { afterEach, expect, it } from 'vitest'
|
|
import { GenerationDetails } from '../src/components/GenerationDetails'
|
|
import type { GenerationOutcome } from '../src/api/summaries'
|
|
|
|
afterEach(cleanup)
|
|
|
|
function outcome(sourceType: string, sourceKey?: string): GenerationOutcome {
|
|
return {
|
|
id: 'generation-23', status: 'partial', language: 'fr', ranking_mode: 'title',
|
|
total_candidates: 0, content_fallbacks: 0, laya_selected: 0, selected: 0, global_limit: 50,
|
|
source_stats: [{ source_id: 'source-23', source_key: sourceKey, source_type: sourceType, status: 'failed', candidates: 0, laya_selected: 0, selected: 0, article_limit: 20, content_fallbacks: 0, failure_code: 'source_unavailable' }],
|
|
}
|
|
}
|
|
|
|
it('nomme CNBC Business dans le diagnostic agrégé sans exposer de détails de récupération', () => {
|
|
const result = outcome('cnbc_business', 'cnbc_business')
|
|
render(<GenerationDetails outcome={result} />)
|
|
expect(screen.getByText('Cette synthèse a été générée sans CNBC Business, indisponible lors du traitement.')).toBeInTheDocument()
|
|
const row = screen.getByText('CNBC Business').closest('tr')!
|
|
expect(within(row).getByText('Récupération impossible')).toBeInTheDocument()
|
|
expect(screen.queryByText('source_unavailable')).not.toBeInTheDocument()
|
|
expect(screen.queryByRole('link')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it.each(['watcherguru', 'Watcher.Guru', 'Watcher Guru'])('affiche le fallback du bilan historique %s sans réécrire ses données', sourceType => {
|
|
const result = outcome(sourceType)
|
|
const before = JSON.stringify(result)
|
|
render(<GenerationDetails outcome={result} />)
|
|
expect(screen.getByText('Source non identifiée', { exact: true })).toBeInTheDocument()
|
|
expect(screen.queryByText(sourceType, { exact: true })).not.toBeInTheDocument()
|
|
expect(screen.queryByText(/CNBC Business/)).not.toBeInTheDocument()
|
|
expect(JSON.stringify(result)).toBe(before)
|
|
})
|