import { cleanup, fireEvent, 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) const outcome = (status: string, sourceKey = 'bloomberg'): GenerationOutcome => ({ id: 'g', status: 'partial', language: 'fr', ranking_mode: 'title_content', failure_code: 'content_incomplete', total_candidates: 6, laya_selected: 2, selected: 2, global_limit: 50, content_fallbacks: 1, content_complete: 3, content_incomplete: 2, content_unavailable: 1, source_stats: [{ source_id: 'b', source_key: sourceKey, source_type: 'stocktwits', status, candidates: 6, laya_selected: 2, selected: 2, article_limit: 20, content_fallbacks: 1, content_complete: 3, content_incomplete: 2, content_unavailable: 1, feeds: { attempted: 5, succeeded: status === 'failed' ? 0 : 4, failed: status === 'failed' ? 5 : 1 }, }], }) function show(value: GenerationOutcome) { const result = render() fireEvent.click(screen.getByText('Détails de la génération')) return result } it('annonce une récupération partielle de feeds distincte de la complétude, sans perdre les agrégats', () => { show(outcome('partial')) expect(screen.getByText(/Certains flux RSS de Bloomberg n’ont pas pu être récupérés/)).toBeInTheDocument() const row = screen.getByRole('row', { name: /Bloomberg/ }) expect(within(row).getByRole('cell', { name: 'Récupération partielle · contenus de complétude variable' })).toBeInTheDocument() expect(within(row).getByText('Tentés : 5 · récupérés : 4 · en échec : 1')).toBeInTheDocument() expect(screen.getByText('Contenus complets : 3')).toBeInTheDocument() expect(screen.getByText(/Seuls les contenus complets sont éligibles/)).toBeInTheDocument() }) it('nomme Investing.com et rend une indisponibilité complète des feeds sans diagnostic brut', () => { const { container } = show(outcome('failed', 'investing_com')) expect(screen.getByRole('rowheader', { name: 'Investing.com' })).toBeInTheDocument() expect(screen.getByRole('cell', { name: 'Récupération impossible' })).toBeInTheDocument() expect(screen.getByText('Tentés : 5 · récupérés : 0 · en échec : 5')).toBeInTheDocument() expect(container.innerHTML).not.toMatch(/stocktwits|https?:|abonnement|authentification|challenge/i) })