feat(ui): open synthesis Q&A from selected passage (#56)
This commit is contained in:
@ -1,14 +1,15 @@
|
||||
import { expect, test } from '@playwright/test'
|
||||
import { readStackManifest } from './stack-manifest.mjs'
|
||||
|
||||
for (const width of [1280, 375]) test(`ticket #54: passage and Q&A remain accessible at ${width}px`, async ({ page }) => {
|
||||
for (const width of [1280, 375]) test(`ticket #56: fixed selection action and modal Q&A remain accessible at ${width}px`, async ({ page }) => {
|
||||
const stack = readStackManifest()
|
||||
await page.setViewportSize({ width, height: 850 })
|
||||
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 summary = { id: '00000000-0000-0000-0000-000000005401', user_id: 'reader', content: 'Passage de la synthèse pour poser une question.', ai_provider_id: null, generated_at: '2026-11-25T00:00:00Z' }
|
||||
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 questions = []
|
||||
await page.route('**/api/**', async route => {
|
||||
@ -31,8 +32,10 @@ for (const width of [1280, 375]) test(`ticket #54: passage and Q&A remain access
|
||||
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()
|
||||
const passage = page.getByText(summary.content, { exact: true })
|
||||
const passage = page.getByText(excerpt, { exact: true })
|
||||
await expect(passage).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'Interroger ce passage' })).toHaveCount(0)
|
||||
await expect(page.getByRole('button', { name: 'Questions sur cette synthèse' })).toHaveCount(0)
|
||||
await passage.evaluate(element => {
|
||||
for (const name of ['contextmenu', 'selectstart', 'copy', 'touchstart']) {
|
||||
if (!element.dispatchEvent(new Event(name, { bubbles: true, cancelable: true }))) throw new Error(`${name} blocked`)
|
||||
@ -46,18 +49,45 @@ for (const width of [1280, 375]) test(`ticket #54: passage and Q&A remain access
|
||||
document.dispatchEvent(new Event('selectionchange'))
|
||||
})
|
||||
await expect(page.getByRole('textbox', { name: 'Votre question' })).toHaveCount(0)
|
||||
await page.getByRole('button', { name: 'Interroger ce passage' }).click()
|
||||
const action = page.getByRole('button', { name: 'Interroger ce passage' })
|
||||
await expect(action).toBeVisible()
|
||||
const initialBox = await action.boundingBox()
|
||||
await page.evaluate(() => { window.getSelection().removeAllRanges(); document.querySelector('main').scrollTop = 1100 })
|
||||
await expect(action).toBeVisible()
|
||||
expect((await action.boundingBox()).y).toBe(initialBox.y)
|
||||
const beforeScroll = await page.locator('main').evaluate(element => element.scrollTop)
|
||||
await action.click()
|
||||
const dialog = page.getByRole('dialog', { name: 'Questions sur cette synthèse' })
|
||||
await expect(dialog).toBeVisible()
|
||||
await expect(dialog.getByRole('heading', { name: 'Questions sur cette synthèse' })).toBeFocused()
|
||||
await expect(page.getByLabel('Passage sélectionné')).toHaveCSS('-webkit-line-clamp', '3')
|
||||
await expect(page.getByLabel('Passage sélectionné')).toHaveText(excerpt)
|
||||
const question = page.getByRole('textbox', { name: 'Votre question' })
|
||||
await expect(question).toBeFocused()
|
||||
|
||||
await expect(page.getByText(/Les sources ont expiré/)).toBeVisible()
|
||||
await question.fill('Que signifie ce passage ?')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(dialog).toHaveCount(0)
|
||||
await expect(action).toBeFocused()
|
||||
expect(await page.locator('main').evaluate(element => element.scrollTop)).toBe(beforeScroll)
|
||||
await action.click()
|
||||
await expect(question).toHaveValue('Que signifie ce passage ?')
|
||||
// Keyboard navigation stays inside the modal, including after a smaller viewport.
|
||||
await page.setViewportSize({ width, height: 450 })
|
||||
const box = await dialog.boundingBox()
|
||||
expect(box.y).toBeGreaterThanOrEqual(0)
|
||||
expect(box.y + box.height).toBeLessThanOrEqual(450)
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await page.keyboard.press('Tab')
|
||||
expect(await dialog.evaluate(element => element.contains(document.activeElement))).toBe(true)
|
||||
}
|
||||
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: summary.content, question: 'Que signifie ce passage ?', request_id: expect.stringMatching(/^[a-f0-9-]{36}$/) })
|
||||
expect(questions[0]).toMatchObject({ passage: excerpt, question: 'Que signifie ce passage ?', request_id: expect.stringMatching(/^[a-f0-9-]{36}$/) })
|
||||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
|
||||
await page.getByRole('button', { name: 'Retour à la synthèse' }).click()
|
||||
await page.getByRole('button', { name: 'Fermer', exact: true }).click()
|
||||
await expect(page.getByRole('button', { name: 'Interroger ce passage' })).toBeFocused()
|
||||
await page.getByRole('button', { name: 'Questions sur cette synthèse' }).click()
|
||||
await page.getByRole('button', { name: 'Interroger ce passage' }).click()
|
||||
await expect(page.getByText('Réponse sur cette synthèse.', { exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user