test(e2e): cover summary generation navigation resume
This commit is contained in:
@ -19,3 +19,11 @@ The E2E executable rejects nonliteral/nonloopback destination URLs and installs
|
||||
The Firefox journey covers admin login/account creation, new-user login, explicit OpenFIGI search/selection/follow, language/ranking/model preferences and fake-backed generation. It checks the saved provider/model snapshot against the actual model recorded by the fake summary service. It compares counts and hashes for `articles`, `article_symbols` and `scrape_jobs`, verifies retired routes are 404, reads the authenticated aggregate history, verifies its single-source counters, and rejects fixture article fields and actual candidate IDs in that outcome. HTTP success through the real application is required; API/provider routes are not mocked in the browser.
|
||||
|
||||
`npm run test:e2e` alone still fails closed without a valid running stack manifest. Use `make test-e2e` for complete lifecycle management. The scenario has no automatic retry. Browser traces and logs can contain disposable credentials and are deliberately kept inside the cleaned workspace.
|
||||
|
||||
Ticket #27 has a focused browser scenario with real login and client-side navigation, and mocked generation/preference/summary endpoints. The mock keeps the job running until the test explicitly completes it. The scenario checks the restored banner after leaving and returning to the Dashboard, polling by job id, exactly one generation POST, and the final summary, aggregate outcome and refreshed history. Run it independently (without the unrelated source assertions) from the project root:
|
||||
|
||||
```sh
|
||||
TRADARR_E2E_GREP='ticket #27:' make test-e2e
|
||||
```
|
||||
|
||||
`TRADARR_E2E_GREP` is an optional Playwright title regular expression; without it the complete E2E suite still runs.
|
||||
|
||||
107
frontend/e2e/ticket27-generation-navigation.spec.mjs
Normal file
107
frontend/e2e/ticket27-generation-navigation.spec.mjs
Normal file
@ -0,0 +1,107 @@
|
||||
import { expect, test } from '@playwright/test'
|
||||
import { readStackManifest } from './stack-manifest.mjs'
|
||||
|
||||
test('ticket #27: resumes a running job after leaving Dashboard without a second POST, then displays its result', async ({ page }) => {
|
||||
const stack = readStackManifest()
|
||||
await page.context().route('**/*', route => {
|
||||
const host = new URL(route.request().url()).hostname
|
||||
return host === '127.0.0.1' || host === '[::1]' ? route.continue() : route.abort('blockedbyclient')
|
||||
})
|
||||
|
||||
const previous = {
|
||||
id: 'summary-before-27', user_id: 'reader-27', content: 'Synthèse précédente ticket 27.',
|
||||
ai_provider_id: null, generated_at: '2026-11-23T10:00:00Z',
|
||||
}
|
||||
const summary = { ...previous, id: 'summary-after-27', content: 'Résultat terminal observable ticket 27.', generated_at: '2026-11-23T11:00:00Z' }
|
||||
const outcome = {
|
||||
id: 'outcome-27', status: 'succeeded', language: 'fr', ranking_mode: 'title',
|
||||
total_candidates: 3, laya_selected: 2, selected: 2, global_limit: 10,
|
||||
content_fallbacks: 0, source_stats: [],
|
||||
}
|
||||
let job = null
|
||||
let posts = 0
|
||||
let recentReads = 0
|
||||
let jobReads = 0
|
||||
let completedListReads = 0
|
||||
let completedHistoryReads = 0
|
||||
await page.route('**/api/**', async route => {
|
||||
const path = new URL(route.request().url()).pathname
|
||||
const method = route.request().method()
|
||||
const respond = (data, status = 200) => route.fulfill({ status, json: { data } })
|
||||
if (path === '/api/me/assets' && method === 'GET') return respond([{ id: 'asset-27', name: 'Entreprise test', symbol: 'TEST', user_id: 'reader-27' }])
|
||||
if (path === '/api/me/preferences' && method === 'GET') return respond({ language: 'fr', ranking_mode: 'title', summary_model_id: 'model-27' })
|
||||
if (path === '/api/me/summary-models') return respond([{ id: 'model-27', provider: 'Test', model: 'summary-27' }])
|
||||
if (path === '/api/summaries/generate' && method === 'POST') {
|
||||
posts++
|
||||
job = { id: 'job-27', status: 'running', created_at: '2026-11-23T11:00:00Z', finished_at: null, summary_id: null, outcome: null }
|
||||
return respond(job, 202)
|
||||
}
|
||||
if (path === '/api/summaries/generation-jobs/recent') {
|
||||
recentReads++
|
||||
return respond(job)
|
||||
}
|
||||
if (path === '/api/summaries/generation-jobs/job-27') {
|
||||
jobReads++
|
||||
return respond(job)
|
||||
}
|
||||
if (path === '/api/summaries') {
|
||||
if (job?.status === 'succeeded') { completedListReads++; return respond([summary, previous]) }
|
||||
return respond([previous])
|
||||
}
|
||||
if (path === '/api/summaries/generations') {
|
||||
if (job?.status === 'succeeded') {
|
||||
completedHistoryReads++
|
||||
return respond([{ id: outcome.id, summary_id: summary.id, outcome, created_at: summary.generated_at }])
|
||||
}
|
||||
return respond([])
|
||||
}
|
||||
return route.continue()
|
||||
})
|
||||
|
||||
await test.step('start one generation and keep the mocked job running', async () => {
|
||||
await page.goto(new URL('/login', stack.frontendUrl).href)
|
||||
await page.getByLabel('Adresse email').fill(stack.bootstrapAdmin.email)
|
||||
await page.getByLabel('Mot de passe').fill(stack.bootstrapAdmin.password)
|
||||
await page.getByRole('button', { name: 'Se connecter' }).click()
|
||||
await expect(page).toHaveURL(new URL('/', stack.frontendUrl).href)
|
||||
await expect(page.getByText(previous.content, { exact: true })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Générer une synthèse', exact: true }).click()
|
||||
await expect(page.getByRole('status').filter({ hasText: 'Synthèse en cours.' })).toBeVisible()
|
||||
expect(posts).toBe(1)
|
||||
})
|
||||
|
||||
await test.step('navigate away and return while the same job is still running', async () => {
|
||||
await page.getByRole('link', { name: 'Mes préférences', exact: true }).filter({ visible: true }).click()
|
||||
await expect(page).toHaveURL(new URL('/preferences', stack.frontendUrl).href)
|
||||
await expect(page.getByRole('heading', { name: 'Mes préférences', exact: true })).toBeVisible()
|
||||
await expect(page.getByText('Synthèse en cours. Le traitement peut prendre plusieurs minutes.', { exact: true })).toHaveCount(0)
|
||||
const readsBeforeReturn = recentReads
|
||||
await page.getByRole('link', { name: 'Synthèses', exact: true }).filter({ visible: true }).click()
|
||||
await expect(page).toHaveURL(new URL('/', stack.frontendUrl).href)
|
||||
await expect(page.getByRole('status').filter({ hasText: 'Synthèse en cours.' })).toBeVisible({ timeout: 3000 })
|
||||
expect(recentReads).toBeGreaterThan(readsBeforeReturn)
|
||||
expect(job.status).toBe('running')
|
||||
const generate = page.getByRole('button', { name: 'Génération en cours', exact: true })
|
||||
await expect(generate).toBeDisabled()
|
||||
await expect(page.getByText(previous.content, { exact: true })).toBeVisible()
|
||||
// Observe an actual polling request while the job remains active.
|
||||
const readsBeforePoll = jobReads
|
||||
await expect.poll(() => jobReads, { timeout: 10_000 }).toBeGreaterThan(readsBeforePoll)
|
||||
await expect(generate).toBeDisabled()
|
||||
expect(posts).toBe(1)
|
||||
})
|
||||
|
||||
await test.step('finish the job and observe the refreshed summary and history', async () => {
|
||||
job = { ...job, status: 'succeeded', finished_at: summary.generated_at, summary_id: summary.id, outcome }
|
||||
await expect(page.getByText('Nouvelle synthèse disponible.', { exact: true })).toBeVisible({ timeout: 10_000 })
|
||||
await expect(page.getByText(summary.content, { exact: true })).toBeVisible()
|
||||
await expect(page.getByRole('status').filter({ hasText: 'Synthèse en cours.' })).toHaveCount(0)
|
||||
await expect(page.getByRole('button', { name: 'Générer une synthèse', exact: true })).toBeEnabled()
|
||||
await expect(page.getByRole('region', { name: 'Bilan de la génération' })).toContainText('3 articles examinés')
|
||||
await expect(page.getByRole('heading', { name: 'Historique', exact: true })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: `${previous.content}…`, exact: true })).toBeVisible()
|
||||
expect(completedListReads).toBeGreaterThan(0)
|
||||
expect(completedHistoryReads).toBeGreaterThan(0)
|
||||
expect(posts).toBe(1)
|
||||
})
|
||||
})
|
||||
@ -3,6 +3,7 @@ import { defineConfig } from '@playwright/test'
|
||||
export default defineConfig({
|
||||
testDir: './e2e',
|
||||
testMatch: '**/*.spec.mjs',
|
||||
grep: process.env.TRADARR_E2E_GREP ? new RegExp(process.env.TRADARR_E2E_GREP) : undefined,
|
||||
fullyParallel: false,
|
||||
forbidOnly: Boolean(process.env.CI),
|
||||
retries: 0,
|
||||
|
||||
Reference in New Issue
Block a user