diff --git a/frontend/e2e/ticket54-summary-qa.spec.mjs b/frontend/e2e/ticket54-summary-qa.spec.mjs index 2c4ac80..3c5171f 100644 --- a/frontend/e2e/ticket54-summary-qa.spec.mjs +++ b/frontend/e2e/ticket54-summary-qa.spec.mjs @@ -1,7 +1,7 @@ import { expect, test } from '@playwright/test' import { readStackManifest } from './stack-manifest.mjs' -for (const width of [1280, 375]) test(`ticket #64: synthesis chat, attachments and web citations at ${width}px`, async ({ page }) => { +for (const width of [1280, 375]) test(`ticket #65: fixed chat launcher, synthesis chat and web citations at ${width}px`, async ({ page }) => { const stack = readStackManifest() await page.setViewportSize({ width, height: 850 }) await page.context().route('**/*', route => { @@ -39,14 +39,70 @@ for (const width of [1280, 375]) test(`ticket #64: synthesis chat, attachments a const passage = page.getByText(excerpt, { exact: true }) await expect(passage).toBeVisible() const action = page.getByRole('button', { name: 'Ouvrir le chat de cette synthèse' }) - const generate = page.getByRole('button', { name: 'Générer une synthèse' }) await expect(action).toBeVisible() await expect(action).toHaveAttribute('title', 'Ouvrir le chat de cette synthèse') - expect(await action.evaluate(element => element.parentElement.nextElementSibling === [...element.parentElement.parentElement.querySelectorAll('button')].find(button => button.textContent.includes('Générer')))).toBe(true) - const actionBox = await action.boundingBox() - const generateBox = await generate.boundingBox() - expect(actionBox.y + actionBox.height).toBeLessThanOrEqual(generateBox.y) - expect(await action.evaluate(element => getComputedStyle(element).position)).not.toBe('fixed') + const wrapper = action.locator('..') + expect(await wrapper.evaluate(element => element.parentElement === document.body)).toBe(true) + await expect(wrapper).toHaveCSS('position', 'fixed') + await expect(action).toHaveCSS('width', '48px') + await expect(action).toHaveCSS('height', '48px') + const nav = page.getByRole('navigation', { name: 'Navigation mobile' }) + async function checkPosition() { + const box = await action.boundingBox() + const viewport = page.viewportSize() + if (viewport.width >= 768) { + expect(viewport.width - box.x - box.width).toBeCloseTo(24) + expect(viewport.height - box.y - box.height).toBeCloseTo(24) + await expect(nav).not.toBeVisible() + } else { + const safeRight = await page.evaluate(() => { + const probe = document.createElement('div') + probe.style.paddingRight = 'env(safe-area-inset-right, 0px)' + document.body.append(probe) + const inset = parseFloat(getComputedStyle(probe).paddingRight) + probe.remove() + return inset + }) + expect(viewport.width - box.x - box.width).toBeCloseTo(16 + safeRight) + await expect.poll(async () => { + const navBox = await nav.boundingBox(), launcherBox = await action.boundingBox() + return Math.round((navBox.y - launcherBox.y - launcherBox.height) * 10) / 10 + }).toBe(16) + expect(Number(await wrapper.evaluate(element => getComputedStyle(element).zIndex))).toBeGreaterThan(Number(await nav.evaluate(element => getComputedStyle(element).zIndex))) + } + expect(await action.evaluate(element => { + const rect = element.getBoundingClientRect() + return element.contains(document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2)) + })).toBe(true) + } + await checkPosition() + const initialBox = await action.boundingBox() + const main = page.locator('main') + await main.evaluate(element => { element.scrollTop = element.scrollHeight }) + expect(await main.evaluate(element => element.scrollTop)).toBeGreaterThan(0) + const scrolledBox = await action.boundingBox() + expect(scrolledBox.x).toBeCloseTo(initialBox.x) + expect(scrolledBox.y).toBeCloseTo(initialBox.y) + await checkPosition() + if (width < 768) { + // Exercise actual nav height changes (including extra safe-area-like padding). + await nav.evaluate(element => { element.style.paddingBottom = '23px' }) + await checkPosition() + await nav.evaluate(element => { element.style.removeProperty('padding-bottom') }) + await checkPosition() + await page.setViewportSize({ width, height: 650 }) + await page.evaluate(() => window.dispatchEvent(new Event('orientationchange'))) + await checkPosition() + await page.setViewportSize({ width, height: 850 }) + await checkPosition() + // Extra main padding keeps the final history card above the launcher and nav. + await main.evaluate(element => { element.scrollTop = element.scrollHeight }) + const lastCard = await page.getByRole('button', { name: 'Autre synthèse de test.…' }).boundingBox() + const launcherBox = await action.boundingBox() + expect(lastCard.y + lastCard.height).toBeLessThanOrEqual(launcherBox.y) + } + const mainScrollBeforeChat = await main.evaluate(element => element.scrollTop) + const launcherZ = Number(await wrapper.evaluate(element => getComputedStyle(element).zIndex)) // Global question is possible without selecting or attaching any text. await action.click() @@ -55,6 +111,7 @@ for (const width of [1280, 375]) test(`ticket #64: synthesis chat, attachments a const webSearch = dialog.getByRole('checkbox', { name: 'Utiliser la recherche Web si nécessaire pour répondre ; la synthèse complète, les échanges précédents, votre question et tout passage joint seront transmis au fournisseur du modèle sélectionné.' }) const add = dialog.getByRole('button', { name: 'Ajouter le passage sélectionné à la question' }) await expect(dialog.getByRole('heading')).toBeFocused() + expect(Number(await dialog.evaluate(element => getComputedStyle(element).zIndex))).toBeGreaterThan(launcherZ) await expect(question).toHaveValue('') await expect(add).toHaveCount(0) expect(questions).toHaveLength(0) @@ -69,6 +126,7 @@ for (const width of [1280, 375]) test(`ticket #64: synthesis chat, attachments a await expect(question).toHaveValue('') await page.keyboard.press('Escape') await expect(action).toBeFocused() + expect(await main.evaluate(element => element.scrollTop)).toBe(mainScrollBeforeChat) async function selectText(element) { await element.evaluate(element => { diff --git a/frontend/src/components/SummaryQA.tsx b/frontend/src/components/SummaryQA.tsx index ae5d383..9fdf803 100644 --- a/frontend/src/components/SummaryQA.tsx +++ b/frontend/src/components/SummaryQA.tsx @@ -58,14 +58,13 @@ export interface SummaryQADraft { type SummaryQAProps = { summaryId: string content: string - launcherHost?: HTMLElement | null initialDraft?: SummaryQADraft onDraftChange?: (summaryId: string, draft: SummaryQADraft) => void } export function SummaryQA(props: SummaryQAProps) { return } -function Conversation({ summaryId, content, launcherHost, initialDraft, onDraftChange }: SummaryQAProps) { +function Conversation({ summaryId, content, initialDraft, onDraftChange }: SummaryQAProps) { const id = useId() const text = useRef(null) const title = useRef(null) @@ -179,14 +178,14 @@ function Conversation({ summaryId, content, launcherHost, initialDraft, onDraftC } const busy = conversation?.messages.some(turn => turn.status === 'pending') const launcher = - return
- {launcherHost === undefined ? launcher : launcherHost ? createPortal(launcher, launcherHost) : null} + {createPortal(
{launcher}
, document.body)} {/* Main content */} -
+
{notice &&

{notice}

}
diff --git a/frontend/src/components/layout/MobileNav.tsx b/frontend/src/components/layout/MobileNav.tsx index 3562128..d34caab 100644 --- a/frontend/src/components/layout/MobileNav.tsx +++ b/frontend/src/components/layout/MobileNav.tsx @@ -1,3 +1,4 @@ +import { useLayoutEffect, useRef } from 'react' import { NavLink } from 'react-router-dom' import { LayoutDashboard, Star, Settings, FileText } from 'lucide-react' import { useAuth } from '@/lib/auth' @@ -12,9 +13,34 @@ const items = [ export function MobileNav() { const { isAdmin } = useAuth() + const nav = useRef(null) + useLayoutEffect(() => { + const element = nav.current + if (!element) return + const root = document.documentElement + const previous = root.style.getPropertyValue('--mobile-nav-offset') + const measure = () => { + const rect = element.getBoundingClientRect() + // The real rect already includes the current safe area and wrapping/layout. + const offset = rect.height > 0 ? Math.max(0, window.innerHeight - rect.top) : 0 + root.style.setProperty('--mobile-nav-offset', `${offset}px`) + } + measure() + const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(measure) + observer?.observe(element, { box: 'border-box' }) + window.addEventListener('resize', measure) + window.addEventListener('orientationchange', measure) + return () => { + observer?.disconnect() + window.removeEventListener('resize', measure) + window.removeEventListener('orientationchange', measure) + if (previous) root.style.setProperty('--mobile-nav-offset', previous) + else root.style.removeProperty('--mobile-nav-offset') + } + }, []) const visibleItems = isAdmin ? [...items, { to: '/admin', icon: Settings, label: 'Admin' }] : items return ( -
-
-
-
{loadError &&

{loadError}

} @@ -220,7 +216,7 @@ export function Dashboard() {

Langue de cette synthèse : {currentOutcome ? (currentOutcome.language === 'fr' ? 'Français' : 'English') : 'non renseignée'}

- +

Modèle utilisé : {current.provider_name && current.model_name ? `${current.provider_name} · ${current.model_name}` : 'non renseigné pour cette synthèse historique'}

diff --git a/frontend/tests/chat-launcher-ticket65.test.tsx b/frontend/tests/chat-launcher-ticket65.test.tsx new file mode 100644 index 0000000..753789f --- /dev/null +++ b/frontend/tests/chat-launcher-ticket65.test.tsx @@ -0,0 +1,60 @@ +import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import { afterEach, expect, it, vi } from 'vitest' +import { MemoryRouter } from 'react-router-dom' +import { SummaryQA } from '../src/components/SummaryQA' +import { MobileNav } from '../src/components/layout/MobileNav' +vi.mock('@/api/summaryQA', () => ({ summaryQAApi: { get: vi.fn().mockResolvedValue({ id: 'c', messages: [], web_search_supported: true }) } })) +vi.mock('@/lib/auth', () => ({ useAuth: () => ({ isAdmin: false }) })) +afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.unstubAllGlobals() }) +it('porte le trigger dans body hors du main scrollable, avec wrapper fixe et retour du focus', async () => { + vi.spyOn(window, 'scrollTo').mockImplementation(() => {}) + const result = render(
) + Object.defineProperty(result.container.querySelector('main'), 'scrollTo', { value: vi.fn() }) + const action = screen.getByRole('button', { name: 'Ouvrir le chat de cette synthèse' }) + const wrapper = action.parentElement! + expect(wrapper.parentElement).toBe(document.body) + expect(wrapper).toHaveClass('fixed') + expect(wrapper.className).toContain('safe-area-inset-right') + expect(within(result.container).queryByRole('button', { name: 'Ouvrir le chat de cette synthèse' })).not.toBeInTheDocument() + fireEvent.scroll(result.container.querySelector('main')!, { target: { scrollTop: 700 } }) + expect(action.parentElement).toBe(wrapper) + await userEvent.click(action) + expect(await screen.findByRole('dialog')).toBeInTheDocument() + await userEvent.keyboard('{Escape}') + expect(action).toHaveFocus() +}) +it('publie la distance réelle nav→bas viewport et réagit au ResizeObserver, resize et rotation', () => { + let top = 730, height = 120 + vi.stubGlobal('innerHeight', 850) + vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(() => new DOMRect(0, top, 375, height)) + let notify!: () => void + const observe = vi.fn(), disconnect = vi.fn() + vi.stubGlobal('ResizeObserver', class { + constructor(callback: () => void) { notify = callback } + observe = observe + disconnect = disconnect + }) + const result = render() + const offset = () => document.documentElement.style.getPropertyValue('--mobile-nav-offset') + expect(offset()).toBe('120px') + expect(observe).toHaveBeenCalledWith(screen.getByRole('navigation'), { box: 'border-box' }) + top = 700; height = 150 + act(() => notify()) + expect(offset()).toBe('150px') + // A moved nav with the same height must still update on viewport changes. + top = 680 + fireEvent(window, new Event('resize')) + expect(offset()).toBe('170px') + top = 650 + fireEvent(window, new Event('orientationchange')) + expect(offset()).toBe('200px') + height = 0; top = 0 + fireEvent(window, new Event('resize')) + expect(offset()).toBe('0px') + result.unmount() + expect(disconnect).toHaveBeenCalledOnce() + expect(offset()).toBe('') + fireEvent(window, new Event('resize')) + expect(offset()).toBe('') +}) diff --git a/frontend/tests/dashboard-generation.test.tsx b/frontend/tests/dashboard-generation.test.tsx index c3cb650..c2d663c 100644 --- a/frontend/tests/dashboard-generation.test.tsx +++ b/frontend/tests/dashboard-generation.test.tsx @@ -171,15 +171,18 @@ describe('Dashboard — génération de synthèses éphémères', () => { } finally { window.getSelection()?.removeAllRanges(); vi.restoreAllMocks() } }) - it('place le launcher chat dans le header directement au-dessus de Générer', async () => { - renderDashboard() + it('rend le launcher hors du header Dashboard et le masque sans synthèse', async () => { + const result = 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.parentElement).toHaveClass('fixed') + expect(launcher.parentElement?.parentElement).toBe(document.body) + expect(result.container.contains(launcher)).toBe(false) expect(launcher.querySelector('svg')).toBeInTheDocument() + result.unmount() + listSummaries.mockResolvedValue([]) + renderDashboard() + await screen.findByText('Aucune synthèse disponible') + expect(screen.queryByRole('button', { name: 'Ouvrir le chat de cette synthèse' })).not.toBeInTheDocument() }) it.each(['ranking_model_unavailable', 'ranking_model_incompatible'])('guide vers les préférences pour %s', async (failure_code) => { diff --git a/frontend/tests/summary-qa-ticket54.test.tsx b/frontend/tests/summary-qa-ticket54.test.tsx index fe76801..c1496f3 100644 --- a/frontend/tests/summary-qa-ticket54.test.tsx +++ b/frontend/tests/summary-qa-ticket54.test.tsx @@ -115,10 +115,10 @@ it.each([45, undefined])('explique le quota Q&A avec délai %s et conserve la qu expect(alert).toHaveTextContent(seconds === undefined ? 'Réessayez dans quelques instants.' : 'Réessayez dans 45 secondes.') expect(screen.getByRole('textbox')).toHaveValue('Pourquoi ?') }) -it('garde le launcher dans le flux et mémorise une sélection au scroll/collapse sans ouvrir', () => { +it('garde le launcher fixe et mémorise une sélection au scroll/collapse sans ouvrir', () => { render() const action = screen.getByRole('button', { name: 'Ouvrir le chat de cette synthèse' }) - expect(action).not.toHaveClass('fixed') + expect(action.parentElement).toHaveClass('fixed') selectPassage() window.getSelection()?.removeAllRanges() fireEvent(document, new Event('selectionchange')) diff --git a/frontend/tests/summary-qa-ticket64.test.tsx b/frontend/tests/summary-qa-ticket64.test.tsx index 0e0021f..c5d26e2 100644 --- a/frontend/tests/summary-qa-ticket64.test.tsx +++ b/frontend/tests/summary-qa-ticket64.test.tsx @@ -118,15 +118,12 @@ it('le polling ne supprime jamais le nouveau brouillon rédigé après envoi pen expect(screen.getByRole('textbox')).toHaveValue('Nouveau brouillon') expect(screen.getByLabelText('Passage joint')).toHaveTextContent('Premier passage.') }) -it('le launcher est rendu dans le host header sans déplacer le lecteur de synthèse', async () => { - const host = document.createElement('div'); document.body.append(host) - try { - const result = render() - expect(within(host).getByRole('button', { name: launcher })).toBeInTheDocument() - expect(within(result.container).getByText('Contenu')).toBeInTheDocument() - expect(within(result.container).queryByRole('button', { name: launcher })).not.toBeInTheDocument() - await open() - } finally { host.remove() } +it('le launcher est portalé dans body sans déplacer le lecteur de synthèse', async () => { + const result = render() + expect(screen.getByRole('button', { name: launcher }).parentElement?.parentElement).toBe(document.body) + expect(within(result.container).getByText('Contenu')).toBeInTheDocument() + expect(within(result.container).queryByRole('button', { name: launcher })).not.toBeInTheDocument() + await open() }) it('valide question vide/plus de 4000 caractères et accepte une question d’un caractère sans passage', async () => {