feat(sources): retire Yahoo and CNBC feeds (#42)
This commit is contained in:
@ -22,14 +22,19 @@ test('admin source controls stay accessible and fit at 320, 375 and 390 px', asy
|
||||
await expect(page.getByRole('heading', { name: 'Sources et plafonds' })).toBeVisible()
|
||||
|
||||
const activationControls = page.locator('button[aria-label^="Activer "], button[aria-label^="Désactiver "]')
|
||||
await expect(activationControls).toHaveCount(4)
|
||||
const activationNames = (await activationControls.evaluateAll(nodes => nodes.map(node => node.getAttribute('aria-label').replace(/^(Activer|Désactiver) /, '')).sort()))
|
||||
expect(activationNames).toEqual(['Bloomberg', 'CNBC Business', 'Investing.com', 'Yahoo Finance'])
|
||||
await expect(page.locator('form[aria-label^="Réglages de "]')).toHaveCount(4)
|
||||
await expect(activationControls).toHaveCount(2)
|
||||
const activationNames = await activationControls.evaluateAll(nodes => nodes.map(node => node.getAttribute('aria-label').replace(/^(Activer|Désactiver) /, '')).sort())
|
||||
expect(activationNames).toEqual(['Bloomberg', 'Investing.com'])
|
||||
await expect(page.locator('form[aria-label^="Réglages de "]')).toHaveCount(2)
|
||||
|
||||
const historical = page.getByRole('region', { name: 'Anciennes sources exclues' })
|
||||
const historical = page.getByRole('region', { name: 'Sources retirées' })
|
||||
await expect(historical).toBeVisible()
|
||||
await historical.getByText(/^Consulter les anciennes sources/).click()
|
||||
await historical.getByText(/^Consulter les sources retirées/).click()
|
||||
for (const name of ['Yahoo Finance', 'CNBC Business']) {
|
||||
await expect(historical.getByText(name, { exact: true })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: `Activer ${name}`, exact: true })).toHaveCount(0)
|
||||
await expect(page.getByRole('button', { name: `Désactiver ${name}`, exact: true })).toHaveCount(0)
|
||||
}
|
||||
const historicalRows = historical.locator('li')
|
||||
expect(await historicalRows.count()).toBeGreaterThan(0)
|
||||
await expect(historicalRows.locator('button, input, form, a')).toHaveCount(0)
|
||||
@ -43,8 +48,8 @@ test('admin source controls stay accessible and fit at 320, 375 and 390 px', asy
|
||||
expect(dimensions.document, `horizontal overflow at ${width}px: ${JSON.stringify(dimensions)}`).toBeLessThanOrEqual(dimensions.viewport)
|
||||
|
||||
await expect(page.getByRole('spinbutton', { name: 'Articles max par résumé' })).toBeVisible()
|
||||
for (const name of ['Yahoo Finance', 'Bloomberg', 'CNBC Business', 'Investing.com']) {
|
||||
const toggle = page.getByRole('button', { name: new RegExp(`^(?:Activer|Désactiver) ${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`) })
|
||||
for (const name of ['Bloomberg', 'Investing.com']) {
|
||||
const toggle = activationControls.filter({ hasText: /Activer|Désactiver/ }).and(page.getByRole('button', { name: new RegExp(name) }))
|
||||
const cap = page.getByRole('spinbutton', { name: `Plafond ${name}` })
|
||||
await expect(toggle).toBeVisible()
|
||||
await expect(toggle).toBeEnabled()
|
||||
|
||||
@ -6,7 +6,17 @@ import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
||||
const SOURCE_KEYS = new Set(['yahoo_finance', 'bloomberg', 'cnbc_business', 'investing_com'])
|
||||
const SOURCE_KEYS = new Set(['bloomberg', 'investing_com'])
|
||||
|
||||
function sourceName(source: Source) {
|
||||
switch (source.source_key) {
|
||||
case 'yahoo_finance': return 'Yahoo Finance'
|
||||
case 'cnbc_business': return 'CNBC Business'
|
||||
case 'bloomberg': return 'Bloomberg'
|
||||
case 'investing_com': return 'Investing.com'
|
||||
default: return source.name
|
||||
}
|
||||
}
|
||||
|
||||
function isSupported(source: Source) {
|
||||
return source.supported === true && source.source_key !== null && SOURCE_KEYS.has(source.source_key)
|
||||
@ -115,7 +125,7 @@ export function Sources() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-2xl font-bold">Sources et plafonds</h1>
|
||||
<p className="text-sm text-muted-foreground">Yahoo Finance, Bloomberg, CNBC Business et Investing.com peuvent participer aux synthèses manuelles et planifiées. Seules les sources activées sont utilisées, dans la limite de leurs plafonds. Modifier ces réglages ne lance aucune récupération d’articles ni génération immédiate.</p>
|
||||
<p className="text-sm text-muted-foreground">Seules Bloomberg et Investing.com peuvent participer aux synthèses manuelles et planifiées, à partir de leurs flux RSS. Seules les sources activées sont utilisées, dans la limite de leurs plafonds. Modifier ces réglages ne lance aucune récupération d’articles ni génération immédiate.</p>
|
||||
{loading ? <p role="status">Chargement des sources et plafonds…</p> : loadError ? (
|
||||
<div className="space-y-3"><p role="alert">{loadError}</p><Button onClick={() => void load()}>Réessayer</Button></div>
|
||||
) : <>
|
||||
@ -133,16 +143,16 @@ export function Sources() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
{sources.length === 0 && <p>Aucune source disponible.</p>}
|
||||
<div className="grid min-w-0 gap-4 lg:grid-cols-3">
|
||||
{supported.map(source => <SourceLimit key={source.id} source={source.source_key === 'yahoo_finance' ? { ...source, name: 'Yahoo Finance' } : source.source_key === 'cnbc_business' ? { ...source, name: 'CNBC Business' } : source.source_key === 'investing_com' ? { ...source, name: 'Investing.com' } : source.source_key === 'bloomberg' ? { ...source, name: 'Bloomberg' } : source} />)}
|
||||
<div className="grid min-w-0 gap-4 lg:grid-cols-2">
|
||||
{supported.map(source => <SourceLimit key={source.id} source={{ ...source, name: sourceName(source) }} />)}
|
||||
</div>
|
||||
{historical.length > 0 && <section aria-labelledby="historical-sources-title" className="space-y-3">
|
||||
<h2 id="historical-sources-title" className="text-lg font-semibold">Anciennes sources exclues</h2>
|
||||
<h2 id="historical-sources-title" className="text-lg font-semibold">Sources retirées</h2>
|
||||
<details className="rounded-md border p-4">
|
||||
<summary className="cursor-pointer font-medium">Consulter les anciennes sources ({historical.length})</summary>
|
||||
<summary className="cursor-pointer font-medium">Consulter les sources retirées ({historical.length})</summary>
|
||||
<p className="mt-3 text-sm text-muted-foreground">Ces sources sont conservées en lecture seule et exclues des synthèses manuelles et planifiées. Elles ne peuvent pas être réactivées. Les bilans des générations passées restent inchangés.</p>
|
||||
<ul className="mt-3 space-y-3">{historical.map(source => <li key={source.id} className="break-words">
|
||||
<p className="font-medium">{source.name}</p>
|
||||
<p className="font-medium">{sourceName(source)}</p>
|
||||
<p className="text-sm text-muted-foreground">Exclue des synthèses · Plafond historique : {source.article_limit}</p>
|
||||
</li>)}</ul>
|
||||
</details>
|
||||
|
||||
@ -23,7 +23,7 @@ describe('plafonds d’articles administrateur', () => {
|
||||
listSettings.mockResolvedValue([{ key: 'summary_max_articles', value: '700' }])
|
||||
getDefaultPrompt.mockResolvedValue({ prompt: 'system' })
|
||||
updateSettings.mockResolvedValue(undefined)
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Yahoo Finance', type: 'yahoo', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true, article_limit: 240 }])
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Bloomberg', type: 'rss', source_key: 'bloomberg', supported: true, operational: true, enabled: true, article_limit: 240 }])
|
||||
updateSource.mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
@ -47,7 +47,7 @@ describe('plafonds d’articles administrateur', () => {
|
||||
|
||||
it('borne chaque plafond source de 1 à 200 et conserve une ancienne valeur hors plage', async () => {
|
||||
render(<Sources />)
|
||||
const input = await screen.findByLabelText('Plafond Yahoo Finance')
|
||||
const input = await screen.findByLabelText('Plafond Bloomberg')
|
||||
expect(input).toHaveValue(240)
|
||||
expect(input).toHaveAttribute('min', '1')
|
||||
expect(input).toHaveAttribute('max', '200')
|
||||
@ -56,10 +56,10 @@ describe('plafonds d’articles administrateur', () => {
|
||||
it('sauvegarde le plafond de la source via l’API admin', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const input = await screen.findByLabelText('Plafond Yahoo Finance')
|
||||
const input = await screen.findByLabelText('Plafond Bloomberg')
|
||||
await user.clear(input)
|
||||
await user.type(input, '20')
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Yahoo Finance' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Bloomberg' }))
|
||||
await waitFor(() => expect(updateSource).toHaveBeenCalledWith('source-1', true, 20))
|
||||
})
|
||||
it('remplace l’éditeur en doublon dans Paramètres par un lien et garde le filtre séparé', async () => {
|
||||
@ -93,21 +93,21 @@ describe('plafonds d’articles administrateur', () => {
|
||||
|
||||
it('initialise uniquement les valeurs absentes à 50 et 20', async () => {
|
||||
listSettings.mockResolvedValue([])
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Yahoo Finance', type: 'yahoo', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true }])
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Bloomberg', type: 'rss', source_key: 'bloomberg', supported: true, operational: true, enabled: true }])
|
||||
render(<Sources />)
|
||||
expect(await screen.findByLabelText('Articles max par résumé')).toHaveValue(50)
|
||||
expect(screen.getByLabelText('Plafond Yahoo Finance')).toHaveValue(20)
|
||||
expect(screen.getByLabelText('Plafond Bloomberg')).toHaveValue(20)
|
||||
})
|
||||
|
||||
it('conserve le plafond historique pendant la désactivation et la réactivation', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const input = await screen.findByLabelText('Plafond Yahoo Finance')
|
||||
await user.click(screen.getByRole('button', { name: 'Désactiver Yahoo Finance' }))
|
||||
const input = await screen.findByLabelText('Plafond Bloomberg')
|
||||
await user.click(screen.getByRole('button', { name: 'Désactiver Bloomberg' }))
|
||||
await waitFor(() => expect(input).toBeDisabled())
|
||||
expect(input).toHaveValue(240)
|
||||
expect(updateSource).toHaveBeenLastCalledWith('source-1', false)
|
||||
await user.click(screen.getByRole('button', { name: 'Activer Yahoo Finance' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Activer Bloomberg' }))
|
||||
await waitFor(() => expect(input).toBeEnabled())
|
||||
expect(input).toHaveValue(240)
|
||||
expect(updateSource).toHaveBeenLastCalledWith('source-1', true)
|
||||
@ -127,10 +127,10 @@ describe('plafonds d’articles administrateur', () => {
|
||||
expect(screen.queryByRole('status')).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer', exact: true }))
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Plafond global enregistré.')
|
||||
const source = screen.getByLabelText('Plafond Yahoo Finance')
|
||||
const source = screen.getByLabelText('Plafond Bloomberg')
|
||||
await user.clear(source)
|
||||
await user.type(source, '20')
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Yahoo Finance' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Bloomberg' }))
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('Impossible d’enregistrer le plafond.')
|
||||
expect(source).toHaveValue(20)
|
||||
})
|
||||
@ -138,8 +138,8 @@ describe('plafonds d’articles administrateur', () => {
|
||||
it('rejette les plafonds source hors bornes et fractionnaires sans les écrêter', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const input = await screen.findByLabelText('Plafond Yahoo Finance')
|
||||
const save = screen.getByRole('button', { name: 'Enregistrer le plafond Yahoo Finance' })
|
||||
const input = await screen.findByLabelText('Plafond Bloomberg')
|
||||
const save = screen.getByRole('button', { name: 'Enregistrer le plafond Bloomberg' })
|
||||
for (const value of ['0', '201', '1.5']) {
|
||||
await user.clear(input)
|
||||
await user.type(input, value)
|
||||
@ -149,35 +149,31 @@ describe('plafonds d’articles administrateur', () => {
|
||||
expect(updateSource).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('ne rend activables que Yahoo, Bloomberg et CNBC Business; garde Watcher Guru, StockTwits et Reuters en historique sans commandes', async () => {
|
||||
it('ne rend activables que Bloomberg et Investing.com; conserve les autres sources sans commandes', async () => {
|
||||
listSources.mockResolvedValue([
|
||||
{ id: 'y', name: 'Yahoo Finance', type: 'stocktwits', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true, article_limit: 83 },
|
||||
{ id: 'b', name: 'Bloomberg', type: 'bloomberg', source_key: 'bloomberg', supported: true, operational: true, enabled: false, article_limit: 77 },
|
||||
{ id: 'c', name: 'CNBC Business', type: 'cnbc_business', source_key: 'cnbc_business', supported: true, operational: true, enabled: true, article_limit: 20 },
|
||||
{ id: 'y', name: 'Yahoo Finance', type: 'stocktwits', source_key: 'yahoo_finance', supported: false, operational: false, enabled: false, article_limit: 83 },
|
||||
{ id: 'b', name: 'Bloomberg', type: 'bloomberg', source_key: 'bloomberg', supported: true, operational: false, enabled: false, article_limit: 77 },
|
||||
{ id: 'i', name: 'Investing.com', type: 'rss', source_key: 'investing_com', supported: true, operational: true, enabled: true, article_limit: 20 },
|
||||
{ id: 'c', name: 'CNBC Business', type: 'cnbc_business', source_key: 'cnbc_business', supported: false, operational: false, enabled: false, article_limit: 20 },
|
||||
{ id: 'w', name: 'Watcher.Guru', type: 'watcherguru', source_key: 'watcher_guru', supported: false, operational: false, enabled: false, article_limit: 64 },
|
||||
{ id: 's', name: 'StockTwits', type: 'stocktwits', source_key: null, supported: false, operational: false, enabled: false, article_limit: 31 },
|
||||
{ id: 'r', name: 'Reuters', type: 'reuters', source_key: null, supported: false, operational: false, enabled: false, article_limit: 42 },
|
||||
])
|
||||
render(<Sources />)
|
||||
expect(await screen.findByRole('heading', { name: 'Anciennes sources exclues' })).toBeInTheDocument()
|
||||
for (const name of ['Yahoo Finance', 'Bloomberg', 'CNBC Business']) {
|
||||
expect(await screen.findByRole('heading', { name: 'Sources retirées' })).toBeInTheDocument()
|
||||
for (const name of ['Bloomberg', 'Investing.com']) {
|
||||
expect(screen.getByRole('button', { name: new RegExp(`^(?:Activer|Désactiver) ${name}$`) })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText(`Plafond ${name}`)).toBeInTheDocument()
|
||||
}
|
||||
const historical = screen.getByRole('region', { name: 'Anciennes sources exclues' })
|
||||
expect(within(historical).getByText('StockTwits')).toBeInTheDocument()
|
||||
expect(within(historical).getByText('Watcher.Guru')).toBeInTheDocument()
|
||||
const historical = screen.getByRole('region', { name: 'Sources retirées' })
|
||||
for (const name of ['Yahoo Finance', 'CNBC Business', 'StockTwits', 'Watcher.Guru', 'Reuters']) {
|
||||
expect(within(historical).getByText(name)).toBeInTheDocument()
|
||||
expect(screen.queryByLabelText(`Plafond ${name}`)).not.toBeInTheDocument()
|
||||
}
|
||||
expect(within(historical).getByText('Exclue des synthèses · Plafond historique : 64')).toBeInTheDocument()
|
||||
expect(within(historical).getByText('Reuters')).toBeInTheDocument()
|
||||
expect(within(historical).queryByRole('button')).not.toBeInTheDocument()
|
||||
expect(within(historical).queryByRole('spinbutton')).not.toBeInTheDocument()
|
||||
const yahooCard = screen.getByRole('form', { name: 'Réglages de Yahoo Finance' }).closest('.rounded-md')
|
||||
expect(yahooCard).not.toBeNull()
|
||||
expect(within(yahooCard as HTMLElement).queryByText(/stocktwits/i)).not.toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Plafond Yahoo Finance')).toHaveValue(83)
|
||||
expect(historical.querySelectorAll('button,input,form,a')).toHaveLength(0)
|
||||
expect(screen.getByLabelText('Plafond Bloomberg')).toHaveValue(77)
|
||||
expect(screen.getByLabelText('Plafond CNBC Business')).toHaveValue(20)
|
||||
expect(screen.queryByLabelText('Plafond Watcher.Guru')).not.toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Plafond Investing.com')).toHaveValue(20)
|
||||
})
|
||||
|
||||
it('garde les anciennes sources repliées et en lecture seule même si enabled est historique', async () => {
|
||||
@ -186,10 +182,10 @@ describe('plafonds d’articles administrateur', () => {
|
||||
])
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const region = await screen.findByRole('region', { name: 'Anciennes sources exclues' })
|
||||
const region = await screen.findByRole('region', { name: 'Sources retirées' })
|
||||
const disclosure = region.querySelector('details')!
|
||||
expect(disclosure).not.toHaveAttribute('open')
|
||||
await user.click(within(region).getByText('Consulter les anciennes sources (1)'))
|
||||
await user.click(within(region).getByText('Consulter les sources retirées (1)'))
|
||||
expect(disclosure).toHaveAttribute('open')
|
||||
expect(within(region).getByText('Reuters')).toBeVisible()
|
||||
expect(within(region).queryByRole('button')).not.toBeInTheDocument()
|
||||
@ -198,19 +194,19 @@ describe('plafonds d’articles administrateur', () => {
|
||||
})
|
||||
|
||||
it('annonce les réglages des prochaines synthèses sans annoncer de génération lancée', async () => {
|
||||
listSources.mockResolvedValue([{ id: 'y', name: 'Stocktwits', type: 'stocktwits', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true, article_limit: 83 }])
|
||||
listSources.mockResolvedValue([{ id: 'y', name: 'Stocktwits', type: 'stocktwits', source_key: 'bloomberg', supported: true, operational: true, enabled: true, article_limit: 83 }])
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const input = await screen.findByLabelText('Plafond Yahoo Finance')
|
||||
const input = await screen.findByLabelText('Plafond Bloomberg')
|
||||
expect(screen.queryByText('Stocktwits')).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Désactiver Yahoo Finance' }))
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Yahoo Finance désactivée pour les prochaines synthèses. Aucune génération n’a été lancée.')
|
||||
await user.click(screen.getByRole('button', { name: 'Désactiver Bloomberg' }))
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Bloomberg désactivée pour les prochaines synthèses. Aucune génération n’a été lancée.')
|
||||
expect(input).toHaveValue(83)
|
||||
expect(input).toBeDisabled()
|
||||
await user.click(screen.getByRole('button', { name: 'Activer Yahoo Finance' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Activer Bloomberg' }))
|
||||
await waitFor(() => expect(input).toBeEnabled())
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Yahoo Finance' }))
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Plafond Yahoo Finance enregistré pour les prochaines synthèses.')
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Bloomberg' }))
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Plafond Bloomberg enregistré pour les prochaines synthèses.')
|
||||
expect(updateSource).toHaveBeenLastCalledWith('y', true, 83)
|
||||
})
|
||||
|
||||
@ -221,37 +217,37 @@ describe('plafonds d’articles administrateur', () => {
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('Impossible de charger')
|
||||
expect(screen.queryByRole('spinbutton')).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Réessayer' }))
|
||||
expect(await screen.findByLabelText('Plafond Yahoo Finance')).toHaveValue(240)
|
||||
expect(await screen.findByLabelText('Plafond Bloomberg')).toHaveValue(240)
|
||||
})
|
||||
|
||||
it('sauvegarde le plafond CNBC et refuse toute commande Watcher Guru même avec un ancien DTO activable', async () => {
|
||||
it('sauvegarde le plafond Investing.com et refuse toute commande Watcher Guru même avec un ancien DTO activable', async () => {
|
||||
listSources.mockResolvedValue([
|
||||
{ id: 'cnbc-new', name: 'CNBC Business', type: 'cnbc_business', source_key: 'cnbc_business', supported: true, operational: true, enabled: true, article_limit: 37 },
|
||||
{ id: 'investing-new', name: 'Investing.com', type: 'rss', source_key: 'investing_com', supported: true, operational: true, enabled: true, article_limit: 37 },
|
||||
{ id: 'watcher-old', name: 'Watcher.Guru', type: 'watcherguru', source_key: 'watcher_guru', supported: true, operational: true, enabled: true, article_limit: 64 },
|
||||
])
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const cap = await screen.findByLabelText('Plafond CNBC Business')
|
||||
const cap = await screen.findByLabelText('Plafond Investing.com')
|
||||
expect(cap).toHaveValue(37)
|
||||
expect(screen.queryByRole('button', { name: /^(Activer|Désactiver) Watcher/ })).not.toBeInTheDocument()
|
||||
const historical = screen.getByRole('region', { name: 'Anciennes sources exclues' })
|
||||
const historical = screen.getByRole('region', { name: 'Sources retirées' })
|
||||
expect(within(historical).getByText('Watcher.Guru')).toBeInTheDocument()
|
||||
expect(within(historical).queryByRole('spinbutton')).not.toBeInTheDocument()
|
||||
expect(within(historical).queryByRole('button')).not.toBeInTheDocument()
|
||||
await user.clear(cap)
|
||||
await user.type(cap, '42')
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond CNBC Business' }))
|
||||
await waitFor(() => expect(updateSource).toHaveBeenCalledWith('cnbc-new', true, 42))
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Investing.com' }))
|
||||
await waitFor(() => expect(updateSource).toHaveBeenCalledWith('investing-new', true, 42))
|
||||
expect(updateSource).toHaveBeenCalledTimes(1)
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Plafond CNBC Business enregistré pour les prochaines synthèses.')
|
||||
expect(screen.getByText(/Yahoo Finance, Bloomberg, CNBC Business et Investing.com/)).toBeInTheDocument()
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Plafond Investing.com enregistré pour les prochaines synthèses.')
|
||||
expect(screen.getByText(/Seules Bloomberg et Investing.com/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('ticket #41 — sources additives', () => {
|
||||
describe('ticket #42 — sources RSS et sources retirées', () => {
|
||||
afterEach(cleanup)
|
||||
it('affiche Investing.com depuis la clé canonique backend et conserve Yahoo Finance et CNBC Business', async () => {
|
||||
it('affiche Investing.com depuis la clé canonique backend et conserve Yahoo Finance et CNBC Business en lecture seule', async () => {
|
||||
listSettings.mockResolvedValue([])
|
||||
listSources.mockResolvedValue([
|
||||
{ id: 'b', source_key: 'bloomberg', name: 'Bloomberg', type: 'rss', supported: true, operational: true, enabled: true, article_limit: 20 },
|
||||
@ -263,8 +259,11 @@ describe('ticket #41 — sources additives', () => {
|
||||
expect(await screen.findByRole('heading', { name: 'Investing.com' })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Plafond Investing.com')).toHaveValue(40)
|
||||
expect(screen.getByRole('button', { name: 'Activer Investing.com' })).toBeEnabled()
|
||||
expect(screen.getByRole('button', { name: 'Désactiver Yahoo Finance' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Désactiver CNBC Business' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /^(Activer|Désactiver) Yahoo Finance$/ })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /^(Activer|Désactiver) CNBC Business$/ })).not.toBeInTheDocument()
|
||||
const retired = screen.getByRole('region', { name: 'Sources retirées' })
|
||||
expect(within(retired).getByText('Yahoo Finance')).toBeInTheDocument()
|
||||
expect(within(retired).getByText('CNBC Business')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('heading', { name: 'Legacy RSS label' })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
80
frontend/tests/retired-sources-ticket42.test.tsx
Normal file
80
frontend/tests/retired-sources-ticket42.test.tsx
Normal file
@ -0,0 +1,80 @@
|
||||
import { cleanup, render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import { Sources } from '../src/pages/admin/Sources'
|
||||
import { GenerationDetails } from '../src/components/GenerationDetails'
|
||||
import type { GenerationOutcome } from '../src/api/summaries'
|
||||
|
||||
const { listSources, listSettings, updateSource, updateSettings, updateSourceFeeds } = vi.hoisted(() => ({
|
||||
listSources: vi.fn(), listSettings: vi.fn(), updateSource: vi.fn(), updateSettings: vi.fn(), updateSourceFeeds: vi.fn(),
|
||||
}))
|
||||
vi.mock('@/api/admin', () => ({ adminApi: { listSources, listSettings, updateSource, updateSettings, updateSourceFeeds } }))
|
||||
const sources = [
|
||||
{ id: 'b', source_key: 'bloomberg', name: 'Bloomberg', type: 'rss', supported: true, operational: true, enabled: true, article_limit: 20, feed_urls: ['https://feed.quanwenrss.com/feed/bloomberg-latest.xml'] },
|
||||
{ id: 'i', source_key: 'investing_com', name: 'Investing.com', type: 'rss', supported: true, operational: false, enabled: false, article_limit: 40, feed_urls: ['https://feed.quanwenrss.com/feed/investing-news.xml'] },
|
||||
{ id: 'y', source_key: 'yahoo_finance', name: 'Stocktwits', type: 'stocktwits', supported: false, operational: false, enabled: false, article_limit: 83 },
|
||||
{ id: 'c', source_key: 'cnbc_business', name: 'legacy', type: 'cnbc_business', supported: false, operational: false, enabled: false, article_limit: 37 },
|
||||
]
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
listSources.mockResolvedValue(sources)
|
||||
listSettings.mockResolvedValue([{ key: 'summary_max_articles', value: '50' }])
|
||||
updateSource.mockResolvedValue(undefined); updateSettings.mockResolvedValue(undefined); updateSourceFeeds.mockResolvedValue(undefined)
|
||||
})
|
||||
afterEach(cleanup)
|
||||
|
||||
it('ne propose que les deux sources RSS configurables et conserve leurs plafonds, flux et activation', async () => {
|
||||
render(<Sources />)
|
||||
await screen.findByRole('heading', { name: 'Bloomberg' })
|
||||
expect(screen.getAllByRole('button', { name: /^(Activer|Désactiver) / })).toHaveLength(2)
|
||||
for (const name of ['Bloomberg', 'Investing.com']) {
|
||||
expect(screen.getByLabelText(`Plafond ${name}`)).toBeInTheDocument()
|
||||
expect(screen.getByRole('form', { name: `Flux RSS ${name}` })).toBeInTheDocument()
|
||||
}
|
||||
expect(screen.getByLabelText('Articles max par résumé')).toHaveValue(50)
|
||||
expect(screen.getByText(/Seules Bloomberg et Investing.com/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('présente Yahoo/CNBC dans Sources retirées repliée et en lecture seule, avec leurs anciens plafonds', async () => {
|
||||
const before = JSON.stringify(sources)
|
||||
render(<Sources />)
|
||||
const region = await screen.findByRole('region', { name: 'Sources retirées' })
|
||||
const details = region.querySelector('details')!
|
||||
expect(details).not.toHaveAttribute('open')
|
||||
await userEvent.click(within(region).getByText('Consulter les sources retirées (2)'))
|
||||
expect(details).toHaveAttribute('open')
|
||||
expect(within(region).getByText('Yahoo Finance')).toBeVisible()
|
||||
expect(within(region).getByText('CNBC Business')).toBeVisible()
|
||||
expect(within(region).getByText('Exclue des synthèses · Plafond historique : 83')).toBeVisible()
|
||||
expect(within(region).getByText('Exclue des synthèses · Plafond historique : 37')).toBeVisible()
|
||||
expect(region.querySelectorAll('button,input,select,form,a')).toHaveLength(0)
|
||||
expect(screen.queryByLabelText('Plafond Yahoo Finance')).not.toBeInTheDocument()
|
||||
expect(screen.queryByLabelText('Plafond CNBC Business')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Stocktwits')).not.toBeInTheDocument()
|
||||
expect(updateSource).not.toHaveBeenCalled()
|
||||
expect(updateSettings).not.toHaveBeenCalled()
|
||||
expect(updateSourceFeeds).not.toHaveBeenCalled()
|
||||
expect(JSON.stringify(sources)).toBe(before)
|
||||
})
|
||||
|
||||
it('ne réactive pas Yahoo/CNBC même avec un ancien DTO déclarant ces lignes activées et prises en charge', async () => {
|
||||
listSources.mockResolvedValue(sources.map(source => ({ ...source, enabled: true, supported: true, operational: true })))
|
||||
render(<Sources />)
|
||||
await screen.findByRole('heading', { name: 'Bloomberg' })
|
||||
expect(screen.queryByRole('button', { name: /^(Activer|Désactiver) (Yahoo Finance|CNBC Business)$/ })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('form', { name: /Réglages de (Yahoo Finance|CNBC Business)/ })).not.toBeInTheDocument()
|
||||
const retired = screen.getByRole('region', { name: 'Sources retirées' })
|
||||
expect(within(retired).getByText('Yahoo Finance')).toBeInTheDocument()
|
||||
expect(within(retired).getByText('CNBC Business')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([['yahoo_finance', 'Yahoo Finance'], ['cnbc_business', 'CNBC Business']])('conserve le libellé du bilan historique %s et ses agrégats', (source_key, name) => {
|
||||
const outcome: GenerationOutcome = { id: 'historic', status: 'partial', language: 'fr', ranking_mode: 'title', total_candidates: 4, selected: 2, laya_selected: 2, content_fallbacks: 0, global_limit: 50,
|
||||
source_stats: [{ source_id: 'old', source_key, source_type: 'stocktwits', status: 'failed', candidates: 4, selected: 2, laya_selected: 2, article_limit: 83, content_fallbacks: 0 }] }
|
||||
const before = JSON.stringify(outcome)
|
||||
render(<GenerationDetails outcome={outcome} />)
|
||||
expect(screen.getByText(`Cette synthèse a été générée sans ${name}, indisponible lors du traitement.`)).toBeInTheDocument()
|
||||
expect(screen.getByText(name, { exact: true })).toBeInTheDocument()
|
||||
expect(screen.getByText('4 articles examinés · 2 sélectionnés par Laya · 2 retenus après plafonds')).toBeInTheDocument()
|
||||
expect(JSON.stringify(outcome)).toBe(before)
|
||||
})
|
||||
Reference in New Issue
Block a user