diff --git a/apps/app/e2e/shell/editor-shell-layout.spec.ts b/apps/app/e2e/shell/editor-shell-layout.spec.ts index 7713514e..d2b24613 100644 --- a/apps/app/e2e/shell/editor-shell-layout.spec.ts +++ b/apps/app/e2e/shell/editor-shell-layout.spec.ts @@ -459,6 +459,130 @@ test.describe('citations panel at 375 px, read-only (O4-2)', () => { expect(await drawingBox()).toEqual(drawing) }) + test('667 x 375 by touch: the trigger scrolls into reach, the panel heading and close stay in view @phone', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await page.setViewportSize({ width: 667, height: 375 }) + await openTab(page, dict, 'findings') + const item = page.getByRole('treeitem', { name: 'Constat A' }) + for (let depth = 0; depth < 4 && (await item.count()) === 0; depth++) { + const closed = page.getByRole('treeitem', { expanded: false }).first() + await closed.locator('span').first().tap() // the caret opens the branch + } + await item.tap() + const trigger = page.locator('[data-citations-trigger]:visible') + await expect(trigger).toBeVisible() + await page.evaluate(() => window.scrollTo(0, 0)) + await settle(page) + // The worst distance: the trigger's bottom lands on the viewport's bottom. + const before = await trigger.evaluate((el) => ({ + bottom: el.getBoundingClientRect().bottom, + top: el.getBoundingClientRect().top, + height: window.innerHeight, + })) + const distance = Math.max(0, Math.ceil(before.bottom - before.height)) + const cdp = await page.context().newCDPSession(page) + // A real finger swipe (CDP touch events; `synthesizeScrollGesture` with touch scrolls + // nothing in this Chromium): up to 200 px at a time, a pause before the lift so no + // fling carries on, repeated until the trigger's bottom is on screen. + const swipe = async (step: number) => { + const from = 340 + await cdp.send('Input.dispatchTouchEvent', { + type: 'touchStart', + touchPoints: [{ x: 200, y: from }], + }) + for (let i = 1; i <= 10; i++) { + await cdp.send('Input.dispatchTouchEvent', { + type: 'touchMove', + touchPoints: [{ x: 200, y: from - (step * i) / 10 }], + }) + } + await page.waitForTimeout(150) + await cdp.send('Input.dispatchTouchEvent', { + type: 'touchEnd', + touchPoints: [], + }) + await settle(page) + } + const gap = async () => + Math.ceil( + (await trigger.evaluate((el) => el.getBoundingClientRect().bottom)) - + before.height, + ) + let swipes = 0 + for (let left = distance; left > 0 && swipes < 12; swipes++) { + await swipe(Math.min(Math.max(left, 60), 200)) // under ~60 px a swipe is below the touch slop + left = await gap() + } + await settle(page) + const reached = await page.evaluate(() => window.scrollY) + const hit = await trigger.evaluate((el) => { + const box = el.getBoundingClientRect() + const at = document.elementFromPoint( + box.x + box.width / 2, + box.y + box.height / 2, + ) + return { + covered: !at || !el.contains(at), + bottom: box.bottom, + top: box.top, + scrollMax: document.documentElement.scrollHeight - window.innerHeight, + at: at ? `${at.tagName}.${String(at.className).slice(0, 60)}` : null, + } + }) + test.info().annotations.push({ + type: 'c4-measure', + description: `trigger top=${before.top} bottom=${before.bottom} at scroll 0, distance=${distance}, swipes=${swipes}, scrollY=${reached}, bottom after=${hit.bottom}`, + }) + expect(hit.bottom, 'trigger bottom on screen').toBeLessThanOrEqual(before.height) + expect(hit.covered, 'trigger hit-testable after the touch scroll').toBe(false) + await trigger.tap() + await expect(page.locator('#editor-citations-title')).toBeFocused() + await settle(page) + const inView = await page.evaluate((label) => { + const probe = (selector: string) => { + const el = document.querySelector(selector)! + const box = el.getBoundingClientRect() + const at = document.elementFromPoint( + box.x + box.width / 2, + box.y + box.height / 2, + ) + return { + inside: + box.top >= 0 && + box.bottom <= window.innerHeight && + box.left >= 0 && + box.right <= window.innerWidth, + hit: !!at && el.contains(at), + } + } + const panel = document.querySelector('#editor-citations-panel')! + const rect = panel.getBoundingClientRect() + const visible = + Math.min(rect.bottom, window.innerHeight) - Math.max(rect.top, 0) + return { + heading: probe('#editor-citations-title'), + close: probe(`#editor-citations-panel button[aria-label="${label}"]`), + visible, + scrollY: window.scrollY, + } + }, dict['editor.references.close']) + test.info().annotations.push({ + type: 'c4-measure', + description: `panel visible height=${inView.visible}, scrollY after open=${inView.scrollY}`, + }) + expect(inView.heading, 'heading in view and hit-testable').toEqual({ + inside: true, + hit: true, + }) + expect(inView.close, 'close button in view and hit-testable').toEqual({ + inside: true, + hit: true, + }) + }) + test('the document size does not change while the panel opens and closes @phone', async ({ page, }) => {