Files
faunosteo/apps/app/e2e/shell/editor-more-menu.spec.ts
T

242 lines
8.5 KiB
TypeScript

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,
morePlus,
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) => morePlus(page, dict)
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`)
})
}
for (const width of [375, 320]) {
test(`at ${width} px the entries stack in tab order inside the viewport`, async ({
page,
}) => {
await openAt(page, width)
await expect(page.getByRole('tablist').getByRole('tab')).toHaveText([
dict['editor.tab.general'],
dict['editor.tab.annotations'],
])
await more(page).click()
const rows = list(page).getByRole('button')
await expect(rows).toHaveCount(3)
// Vérification may carry its error count.
await expect(rows).toHaveText([
dict['editor.tab.findings'],
dict['editor.tab.references'],
new RegExp(`^${dict['editor.tab.verification']}`),
])
const boxes = await rows.evaluateAll((els) =>
els.map((el) => el.getBoundingClientRect().toJSON()),
)
expect(new Set(boxes.map((b) => Math.round(b.x))).size, 'same x').toBe(1)
expect(
new Set(boxes.map((b) => Math.round(b.width))).size,
'same width',
).toBe(1)
boxes.forEach((box, at) => {
expect(box.height, `row ${at} height`).toBeGreaterThanOrEqual(44)
expect(box.x, `row ${at} left`).toBeGreaterThanOrEqual(0)
expect(box.right, `row ${at} right`).toBeLessThanOrEqual(width)
if (at > 0) {
expect(box.y, `row ${at} below`).toBeGreaterThanOrEqual(
boxes[at - 1].bottom,
)
}
})
await expectAccessible(page, `« Plus » list at ${width} px`)
// An active row: pick Constats, reopen, axe with the tint and the check.
await rows.first().click()
await more(page).click()
await expect(list(page).locator('[aria-current="true"]')).toHaveCount(1)
// Axe reads the colours: wait until the fade-in has ended.
await expect(list(page)).toHaveCSS('opacity', '1')
await expectAccessible(page, `« Plus » list, active row, 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')
})
})