fix(ui): keep synthesis chat launcher above mobile navigation (#65)
This commit is contained in:
60
frontend/tests/chat-launcher-ticket65.test.tsx
Normal file
60
frontend/tests/chat-launcher-ticket65.test.tsx
Normal file
@ -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(<main style={{ overflowY: 'auto', height: 400 }}><SummaryQA summaryId="s" content="Synthèse" /></main>)
|
||||
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(<MemoryRouter><MobileNav /></MemoryRouter>)
|
||||
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('')
|
||||
})
|
||||
@ -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) => {
|
||||
|
||||
@ -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(<SummaryQA summaryId="s" content="Un passage de synthèse." />)
|
||||
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'))
|
||||
|
||||
@ -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(<SummaryQA summaryId="s" content="Contenu" launcherHost={host} />)
|
||||
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(<SummaryQA summaryId="s" content="Contenu" />)
|
||||
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 () => {
|
||||
|
||||
Reference in New Issue
Block a user