feat(editor): one tab order, vertical Plus list with the error count

This commit is contained in:
bchanot committed 2026-11-15 15:52:28 +01:00
1 parent b41c24b29d
commit ff21b0315e
11 files changed
+155 -75

No files matched your search

+37 -2
View File
@@ -12,6 +12,7 @@ import {
draftPath,
draftTitle,
editorActor,
morePlus,
pointOf,
seedDraft,
shapeWith,
@@ -40,8 +41,7 @@ async function openAt(page: Page, width: number, height = 800) {
).toBeVisible()
}
const more = (page: Page) =>
page.getByRole('button', { name: dict['editor.tab.more'], exact: true })
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. */
@@ -90,6 +90,41 @@ test.describe('« Plus » dropdown', () => {
})
}
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()),
)
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`)
})
}
test('closes on a selection, outside tap and Escape, focus kept sane', async ({
page,
}) => {
+28 -29
View File
@@ -345,13 +345,34 @@ export const TABS = [
/** The Annotations sections and the panel, in the order the overview offers them. */
export const SECTIONS = ['views', 'categories', 'regions'] as const
/** Below this width only the tabs of SHOWN_SMALL stay in the row, the others sit under « Plus ». */
const SMALL_TIER_WIDTH = 640
const SHOWN_SMALL = ['general', 'annotations']
/**
* Clicks a tab by role. The name is a pattern: the Vérification tab adds « n erreur(s) »
* to its name while the in-page check has errors.
* Clicks a tab by role, whatever the width: from 640 px the tab button, below it « Plus »
* opened and the tab picked in its list. The name is a pattern: the Vérification tab adds
* « n erreur(s) » to its name while the in-page check has errors.
*/
export async function selectTab(page: Page, dict: Dict, tab: string) {
const name = dict[`editor.tab.${tab}`]
await page.getByRole('tab', { name: new RegExp(`^${name}( |$)`) }).click()
const width = page.viewportSize()?.width ?? SMALL_TIER_WIDTH
const name = new RegExp(`^${dict[`editor.tab.${tab}`]}( |$)`)
if (width >= SMALL_TIER_WIDTH || SHOWN_SMALL.includes(tab)) {
await page.getByRole('tab', { name }).click()
return
}
const more = morePlus(page, dict)
if ((await more.getAttribute('aria-expanded')) !== 'true') await more.click()
await page.locator('#editor-tabs-more').getByRole('button', { name }).click()
// The dropdown fades out: wait for it to be gone before the next move.
await expect(page.locator('#editor-tabs-more')).toHaveCount(0)
}
/** « Plus », located without an exact name: it carries the Vérification error count. */
export function morePlus(page: Page, dict: Dict): Locator {
return page.getByRole('button', {
name: new RegExp(`^${dict['editor.tab.more']}( |$)`),
})
}
/** The visible place with this `data-place` name; a hidden copy never answers. */
@@ -395,34 +416,12 @@ export function libraryRoot(page: Page): Locator {
return place(page, 'references')
}
/** Below this width the tabs other than Annotations and Vérification sit under « Plus ». */
const SMALL_TIER_WIDTH = 640
/**
* Shows a tab whatever the width: the tab button from 640 px, below it « Plus » opened and
* the tab picked in its list. Waits for the tab's place to be visible (Annotations names
* its sections, so any of them).
* Shows a tab whatever the width (selectTab). Waits for the tab's place to be visible
* (Annotations names its sections, so any of them).
*/
export async function openTab(page: Page, dict: Dict, tab: string) {
const width = page.viewportSize()?.width ?? SMALL_TIER_WIDTH
const name = new RegExp(`^${dict[`editor.tab.${tab}`]}( |$)`)
const listed = ['annotations', 'verification'].includes(tab)
if (width < SMALL_TIER_WIDTH && !listed) {
const more = page.getByRole('button', {
name: dict['editor.tab.more'],
exact: true,
})
if ((await more.getAttribute('aria-expanded')) !== 'true')
await more.click()
await page
.locator('#editor-tabs-more')
.getByRole('button', { name })
.click()
// The dropdown fades out: wait for it to be gone before the next move.
await expect(page.locator('#editor-tabs-more')).toHaveCount(0)
} else {
await page.getByRole('tab', { name }).click()
}
await selectTab(page, dict, tab)
await expect(
tab === 'annotations'
? page.locator('[data-place^=annotations]:visible').first()