feat(ui): turn synthesis Q&A into persistent chat (#64)

This commit is contained in:
2026-11-26 14:56:13 +01:00
parent 0a19d1c617
commit f75de489cc
9 changed files with 458 additions and 131 deletions

View File

@ -1,6 +1,7 @@
import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { summaryQAApi } from '../src/api/summaryQA'
import { Dashboard } from '../src/pages/Dashboard'
const {
@ -113,6 +114,74 @@ describe('Dashboard — génération de synthèses éphémères', () => {
createReport.mockResolvedValue({ id: 'report-1' })
})
it('restaure indépendamment question, passage joint et Web après A → B → A → B', async () => {
const a = { ...previousSummary, id: 'summary-a', content: 'Passage synthèse A.' }
const b = { ...previousSummary, id: 'summary-b', content: 'Passage synthèse B.' }
listSummaries.mockResolvedValue([generatedSummary, a, b])
const getChat = vi.spyOn(summaryQAApi, 'get').mockImplementation(async id => ({
id: `chat-${id}`, summary_id: id, mode: 'stateless', web_search_supported: true,
uses_source_articles: false, provider_session_supported: false, source_expires_at: '', sources_expired: true, source_count: 0,
messages: [{ id: `turn-${id}`, request_id: `request-${id}`, passage: '', question: `Historique ${id}`, answer: `Réponse ${id}`, status: 'answered', created_at: '', replayed: false, use_web_search: false, web_search_performed: false, citations: [] }],
}))
vi.spyOn(window, 'scrollTo').mockImplementation(() => {})
const select = (content: string) => {
const range = document.createRange(); range.selectNodeContents(screen.getByText(content, { exact: true }))
window.getSelection()!.removeAllRanges(); window.getSelection()!.addRange(range)
fireEvent(document, new Event('selectionchange'))
}
const open = async () => {
await userEvent.click(screen.getByRole('button', { name: 'Ouvrir le chat de cette synthèse' }))
return screen.findByRole('textbox')
}
try {
renderDashboard(); await screen.findByText(generatedSummary.content)
await userEvent.click(screen.getByRole('button', { name: /Passage synthèse A/ }))
select(a.content)
const questionA = await open()
expect(questionA).toHaveValue('')
await userEvent.type(questionA, 'Brouillon A')
await userEvent.click(screen.getByRole('button', { name: 'Ajouter le passage sélectionné à la question' }))
await userEvent.click(screen.getByRole('checkbox'))
await userEvent.keyboard('{Escape}')
await userEvent.click(screen.getByRole('button', { name: /Passage synthèse B/ }))
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
const questionB = await open()
expect(questionB).toHaveValue('')
expect(screen.queryByLabelText('Passage joint')).not.toBeInTheDocument()
expect(screen.getByRole('checkbox')).toBeChecked()
expect(screen.getByText('Historique summary-b')).toBeInTheDocument()
expect(screen.queryByText('Historique summary-a')).not.toBeInTheDocument()
await userEvent.type(questionB, 'Brouillon B')
await userEvent.keyboard('{Escape}')
select(b.content); await open()
await userEvent.click(screen.getByRole('button', { name: 'Ajouter le passage sélectionné à la question' }))
await userEvent.keyboard('{Escape}')
await userEvent.click(screen.getByRole('button', { name: /Passage synthèse A/ }))
expect(await open()).toHaveValue('Brouillon A')
expect(screen.getByLabelText('Passage joint')).toHaveTextContent(a.content)
expect(screen.getByRole('checkbox')).not.toBeChecked()
expect(screen.getByText('Historique summary-a')).toBeInTheDocument()
expect(screen.queryByText('Historique summary-b')).not.toBeInTheDocument()
await userEvent.keyboard('{Escape}')
await userEvent.click(screen.getByRole('button', { name: /Passage synthèse B/ }))
expect(await open()).toHaveValue('Brouillon B')
expect(screen.getByLabelText('Passage joint')).toHaveTextContent(b.content)
expect(screen.getByRole('checkbox')).toBeChecked()
expect(getChat.mock.calls.map(([id]) => id)).toEqual(['summary-a', 'summary-b', 'summary-a', 'summary-b'])
} finally { window.getSelection()?.removeAllRanges(); vi.restoreAllMocks() }
})
it('place le launcher chat dans le header directement au-dessus de Générer', async () => {
renderDashboard()
const launcher = await screen.findByRole('button', { name: 'Ouvrir le chat de cette synthèse' })
const generate = screen.getByRole('button', { name: 'Générer une synthèse' })
expect(launcher.parentElement?.nextElementSibling).toBe(generate)
expect(launcher.parentElement?.parentElement).toBe(generate.parentElement)
expect(generate.parentElement).toHaveClass('flex-col')
expect(launcher).not.toHaveClass('fixed')
expect(launcher.querySelector('svg')).toBeInTheDocument()
})
it.each(['ranking_model_unavailable', 'ranking_model_incompatible'])('guide vers les préférences pour %s', async (failure_code) => {
generationStatus.mockResolvedValueOnce({ id: 'failed', status: 'failed', failure_code })
renderDashboard()
@ -163,7 +232,8 @@ describe('Dashboard — génération de synthèses éphémères', () => {
expect(screen.getByText('2 articles parmi les plus anciens ont été retirés pour respecter le plafond du prompt.')).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: /Ancienne synthèse/ }))
expect(screen.getAllByText('2 articles parmi les plus anciens ont été retirés pour respecter le plafond du prompt.')).toHaveLength(2)
if (count) expect(screen.getAllByText(expected)).toHaveLength(1)
// The newest summary is now selectable in history as well as shown in the latest-result notice.
if (count) expect(screen.getAllByText(expected)).toHaveLength(2)
})
it('affiche le compteur du résultat récent lié à la synthèse sans historique disponible', async () => {