Files
TradarrV2/frontend/tests/source-completeness-ticket40.test.tsx

81 lines
5.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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, SourceGenerationStat } from '../src/api/summaries'
afterEach(cleanup)
const stat = (overrides: Record<string, unknown> = {}): SourceGenerationStat => ({
source_id: 'source', source_type: 'stocktwits', status: 'ok', candidates: 6,
selected: 2, laya_selected: 2, article_limit: 10, content_fallbacks: 1,
content_complete: 3, content_incomplete: 2, content_unavailable: 1, dates_available: 4,
...overrides,
})
const outcome = (source: SourceGenerationStat, overrides: Partial<GenerationOutcome> = {}): GenerationOutcome => ({
id: 'generation', status: 'partial', language: 'fr', ranking_mode: 'title_content',
total_candidates: 6, selected: 2, laya_selected: 2, global_limit: 50, content_fallbacks: 1,
content_complete: 3, content_incomplete: 2, content_unavailable: 1, dates_available: 4,
failure_code: 'content_incomplete', source_stats: [source], ...overrides,
})
function show(value: GenerationOutcome) {
const view = render(<GenerationDetails outcome={value} />)
fireEvent.click(screen.getByText('Détails de la génération'))
return view
}
it.each([
['yahoo_finance', 'Yahoo Finance'], ['bloomberg', 'Bloomberg'], ['cnbc_business', 'CNBC Business'],
[undefined, 'Source non identifiée'], [null, 'Source non identifiée'], ['unknown', 'Source non identifiée'],
['stocktwits', 'Source non identifiée'], ['toString', 'Source non identifiée'],
])('nomme %s à partir de la clé canonique, sans exposer le type legacy', (source_key, label) => {
const { container } = show(outcome(stat({ source_key })))
expect(screen.getByRole('rowheader', { name: label })).toBeInTheDocument()
expect(container.innerHTML).not.toMatch(/stocktwits/i)
})
it.each([
[0, 0, 6, 'Source joignable · contenu absent'],
[0, 6, 0, 'Source joignable · contenu partiel'],
[6, 0, 0, 'Source joignable · contenus complets'],
[3, 2, 1, 'Source joignable · contenus de complétude variable'],
[0, 2, 4, 'Source joignable · contenus de complétude variable'],
])('distingue la collecte de la complétude (%s/%s/%s)', (complete, incomplete, unavailable, label) => {
show(outcome(stat({ source_key: 'bloomberg', content_complete: complete, content_incomplete: incomplete, content_unavailable: unavailable })))
const row = screen.getByRole('row', { name: /Bloomberg/ })
expect(within(row).getByRole('cell', { name: label, exact: true })).toBeInTheDocument()
expect(screen.queryByRole('cell', { name: 'Disponible', exact: true })).not.toBeInTheDocument()
expect(screen.getByText(/HTTP 200 ne garantit pas/)).toBeInTheDocument()
})
it('conserve les agrégats, les compteurs par source et l’éligibilité sans inventer une cause', () => {
const { container } = show(outcome(stat({ source_key: 'yahoo_finance', failure_code: 'PRIVATE_CAUSE', title: 'PRIVATE_TITLE', url: 'https://private.invalid', content: 'PRIVATE_CONTENT', prompt: 'PRIVATE_PROMPT' })))
const table = screen.getByRole('table', { name: 'Bilan par source' })
for (const name of ['Articles examinés', 'Contenus complets', 'Contenus partiels', 'Contenus absents']) {
expect(within(table).getByRole('columnheader', { name })).toBeInTheDocument()
}
const row = within(table).getByRole('row', { name: /Yahoo Finance/ })
expect(within(row).getAllByRole('cell').map(cell => cell.textContent)).toEqual([
'Source joignable · contenus de complétude variable', '6', '2', '2', '10', '4', '3', '2', '1',
])
expect(screen.getByText('Contenus complets : 3')).toBeInTheDocument()
expect(screen.getByText(/Seuls les contenus complets sont éligibles/)).toBeInTheDocument()
expect(screen.getByText(/Le texte intégral n’a pas pu être récupéré pour certains articles/)).toBeInTheDocument()
expect(container.innerHTML).not.toMatch(/PRIVATE_|private.invalid|abonnement|authentification|challenge|captcha|paywall/i)
})
it('signale un échec de récupération et utilise aussi la clé dans l’avertissement de couverture', () => {
const { container } = show(outcome(stat({ source_key: 'bloomberg', status: 'failed' })))
expect(screen.getByRole('cell', { name: 'Récupération impossible' })).toBeInTheDocument()
expect(screen.getByText(/sans Bloomberg, indisponible lors du traitement/)).toBeInTheDocument()
expect(container.innerHTML).not.toMatch(/stocktwits/i)
})
it.each([
['title', { content_complete: 0, content_incomplete: 0, content_unavailable: 0 }, 'Source joignable · contenu non évalué'],
['title_content', { content_complete: undefined, content_incomplete: undefined, content_unavailable: undefined }, 'Source joignable · complétude non renseignée'],
['title_content', { candidates: 0, content_complete: 0, content_incomplete: 0, content_unavailable: 0 }, 'Source joignable · aucun article examiné'],
['title_content', { status: 'unknown' }, 'État de collecte non renseigné'],
])('ne fabrique pas de complétude en mode %s', (ranking_mode, values, label) => {
show(outcome(stat({ source_key: 'cnbc_business', ...values }), { ranking_mode: ranking_mode as 'title' | 'title_content' }))
expect(screen.getByRole('cell', { name: label, exact: true })).toBeInTheDocument()
})