test(editor): reference dialog, filter and the owner journey, specs follow the dialog

This commit is contained in:
bchanot committed 2026-11-13 20:27:01 +01:00
1 parent 7a64daf251
commit 8b42816270
20 files changed
+1546 -1171

No files matched your search

@@ -0,0 +1,348 @@
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,
expectNoDialog,
findingDialog,
historyButton,
libraryRoot,
openEditor,
openFinding,
openTab,
place,
referenceDialog,
referenceSettled,
seedDraft,
showCitations,
standardShape,
} from '../support/editor'
// R2 UX finish, task 3 (R2F-5, R2F-6): the reference dialog, the reading tiles, the
// references filtered by a finding, and the owner's journey through the browser history:
// finding A, its sheet, « Tout afficher », the filtered tab, a reference edited, Back,
// Forward, « Revenir au constat », then every Back down to the first entry. The top
// layer, the focus and the history rules are the browser's, so they are proved here.
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const panel = (page: Page) => page.getByTestId('editor-citations-panel')
const chip = (page: Page) =>
libraryRoot(page).getByTestId('editor-references-filter')
const headers = (page: Page) =>
libraryRoot(page).locator('button[aria-controls][id$="-header"]')
const undo = (page: Page) => historyButton(page, dict, 'undo')
const dialogs = (page: Page) => page.locator('dialog[open]')
/** « Constat A » cites A and B; « Source libre » is cited by nobody. */
function shape(document: Record<string, unknown>) {
standardShape(document)
const reference = (id: string, citation: string) => ({
id,
type: 'book',
citation,
url: null,
doi: null,
})
document.references = [
reference('ref-a', 'Référence A'),
reference('ref-b', 'Référence B'),
reference('ref-c', 'Source libre'),
]
const zone = (document.finding_zones as { categories: unknown[] }[])[0]
const family = zone.categories[0] as {
children: { reference_ids: string[] }[]
}
family.children[0].reference_ids = ['ref-a', 'ref-b']
}
async function open(page: Page) {
const actor = await editorActor('fr')
const seed = await seedDraft(actor, { shape })
await openEditor(page, dict, actor, seed.sheetId)
return seed
}
/** The id of the history entry on top: it changes with every push, never with a replace. */
const entryId = (page: Page) =>
page.evaluate(() => history.state?.usr?.editorEntry?.id as string)
/** Waits until the entry on top satisfies `view`: the adapter writes a moment after a move. */
async function entryHolds(page: Page, test: string) {
const view = 'history.state?.usr?.editorEntry?.view'
await page.waitForFunction(
`(() => { const view = ${view}; return !!(${test}) })()`,
)
}
/** Whether the sheet is the dialog on top at the right edge of the viewport. */
const sheetOnTop = (page: Page) =>
page.evaluate(() => {
const top = document.elementFromPoint(window.innerWidth - 40, 100)
return !!top?.closest('dialog')?.querySelector('[data-place="citations"]')
})
/** Finding A, its sheet, then « Tout afficher »: the References tab filtered by Constat A. */
async function filteredTab(page: Page) {
await openFinding(page, dict, 'Constat A')
await entryHolds(page, 'view.finding !== null')
await showCitations(page)
await entryHolds(page, 'view.finding && view.finding.citations')
await panel(page)
.getByRole('button', { name: dict['editor.references.panel_show_all'] })
.click()
await expectNoDialog(page)
await entryHolds(page, "view.tab === 'references' && !!view.referenceFilter")
await expect(chip(page)).toContainText('Constat A')
}
test.describe('the owner journey through the history', () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
test.beforeEach(async ({ context }) => {
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
})
test('eight steps: finding, sheet, filter, edit, Back, Forward, Revenir au constat, every Back', async ({
page,
}, info) => {
test.setTimeout(240_000)
await open(page)
// 1 to 3: the finding dialog, its sheet, « Tout afficher »; 4: the filtered tab.
await filteredTab(page)
await expect(headers(page)).toHaveCount(2)
await expect(
libraryRoot(page).getByText('2 références', { exact: true }),
).toBeVisible()
await expect(page.getByText('Source libre')).toHaveCount(0)
const filteredId = await entryId(page)
if (!isPhone(info)) {
// 5: « Modifier » a tile: the dialog is a layer above the filtered tab, one entry.
await headers(page).first().click()
await libraryRoot(page)
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
const form = referenceDialog(page)
await expect(form).toBeVisible()
await entryHolds(page, 'view.reference !== null')
await form
.getByLabel(dict['editor.reference.citation'])
.fill('Référence A bis')
await form
.getByRole('button', { name: dict['editor.findings.save'] })
.click()
await expectNoDialog(page)
await referenceSettled(page)
// One command, one undo; the entry on top is the filtered tab again, no orphan.
await expect(undo(page)).toHaveAttribute('aria-disabled', 'false')
expect(await entryId(page)).toBe(filteredId)
await expect(chip(page)).toBeVisible()
}
// 6: Back lands on finding A with its sheet open and on top; Forward, on the filter.
await page.goBack()
await expect(dialogs(page)).toHaveCount(2)
expect(await sheetOnTop(page)).toBe(true)
await expect(findingDialog(page)).toBeVisible()
await page.goForward()
await expectNoDialog(page)
await expect(chip(page)).toBeVisible()
await expect(headers(page)).toHaveCount(2)
// 7: « Revenir au constat » pops to the dialog with its sheet (the entry below shows it).
await page
.getByRole('button', { name: dict['editor.references.filter_back'] })
.click()
await expect(dialogs(page)).toHaveCount(2)
expect(await sheetOnTop(page)).toBe(true)
await entryHolds(page, 'view.finding && view.finding.citations')
// 8: every Back down to the first entry: sheet, dialog, tab, drawing, then it leaves.
await page.goBack()
await expect(dialogs(page)).toHaveCount(1)
await expect(findingDialog(page)).toBeVisible()
await page.goBack()
await expectNoDialog(page)
await expect(place(page, 'findings')).toBeVisible()
await page.goBack()
await expect(page.getByRole('tab', { selected: true })).toHaveText(
new RegExp(`^${dict['editor.tab.annotations']}`),
)
const here = page.url()
await page.goBack()
await expect.poll(() => page.url()).not.toBe(here)
})
test('a reload keeps the filtered tab and the chip, never a form; Back then returns to the sheet', async ({
page,
}) => {
test.setTimeout(150_000)
await open(page)
await filteredTab(page)
await page.reload()
await expect(place(page, 'references')).toBeVisible()
await expect(chip(page)).toContainText('Constat A')
await expect(headers(page)).toHaveCount(2)
await page.goBack()
await expect(dialogs(page)).toHaveCount(2)
expect(await sheetOnTop(page)).toBe(true)
})
test('the × removes the filter by replace; the search text is not in the history', async ({
page,
}) => {
test.setTimeout(150_000)
await open(page)
await filteredTab(page)
const id = await entryId(page)
await libraryRoot(page).getByRole('searchbox').fill('Référence')
await chip(page)
.getByRole('button', {
name: dict['editor.references.filter_remove'].replace(
'{name}',
'Constat A',
),
})
.click()
await entryHolds(page, 'view.referenceFilter === null')
expect(await entryId(page)).toBe(id)
expect(
await page.evaluate(() => JSON.stringify(history.state?.usr)),
).not.toContain('Référence')
// The search is a personal one: removing the filter keeps it (two titles start with it).
await expect(headers(page)).toHaveCount(2)
await expect(chip(page)).toHaveCount(0)
})
})
test.describe('the reference dialog and the 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; the reading journey above runs at 375
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
})
/** The References tab with the dialog of the first tile open on its pushed entry. */
async function dialogOpen(page: Page) {
await open(page)
await openTab(page, dict, 'references')
await entryHolds(page, "view.tab === 'references'")
const base = await entryId(page)
await headers(page).first().click()
await libraryRoot(page)
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
await expect(referenceDialog(page)).toBeVisible()
await entryHolds(page, 'view.reference !== null')
return base
}
test('a double click on ✕ and on « Enregistrer » pops at most one entry', async ({
page,
}) => {
test.setTimeout(150_000)
const base = await dialogOpen(page)
const form = referenceDialog(page)
await form
.getByRole('button', { name: dict['common.close'], exact: true })
.dblclick()
await expectNoDialog(page)
await referenceSettled(page)
expect(await entryId(page)).toBe(base)
await libraryRoot(page)
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
await entryHolds(page, 'view.reference !== null')
await form
.getByLabel(dict['editor.reference.citation'])
.fill('Référence A bis')
await form
.getByRole('button', { name: dict['editor.findings.save'] })
.dblclick()
await expectNoDialog(page)
await referenceSettled(page)
expect(await entryId(page)).toBe(base)
// One command: one « Défaire » restores the citation.
await expect(libraryRoot(page).getByText('Référence A bis')).toBeVisible()
await undo(page).click()
await expect(libraryRoot(page).getByText('Référence A bis')).toHaveCount(0)
await expect(undo(page)).toHaveAttribute('aria-disabled', 'true')
})
test('a held Escape closes a pristine dialog and pops at most one entry', async ({
page,
}) => {
test.setTimeout(150_000)
const base = await dialogOpen(page)
await page.keyboard.down('Escape')
await page.keyboard.down('Escape')
await page.keyboard.down('Escape')
await page.keyboard.up('Escape')
await expectNoDialog(page)
await referenceSettled(page)
expect(await entryId(page)).toBe(base)
await expect(place(page, 'references')).toBeVisible()
})
test('a real dialog.close() on a dirty dialog keeps it, with its confirmation', async ({
page,
}) => {
test.setTimeout(150_000)
await dialogOpen(page)
const form = referenceDialog(page)
await form.getByLabel(dict['editor.reference.doi']).fill('10.1000/x')
await page.evaluate(() => {
const open = [...document.querySelectorAll('dialog[open]')]
;(open.at(-1) as HTMLDialogElement).close()
})
await expect(form).toBeVisible()
await expect(
form.getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await expect(form.getByLabel(dict['editor.reference.doi'])).toHaveValue(
'10.1000/x',
)
})
test('a dirty dialog keeps its draft on Back, one step and a jump across tabs', async ({
page,
}) => {
test.setTimeout(180_000)
await open(page)
await openTab(page, dict, 'findings')
await entryHolds(page, "view.tab === 'findings'")
await openTab(page, dict, 'references')
await entryHolds(page, "view.tab === 'references'")
await headers(page).first().click()
await libraryRoot(page)
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
await entryHolds(page, 'view.reference !== null')
const form = referenceDialog(page)
const doi = form.getByLabel(dict['editor.reference.doi'])
await doi.fill('10.1000/x')
const top = await entryId(page)
await page.goBack()
await expect(
form.getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await expect(doi).toHaveValue('10.1000/x')
await form
.getByRole('button', { name: dict['editor.findings.keep_typing'] })
.click()
// The refused Back pushed the view again: a jump of two entries is refused the same way.
await entryHolds(page, 'view.reference !== null')
await page.evaluate(() => history.go(-2))
await expect(
form.getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await expect(doi).toHaveValue('10.1000/x')
await expect(form).toBeVisible()
expect(await entryId(page)).not.toBe(top)
await entryHolds(page, 'view.reference !== null')
})
})