test(editor): e2e on the references dialog instead of the sheet

Helpers citationsDialog, closeCitations by the dialog's ✕. Owner journey
with tap at 375, keyboard and axe; geometry checks now dialog in viewport
with focus inside; refused « Tout afficher » over a dirty form.
This commit is contained in:
bchanot committed 2026-11-15 16:15:43 +01:00
1 parent abc781df52
commit 2c4c771269
10 files changed
+260 -323

No files matched your search

+40 -36
View File
@@ -84,30 +84,33 @@ async function watchDocumentSize(page: Page) {
})
}
const REM = 16
/**
* The sheet is a modal at the right edge: at most 34 rem and no wider than the viewport,
* as tall as the window whatever the page's scroll (it is in the top layer).
* The references dialog lies inside the viewport whatever the page's scroll (it is in
* the top layer), and the focus is inside it.
*/
async function expectSheetWithin(page: Page, viewportWidth: number) {
const layer = page.locator('[data-place="citations"]')
const box = await layer.boundingBox()
expect(box!.width).toBeLessThanOrEqual(34 * REM + 0.5)
// Sub-pixel layout rounding (375.00001…): the same tolerance as the line above.
expect(box!.width).toBeLessThanOrEqual(viewportWidth + 0.5)
const edges = await page.evaluate(() => {
const sheet = document.querySelector('[data-place="citations"]')!
const rect = sheet.getBoundingClientRect()
return { top: rect.top, bottom: rect.bottom, right: rect.right }
async function expectCitationsWithin(page: Page) {
const box = await page.evaluate(() => {
const panel = document.querySelector('[data-place="citations"]')!
const rect = panel
.closest('dialog > div:last-child')!
.getBoundingClientRect()
const focused = document.activeElement?.closest('dialog')
return {
left: rect.left,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
width: window.innerWidth,
height: window.innerHeight,
focusInside: !!focused?.contains(panel),
}
})
expect(edges.top, 'sheet top').toBeLessThanOrEqual(1)
expect(
Math.abs(edges.right - viewportWidth),
'sheet right edge',
).toBeLessThan(1)
const height = await page.evaluate(() => window.innerHeight)
expect(Math.abs(edges.bottom - height), 'sheet bottom').toBeLessThanOrEqual(1)
// Sub-pixel layout rounding (375.00001…): the tolerance of 3a7ffa2.
expect(box.left, 'dialog left edge').toBeGreaterThanOrEqual(0)
expect(box.top, 'dialog top edge').toBeGreaterThanOrEqual(0)
expect(box.right, 'dialog right edge').toBeLessThanOrEqual(box.width + 0.5)
expect(box.bottom, 'dialog bottom edge').toBeLessThanOrEqual(box.height + 0.5)
expect(box.focusInside, 'focus inside the references dialog').toBe(true)
}
async function settle(page: Page) {
@@ -129,7 +132,7 @@ test.describe('editor shell layout (H)', () => {
await dropLateReplays(context)
})
test('no horizontal scroll from 1 024 to 1 280 px on the five tabs, the three sections and the open citations sheet', async ({
test('no horizontal scroll from 1 024 to 1 280 px on the five tabs, the three sections and the open references dialog', async ({
page,
}) => {
test.setTimeout(150_000)
@@ -145,7 +148,7 @@ test.describe('editor shell layout (H)', () => {
await expectNoHorizontalOverflow(page, `${section} at ${width} px`)
}
await openCitations(page, dict, 'Constat A')
await expectNoHorizontalOverflow(page, `the sheet at ${width} px`)
await expectNoHorizontalOverflow(page, `the references at ${width} px`)
await closeCitations(page, dict)
await closeFinding(page, dict)
// The walk is a script: about 20 history entries per width would pass the adapter's
@@ -154,7 +157,7 @@ test.describe('editor shell layout (H)', () => {
}
})
test('the open sheet is at most 34 rem and the viewport wide, and the document never changes size, before, during and after', async ({
test('the open references dialog lies inside the viewport, focus inside, and the document never changes size', async ({
page,
}) => {
test.setTimeout(150_000)
@@ -164,8 +167,8 @@ test.describe('editor shell layout (H)', () => {
await openFinding(page, dict, 'Constat A')
const stop = await watchDocumentSize(page)
await showCitations(page)
await expectSheetWithin(page, width)
await expectNoHorizontalOverflow(page, `the open sheet at ${width} px`)
await expectCitationsWithin(page)
await expectNoHorizontalOverflow(page, `the references at ${width} px`)
await closeCitations(page, dict)
await closeFinding(page, dict)
const sizes = await stop()
@@ -210,7 +213,7 @@ test.describe('editor shell layout (H)', () => {
}
})
test('the canvas width is the same before the citations sheet opens and after both layers close', async ({
test('the canvas width is the same before the references dialog opens and after both layers close', async ({
page,
}) => {
test.setTimeout(150_000)
@@ -239,7 +242,7 @@ test.describe('editor shell layout (H)', () => {
}
})
test('axe from the top on the five tabs, each section and the open dialog and sheet', async ({
test('axe from the top on the five tabs, each section and the two open dialogs', async ({
page,
}) => {
test.setTimeout(150_000)
@@ -265,7 +268,7 @@ test.describe('editor shell layout (H)', () => {
await expectAccessible(page, `the finding dialog at ${width} px`)
await showCitations(page)
await settle(page)
await expectAccessible(page, `the open sheet at ${width} px`)
await expectAccessible(page, `the references dialog at ${width} px`)
await closeCitations(page, dict)
await closeFinding(page, dict)
}
@@ -313,7 +316,8 @@ function focusKind(page: Page): Promise<Kind> {
return page.evaluate((undoName) => {
const el = document.activeElement
if (!el) return 'other'
if (el.closest('[data-place="citations"]')) return 'panel'
const dialog = el.closest('dialog')
if (dialog?.querySelector('[data-place="citations"]')) return 'panel'
if (el.getAttribute('role') === 'tab') return 'tab'
if (el.closest('[data-testid="history-buttons"]')) {
return el.getAttribute('aria-label') === undoName ? 'undo' : 'redo'
@@ -366,7 +370,7 @@ test.describe('editor shell keyboard order (H)', () => {
expect(order).toEqual(['tab', 'undo', 'redo', 'tools', 'canvas', 'side'])
})
test('with the sheet open: Tab stays in the sheet; closed, the order is the page again', async ({
test('with the references dialog open: Tab stays in it; closed, the order is the page again', async ({
page,
}) => {
await open(page)
@@ -401,7 +405,7 @@ test.describe('editor shell keyboard order (H)', () => {
})
})
test.describe('citations sheet at 375 px, read-only (O4-2)', () => {
test.describe('references dialog at 375 px, read-only (O4-2)', () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
test.beforeEach(async ({ context }, info) => {
test.skip(!isPhone(info), 'the phone sizes are set by the test itself')
@@ -411,7 +415,7 @@ test.describe('citations sheet at 375 px, read-only (O4-2)', () => {
await dropLateReplays(context)
})
test('the whole screen, never wider than it, as tall as the window through a height change and a rotation, the drawing box unchanged @phone', async ({
test('inside the screen through a height change and a rotation, focus inside, the drawing box unchanged @phone', async ({
page,
}) => {
test.setTimeout(150_000)
@@ -430,10 +434,10 @@ test.describe('citations sheet at 375 px, read-only (O4-2)', () => {
await page.evaluate(
() => new Promise((done) => requestAnimationFrame(() => done(null))),
)
await expectSheetWithin(page, size.width)
await expectCitationsWithin(page)
await expectNoHorizontalOverflow(
page,
`the sheet at ${size.width} x ${size.height}`,
`the references at ${size.width} x ${size.height}`,
)
}
await page.setViewportSize({ width: 375, height: 667 })
@@ -444,7 +448,7 @@ test.describe('citations sheet at 375 px, read-only (O4-2)', () => {
expect(await drawingBox()).toEqual(drawing)
})
test('the document size does not change while the dialog and the sheet open and close @phone', async ({
test('the document size does not change while the two dialogs open and close @phone', async ({
page,
}) => {
test.setTimeout(150_000)