import { fr } from '@/i18n/fr' import type { Page, TestInfo } from '@playwright/test' import { stepUpAdmin } from '../support/admin' import { expect, expectAccessible, expectNoHorizontalOverflow, test, } from '../support/browser' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { draftPath, draftTitle, editorActor, pointOf, seedDraft, shapeWith, } from '../support/editor' import { signIn } from '../support/shell' // V1-2.6 R2F-7 (items 6, 7): « Plus » is an overlay that moves nothing, and the left // sidebar stays in view while the content scrolls. const dict = fr const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' const seedShape = shapeWith( pointOf('p1', 'main', { cx: 500, cy: 400, r: 40 }, 'Point un'), ) async function openAt(page: Page, width: number, height = 800) { const actor = await editorActor('fr') const seed = await seedDraft(actor, { shape: seedShape }) await signIn(page, actor.account, dict) await page.goto('/app/admin') await stepUpAdmin(page, dict, actor.secret) await page.setViewportSize({ width, height }) await page.goto(draftPath(seed.sheetId)) await expect( page.getByRole('heading', { level: 1, name: draftTitle(dict) }), ).toBeVisible() } const more = (page: Page) => page.getByRole('button', { name: dict['editor.tab.more'], exact: true }) const list = (page: Page) => page.locator('#editor-tabs-more') /** The boxes that must not move when « Plus » opens: the row, the page below it, the document. */ async function layout(page: Page) { return page.evaluate(() => { const row = document.querySelector('[data-editor-tabs]')! const below = row.nextElementSibling const box = (el: Element | null) => { const r = el?.getBoundingClientRect() return r && [r.x, r.y, r.width, r.height].map(Math.round) } const root = document.documentElement return { row: box(row), below: box(below), doc: [root.scrollWidth, root.scrollHeight], } }) } test.describe('« Plus » dropdown', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 phone width read-only, set by the tests await routeToSandbox(context) }) test.afterEach(async ({ context }) => { await dropLateReplays(context) }) for (const width of [375, 320]) { test(`at ${width} px it overlays without moving anything, axe open`, async ({ page, }) => { await openAt(page, width) await expect(more(page)).toBeVisible() const closed = await layout(page) await more(page).click() await expect(list(page)).toBeVisible() expect(await layout(page), 'boxes open vs closed').toEqual(closed) const menu = await list(page).boundingBox() expect(menu!.x).toBeGreaterThanOrEqual(0) expect(menu!.x + menu!.width).toBeLessThanOrEqual(width) await expectNoHorizontalOverflow(page, `« Plus » open at ${width} px`) await expectAccessible(page, `« Plus » open at ${width} px`) }) } test('closes on a selection, outside tap and Escape, focus kept sane', async ({ page, }) => { await openAt(page, 375) await more(page).click() await page.keyboard.press('Escape') await expect(list(page)).toHaveCount(0) await expect(more(page)).toBeFocused() await more(page).click() await page .getByRole('heading', { level: 1, name: draftTitle(dict) }) .click() await expect(list(page)).toHaveCount(0) await more(page).click() await list(page) .getByRole('button', { name: dict['editor.tab.findings'] }) .click() await expect(list(page)).toHaveCount(0) await expect(more(page)).toHaveAttribute('aria-expanded', 'false') }) test('Enter on an entry focuses the panel of that tab', async ({ page }) => { await openAt(page, 375) await more(page).click() await list(page) .getByRole('button', { name: dict['editor.tab.findings'] }) .focus() await page.keyboard.press('Enter') await expect(list(page)).toHaveCount(0) const panel = page.getByRole('tabpanel', { name: dict['editor.tab.findings'], }) await expect(panel).toBeFocused() }) }) test.describe('the sidebar stays fixed', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 sidebar needs a desktop width await routeToSandbox(context) }) test.afterEach(async ({ context }) => { await dropLateReplays(context) }) const firstLink = (page: Page) => page .getByRole('navigation', { name: dict['shell.nav_label'] }) .getByRole('link') .first() async function expectInView(page: Page, state: string) { const box = await firstLink(page).boundingBox() const height = await page.evaluate(() => window.innerHeight) expect(box!.y, `${state}: top`).toBeGreaterThanOrEqual(0) expect(box!.y + box!.height, `${state}: bottom`).toBeLessThanOrEqual(height) } test('at 1280 px the editor sidebar stays while the page scrolls, no sideways scroll', async ({ page, }) => { await openAt(page, 1280) await expectAccessible(page, 'the editor at 1280 px, top') await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)) expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) await expectInView(page, 'scrolled editor') await expectNoHorizontalOverflow(page, 'the editor at 1280 px') }) test('at 1280 x 500 the sidebar scrolls on its own', async ({ page }) => { await openAt(page, 1280, 500) const own = await page.evaluate(() => { const aside = document.querySelector('aside') as HTMLElement aside.scrollTop = aside.scrollHeight return { scrolls: aside.scrollHeight > aside.clientHeight, top: aside.scrollTop, page: window.scrollY, } }) expect(own.scrolls).toBe(true) expect(own.top).toBeGreaterThan(0) expect(own.page).toBe(0) }) test('at 1024 px the default shell sidebar stays while the page scrolls', async ({ page, }) => { await openAt(page, 1024) await page.goto('/app') await expect(firstLink(page)).toBeVisible() await expectAccessible(page, 'the dashboard at 1024 px, top') await page.evaluate(() => { document.querySelector('main')!.style.minHeight = '3000px' window.scrollTo(0, 1000) }) expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0) await expectInView(page, 'scrolled dashboard') await expectNoHorizontalOverflow(page, 'the dashboard at 1024 px') }) })