feat(ui): add web citations to synthesis Q&A (#61)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { expect, test } from '@playwright/test'
|
||||
import { readStackManifest } from './stack-manifest.mjs'
|
||||
|
||||
for (const width of [1280, 375]) test(`ticket #57: simplified modal Q&A remains accessible at ${width}px`, async ({ page }) => {
|
||||
for (const width of [1280, 375]) test(`ticket #61: web search choice and citations remain accessible at ${width}px`, async ({ page }) => {
|
||||
const stack = readStackManifest()
|
||||
await page.setViewportSize({ width, height: 850 })
|
||||
await page.context().route('**/*', route => {
|
||||
@ -10,7 +10,7 @@ for (const width of [1280, 375]) test(`ticket #57: simplified modal Q&A remains
|
||||
})
|
||||
const excerpt = 'Passage de la synthèse pour poser une question. '.repeat(12).trim()
|
||||
const summary = { id: '00000000-0000-0000-0000-000000005401', user_id: 'reader', content: excerpt + '\n\n' + Array.from({ length: 30 }, (_, i) => `Contexte ${i}. ` + 'Texte de contexte. '.repeat(20)).join('\n'), ai_provider_id: null, generated_at: '2026-11-25T00:00:00Z' }
|
||||
const conversation = { id: 'c', summary_id: summary.id, mode: 'stateless', uses_source_articles: false, provider_session_supported: false, source_expires_at: '2026-01-01T00:00:00Z', sources_expired: true, source_count: 0, messages: [] }
|
||||
const conversation = { id: 'c', web_search_supported: true, summary_id: summary.id, mode: 'stateless', uses_source_articles: false, provider_session_supported: false, source_expires_at: '2026-01-01T00:00:00Z', sources_expired: true, source_count: 0, messages: [] }
|
||||
const questions = []
|
||||
await page.route('**/api/**', async route => {
|
||||
const path = new URL(route.request().url()).pathname
|
||||
@ -22,7 +22,7 @@ for (const width of [1280, 375]) test(`ticket #57: simplified modal Q&A remains
|
||||
if (path === `/api/summaries/${summary.id}/conversation/messages`) {
|
||||
const question = route.request().postDataJSON()
|
||||
questions.push(question)
|
||||
const turn = { ...question, id: 't', answer: 'Réponse sur cette synthèse.', status: 'answered', replayed: false, created_at: '2026-11-25T00:00:00Z' }
|
||||
const turn = { ...question, id: `t-${questions.length}`, web_search_performed: question.use_web_search, citations: question.use_web_search ? [{ title: 'Source de test', url: 'https://example.test/source' }] : [], answer: question.use_web_search ? 'Réponse avec recherche simulée.' : 'Réponse sur cette synthèse.', status: 'answered', replayed: false, created_at: '2026-11-25T00:00:00Z' }
|
||||
conversation.messages.push(turn)
|
||||
return respond(turn)
|
||||
}
|
||||
@ -66,6 +66,9 @@ for (const width of [1280, 375]) test(`ticket #57: simplified modal Q&A remains
|
||||
|
||||
await expect(dialog.getByText(/Les sources ont expiré|Expiration des sources|Posez une question sur le passage sélectionné|sans articles sources ni session fournisseur/)).toHaveCount(0)
|
||||
await expect(dialog.getByRole('button', { name: /Actualiser|Développer|Réduire/ })).toHaveCount(0)
|
||||
const webSearch = dialog.getByRole('checkbox', { name: 'Utiliser la recherche Web si nécessaire pour répondre, en transmettant au fournisseur de recherche les termes et éléments de contexte utiles.' })
|
||||
await expect(webSearch).toBeChecked()
|
||||
await webSearch.uncheck()
|
||||
await question.fill('Que signifie ce passage ?')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(dialog).toHaveCount(0)
|
||||
@ -73,6 +76,7 @@ for (const width of [1280, 375]) test(`ticket #57: simplified modal Q&A remains
|
||||
expect(await page.locator('main').evaluate(element => element.scrollTop)).toBe(beforeScroll)
|
||||
await action.click()
|
||||
await expect(question).toHaveValue('Que signifie ce passage ?')
|
||||
await expect(webSearch).not.toBeChecked()
|
||||
// Keyboard navigation stays inside the modal, including after a smaller viewport.
|
||||
await page.setViewportSize({ width, height: 450 })
|
||||
const box = await dialog.boundingBox()
|
||||
@ -85,7 +89,21 @@ for (const width of [1280, 375]) test(`ticket #57: simplified modal Q&A remains
|
||||
await page.getByRole('button', { name: 'Envoyer la question' }).click()
|
||||
await expect(page.getByText('Réponse sur cette synthèse.', { exact: true })).toBeVisible()
|
||||
expect(questions).toHaveLength(1)
|
||||
expect(questions[0]).toMatchObject({ passage: excerpt, question: 'Que signifie ce passage ?', request_id: expect.stringMatching(/^[a-f0-9-]{36}$/) })
|
||||
expect(questions[0]).toMatchObject({ passage: excerpt, question: 'Que signifie ce passage ?', use_web_search: false, request_id: expect.stringMatching(/^[a-f0-9-]{36}$/) })
|
||||
await expect(dialog.getByRole('link')).toHaveCount(0)
|
||||
await expect(dialog.getByRole('list', { name: 'Sources de la réponse' })).toHaveCount(0)
|
||||
await expect(webSearch).toBeChecked()
|
||||
await expect(question).toHaveValue('')
|
||||
await question.fill('Quels éléments récents ?')
|
||||
await page.getByRole('button', { name: 'Envoyer la question' }).click()
|
||||
await expect(page.getByText('Réponse avec recherche simulée.', { exact: true })).toBeVisible()
|
||||
expect(questions).toHaveLength(2)
|
||||
expect(questions[1].use_web_search).toBe(true)
|
||||
expect(questions[1].request_id).not.toBe(questions[0].request_id)
|
||||
const source = dialog.getByRole('link', { name: 'Source de test (nouvel onglet)' })
|
||||
await expect(source).toHaveAttribute('href', 'https://example.test/source')
|
||||
await expect(source).toHaveAttribute('target', '_blank')
|
||||
await expect(source).toHaveAttribute('rel', 'noopener noreferrer')
|
||||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
|
||||
await page.getByRole('button', { name: 'Fermer', exact: true }).click()
|
||||
await expect(page.getByRole('button', { name: 'Interroger ce passage' })).toBeFocused()
|
||||
|
||||
Reference in New Issue
Block a user