feat(editor): browser history for tabs, sections and Aller a

EditorView held by the navigation reducer (restore_view), a history
adapter hook mounted in EditorWorkspace (push, replace, back, mount
rule, ownership, write budget, scroll map, refused POP), a guard stack
by layer, an announcer queue joined after open dialogs.
This commit is contained in:
bchanot committed 2026-11-13 17:57:52 +01:00
1 parent 69e225ca7a
commit 792394d3b2
11 files changed
+1268 -40

No files matched your search

+155
View File
@@ -0,0 +1,155 @@
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 {
editorActor,
openEditor,
openSection,
place,
pointOf,
seedDraft,
selectTab,
shapeWith,
} from '../support/editor'
// R2 UX finish, task 1 (R2F-1): the browser's Back and Forward walk the editor's tabs and
// Annotations sections. Chromium's own history (page.goBack) drives them; the top-layer and
// focus rules are the browser's, so they are proved here and not in happy-dom.
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const dialog = (page: Page) => page.getByRole('dialog')
const selected = (page: Page) => page.getByRole('tab', { selected: true })
const tabName = (tab: string) =>
new RegExp(`^${dict[`editor.tab.${tab}`]}( |$)`)
/**
* The history follows a move from an effect, a few milliseconds after the click: wait for
* the entry on top to name the tab before pressing Back (a user cannot be that quick).
*/
async function written(page: Page, tab: string) {
await page.waitForFunction(
(wanted) => history.state?.usr?.editorEntry?.view?.tab === wanted,
tab,
)
}
async function sectionWritten(page: Page, section: string) {
await page.waitForFunction(
(wanted) => history.state?.usr?.editorEntry?.view?.section === wanted,
section,
)
}
async function open(page: Page) {
const actor = await editorActor('fr')
const linked = pointOf('p1', 'main', { cx: 500, cy: 400, r: 40 }, 'Point lié')
const seed = await seedDraft(actor, { shape: shapeWith(linked) })
await openEditor(page, dict, actor, seed.sheetId)
await expect(selected(page)).toHaveText(tabName('annotations'))
return seed
}
test.describe('editor browser history', () => {
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('tabs: Back and Forward restore them, the tab button holds the focus', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'findings')
await written(page, 'findings')
await selectTab(page, dict, 'references')
await written(page, 'references')
await page.goBack()
await expect(selected(page)).toHaveText(tabName('findings'))
await expect(page.locator(':focus')).toHaveAttribute(
'id',
'editor-tab-findings',
)
await page.goBack()
await expect(selected(page)).toHaveText(tabName('annotations'))
await expect(page.locator(':focus')).toHaveAttribute(
'id',
'editor-tab-annotations',
)
await page.goForward()
await expect(selected(page)).toHaveText(tabName('findings'))
await page.goForward()
await expect(selected(page)).toHaveText(tabName('references'))
})
test('an Annotations section is an entry of its own: Back shows the drawing, Forward the section', async ({
page,
}) => {
await open(page)
await openSection(page, dict, 'categories')
await sectionWritten(page, 'categories')
await page.goBack()
await expect(place(page, 'annotations.drawing')).toBeVisible()
await expect(place(page, 'annotations.categories')).toBeHidden()
await expect(page.locator(':focus')).not.toHaveJSProperty('tagName', 'BODY')
await page.goForward()
await expect(place(page, 'annotations.categories')).toBeVisible()
})
test('arrow keys along the tab row replace the entry: one Back leaves the walk', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'findings')
await written(page, 'findings')
await page.keyboard.press('ArrowRight')
await expect(selected(page)).toHaveText(tabName('references'))
await written(page, 'references')
await page.keyboard.press('ArrowRight')
await expect(selected(page)).toHaveText(tabName('verification'))
await written(page, 'verification')
await page.goBack()
await expect(selected(page)).toHaveText(tabName('annotations'))
})
test('a reload reopens the view of the entry', async ({ page }) => {
await open(page)
await selectTab(page, dict, 'findings')
await written(page, 'findings')
await page.reload()
await expect(selected(page)).toHaveText(tabName('findings'))
await page.goBack()
await expect(selected(page)).toHaveText(tabName('annotations'))
})
test('a DeleteDialog open when Back is pressed stays open, the view unchanged', async ({
page,
}) => {
await open(page)
await openSection(page, dict, 'categories')
await sectionWritten(page, 'categories')
await page
.getByRole('listitem')
.filter({ has: page.locator('#category-cat-a-name-fr') })
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await expect(dialog(page)).toBeVisible()
await page.goBack()
await expect(dialog(page)).toBeVisible()
await expect(place(page, 'annotations.categories')).toBeVisible()
await dialog(page)
.getByRole('button', { name: dict['editor.delete.close'], exact: true })
.last()
.click()
await expect(dialog(page)).toHaveCount(0)
// The refused Back left the section one entry above the drawing: this one goes.
await page.goBack()
await expect(place(page, 'annotations.drawing')).toBeVisible()
})
})