diff --git a/apps/app/e2e/shell/editor-citations.spec.ts b/apps/app/e2e/shell/editor-citations.spec.ts new file mode 100644 index 00000000..a3dc8644 --- /dev/null +++ b/apps/app/e2e/shell/editor-citations.spec.ts @@ -0,0 +1,491 @@ +import { fr } from '@/i18n/fr' +import type { Locator, Page, TestInfo } from '@playwright/test' +import { + expect, + expectAccessible, + expectNoHorizontalOverflow, + test, +} from '../support/browser' +import { dropLateReplays, routeToSandbox } from '../support/sandbox' +import { + closeCitations, + editorActor, + libraryRoot, + openCitations, + openEditor, + openTab, + place, + saveDraft, + seedDraft, + serverDocument, + standardShape, +} from '../support/editor' + +// V1-2.6 R2.4: the contextual citations panel of one finding (board 25): its contents, +// « Retirer de ce constat » and « Défaire », « Tout afficher », every close path with the +// focus checked after the exit (motion and reduced motion), Escape in a tile field, the +// inert page during the exit sampled in the page, axe open (edit, read-only at 375 px). +// The spec seeds its own sheet and never touches another. + +const dict = fr + +const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' + +/** « Constat A » cites twelve references: its panel list outgrows the screen. */ +function longShape(document: Record) { + shape(document) + const refs = Array.from({ length: 12 }, (_, index) => ({ + id: `ref-${index}`, + type: 'book', + citation: `Ouvrage numéro ${index + 1}`, + url: null, + doi: null, + })) + document.references = refs + const zone = (document.finding_zones as { categories: unknown[] }[])[0] + const family = zone.categories[0] as { + reference_ids: string[] + children: { reference_ids: string[] }[] + } + family.reference_ids = [] + family.children[0].reference_ids = refs.map((ref) => ref.id) +} + +/** « Constat A » cites A, B and C; the family cites B; D is cited by nobody. */ +function shape(document: Record) { + standardShape(document) + const reference = (id: string, citation: string, type = 'book') => ({ + id, + type, + citation, + url: null, + doi: null, + }) + document.references = [ + reference('ref-a', 'Référence A'), + reference('ref-b', 'Source B', 'web'), + reference('ref-c', 'Source C', 'journal'), + reference('ref-d', 'Source libre', 'manual'), + ] + const zone = (document.finding_zones as { categories: unknown[] }[])[0] + const family = zone.categories[0] as { + reference_ids: string[] + children: { reference_ids: string[] }[] + } + family.reference_ids = ['ref-b'] + family.children[0].reference_ids = ['ref-a', 'ref-b', 'ref-c'] +} + +async function open(page: Page, seedShape = shape) { + const actor = await editorActor('fr') + const seed = await seedDraft(actor, { shape: seedShape }) + await openEditor(page, dict, actor, seed.sheetId) + return { actor, seed } +} + +const panel = (page: Page) => page.getByTestId('editor-citations-panel') +const heads = (page: Page) => + panel(page).locator('button[aria-controls][id$="-header"]') +const trigger = (page: Page) => page.locator('[data-citations-trigger]:visible') +const link = (page: Page) => + panel(page).getByRole('button', { + name: dict['editor.references.panel_show_all'], + }) +const undo = (page: Page) => page.getByRole('button', { name: /Défaire/ }) +const retire = (tile: Locator) => + tile.getByRole('button', { name: dict['editor.references.remove_citation'] }) + +type Node = { reference_ids: string[]; review_status: string } +const nodeOf = (document: Record) => + ( + document.finding_zones as { + categories: { children: Node[] }[] + }[] + )[0].categories[0].children[0] + +test.describe('citations panel, editing', () => { + test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) + test.beforeEach(async ({ context }, info) => { + test.skip( + isPhone(info), + 'editing needs >= 1 024 px; the read-only twin at 375 px is below', + ) // floor-guard: allow C16 editing needs >= 1024 px; read-only twin in this file + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('opens filtered on its finding, « Retirer » and one « Défaire », saved status', async ({ + page, + requests, + }) => { + test.setTimeout(150_000) + const { actor, seed } = await open(page) + requests.forbid(actor.account.email, actor.account.password) + await openCitations(page, dict, 'Constat A') + await expect(trigger(page)).toHaveAttribute('aria-expanded', 'true') + await expect(panel(page).getByRole('heading')).toHaveText( + dict['editor.references.panel_title'], + ) + await expect(panel(page)).toContainText( + 'Zone A › Dysfonction A › Constat A', + ) + await expect(panel(page)).toContainText( + dict['editor.references.panel_count_other'].replace('{count}', '3'), + ) + await expect(heads(page)).toHaveCount(3) + await expect(panel(page).getByText('Source libre')).toHaveCount(0) + await expect(panel(page).getByRole('searchbox')).toHaveCount(0) + await expectAccessible(page, 'the citations panel, closed tiles') + + await heads(page).nth(1).click() + const tile = heads(page).nth(1).locator('xpath=ancestor::li[1]') + await expect( + tile.getByText(dict['editor.references.this_finding'], { exact: true }), + ).toBeVisible() + await expect(retire(tile)).toBeVisible() + for (const name of [ + dict['editor.action.delete'], + dict['editor.action.move_up'], + ]) { + await expect(panel(page).getByRole('button', { name })).toHaveCount(0) + } + await expectAccessible(page, 'the citations panel, an open tile') + + // « Retirer » then one « Défaire » restores the citation and the status together. + await retire(tile).click() + await expect(heads(page)).toHaveCount(2) + // The next tile (« Source C », now second) takes the focus (P20). + await expect(heads(page).nth(1)).toBeFocused() + await expect(heads(page).nth(1)).toContainText('Source C') + await undo(page).click() + await expect(heads(page)).toHaveCount(3) + // The tile that came back is closed (its open state went with it): open it again. + await heads(page).nth(1).click() + await retire(tile).click() + await expect(heads(page)).toHaveCount(2) + await saveDraft(page, dict, seed.revision + 1) + const saved = await serverDocument>(seed.draftId) + expect(nodeOf(saved).reference_ids).toEqual(['ref-a', 'ref-c']) + expect(nodeOf(saved).review_status).toBe('to_confirm') + expect((saved.references as unknown[]).length).toBe(4) + }) + + test('a long list scrolls inside the panel: the last tile is reachable from scroll 0, the page never moves', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page, longShape) + await openCitations(page, dict, 'Constat A') + await expect(heads(page)).toHaveCount(12) + expect(await page.evaluate(() => window.scrollY)).toBe(0) + const list = panel(page).locator('div.overflow-y-auto') + await list.evaluate((node) => { + node.scrollTop = node.scrollHeight + }) + const last = heads(page).last() + await expect(last).toBeInViewport({ ratio: 1 }) + const view = await page.evaluate(() => window.innerHeight) + const box = await last.boundingBox() + expect(box!.y + box!.height).toBeLessThanOrEqual(view + 1) + expect(await page.evaluate(() => window.scrollY)).toBe(0) + await last.click() + await expect(last).toHaveAttribute('aria-expanded', 'true') + }) + + test('the last citations gone: the panel stays with its line, then closes on the tab', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openCitations(page, dict, 'Constat A') + for (const remaining of [2, 1, 0]) { + await heads(page).first().click() + await retire(heads(page).first().locator('xpath=ancestor::li[1]')).click() + await expect(heads(page)).toHaveCount(remaining) + } + await expect( + panel(page).getByText(dict['editor.references.panel_empty']), + ).toBeVisible() + await expect(link(page)).toBeVisible() + await expect(page.locator('#editor-citations-title')).toBeFocused() + await page.keyboard.press('Escape') + await expect(panel(page)).toHaveCount(0) + // The trigger went with the last citation: the active tab takes the focus (P6). + await expect( + page.getByRole('tab', { name: dict['editor.tab.findings'] }), + ).toBeFocused() + }) + + test('« Tout afficher » closes it, resets search and sort, keeps open tiles, focuses the tab heading', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openTab(page, dict, 'references') + const root = libraryRoot(page) + await root.getByRole('searchbox').fill('Source') + await root + .getByLabel(dict['editor.references.sort_by']) + .selectOption('citation') + await root.getByRole('button', { name: /Source B/ }).click() + await openCitations(page, dict, 'Constat A') + await link(page).click() + await expect(panel(page)).toHaveCount(0) + await expect(page.locator('#editor-references-title')).toBeFocused() + await expect(root.getByRole('searchbox')).toHaveValue('') + await expect( + root.getByLabel(dict['editor.references.sort_by']), + ).toHaveValue('sheet') + await expect( + root.getByRole('button', { name: /Source B/ }), + ).toHaveAttribute('aria-expanded', 'true') + await expect( + root.locator('button[aria-controls][id$="-header"]'), + ).toHaveCount(4) + }) + + test('Escape in a field of a tile neither closes the panel nor commits; ✕ then commits', async ({ + page, + }) => { + test.setTimeout(150_000) + const { seed } = await open(page) + await openCitations(page, dict, 'Constat A') + await heads(page).first().click() + await panel(page) + .getByRole('button', { name: dict['editor.references.edit'] }) + .click() + const field = panel(page).getByLabel(dict['editor.reference.citation']) + await field.fill('Référence A, révisée') + await field.press('Escape') + await expect(panel(page)).toBeVisible() + await expect(field).toHaveValue('Référence A, révisée') + await expect(undo(page)).toBeDisabled() + // A user close applies a valid draft first (P22''), then the panel exits. + await panel(page) + .getByRole('button', { name: dict['editor.references.close'] }) + .click() + await expect(panel(page)).toHaveCount(0) + await saveDraft(page, dict, seed.revision + 1) + const saved = await serverDocument<{ references: { citation: string }[] }>( + seed.draftId, + ) + expect(saved.references[0].citation).toBe('Référence A, révisée') + }) + + test('a refused draft cancels the close: panel open, field focused, message shown', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openCitations(page, dict, 'Constat A') + await heads(page).first().click() + await panel(page) + .getByRole('button', { name: dict['editor.references.edit'] }) + .click() + const field = panel(page).getByLabel(dict['editor.reference.citation']) + await field.fill('') + await page + .getByRole('tab', { + name: new RegExp(`^${dict['editor.tab.verification']}`), + }) + .click() + await expect(panel(page)).toBeVisible() + await expect(field).toBeFocused() + await expect(panel(page).getByRole('alert')).toBeVisible() + await expect(page.getByRole('tab', { selected: true })).toHaveText( + new RegExp(`^${dict['editor.tab.findings']}`), + ) + }) + + test('the page and the panel are inert through the exit (sampled in the page)', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openCitations(page, dict, 'Constat A') + await page.evaluate(() => { + const samples: { panel: boolean; page: boolean; inert: boolean }[] = [] + Object.assign(window, { samples }) + const tick = () => { + const layer = document.querySelector('[data-place="citations"]') + const body = document.querySelector('[data-place="findings"]') + samples.push({ + panel: layer !== null, + page: body?.closest('[inert]') !== null, + inert: layer?.hasAttribute('inert') ?? false, + }) + if (layer !== null) requestAnimationFrame(tick) + } + tick() + }) + await panel(page) + .getByRole('button', { name: dict['editor.references.close'] }) + .click() + await expect(panel(page)).toHaveCount(0) + const samples = await page.evaluate( + () => + ( + window as unknown as { + samples: { panel: boolean; page: boolean; inert: boolean }[] + } + ).samples, + ) + const leaving = samples.filter((sample) => sample.panel && sample.inert) + expect(leaving.length).toBeGreaterThan(0) + expect(leaving.every((sample) => sample.page)).toBe(true) + await expect(page.locator('[data-place="findings"]')).toBeVisible() + expect( + await page + .locator('[data-place="findings"]') + .evaluate((body) => body.closest('[inert]') === null), + ).toBe(true) + }) +}) + +/** Every way out of the panel, the focus read from the document after the exit. */ +for (const reduced of [false, true]) { + test.describe(`citations panel closes, ${reduced ? 'reduced motion' : 'motion'}`, () => { + test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) + test.beforeEach(async ({ context, page }, info) => { + test.skip(isPhone(info), 'the paths are walked on desktop') // floor-guard: allow C16 editing needs >= 1 024 px + await routeToSandbox(context) + await page.emulateMedia({ + reducedMotion: reduced ? 'reduce' : 'no-preference', + }) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('✕, Escape and the scrim give the focus back to the trigger', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openCitations(page, dict, 'Constat A') + await closeCitations(page, dict) + await expect(trigger(page)).toBeFocused() + await expect(trigger(page)).toHaveAttribute('aria-expanded', 'false') + await trigger(page).click() + await expect(page.locator('#editor-citations-title')).toBeFocused() + await page.keyboard.press('Escape') + await expect(panel(page)).toHaveCount(0) + await expect(trigger(page)).toBeFocused() + await trigger(page).click() + await expect(page.locator('#editor-citations-title')).toBeFocused() + await page + .getByTestId('references-scrim') + .click({ position: { x: 12, y: 40 } }) + await expect(panel(page)).toHaveCount(0) + await expect(trigger(page)).toBeFocused() + }) + + test('« Tout afficher », « Aller à » and a tab choice land where the pending move says', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openCitations(page, dict, 'Constat A') + await link(page).click() + await expect(panel(page)).toHaveCount(0) + await expect(page.locator('#editor-references-title')).toBeFocused() + + await openCitations(page, dict, 'Constat A') + await heads(page).nth(1).click() + await panel(page) + .getByRole('button', { name: dict['editor.references.go_to'] }) + .first() + .click() + await expect(panel(page)).toHaveCount(0) + await expect( + page.getByRole('treeitem', { name: /Dysfonction A/ }), + ).toBeFocused() + + await openCitations(page, dict, 'Constat A') + const verification = page.getByRole('tab', { + name: new RegExp(`^${dict['editor.tab.verification']}`), + }) + await verification.click() + await expect(panel(page)).toHaveCount(0) + await expect(verification).toBeFocused() + }) + + test('the panel slides only when motion is allowed', async ({ page }) => { + test.setTimeout(150_000) + await open(page) + await page.getByRole('tab', { name: dict['editor.tab.findings'] }).click() + await page + .getByRole('treeitem', { expanded: false }) + .first() + .press('ArrowRight') + await page.getByRole('treeitem', { name: 'Constat A' }).click() + await page.evaluate(() => { + const seen: string[] = [] + Object.assign(window, { seen }) + new MutationObserver(() => { + const layer = document.querySelector('[data-place="citations"]') + const slider = layer?.firstElementChild as HTMLElement | null + if (slider) seen.push(slider.style.transform) + }).observe(document.body, { + subtree: true, + childList: true, + attributes: true, + attributeFilter: ['style'], + }) + }) + await trigger(page).click() + await expect(page.locator('#editor-citations-title')).toBeFocused() + const seen = await page.evaluate( + () => (window as unknown as { seen: string[] }).seen, + ) + const slid = seen.some((value) => /translateX\((?!0)[1-9]/.test(value)) + expect(slid).toBe(!reduced) + }) + }) +} + +test.describe('citations panel, read-only at 375 px', () => { + test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) + test.beforeEach(async ({ context }, info) => { + test.skip(!isPhone(info), 'the read-only twin runs at 375 px only') + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('full width through « Plus » then Constats, no edit control, axe open @phone', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openCitations(page, dict, 'Constat A') + // Full width: the whole content area (the page's side gutters stay). + const layer = page.locator('[data-place="citations"]') + const box = await layer.boundingBox() + const area = await layer.locator('xpath=..').boundingBox() + expect(box?.width ?? 0).toBeLessThanOrEqual(375) + expect(Math.abs((box?.width ?? 0) - (area?.width ?? 0))).toBeLessThan(1) + await expect(heads(page)).toHaveCount(3) + await expectNoHorizontalOverflow(page, 'the panel at 375 px') + await heads(page).first().click() + for (const name of [ + dict['editor.references.edit'], + dict['editor.references.remove_citation'], + ]) { + await expect(panel(page).getByRole('button', { name })).toHaveCount(0) + } + await expect(panel(page).getByRole('textbox')).toHaveCount(0) + const close = await panel(page) + .getByRole('button', { name: dict['editor.references.close'] }) + .boundingBox() + expect(close?.width ?? 0).toBeGreaterThanOrEqual(44) + expect(close?.height ?? 0).toBeGreaterThanOrEqual(44) + await expectAccessible(page, 'the citations panel, read-only at 375 px') + await closeCitations(page, dict) + await expect(trigger(page)).toBeFocused() + await expect(place(page, 'findings')).toBeVisible() + }) +}) diff --git a/apps/app/e2e/shell/editor-shell-layout.spec.ts b/apps/app/e2e/shell/editor-shell-layout.spec.ts index 7ec2f01c..7713514e 100644 --- a/apps/app/e2e/shell/editor-shell-layout.spec.ts +++ b/apps/app/e2e/shell/editor-shell-layout.spec.ts @@ -52,6 +52,100 @@ async function open(page: Page) { return { ...seed, actor } } +/** Selects a finding in the tree of Constats (expanding down to it), the panel closed. */ +async function selectFinding(page: Page, name: string) { + await openTab(page, dict, 'findings') + const item = page.getByRole('treeitem', { name }) + for (let depth = 0; depth < 4 && (await item.count()) === 0; depth++) { + const closed = page.getByRole('treeitem', { expanded: false }).first() + await closed.focus() + await closed.press('ArrowRight') + } + await item.click() +} + +/** + * Samples the document's size on every frame until stopped (the click that opens or + * closes the panel is inside the window): the distinct sizes seen come back. + */ +async function watchDocumentSize(page: Page) { + await page.evaluate(() => { + const seen = new Set() + const state = { live: true } + const tick = () => { + const root = document.documentElement + seen.add(`${root.scrollWidth}x${root.scrollHeight}`) + if (state.live) requestAnimationFrame(tick) + } + Object.assign(window, { sizes: seen, sampling: state }) + tick() + }) + return () => + page.evaluate(() => { + const w = window as unknown as { + sizes: Set + sampling: { live: boolean } + } + w.sampling.live = false + return [...w.sizes] + }) +} + +const REM = 16 +/** The panel's own padding (`p-4` top and bottom): its box cannot be shorter than this. */ +const PANEL_PADDING_PX = 32 + +/** + * The panel is at most 34 rem and no wider than the viewport, and at scroll 0, halfway and + * at the end of the page its bottom is the nearer of the viewport's bottom and its + * container's bottom (its visible height is kept right on scroll). + */ +async function expectPanelWithin( + page: Page, + viewportWidth: number, + cramped = false, +) { + const layer = page.locator('[data-place="citations"]') + const box = await layer.boundingBox() + expect(box!.width).toBeLessThanOrEqual(34 * REM + 0.5) + expect(box!.width).toBeLessThanOrEqual(viewportWidth) + for (const at of [0, 0.5, 1]) { + await page.evaluate((share) => { + const root = document.documentElement + window.scrollTo(0, (root.scrollHeight - window.innerHeight) * share) + }, at) + await page.evaluate( + () => new Promise((done) => requestAnimationFrame(() => done(null))), + ) + const edges = await page.evaluate(() => { + const container = document.querySelector('[data-place="citations"]')! + const panel = document.querySelector('#editor-citations-panel')! + const outer = container.getBoundingClientRect() + const inner = panel.getBoundingClientRect() + const viewport = window.visualViewport?.height ?? window.innerHeight + return { + panelBottom: inner.bottom, + expected: Math.min(viewport, outer.bottom), + panelTop: inner.top, + } + }) + if (edges.expected - edges.panelTop < PANEL_PADDING_PX) { + // Only the landscape phone at scroll 0 may leave less room than the padding. + expect( + cramped && at === 0, + `panel room below its padding at scroll share ${at}`, + ).toBe(true) + continue + } + expect( + Math.abs(edges.panelBottom - edges.expected), + `panel bottom at scroll share ${at}`, + ).toBeLessThanOrEqual(1) + expect(edges.panelBottom).toBeGreaterThan(edges.panelTop) + } + await page.evaluate(() => window.scrollTo(0, 0)) +} + async function settle(page: Page) { await page.evaluate( () => @@ -92,6 +186,28 @@ test.describe('editor shell layout (H)', () => { } }) + test('the open panel is at most 34 rem and the viewport wide, and the document never changes size, before, during and after', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + for (const width of WIDTHS) { + await page.setViewportSize({ width, height: 800 }) + await selectFinding(page, 'Constat A') + const stop = await watchDocumentSize(page) + await page.locator('[data-citations-trigger]:visible').click() + await expect(page.locator('#editor-citations-title')).toBeFocused() + await expectPanelWithin(page, width) + await expectNoHorizontalOverflow(page, `the open panel at ${width} px`) + await closeCitations(page, dict) + const sizes = await stop() + expect( + sizes, + `document size at ${width} px, before/during/after`, + ).toHaveLength(1) + } + }) + test('read-only at 320, 375 and 768 px: the five tabs fit and pass axe', async ({ page, requests, @@ -273,14 +389,7 @@ test.describe('editor shell keyboard order (H)', () => { type: 'keyboard-order', description: order.join(' > '), }) - expect(order).toEqual([ - 'tab', - 'undo', - 'redo', - 'tools', - 'canvas', - 'side', - ]) + expect(order).toEqual(['tab', 'undo', 'redo', 'tools', 'canvas', 'side']) }) test('with the panel open: tab list, Défaire, Refaire, the panel, then the page content', async ({ @@ -305,3 +414,61 @@ test.describe('editor shell keyboard order (H)', () => { expect(after.at(-1)).toBe('side') }) }) + +test.describe('citations panel 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') + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('full width, never wider than the screen, bottom on the viewport bottom through a height change and a rotation, the drawing box unchanged @phone', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await openTab(page, dict, 'annotations') + const drawingBox = () => place(page, 'annotations.drawing').boundingBox() + await expect(place(page, 'annotations.drawing')).toBeVisible() + const drawing = await drawingBox() + await selectFinding(page, 'Constat A') + await page.locator('[data-citations-trigger]:visible').click() + await expect(page.locator('#editor-citations-title')).toBeFocused() + for (const size of [ + { width: 375, height: 667 }, + { width: 375, height: 560 }, + { width: 667, height: 375 }, + ]) { + await page.setViewportSize(size) + await page.evaluate( + () => new Promise((done) => requestAnimationFrame(() => done(null))), + ) + await expectPanelWithin(page, size.width, size.width === 667) + await expectNoHorizontalOverflow( + page, + `the panel at ${size.width} x ${size.height}`, + ) + } + await page.setViewportSize({ width: 375, height: 667 }) + await closeCitations(page, dict) + await openTab(page, dict, 'annotations') + await expect(place(page, 'annotations.drawing')).toBeVisible() + expect(await drawingBox()).toEqual(drawing) + }) + + test('the document size does not change while the panel opens and closes @phone', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await selectFinding(page, 'Constat A') + const stop = await watchDocumentSize(page) + await page.locator('[data-citations-trigger]:visible').click() + await expect(page.locator('#editor-citations-title')).toBeFocused() + await closeCitations(page, dict) + expect(await stop()).toHaveLength(1) + }) +}) diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts index 7fcdd3a4..0ec24418 100644 --- a/apps/app/e2e/support/editor.ts +++ b/apps/app/e2e/support/editor.ts @@ -407,7 +407,10 @@ export async function openTab(page: Page, dict: Dict, tab: string) { }) if ((await more.getAttribute('aria-expanded')) !== 'true') await more.click() - await page.locator('#editor-tabs-more').getByRole('button', { name }).click() + await page + .locator('#editor-tabs-more') + .getByRole('button', { name }) + .click() } else { await page.getByRole('tab', { name }).click() } @@ -416,7 +419,8 @@ export async function openTab(page: Page, dict: Dict, tab: string) { /** * Opens the citations panel of the finding named `element`: the Constats tab, the tree - * expanded down to it, the element selected, its « n références » trigger pressed. + * expanded down to it, the element selected, its « n références » trigger pressed, the + * slide over (the heading holds the focus). */ export async function openCitations(page: Page, dict: Dict, element: string) { await openTab(page, dict, 'findings') @@ -429,6 +433,8 @@ export async function openCitations(page: Page, dict: Dict, element: string) { await item.click() await page.locator('[data-citations-trigger]:visible').click() await expect(place(page, 'citations')).toBeVisible() + // The slide is over when the panel's heading takes the focus (P9). + await expect(page.locator('#editor-citations-title')).toBeFocused() } /** Closes the citations panel with its ✕ button. */ diff --git a/apps/app/src/components/editor/EditorWorkspace.tsx b/apps/app/src/components/editor/EditorWorkspace.tsx index 362fc855..3e63363b 100644 --- a/apps/app/src/components/editor/EditorWorkspace.tsx +++ b/apps/app/src/components/editor/EditorWorkspace.tsx @@ -1,8 +1,14 @@ import { useEffect, useRef, type ReactNode } from 'react' +import { AnimatePresence } from 'motion/react' +import type { ElementKey } from '@faunosteo/core-wasm/types' import type { OfficialSheetAdmin } from '@faunosteo/supabase' import Notice from '@/components/ui/Notice' import { ReadOnlyContext, ReferencesOpenContext } from '@/editor/editingContext' -import { AnnounceContext, FocusConsumedContext } from '@/editor/focusRequest' +import { + AnnounceContext, + FocusConsumedContext, + isTextField, +} from '@/editor/focusRequest' import { saveFailureMessage } from '@/editor/messages' import type { EditorMode } from '@/editor/mode' import { useEditorStore } from '@/editor/state/editorStore' @@ -18,10 +24,9 @@ import CopyIssueNotice from './CopyIssueNotice' import DraftHeader from './DraftHeader' import EditorTabBody from './EditorTabBody' import EditorTabs from './EditorTabs' -import KeptPlace from './KeptPlace' import ModeNotice from './ModeNotice' import RecoveryNotice from './RecoveryNotice' -import ReferencesPanel from './references/ReferencesPanel' +import CitationsLayer from './references/CitationsLayer' interface Props { sheet: OfficialSheetAdmin @@ -51,16 +56,16 @@ function SaveFailureNotice() { /** What dialogs and edit-only parts below need of the editor's state. */ function EditingState({ readOnly, - referencesOpen, + citationsOf, children, }: { readOnly: boolean - referencesOpen: boolean + citationsOf: ElementKey | null children: ReactNode }) { return ( - + {children} @@ -76,35 +81,29 @@ interface PlacesProps { /** * Under the tab row: the tab panels and the citations panel of a finding beside them. The * container starts after the tab row, so the panel and its scrim never cover the header or - * the tabs; while the panel is open the tab panels are inert (the scrim sits over them). + * the tabs; from the opening to the end of the exit the tab panels are inert. Its minimum + * height is permanent (never toggled): the panel and the scrim reach the bottom of the + * window and the document never changes size when the panel opens or closes (P16'). */ function Places({ nav, readOnly, reloadSheet }: PlacesProps) { const { state } = nav const open = state.citationsOf !== null return ( -
- {state.citationsOf && ( - - + + {state.citationsOf && !nav.exiting && ( + - - )} - {open && ( -