diff --git a/apps/app/e2e/shell/editor-equine.spec.ts b/apps/app/e2e/shell/editor-equine.spec.ts index 3f70ea86..be93803e 100644 --- a/apps/app/e2e/shell/editor-equine.spec.ts +++ b/apps/app/e2e/shell/editor-equine.spec.ts @@ -344,6 +344,32 @@ test.describe('equine working copy and commit latency', () => { expect(line.handler.max, line.handler.max + ' ms').toBeLessThan(BUDGET_MS) }) + test('commit-to-paint on the equine copy with every place visited (U1 shell)', async ({ + page, + requests, + }) => { + test.setTimeout(180_000) + expect(copyId).not.toBe('') + requests.forbid(actor.account.email, actor.account.password) + await signIn(page, actor.account, dict) + await page.goto('/app/admin') + await stepUpAdmin(page, dict, actor.secret) + await page.goto(`/app/admin/sheets/${copyId}/draft`) + await expect(toolButton(page, dict, 'point')).toBeEnabled() + // Every tab, section and the panel mounted once: all of them stay mounted (B2a). + for (const tab of ['general', 'findings', 'verification']) + await selectTab(page, dict, tab) + for (const section of SECTIONS) await openSection(page, dict, section) + await openReferences(page, dict) + await closeReferences(page, dict) + const renames = await measureRenames(page, 'equine, all places: rename') + const additions = await measureAdditions(page, 'equine, all places: add') + for (const line of [renames, additions]) + expect(line.paint.max, `${line.paint.max} ms to paint`).toBeLessThan( + BUDGET_MS, + ) + }) + test('commit latency on a synthetic document near 2 MiB', async ({ page, requests, diff --git a/apps/app/e2e/shell/editor-shell-crossing.spec.ts b/apps/app/e2e/shell/editor-shell-crossing.spec.ts new file mode 100644 index 00000000..9964bafa --- /dev/null +++ b/apps/app/e2e/shell/editor-shell-crossing.spec.ts @@ -0,0 +1,382 @@ +import { fr } from '@/i18n/fr' +import type { Locator, Page, TestInfo } from '@playwright/test' +import { expect, test } from '../support/browser' +import { dropLateReplays, routeToSandbox } from '../support/sandbox' +import { + INKSCAPE_EXPORT, + clientOf, + closeReferences, + copyKeyOf, + editorActor, + geometryField, + historyButton, + openEditor, + openReferences, + openSection, + pickAnnotation, + place, + pointOf, + saveLine, + seedDraft, + selectTab, + shapeWith, + standardShape, + storedCopy, + UNSAVED_LINE, +} from '../support/editor' + +// V1-2.6 U1 H (AC11, AC21): a width change across 1 024 px in a real browser. Every +// edit-only part keeps what was typed, nothing is editable or focused below the threshold, +// the unsaved work stays, dialogs that confirm an edit close, a drag in flight commits +// nothing. Queries go to the visible place or by role; hidden parts stay in the DOM. + +const dict = fr + +const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' +const active = (page: Page) => page.locator(':focus') +const dialogs = (page: Page) => page.locator('dialog[open]') +const NARROW = { width: 800, height: 900 } +const WIDE = { width: 1280, height: 900 } + +const spareCategory = (document: Record) => { + standardShape(document) + ;(document.categories as unknown[]).push({ + id: 'cat-spare', + name: { fr: 'Libre', en: 'Free' }, + color: null, + }) +} + +async function open(page: Page, shape = shapeWith()) { + const actor = await editorActor('fr') + const seed = await seedDraft(actor, { shape }) + await openEditor(page, dict, actor, seed.sheetId) + return { ...seed, actor } +} + +async function commitName(page: Page, value: string) { + await selectTab(page, dict, 'general') + await page.locator('#general-name-fr').fill(value) + await page.locator('#general-name-fr').press('Enter') +} + +/** The editor is read-only in this page: no save, no text field, no edit toolbar. */ +async function expectReadOnly(page: Page) { + await expect( + page.getByRole('button', { name: dict['common.save'], exact: true }), + ).toHaveCount(0) + await expect(page.getByRole('textbox')).toHaveCount(0) + await expect( + page.getByRole('toolbar', { name: dict['editor.annotations.tools'] }), + ).toHaveCount(0) + for (const kind of ['undo', 'redo'] as const) { + await expect(historyButton(page, dict, kind)).toHaveAttribute( + 'aria-disabled', + 'true', + ) + } +} + +/** A real crossing: the dialogs are gone and nothing is left to animate before the checks. */ +async function cross(page: Page, size: { width: number; height: number }) { + await page.setViewportSize(size) + await expect(dialogs(page)).toHaveCount(0) +} + +/** + * Types in `field` with no blur, crosses below 1 024 px, checks the part left the page and + * the focus sits on a named tab, widens, and checks the typed value is back untouched. + */ +async function keepsTypedValue( + page: Page, + field: Locator, + addButton: string, + tab: string, +) { + await field.fill('Saisie') + await cross(page, NARROW) + await expect(field).toBeHidden() + await expect( + page.getByRole('button', { name: addButton, exact: true }), + ).toHaveCount(0) + await expectReadOnly(page) + await expect(active(page)).toHaveAttribute('id', `editor-tab-${tab}`) + await cross(page, WIDE) + await expect(field).toBeVisible() + await expect(field).toHaveValue('Saisie') + await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) +} + +test.describe('editor shell, width crossing (H)', () => { + 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 editing needs >= 1024 px; phone read-only covered in editor-access + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('the category, region and detail view forms keep their typed text', async ({ + page, + }) => { + await open(page) + await openSection(page, dict, 'categories') + await keepsTypedValue( + page, + page.locator('#category-new-fr'), + dict['editor.general.category_add'], + 'annotations', + ) + await openSection(page, dict, 'regions') + await keepsTypedValue( + page, + page.locator('#region-new-code'), + dict['editor.vertebra.add'], + 'annotations', + ) + await openSection(page, dict, 'views') + await keepsTypedValue( + page, + page.locator('#view-new-fr'), + dict['editor.views.add'], + 'annotations', + ) + }) + + test('the crop group editor keeps its typed numbers, its read-only twin has its own ids', async ({ + page, + }) => { + await open(page) + await openSection(page, dict, 'views') + await place(page, 'annotations.views') + .getByRole('button', { name: dict['editor.views.crop.toggle'] }) + .first() + .click() + const field = page.locator('#view-detail-a-crop-min_x') + await field.fill('7x') + await cross(page, NARROW) + await expect(field).toBeHidden() + await expect(page.locator('#ro-view-detail-a-crop-min_x')).toBeVisible() + await cross(page, WIDE) + await expect(field).toHaveValue('7x') + const ids = await page.evaluate(() => { + const all = [...document.querySelectorAll('[id]')].map((e) => e.id) + return all.filter((id, i) => all.indexOf(id) !== i) + }) + expect(ids).toEqual([]) + }) + + test('the findings creation form and the submission note keep their typed text', async ({ + page, + }) => { + await open(page) + await selectTab(page, dict, 'findings') + await page + .getByRole('button', { name: dict['editor.findings.add_zone'] }) + .click() + await keepsTypedValue( + page, + page.locator('#finding-new-name-fr'), + dict['editor.findings.add_zone'], + 'findings', + ) + await selectTab(page, dict, 'verification') + await keepsTypedValue( + page, + page.locator('#verification-note'), + dict['editor.verification.submit'], + 'verification', + ) + }) + + test('the references form keeps its typed text with the panel open', async ({ + page, + }) => { + await open(page) + await openReferences(page, dict) + await keepsTypedValue( + page, + page.locator('#reference-new-citation'), + dict['editor.reference.add'], + 'annotations', + ) + await expect(place(page, 'references')).toBeVisible() + await expect(place(page, 'references').getByRole('searchbox')).toBeVisible() + }) + + test('the annotation edit body keeps its tool and its pending creation', async ({ + page, + }) => { + await open(page) + await selectTab(page, dict, 'annotations') + const zone = page.getByRole('button', { + name: dict['editor.annotations.tool.zone'], + exact: true, + }) + await expect(zone).toBeEnabled() + await zone.click() + await page + .getByRole('button', { name: dict['editor.annotations.add.point'] }) + .click() + const name = page.getByLabel(dict['editor.annotations.name_fr']) + await name.fill('Futur point') + await cross(page, NARROW) + await expect(name).toBeHidden() + await expect(zone).toHaveCount(0) + await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations') + await cross(page, WIDE) + await expect(name).toHaveValue('Futur point') + await expect(zone).toHaveAttribute('aria-pressed', 'true') + await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) + }) + + test('a section open: read-only below the threshold, unsaved work kept, edit back on widening', async ({ + page, + }) => { + const { actor, draftId } = await open(page) + await commitName(page, 'Nom conservé') + await openSection(page, dict, 'categories') + await page.locator('#category-new-fr').fill('Brouillon') + await cross(page, NARROW) + await expectReadOnly(page) + await expect(place(page, 'annotations.categories')).toBeVisible() + await expect(saveLine(page)).toHaveText( + dict['editor.draft.status.unsaved_count_one'].replace('{count}', '1'), + ) + expect( + await storedCopy(page, copyKeyOf(actor.account.id, draftId)), + ).not.toBeNull() + await cross(page, WIDE) + await expect( + page.getByRole('button', { name: dict['common.save'], exact: true }), + ).toBeEnabled() + await expect(historyButton(page, dict, 'undo')).toHaveAttribute( + 'aria-disabled', + 'false', + ) + await expect(page.locator('#category-new-fr')).toHaveValue('Brouillon') + await expect(saveLine(page)).toHaveText(UNSAVED_LINE) + }) + + test('the panel open: read-only below the threshold, unsaved work kept, edit back on widening', async ({ + page, + }) => { + await open(page) + await commitName(page, 'Nom conservé') + await openReferences(page, dict) + await page.locator('#reference-new-citation').fill('Smith 1999') + await cross(page, NARROW) + await expectReadOnly(page) + await expect(place(page, 'references')).toBeVisible() + await expect(saveLine(page)).toHaveText(UNSAVED_LINE) + await cross(page, WIDE) + await expect(page.locator('#reference-new-citation')).toHaveValue( + 'Smith 1999', + ) + await expect( + page.getByRole('button', { name: dict['common.save'], exact: true }), + ).toBeEnabled() + await closeReferences(page, dict) + }) + + test('text typed without a blur is unsaved after the crossing and the copy is written', async ({ + page, + }) => { + const { actor, draftId } = await open(page) + await selectTab(page, dict, 'general') + await page.locator('#general-name-fr').fill('Sans quitter le champ') + await cross(page, NARROW) + await expect(saveLine(page)).toHaveText( + dict['editor.draft.status.unsaved_count_one'].replace('{count}', '1'), + ) + await expect + .poll(() => storedCopy(page, copyKeyOf(actor.account.id, draftId))) + .not.toBeNull() + }) + + test('a drag across the crossing commits nothing', async ({ page }) => { + await open( + page, + shapeWith( + pointOf('anno-free', 'main', { cx: 120, cy: 120, r: 6 }, 'Point libre'), + ), + ) + await selectTab(page, dict, 'annotations') + await pickAnnotation(page, dict, 'Point libre') + const cx = geometryField(page, dict, 'cx') + const before = await cx.inputValue() + const from = await clientOf(page, 120, 120) + const to = await clientOf(page, 200, 160) + await page.mouse.move(from.x, from.y) + await page.mouse.down() + await page.mouse.move(to.x, to.y, { steps: 6 }) + await cross(page, NARROW) + await page.mouse.up() + await cross(page, WIDE) + await expect(geometryField(page, dict, 'cx')).toHaveValue(before) + await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) + await expect(historyButton(page, dict, 'undo')).toHaveAttribute( + 'aria-disabled', + 'true', + ) + }) + + test('a delete confirmation and the discard confirmation close when the editor turns read-only', async ({ + page, + }) => { + await open(page, spareCategory) + await openSection(page, dict, 'categories') + await page + .getByRole('listitem') + .filter({ has: page.locator('#category-cat-spare-name-fr') }) + .getByRole('button', { name: dict['editor.action.delete'] }) + .click() + await expect(dialogs(page)).toHaveCount(1) + await cross(page, NARROW) + await cross(page, WIDE) + await expect(dialogs(page)).toHaveCount(0) + await expect(page.locator('#category-cat-spare-name-fr')).toHaveCount(1) + await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) + + await commitName(page, 'Nom à abandonner') + await page + .getByRole('button', { name: dict['editor.draft.discard'], exact: true }) + .click() + await expect(dialogs(page)).toHaveCount(1) + await cross(page, NARROW) + await cross(page, WIDE) + await expect(saveLine(page)).toHaveText(UNSAVED_LINE) + }) + + test('a decision withheld while the panel was open waits for « Reprendre »; tabs keep the focus', async ({ + page, + }) => { + const actor = await editorActor('fr') + const seed = await seedDraft(actor, { drawing: null, shape: standardShape }) + await openEditor(page, dict, actor, seed.sheetId) + await openSection(page, dict, 'views') + await openReferences(page, dict) + await page.getByTestId('view-main-file').setInputFiles({ + name: 'inkscape.svg', + mimeType: 'image/svg+xml', + buffer: INKSCAPE_EXPORT, + }) + await expect( + page.getByText(dict['editor.views.pending.cleaning']), + ).toBeVisible() + await closeReferences(page, dict) + await expect(dialogs(page)).toHaveCount(0) + await selectTab(page, dict, 'general') + await page.getByRole('tab', { name: dict['editor.tab.general'] }).focus() + await page.keyboard.press('ArrowRight') + await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations') + await expect(dialogs(page)).toHaveCount(0) + await page + .getByRole('button', { name: dict['editor.views.pending.resume'] }) + .click() + await expect( + page.getByRole('dialog', { name: dict['editor.cleaning.title'] }), + ).toBeVisible() + }) +}) diff --git a/apps/app/e2e/shell/editor-shell-journeys.spec.ts b/apps/app/e2e/shell/editor-shell-journeys.spec.ts new file mode 100644 index 00000000..0cbd1661 --- /dev/null +++ b/apps/app/e2e/shell/editor-shell-journeys.spec.ts @@ -0,0 +1,274 @@ +import { fr } from '@/i18n/fr' +import type { Page, TestInfo } from '@playwright/test' +import { expect, test } from '../support/browser' +import { dropLateReplays, routeToSandbox } from '../support/sandbox' +import { + TABS, + closeReferences, + draftTitle, + editorActor, + historyButton, + openEditor, + place, + pointOf, + pressAtBox, + saveLine, + seedDraft, + selectTab, + shapeWith, + standardShape, + UNSAVED_LINE, +} from '../support/editor' + +// V1-2.6 U1 H (AC1, AC5, AC12, AC13, AC17): the journeys of the four-tab shell in a real +// browser. Every query is scoped to the visible place (`place()`) or goes by role, so a +// hidden, kept-mounted copy never answers. + +const dict = fr + +const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' +const active = (page: Page) => page.locator(':focus') +const nameField = (page: Page) => page.locator('#general-name-fr') +const ghost = 'absent' + +/** A document that carries one issue of each kind « Aller à » can reach. */ +function issueShape(document: Record) { + standardShape(document) + const text = (value: string) => ({ fr: value, en: value }) + const views = document.views as unknown[] + views.push({ + id: 'detail-b', + kind: 'detail', + name: text('Détail B'), + svg_asset_id: null, + view_box: { min_x: 0, min_y: 0, width: 100, height: 80 }, + parent_view_id: ghost, + }) + const categories = document.categories as unknown[] + categories.push({ id: 'cat-a', name: text('Catégorie bis'), color: null }) + document.vertebral_config = { + regions: [ + { + code: 'T', + name: text('Thoracique'), + count: 5, + count_range: { min: 9, max: 3 }, + }, + ], + } + const reference = (citation: string) => ({ + id: 'ref-a', + type: 'book', + citation, + url: null, + doi: null, + }) + document.references = [reference('Barone, Ostéologie'), reference('Bis')] + const point = pointOf( + 'anno-free', + 'main', + { cx: 120, cy: 120, r: 6 }, + 'Point libre', + ) + document.annotations = [ + { ...point, category_id: ghost, finding_zone_id: null }, + ] + const zones = document.finding_zones as { + categories: { children: { reference_ids: string[] }[] }[] + }[] + zones[0].categories[0].children[0].reference_ids = [ghost] +} + +async function open(page: Page, shape = shapeWith()) { + const actor = await editorActor('fr') + const seed = await seedDraft(actor, { shape }) + await openEditor(page, dict, actor, seed.sheetId) + return { ...seed, actor } +} + +async function commitName(page: Page, value: string) { + await selectTab(page, dict, 'general') + await nameField(page).fill(value) + await nameField(page).press('Enter') +} + +const unsaved = (page: Page, count: number) => + expect(saveLine(page)).toHaveText( + dict[ + count === 1 + ? 'editor.draft.status.unsaved_count_one' + : 'editor.draft.status.unsaved_count_other' + ].replace('{count}', String(count)), + ) + +test.describe('editor shell journeys (H)', () => { + test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) + test.beforeEach(async ({ context }, info) => { + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('four tabs and no tab of the old layout', async ({ page }) => { + await open(page) + const tabs = page.getByRole('tablist').getByRole('tab') + await expect(tabs).toHaveCount(4) + for (const [index, tab] of TABS.entries()) { + await expect(tabs.nth(index)).toHaveText( + new RegExp(`^${dict[`editor.tab.${tab}`]}`), + ) + } + for (const old of ['Vues et illustrations', 'Références', 'Vertèbres']) { + await expect(page.getByRole('tab', { name: old })).toHaveCount(0) + } + }) + + test('undo from another tab reverts the change, redo brings it back', async ({ + page, + }) => { + await open(page) + const original = await (async () => { + await selectTab(page, dict, 'general') + return nameField(page).inputValue() + })() + await commitName(page, 'Nom depuis Général') + await unsaved(page, 1) + await selectTab(page, dict, 'findings') + await historyButton(page, dict, 'undo').click() + await selectTab(page, dict, 'general') + await expect(nameField(page)).toHaveValue(original) + await historyButton(page, dict, 'redo').click() + await expect(nameField(page)).toHaveValue('Nom depuis Général') + await unsaved(page, 1) + }) + + test('text typed without a blur is committed by the header undo, which then reverts it', async ({ + page, + }) => { + await open(page) + await selectTab(page, dict, 'general') + const original = await nameField(page).inputValue() + await nameField(page).fill('Saisi, jamais validé') + // « Annuler » is aria-disabled until the typed text is committed: press at its box. + await pressAtBox(page, historyButton(page, dict, 'undo')) + await expect(nameField(page)).toHaveValue(original) + await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) + await historyButton(page, dict, 'redo').click() + await expect(nameField(page)).toHaveValue('Saisi, jamais validé') + }) + + test('a field left empty keeps its error: Tab to « Annuler », Enter, nothing undone, focus back', async ({ + page, + }) => { + await open(page) + await commitName(page, 'Premier nom') + await nameField(page).fill('') + const undo = historyButton(page, dict, 'undo') + for (let step = 0; step < 40; step++) { + await page.keyboard.press('Shift+Tab') + if (await undo.evaluate((button) => button === document.activeElement)) + break + } + await expect(undo).toBeFocused() + await expect(nameField(page)).toHaveAttribute('aria-invalid', 'true') + await page.keyboard.press('Enter') + await expect(nameField(page)).toBeFocused() + await unsaved(page, 1) + await expect(undo).toHaveAttribute('aria-disabled', 'false') + await expect(historyButton(page, dict, 'redo')).toHaveAttribute( + 'aria-disabled', + 'true', + ) + }) + + test('Ctrl+Z outside a field undoes, inside a field it leaves the history alone', async ({ + page, + }) => { + await open(page) + await commitName(page, 'Nom un') + await commitName(page, 'Nom deux') + await unsaved(page, 2) + await page + .getByRole('heading', { level: 1, name: draftTitle(dict) }) + .click() + await page.keyboard.press('Control+z') + await unsaved(page, 1) + await expect(nameField(page)).toHaveValue('Nom un') + + await nameField(page).click() + await nameField(page).pressSequentially(' suite') + await page.keyboard.press('Control+z') + // The field's own undo ran; the document history did not (a second step would show 0). + await unsaved(page, 1) + }) + + test('« Aller à » reaches the place and the element of each issue kind', async ({ + page, + }) => { + await open(page, issueShape) + const goTo = (name: string) => + place(page, 'verification') + .getByRole('button', { name: `Aller à ${name}`, exact: true }) + .first() + .click() + const focusKey = (id: string) => + expect(active(page)).toHaveAttribute('data-focus-key', new RegExp(id)) + + await selectTab(page, dict, 'verification') + await goTo('Détail B') + await expect(place(page, 'annotations.views')).toBeVisible() + await focusKey('detail-b') + + await selectTab(page, dict, 'verification') + await goTo('Catégorie A') + await expect(place(page, 'annotations.categories')).toBeVisible() + await focusKey('cat-a') + + await selectTab(page, dict, 'verification') + await goTo('Thoracique') + await expect(place(page, 'annotations.regions')).toBeVisible() + await focusKey('"T"') + + await selectTab(page, dict, 'verification') + await goTo('Point libre') + await expect(place(page, 'annotations.drawing')).toBeVisible() + await expect(active(page)).toHaveAttribute( + 'data-properties-heading', + 'true', + ) + + await selectTab(page, dict, 'verification') + await goTo('Constat A') + await expect(place(page, 'findings')).toBeVisible() + await expect(place(page, 'findings').locator(':focus')).toHaveCount(1) + + await selectTab(page, dict, 'verification') + await goTo('Barone, Ostéologie') + await expect(place(page, 'references')).toBeVisible() + await focusKey('ref-a') + await closeReferences(page, dict) + }) + + test('the save line goes from the count to « Enregistrement… » to the time and the revision', async ({ + page, + context, + }) => { + const seed = await open(page) + await context.route('**/rest/v1/rpc/save_sheet_draft', async (route) => { + await new Promise((done) => setTimeout(done, 1500)) + await route.fallback() + }) + await commitName(page, 'Nom à enregistrer') + await unsaved(page, 1) + await page + .getByRole('button', { name: dict['common.save'], exact: true }) + .click() + await expect(saveLine(page)).toHaveText(dict['editor.draft.status.saving']) + const timed = dict['editor.draft.status.saved_at'] + .replace('{time}', '\\d\\d:\\d\\d') + .replace('{revision}', String(seed.revision + 1)) + await expect(saveLine(page)).toHaveText(new RegExp(`^${timed}$`)) + }) +}) diff --git a/apps/app/e2e/shell/editor-shell-layout.spec.ts b/apps/app/e2e/shell/editor-shell-layout.spec.ts new file mode 100644 index 00000000..e21f9395 --- /dev/null +++ b/apps/app/e2e/shell/editor-shell-layout.spec.ts @@ -0,0 +1,310 @@ +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 { + SECTIONS, + TABS, + closeReferences, + draftPath, + draftTitle, + editorActor, + historyButton, + openEditor, + openReferences, + openSection, + pickAnnotation, + pointOf, + seedDraft, + selectTab, + shapeWith, + showDrawing, +} from '../support/editor' +import { signIn } from '../support/shell' + +// V1-2.6 U1 H (AC10, AC11, AC17): the layout of the four-tab shell at every width, the +// keyboard order of the editor, and axe on every place, edit and narrow read-only. + +const dict = fr + +const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' +const WIDTHS = [1024, 1180, 1279, 1280] +const NARROW_WIDTHS = [320, 375, 768] +const point = pointOf( + 'anno-free', + 'main', + { cx: 120, cy: 120, r: 6 }, + 'Point libre', +) + +async function open(page: Page) { + const actor = await editorActor('fr') + const seed = await seedDraft(actor, { shape: shapeWith(point) }) + await openEditor(page, dict, actor, seed.sheetId) + return { ...seed, actor } +} + +/** Opens the tab, through « Plus » when the width keeps it out of the row. */ +async function goToTab(page: Page, tab: (typeof TABS)[number]) { + const direct = page.locator(`#editor-tab-${tab}`) + if ((await direct.count()) === 0) { + await page.getByRole('button', { name: dict['editor.tab.more'] }).click() + } + await direct.click() + await expect( + page.locator(`[data-place^="${tab}"]:visible`).first(), + ).toBeVisible() +} + +async function settle(page: Page) { + await page.evaluate( + () => + new Promise((done) => + requestAnimationFrame(() => requestAnimationFrame(done)), + ), + ) +} + +test.describe('editor shell layout (H)', () => { + 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 editing needs >= 1024 px; phone read-only covered in editor-access + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('no horizontal scroll from 1 024 to 1 280 px on the four tabs, the three sections and the open panel', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + for (const width of WIDTHS) { + await page.setViewportSize({ width, height: 800 }) + for (const tab of TABS) { + await selectTab(page, dict, tab) + await expectNoHorizontalOverflow(page, `${tab} at ${width} px`) + } + for (const section of SECTIONS) { + await openSection(page, dict, section) + await expectNoHorizontalOverflow(page, `${section} at ${width} px`) + } + await showDrawing(page, dict) + await openReferences(page, dict) + await expectNoHorizontalOverflow(page, `the panel at ${width} px`) + await closeReferences(page, dict) + } + }) + + test('read-only at 320, 375 and 768 px: the four tabs fit and pass axe', async ({ + page, + requests, + }) => { + test.setTimeout(150_000) + const actor = await editorActor('fr') + requests.forbid(actor.account.email, actor.account.password) + const seed = await seedDraft(actor, { shape: shapeWith(point) }) + await signIn(page, actor.account, dict) + await page.goto('/app/admin') + await stepUpAdmin(page, dict, actor.secret) + for (const width of NARROW_WIDTHS) { + await page.setViewportSize({ width, height: 800 }) + await page.goto(draftPath(seed.sheetId)) + await expect( + page.getByRole('heading', { level: 1, name: draftTitle(dict) }), + ).toBeVisible() + for (const tab of TABS) { + await goToTab(page, tab) + await expectNoHorizontalOverflow(page, `${tab} at ${width} px`) + await expect( + page.getByRole('button', { name: dict['common.save'], exact: true }), + ).toHaveCount(0) + if (width !== 320) await expectAccessible(page, `${tab} at ${width} px`) + } + for (const kind of ['undo', 'redo'] as const) { + await expect(historyButton(page, dict, kind)).toHaveAttribute( + 'aria-disabled', + 'true', + ) + } + } + }) + + test('the canvas width, the same measure without and with the references panel', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + for (const panel of [false, true]) { + for (const width of WIDTHS) { + await page.setViewportSize({ width, height: 800 }) + await showDrawing(page, dict) + await pickAnnotation(page, dict, 'Point libre') + if (panel) await openReferences(page, dict) + const canvas = await page.getByTestId('annotation-canvas').boundingBox() + test.info().annotations.push({ + type: panel ? 'canvas-width-panel' : 'canvas-width', + description: `${canvas?.width}px at ${width}px`, + }) + if (panel) await closeReferences(page, dict) + } + } + }) + + test('axe from the top on the four tabs, each section and the open panel', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + for (const width of [1024, 1280]) { + await page.setViewportSize({ width, height: 800 }) + const places: (readonly [string, () => Promise])[] = [ + ...TABS.map((tab) => [tab, () => selectTab(page, dict, tab)] as const), + ...SECTIONS.map( + (section) => + [section, () => openSection(page, dict, section)] as const, + ), + ] + for (const [name, show] of places) { + await show() + await settle(page) + await page.evaluate(() => window.scrollTo(0, 0)) + await expect(page.locator('dialog[open]')).toHaveCount(0) + await expectAccessible(page, `${name} at ${width} px`) + } + await showDrawing(page, dict) + await openReferences(page, dict) + await page.evaluate(() => window.scrollTo(0, 0)) + await expectAccessible(page, `the open panel at ${width} px`) + await closeReferences(page, dict) + } + }) + + for (const width of WIDTHS) { + test(`the history buttons stay reachable at the top of the page at ${width} px`, async ({ + page, + }) => { + await open(page) + await page.setViewportSize({ width, height: 800 }) + await page.evaluate(() => window.scrollTo(0, 0)) + for (const kind of ['undo', 'redo'] as const) { + const hit = await historyButton(page, dict, kind).evaluate((button) => { + const box = button.getBoundingClientRect() + const at = document.elementFromPoint( + box.x + box.width / 2, + box.y + box.height / 2, + ) + return { top: box.y, covered: !at || !button.contains(at) } + }) + test.info().annotations.push({ + type: 'history-button-top', + description: `${kind} y=${hit.top} at ${width}px covered=${hit.covered}`, + }) + expect(hit.covered, `${kind} at ${width} px`).toBe(false) + } + }) + } +}) + +type Kind = + | 'header' + | 'tab' + | 'undo' + | 'redo' + | 'panel' + | 'tools' + | 'canvas' + | 'side' + | 'other' + +/** What the focused element is, in the words of the keyboard order of AC17. */ +function focusKind(page: Page): Promise { + return page.evaluate((undoName) => { + const el = document.activeElement + if (!el) return 'other' + if (el.closest('[data-place="references"]')) return 'panel' + if (el.getAttribute('role') === 'tab') return 'tab' + if (el.closest('[data-testid="history-buttons"]')) { + return el.getAttribute('aria-label') === undoName ? 'undo' : 'redo' + } + if (el.closest('main header')) return 'header' + if (el.closest('[role="toolbar"]')) return 'tools' + if (el.closest('[data-testid="annotation-canvas"]')) return 'canvas' + if (el.closest('[data-testid="annotation-overview"]')) return 'side' + if (el.closest('[data-testid="annotation-properties"]')) return 'side' + return 'other' + }, dict['editor.history.undo_title']) +} + +/** Tabs forward from the page heading until `stop` is reached; the kinds met, without repeats. */ +async function walk(page: Page, stop: Kind): Promise { + await page.getByRole('heading', { level: 1, name: draftTitle(dict) }).focus() + const seen: Kind[] = [] + for (let step = 0; step < 60; step++) { + await page.keyboard.press('Tab') + const kind = await focusKind(page) + if (kind !== 'other' && seen[seen.length - 1] !== kind) seen.push(kind) + if (kind === stop) break + } + return seen +} + +test.describe('editor shell keyboard order (H)', () => { + test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) + test.beforeEach(async ({ context }, info) => { + test.skip(isPhone(info), 'keyboard order is checked at one width') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('header, tab list, Annuler, Rétablir, then the tools, the canvas and the side column', async ({ + page, + }) => { + await open(page) + await selectTab(page, dict, 'annotations') + await expect(page.getByTestId('annotation-canvas')).toBeVisible() + const order = await walk(page, 'side') + test.info().annotations.push({ + type: 'keyboard-order', + description: order.join(' > '), + }) + expect(order).toEqual([ + 'header', + 'tab', + 'undo', + 'redo', + 'tools', + 'canvas', + 'side', + ]) + }) + + test('with the panel open: header, tab list, Annuler, Rétablir, the panel, then the page content', async ({ + page, + }) => { + await open(page) + await openReferences(page, dict) + const order = await walk(page, 'panel') + test.info().annotations.push({ + type: 'keyboard-order-panel', + description: order.join(' > '), + }) + expect(order).toEqual(['header', 'tab', 'undo', 'redo', 'panel']) + await page.keyboard.press('Escape') + await expect(page.locator('[data-place="references"]:visible')).toHaveCount( + 0, + ) + const after = await walk(page, 'side') + expect(after.slice(0, 4)).toEqual(['header', 'tab', 'undo', 'redo']) + expect(after).not.toContain('panel') + }) +}) diff --git a/apps/app/e2e/shell/editor-shell.spec.ts b/apps/app/e2e/shell/editor-shell.spec.ts index 3fd2084b..fc51a444 100644 --- a/apps/app/e2e/shell/editor-shell.spec.ts +++ b/apps/app/e2e/shell/editor-shell.spec.ts @@ -239,7 +239,8 @@ test.describe('editor shell, width crossing (B2b)', () => { await field.fill('Brouillon') await page.setViewportSize({ width: 800, height: 900 }) await expect(field).toBeHidden() - await expect(page.locator(':focus')).toHaveCount(0) + // The field's focus went to the shown tab, never to `body`. + await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations') await page.setViewportSize({ width: 1280, height: 900 }) await expect(field).toBeVisible() await expect(field).toHaveValue('Brouillon') @@ -287,7 +288,9 @@ test.describe('editor shell, sidebar from 1 280 px (F)', () => { await open(page) for (const width of [1024, 1180, 1279]) { const scroll = await measure(page, width) - expect(scroll.scrollWidth, `${width} px`).toBeLessThanOrEqual(scroll.clientWidth) + expect(scroll.scrollWidth, `${width} px`).toBeLessThanOrEqual( + scroll.clientWidth, + ) await expect(nav(page), `${width} px`).toHaveCount(0) await expect(menu(page), `${width} px`).toBeVisible() } @@ -306,7 +309,10 @@ test.describe('editor shell, sidebar from 1 280 px (F)', () => { await expect(drawer(page)).toBeVisible() await page.setViewportSize({ width: 1279, height: 800 }) await page.evaluate( - () => new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done))), + () => + new Promise((done) => + requestAnimationFrame(() => requestAnimationFrame(done)), + ), ) await expect(drawer(page)).toBeVisible() await page.setViewportSize({ width: 1280, height: 800 }) diff --git a/docs/development/BROWSER_TESTS.md b/docs/development/BROWSER_TESTS.md index cfb066f0..6f43b79a 100644 --- a/docs/development/BROWSER_TESTS.md +++ b/docs/development/BROWSER_TESTS.md @@ -10,7 +10,7 @@ engines are installed. The suites live in `apps/app/e2e`. | Command | Backend | Dev server | Content | |---|---|---|---| | `pnpm e2e:ui` | none | Vite on `127.0.0.1:5191` | `e2e/ui/dialog.spec.ts`: the D13 contract of the shared Dialog on a test page; `e2e/ui/local-tool.spec.ts`: the disclaimer, edit and replace dialogs on the real local-tool routes | -| `pnpm e2e:shell` | the isolated stack of `pnpm db:sandbox` | Vite on `127.0.0.1:5192` | `e2e/shell/shell.spec.ts`: sign-in, dashboard, the account photo confirmation, the phone drawer; `e2e/shell/clients.spec.ts`: the client journeys (V1-1.5); `e2e/shell/animals.spec.ts`: the animal and relation journeys (V1-1.6, contract §11.8); `e2e/shell/responsive.spec.ts`: no sideways scroll on nine shell pages, the archive confirmations and the drawer at 320, 360, 375, 390 and 430 px (phone project) and 1280 px, long values, the dashboard e-mail shown whole (RESP-01); `e2e/shell/admin.spec.ts` (V1-2.5): A0 the owner's bootstrap (two TOTP factors from Sécurité, the step-up at `/app/admin` and inside a factor action, no second factor from `aal1`, refresh keeping `aal1` and `aal2`, rights granted and revoked with their reason), A1 a sheet created by an editor on a new inactive species, S1 a species created inactive then activated by the owner, the creation page when the own-grants read fails (« Impossible de vérifier vos autorisations » and « Réessayer », never the form; Retry brings the form back), access per right (a reviewer-only account refused on the creation page), axe and no sideways scroll on every admin page; `e2e/shell/catalogue.spec.ts` (V1-2.5): P1 a reader searches, opens a sheet, picks a zone, reads a retired version, drafts and archived sheets never listed, the same refusal for an existing and an unknown sheet without access, 320, 375 and 430 px with the whole drawing in the box at opening; at 320 and 375 px the zone panel's live region present before a pick and naming the picked zone, the « Références » card starting at or below the drawing's bottom; `e2e/shell/editor-*.spec.ts` (V1-2.6, the draft editor level 1, contract C16 to C34): `editor-drawings` (A2: a hostile file refused with no cleaning box, an Inkscape export cleaned after its preview, a valid file attached, a detail view by crop, the same bytes attached twice), `editor-annotations` (A3: points, zones and links by clicks and by keyboard only, move by drag, a click with jitter never moves, numeric edits, undo and redo, review and delete), `editor-geometry` (a click near a frame edge with the corrected position confirmed and cancelled, an inherited out-of-frame point repaired through the geometry group, a crop change refused when it would invalidate a point, an unmeasured view with its tools disabled, touch-action and a touch drag in real Chromium), `editor-structures` (A4: categories, references, regions, findings tree, reorder, mark reviewed, delete with dependents), `editor-journey` (the steps of `V1-2-6_OWNER_TRIAL.md` §4 with two editor accounts: creation, drawing, findings, annotations, save, reload with the beforeunload dialog and the recovery offer, conflict, submission, the round read back in SQL), `editor-recovery` (two sessions, an older local copy restored then saved over a newer revision, a pending offer blocking edits, an unreadable copy kept until « Ignorer », Escape on the conflict read, the editor grant revoked, the admin role removed and the grant expired under an open session), `editor-access` (a reviewer-only account read-only, the not-found screen for an editor without the admin role and for an admin without a capability, 320, 375 and 800 px read-only, 1 024 px editing, axe on every tab edit and read-only), `editor-equine` (the historical equine sheet opened as a working copy, a copy left active by an earlier run set aside and put back; commit latency on it and on a synthetic document near 2 MiB, printed as `LATENCY` lines and kept as test annotations, budget 500 ms per commit on the equine copy). Editor accounts, drafts and drawings are prepared by `e2e/support/editor.ts` (a drawing in its stored form, written by the core); `e2e/support/warm-up.ts` is the suite's global setup (the dev server reloads the page once when a route first loads a dependency, so one throwaway session visits the editor routes before the tests). Editing needs 1 024 px: these specs skip the 375 px project | +| `pnpm e2e:shell` | the isolated stack of `pnpm db:sandbox` | Vite on `127.0.0.1:5192` | `e2e/shell/shell.spec.ts`: sign-in, dashboard, the account photo confirmation, the phone drawer; `e2e/shell/clients.spec.ts`: the client journeys (V1-1.5); `e2e/shell/animals.spec.ts`: the animal and relation journeys (V1-1.6, contract §11.8); `e2e/shell/responsive.spec.ts`: no sideways scroll on nine shell pages, the archive confirmations and the drawer at 320, 360, 375, 390 and 430 px (phone project) and 1280 px, long values, the dashboard e-mail shown whole (RESP-01); `e2e/shell/admin.spec.ts` (V1-2.5): A0 the owner's bootstrap (two TOTP factors from Sécurité, the step-up at `/app/admin` and inside a factor action, no second factor from `aal1`, refresh keeping `aal1` and `aal2`, rights granted and revoked with their reason), A1 a sheet created by an editor on a new inactive species, S1 a species created inactive then activated by the owner, the creation page when the own-grants read fails (« Impossible de vérifier vos autorisations » and « Réessayer », never the form; Retry brings the form back), access per right (a reviewer-only account refused on the creation page), axe and no sideways scroll on every admin page; `e2e/shell/catalogue.spec.ts` (V1-2.5): P1 a reader searches, opens a sheet, picks a zone, reads a retired version, drafts and archived sheets never listed, the same refusal for an existing and an unknown sheet without access, 320, 375 and 430 px with the whole drawing in the box at opening; at 320 and 375 px the zone panel's live region present before a pick and naming the picked zone, the « Références » card starting at or below the drawing's bottom; `e2e/shell/editor-*.spec.ts` (V1-2.6, the draft editor level 1, contract C16 to C34): `editor-drawings` (A2: a hostile file refused with no cleaning box, an Inkscape export cleaned after its preview, a valid file attached, a detail view by crop, the same bytes attached twice), `editor-annotations` (A3: points, zones and links by clicks and by keyboard only, move by drag, a click with jitter never moves, numeric edits, undo and redo, review and delete), `editor-geometry` (a click near a frame edge with the corrected position confirmed and cancelled, an inherited out-of-frame point repaired through the geometry group, a crop change refused when it would invalidate a point, an unmeasured view with its tools disabled, touch-action and a touch drag in real Chromium), `editor-structures` (A4: categories, references, regions, findings tree, reorder, mark reviewed, delete with dependents), `editor-journey` (the steps of `V1-2-6_OWNER_TRIAL.md` §4 with two editor accounts: creation, drawing, findings, annotations, save, reload with the beforeunload dialog and the recovery offer, conflict, submission, the round read back in SQL), `editor-recovery` (two sessions, an older local copy restored then saved over a newer revision, a pending offer blocking edits, an unreadable copy kept until « Ignorer », Escape on the conflict read, the editor grant revoked, the admin role removed and the grant expired under an open session), `editor-access` (a reviewer-only account read-only, the not-found screen for an editor without the admin role and for an admin without a capability, 320, 375 and 800 px read-only, 1 024 px editing, axe on every tab edit and read-only), `editor-equine` (the historical equine sheet opened as a working copy, a copy left active by an earlier run set aside and put back; commit latency on it and on a synthetic document near 2 MiB, printed as `LATENCY` lines and kept as test annotations, budget 500 ms per commit on the equine copy). U1 shell (V1-2.6 U1, the four-tab shell): `editor-shell` (kept-mounted places, focus on a named element, the open panel leaving the header and the tab row clickable at 1 024 and 1 280 px, the sidebar from 1 280 px and the drawer, canvas widths), `editor-shell-journeys` (four tabs, cross-tab undo, typed text then the header undo, a refused field kept through a real Shift+Tab to « Annuler », Ctrl+Z outside and inside a field, « Aller à » for each issue kind, the save line from the count to « Enregistrement… » to the time and revision), `editor-shell-crossing` (every edit-only part typed, a 1 024 px crossing, no edit control and the focus on the shown tab, widening with the values back; the section and the panel open; unsaved work and the recovery copy kept; a drag across the crossing commits nothing; delete and discard confirmations closing; a decision withheld under the panel waiting for « Reprendre »), `editor-shell-layout` (no sideways scroll at 1 024, 1 180, 1 279 and 1 280 px on the four tabs, the sections and the panel, and at 320, 375 and 768 px read-only; axe from the top on every place; the canvas width without and with the panel as `canvas-width` and `canvas-width-panel` annotations; the keyboard order header, tab list, « Annuler », « Rétablir », the panel when open, then tools, canvas and side column); the equine spec also times commit to paint with every place visited. Editor accounts, drafts and drawings are prepared by `e2e/support/editor.ts` (a drawing in its stored form, written by the core); `e2e/support/warm-up.ts` is the suite's global setup (the dev server reloads the page once when a route first loads a dependency, so one throwaway session visits the editor routes before the tests). Editing needs 1 024 px: these specs skip the 375 px project | Each suite runs on two Chromium projects: `chromium-desktop` (1280 × 800) and `chromium-375` (375 × 667, mobile viewport, touch). A test tagged `@phone`