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

+63 -31
View File
@@ -19,6 +19,8 @@ import {
openFinding,
openTab,
place,
referenceDialog,
referenceSettled,
saveDraft,
seedDraft,
serverDocument,
@@ -251,9 +253,13 @@ test.describe('citations sheet, editing', () => {
await expect(
root.getByRole('button', { name: /Source B/ }),
).toHaveAttribute('aria-expanded', 'true')
// Filtered by the finding the sheet belonged to: its three citations (R2F-6).
await expect(
root.locator('button[aria-controls][id$="-header"]'),
).toHaveCount(4)
).toHaveCount(3)
await expect(root.getByTestId('editor-references-filter')).toContainText(
'Constat A',
)
// The move is an entry of its own: Back returns to the finding with its sheet on top.
await page.goBack()
await expect(place(page, 'citations')).toBeVisible()
@@ -264,26 +270,42 @@ test.describe('citations sheet, editing', () => {
await expect(place(page, 'references')).toBeVisible()
})
test('Escape in a field of a tile neither closes the sheet nor commits; ✕ then commits', async ({
test('« Modifier » opens the reference dialog over the sheet; « Enregistrer » closes it only, one undo', 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'])
const modify = panel(page).getByRole('button', {
name: dict['editor.references.edit'],
})
await modify.click()
await expect(referenceDialog(page)).toBeVisible()
await expect(page.locator('dialog[open]')).toHaveCount(3)
const field = referenceDialog(page).getByLabel(
dict['editor.reference.citation'],
)
await field.fill('Référence A, révisée')
// Escape asks (the draft is kept), it neither closes the sheet nor writes.
await field.press('Escape')
await expect(panel(page)).toBeVisible()
await expect(field).toHaveValue('Référence A, révisée')
// A user close applies a valid draft first (P22''), then the sheet exits.
await panel(page)
.getByRole('button', { name: dict['editor.references.close'] })
await expect(
referenceDialog(page).getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await expect(page.locator('dialog[open]')).toHaveCount(3)
await referenceDialog(page)
.getByRole('button', { name: dict['editor.findings.keep_typing'] })
.click()
await expect(panel(page)).toHaveCount(0)
await expect(field).toHaveValue('Référence A, révisée')
await referenceDialog(page)
.getByRole('button', { name: dict['editor.findings.save'] })
.click()
await expect(referenceDialog(page)).toHaveCount(0)
await referenceSettled(page)
await expect(panel(page)).toBeVisible()
await expect(page.locator('dialog[open]')).toHaveCount(2)
await expect(modify).toBeFocused()
await closeCitations(page, dict)
await closeFinding(page, dict)
await expect(undo(page)).toBeEnabled()
await saveDraft(page, dict, seed.revision + 1)
@@ -293,7 +315,7 @@ test.describe('citations sheet, editing', () => {
expect(saved.references[0].citation).toBe('Référence A, révisée')
})
test('a refused draft cancels every move that unmounts the sheet: ✕, scrim, Back, « Tout afficher »', async ({
test('a dirty reference dialog keeps its draft on ✕ and on Back; « Abandonner » leaves the sheet open', async ({
page,
}) => {
test.setTimeout(150_000)
@@ -303,28 +325,38 @@ test.describe('citations sheet, editing', () => {
await panel(page)
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
const field = panel(page).getByLabel(dict['editor.reference.citation'])
await field.fill('')
await panel(page)
.getByRole('button', { name: dict['editor.references.close'] })
const form = referenceDialog(page)
const field = form.getByLabel(dict['editor.reference.citation'])
await field.fill('Brouillon')
await form
.getByRole('button', { name: dict['common.close'], exact: true })
.click()
await expect(panel(page)).toBeVisible()
await expect(field).toBeFocused()
await expect(panel(page).getByRole('alert')).toBeVisible()
await page
.getByTestId('references-scrim')
.click({ position: { x: 4, y: 40 } })
await expect(panel(page)).toBeVisible()
await link(page).click()
await expect(panel(page)).toBeVisible()
await expect(page.getByRole('tab', { selected: true })).toHaveText(
new RegExp(`^${dict['editor.tab.findings']}`),
)
// Back: the page stays, the view is pushed again, the refusal shows.
await expect(
form.getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await form
.getByRole('button', { name: dict['editor.findings.keep_typing'] })
.click()
// Back: the dialog stays, the view is pushed again, the confirmation shows.
await page.goBack()
await expect(form).toBeVisible()
await expect(
form.getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await expect(field).toHaveValue('Brouillon')
await form
.getByRole('button', { name: dict['editor.findings.keep_typing'] })
.click()
await form
.getByRole('button', { name: dict['editor.findings.cancel'] })
.click()
await form
.getByRole('button', { name: dict['editor.findings.discard'] })
.click()
await expect(referenceDialog(page)).toHaveCount(0)
await expect(panel(page)).toBeVisible()
await expect(findingDialog(page)).toBeVisible()
await expect(panel(page).getByRole('alert')).toBeVisible()
await expect(undo(page)).toHaveAttribute('aria-disabled', 'true')
})
test('the exiting sheet is inert, and a second close finds nothing to close', async ({
@@ -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')
})
})
+130 -131
View File
@@ -9,22 +9,27 @@ import {
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
editorActor,
expectNoDialog,
historyButton,
libraryRoot,
openEditor,
openTab,
place,
referenceDialog,
referenceSettled,
saveDraft,
seedDraft,
serverDocument,
serverRevision,
standardShape,
startReference,
} from '../support/editor'
// V1-2.6 R2.2: the collapsible reference tiles of the Références tab (boards 23, 24, 27):
// closed, open and edit states with axe on each, the keyboard walk through the tile
// headers, the leave guard of the edit view, and the read-only twin at 375 px. The spec
// seeds its own sheet and never touches another.
// V1-2.6 R2.2 and R2F-5: the collapsible reference tiles of the Références tab (boards 23,
// 24, 27): closed and open states with axe on each, the reference dialog (« Modifier »,
// « Ajouter ») with axe, the keyboard walk through the tile headers, the dialog's draft
// and its read-only flip, and the read-only twin at 375 px. The spec seeds its own sheet
// and never touches another.
const dict = fr
@@ -79,7 +84,7 @@ const REF_DOI = 1
const REF_A = 0
const REF_FREE = 2
test.describe('reference tiles, edit mode', () => {
test.describe('reference tiles and the reference dialog', () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
test.beforeEach(async ({ context }, info) => {
test.skip(
@@ -92,7 +97,7 @@ test.describe('reference tiles, edit mode', () => {
await dropLateReplays(context)
})
test('closed, open and edit tiles, accessible in each state', async ({
test('closed and open tiles, then the reference dialog, accessible in each state', async ({
page,
requests,
}) => {
@@ -139,23 +144,30 @@ test.describe('reference tiles, edit mode', () => {
).toBeVisible()
await expectAccessible(page, 'the open reference tiles')
// Edit: the title, the focused citation, « Terminer » only.
await cited
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
// « Modifier » opens the dialog: named, over the page, accessible; the tile has no field.
const modify = cited.getByRole('button', {
name: dict['editor.references.edit'],
})
await modify.click()
const form = referenceDialog(page)
await expect(form).toBeVisible()
await expect(
cited.getByText(dict['editor.references.edit_title']),
form.getByRole('heading', { name: dict['editor.references.edit_title'] }),
).toBeVisible()
await expect(form.locator(':focus')).toHaveCount(1)
await expect(
cited.getByLabel(dict['editor.reference.citation']),
).toBeFocused()
await expect(
cited.getByRole('button', { name: dict['editor.action.move_up'] }),
).toHaveCount(0)
await expectAccessible(page, 'a reference tile in edit')
await expectAccessible(page, 'the reference dialog')
await form
.getByRole('button', { name: dict['editor.findings.cancel'] })
.click()
await expectNoDialog(page)
await referenceSettled(page)
await expect(modify).toBeFocused()
})
test('« Terminer » keeps the edit view while a field is refused', async ({
test('« Enregistrer » refuses a bad address on its field, then saves one command', async ({
page,
}) => {
test.setTimeout(120_000)
@@ -166,29 +178,26 @@ test.describe('reference tiles, edit mode', () => {
await tile
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
const url = tile.getByLabel(dict['editor.reference.url'])
const form = referenceDialog(page)
const url = form.getByLabel(dict['editor.reference.url'])
await url.fill('exemple.org')
await tile
.getByRole('button', {
name: dict['editor.references.done'],
exact: true,
})
await form
.getByRole('button', { name: dict['editor.findings.save'] })
.click()
await expect(url).toBeFocused()
await expect(
tile.getByRole('button', {
name: dict['editor.references.done'],
exact: true,
}),
).toBeVisible()
await expect(url).toHaveAccessibleDescription(
dict['editor.reference.url_invalid'],
)
await expect(historyButton(page, dict, 'undo')).toHaveAttribute(
'aria-disabled',
'true',
)
await url.fill('https://exemple.org/page')
await tile
.getByRole('button', {
name: dict['editor.references.done'],
exact: true,
})
await form
.getByRole('button', { name: dict['editor.findings.save'] })
.click()
await expect(tile.getByLabel(dict['editor.reference.url'])).toHaveCount(0)
await expectNoDialog(page)
await referenceSettled(page)
await expect(
tile.getByRole('link', { name: /exemple\.org/ }),
).toHaveAttribute('href', 'https://exemple.org/page')
@@ -363,7 +372,7 @@ test.describe('reference tiles, search, sort and add', () => {
expect(await serverRevision(seed.draftId)).toBe(revision)
})
test('add a reference, save it, then delete an uncited one', async ({
test('add a reference: the list stays, a notice offers « Afficher »; then delete an uncited one', async ({
page,
requests,
}) => {
@@ -374,28 +383,36 @@ test.describe('reference tiles, search, sort and add', () => {
const bar = toolbar(page)
await bar.sort.selectOption('count')
await bar.search.fill('alpha')
await libraryRoot(page)
.getByRole('button', { name: dict['editor.references.add'] })
.click()
await expect(bar.search).toHaveValue('')
await expect(bar.sort).toHaveValue('sheet')
const citation = libraryRoot(page).getByLabel(
dict['editor.reference.citation'],
)
await expect(citation).toBeFocused()
// The focus scrolled the toolbar under the sticky header: axe judges what is covered.
await libraryRoot(page).getByRole('searchbox').scrollIntoViewIfNeeded()
await expectAccessible(page, 'the draft tile')
await libraryRoot(page)
.getByLabel(dict['editor.reference.type'])
.selectOption('manual')
await citation.fill('Nouvelle source')
await libraryRoot(page)
await startReference(page, dict)
// The dialog is a layer over the page: the search and the sort are untouched.
await expect(bar.search).toHaveValue('alpha')
await expect(bar.sort).toHaveValue('count')
const form = referenceDialog(page)
await expectAccessible(page, 'the creation dialog')
await form.locator('#reference-form-type').selectOption('manual')
await form.locator('#reference-form-citation').fill('Nouvelle source')
await form
.getByRole('button', { name: dict['editor.reference.add'] })
.click()
await expectNoDialog(page)
await referenceSettled(page)
await expect(headers(page)).toHaveCount(1)
const notice = libraryRoot(page).getByText(
dict['editor.references.added'].replace('{citation}', 'Nouvelle source'),
)
await expect(notice).toBeVisible()
await expect(
libraryRoot(page).getByRole('button', {
name: dict['editor.references.add'],
}),
).toBeFocused()
await libraryRoot(page)
.getByRole('button', { name: dict['editor.references.added_show'] })
.click()
await expect(notice).toHaveCount(0)
await expect(bar.search).toHaveValue('')
await expect(headers(page)).toHaveCount(5)
const added = headers(page).last()
await expect(added).toContainText('Nouvelle source')
const added = headers(page).filter({ hasText: 'Nouvelle source' })
await expect(added).toHaveAttribute('aria-expanded', 'true')
await expect(added).toBeFocused()
await saveDraft(page, dict, seed.revision + 1)
@@ -408,6 +425,7 @@ test.describe('reference tiles, search, sort and add', () => {
])
// Delete an uncited reference (Étude): the dialog confirms, the tile goes.
await bar.sort.selectOption('sheet')
await headers(page).nth(3).click()
await tileAt(page, 3)
.getByRole('button', { name: dict['editor.action.delete'] })
@@ -420,7 +438,7 @@ test.describe('reference tiles, search, sort and add', () => {
await expect(libraryRoot(page).getByText('Étude')).toHaveCount(0)
})
test("« Annuler l'ajout » and Escape drop the draft and write nothing", async ({
test('« Annuler » and Escape ask before they drop a typed draft, and write nothing', async ({
page,
requests,
}) => {
@@ -434,61 +452,41 @@ test.describe('reference tiles, search, sort and add', () => {
})
const count = await headers(page).count()
const states = async () => [
await historyButton(page, dict, 'undo').isEnabled(),
await historyButton(page, dict, 'redo').isEnabled(),
await historyButton(page, dict, 'undo').getAttribute('aria-disabled'),
await historyButton(page, dict, 'redo').getAttribute('aria-disabled'),
]
const before = await states()
const draft = root.getByRole('region', {
name: dict['editor.reference.new'],
})
const type = root.getByLabel(dict['editor.reference.type'])
await add.click()
await type.selectOption('manual')
await root.getByLabel(dict['editor.reference.citation']).fill('Brouillon')
await root
.getByRole('button', { name: dict['editor.references.add_cancel'] })
await startReference(page, dict)
const form = referenceDialog(page)
await form.locator('#reference-form-type').selectOption('manual')
await form.locator('#reference-form-citation').fill('Brouillon')
await form
.getByRole('button', { name: dict['editor.findings.cancel'] })
.click()
await expect(draft).toHaveCount(0)
await expect(headers(page)).toHaveCount(count)
await expect(add).toBeFocused()
expect(await states()).toEqual(before)
// A typed draft, then Escape on the type select (not a text target): it cancels.
await add.click()
await root.getByLabel(dict['editor.reference.citation']).fill('Brouillon')
await type.focus()
await expect(
form.getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await form
.getByRole('button', { name: dict['editor.findings.keep_typing'] })
.click()
await expect(form.locator('#reference-form-citation')).toHaveValue(
'Brouillon',
)
await page.keyboard.press('Escape')
await expect(draft).toHaveCount(0)
await expect(
form.getByText(dict['editor.findings.discard_ask']),
).toBeVisible()
await form
.getByRole('button', { name: dict['editor.findings.discard'] })
.click()
await expectNoDialog(page)
await referenceSettled(page)
await expect(headers(page)).toHaveCount(count)
await expect(add).toBeFocused()
expect(await states()).toEqual(before)
})
test('a tile in edit keeps its place under a sort and under a search', async ({
page,
requests,
}) => {
test.setTimeout(150_000)
const { actor } = await open(page, sortShape)
requests.forbid(actor.account.email, actor.account.password)
await openTab(page, dict, 'references')
const bar = toolbar(page)
await bar.sort.selectOption('citation')
await headers(page).nth(3).click()
await tileAt(page, 3)
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
await bar.sort.selectOption('count')
await expect(
tileAt(page, 3).getByLabel(dict['editor.reference.citation']),
).toBeVisible()
await bar.search.fill('alpha')
await expect(headers(page)).toHaveCount(2)
await expect(
libraryRoot(page).getByLabel(dict['editor.reference.citation']),
).toBeVisible()
})
test('a tile edited out of the search stays after « Terminer », with its line, until the next search', async ({
test('a tile edited out of the search stays after « Enregistrer », with its line, until the next search', async ({
page,
requests,
}) => {
@@ -505,14 +503,12 @@ test.describe('reference tiles, search, sort and add', () => {
await tile
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
const citation = tile.getByLabel(dict['editor.reference.citation'])
await citation.fill('Autre titre')
await tile
.getByRole('button', {
name: dict['editor.references.done'],
exact: true,
})
const form = referenceDialog(page)
await form.getByLabel(dict['editor.reference.citation']).fill('Autre titre')
await form
.getByRole('button', { name: dict['editor.findings.save'] })
.click()
await expectNoDialog(page)
await expect(
tile.getByText(dict['editor.references.outside_search']),
).toBeVisible()
@@ -523,42 +519,45 @@ test.describe('reference tiles, search, sort and add', () => {
await expect(headers(page)).toHaveCount(0)
})
test('a refused draft is never dropped silently by a read-only flip', async ({
test('a draft is never dropped by a read-only flip: the dialog keeps it, read-only, with its notice', async ({
page,
}) => {
test.setTimeout(150_000)
await open(page)
await openTab(page, dict, 'references')
const bar = toolbar(page)
await headers(page).nth(REF_DOI).click()
const tile = libraryRoot(page)
.locator('button[id$="-ref-doi-header"]')
.locator('xpath=ancestor::li[1]')
await tile
await tileAt(page, REF_DOI)
.getByRole('button', { name: dict['editor.references.edit'] })
.click()
await bar.search.fill('libre')
const url = tile.getByLabel(dict['editor.reference.url'])
const form = referenceDialog(page)
const url = form.getByLabel(dict['editor.reference.url'])
await url.fill('exemple.org')
const note = dict['editor.references.draft_dropped'].replace(
'{field}',
dict['editor.reference.url'],
)
const size = page.viewportSize() ?? { width: 1280, height: 900 }
await page.setViewportSize({ width: 800, height: size.height })
await expect(tile.getByText(note)).toBeVisible()
await expect(page.locator('p.sr-only[aria-live="polite"]')).toHaveText(note)
await expect(url).toHaveCount(0)
await expect(form).toBeVisible()
await expect(url).toHaveAttribute('readonly', '')
await expect(url).toHaveValue('exemple.org')
await expect(
form.getByText(dict['editor.findings.flip_narrow']),
).toBeVisible()
await expect(
form.getByRole('button', { name: dict['editor.findings.save'] }),
).toBeDisabled()
await page.setViewportSize(size)
await expect(tile.getByText(note)).toBeVisible()
await expect(url).toHaveValue(`https://doi.org/${DOI}`)
await tile
.getByRole('button', {
name: dict['editor.references.done'],
exact: true,
})
await expect(url).not.toHaveAttribute('readonly', '')
await expect(url).toHaveValue('exemple.org')
await form
.getByRole('button', { name: dict['editor.findings.cancel'] })
.click()
await expect(tile.getByText(note)).toHaveCount(0)
await form
.getByRole('button', { name: dict['editor.findings.discard'] })
.click()
await expectNoDialog(page)
await expect(
tileAt(page, REF_DOI)
.getByRole('link', { name: new RegExp(DOI) })
.first(),
).toBeVisible()
})
})
@@ -8,9 +8,9 @@ import {
closeFinding,
copyKeyOf,
editorActor,
expectNoDialog,
geometryField,
historyButton,
libraryRoot,
openEditor,
openCitations,
openTab,
@@ -23,6 +23,7 @@ import {
selectTab,
shapeWith,
standardShape,
startReference,
storedCopy,
UNSAVED_LINE,
} from '../support/editor'
@@ -217,21 +218,37 @@ test.describe('editor shell, width crossing (H)', () => {
)
})
test('the references form keeps its typed text, in the Références tab', async ({
test('the reference dialog stays while narrow: draft, focus and a notice kept (R2F-5)', async ({
page,
}) => {
await open(page)
await openTab(page, dict, 'references')
await startReference(page, dict)
const field = page.locator('#reference-form-citation')
await field.fill('Saisie')
await expect(field).toBeFocused()
await page.setViewportSize(NARROW)
await expect(field).toBeVisible()
await expect(field).toHaveAttribute('readonly', '')
await expect(field).toHaveValue('Saisie')
await expect(field).toBeFocused()
await expect(
page.getByText(dict['editor.findings.flip_narrow']),
).toBeVisible()
await expect(
page.getByRole('button', { name: dict['editor.reference.add'] }),
).toBeDisabled()
await page.setViewportSize(WIDE)
await expect(field).not.toHaveAttribute('readonly', '')
await expect(field).toHaveValue('Saisie')
await expect(field).toBeFocused()
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
await page.keyboard.press('Escape')
await page
.getByRole('button', { name: dict['editor.references.add'] })
.locator('dialog[open]')
.getByRole('button', { name: dict['editor.findings.discard'] })
.click()
await keepsTypedValue(
page,
page.locator('#tab-reference-new-citation'),
dict['editor.reference.add'],
'references',
)
await expect(libraryRoot(page).getByRole('searchbox')).toBeVisible()
await expectNoDialog(page)
})
test('the annotation edit body keeps its tool and its pending creation', async ({
+8 -16
View File
@@ -3,6 +3,7 @@ import type { Locator, Page, TestInfo } from '@playwright/test'
import { expect, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
addReference,
backToDrawing,
copyKeyOf,
storedCopy,
@@ -94,20 +95,18 @@ test.describe('editor shell, kept places (B2a)', () => {
expect(await layerTransform(page)).toBe(zoomed)
})
test('the Références tab keeps its form text and no id repeats, panel open included', async ({
test('the Références tab keeps its search and no id repeats, panel open included', async ({
page,
}) => {
await open(page)
await openTab(page, dict, 'references')
await page
.getByRole('button', { name: dict['editor.references.add'] })
.click()
await page.locator('#tab-reference-new-citation').fill('Smith 1999')
const search = page.getByRole('searchbox', {
name: dict['editor.references.search'],
})
await search.fill('Smith 1999')
await openTab(page, dict, 'general')
await openTab(page, dict, 'references')
await expect(page.locator('#tab-reference-new-citation')).toHaveValue(
'Smith 1999',
)
await expect(search).toHaveValue('Smith 1999')
for (const tab of ['general', 'findings', 'verification']) {
await selectTab(page, dict, tab)
}
@@ -133,14 +132,7 @@ test.describe('editor shell, kept places (B2a)', () => {
await open(page)
// An edit first, so « Enregistrer » is enabled: a reference added in its tab.
await openTab(page, dict, 'references')
await page
.getByRole('button', { name: dict['editor.references.add'] })
.click()
await page.locator('#tab-reference-new-type').selectOption('book')
await page.locator('#tab-reference-new-citation').fill('Smith 1999')
await page
.getByRole('button', { name: dict['editor.reference.add'] })
.click()
await addReference(page, dict, 'Smith 1999')
await openCitations(page, dict, 'Constat A')
const targets = [
page.getByRole('button', { name: dict['common.save'], exact: true }),
+6 -16
View File
@@ -3,6 +3,7 @@ import type { Locator, Page, TestInfo } from '@playwright/test'
import { expect, expectAccessible, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
addReference,
bareShape,
closeFinding,
editorActor,
@@ -85,17 +86,10 @@ test.describe('editor structures (A4)', () => {
// « Référence A » stays first: it is cited by « Constat A »).
await openTab(page, dict, 'references')
for (const citation of ['Première référence', 'Seconde référence']) {
await page
.getByRole('button', { name: dict['editor.references.add'] })
.click()
await page.locator('#tab-reference-new-type').selectOption('book')
await page.locator('#tab-reference-new-citation').fill(citation)
await page
.getByRole('button', { name: dict['editor.reference.add'] })
.click()
await addReference(page, dict, citation)
await expect(
page.getByRole('button', { name: new RegExp(`^${citation}`) }),
).toBeFocused()
).toBeVisible()
}
const tiles = page.locator('[id^="tab-reference-"][id$="-header"]')
const tileOf = (citation: string) =>
@@ -112,17 +106,13 @@ test.describe('editor structures (A4)', () => {
await expect(tiles).toHaveCount(1)
await search.fill('')
await expect(tiles).toHaveCount(3)
// An added tile stays open (P24): no click, a click would close it.
await expect(
tiles.filter({ hasText: 'Seconde référence' }),
).toHaveAttribute('aria-expanded', 'true')
// An added tile is closed (the list does not move, R2F-5): open it, then move it.
await tiles.filter({ hasText: 'Seconde référence' }).click()
await tileOf('Seconde référence')
.getByRole('button', { name: dict['editor.action.move_up'] })
.click()
await expect(tiles.nth(1)).toContainText('Seconde référence')
await expect(
tiles.filter({ hasText: 'Première référence' }),
).toHaveAttribute('aria-expanded', 'true')
await tiles.filter({ hasText: 'Première référence' }).click()
await tileOf('Première référence')
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
+49 -2
View File
@@ -427,11 +427,58 @@ export async function openTab(page: Page, dict: Dict, tab: string) {
).toBeVisible()
}
/** The open finding dialog: the layer dialog that is not the citations sheet. */
/** The open finding dialog: the layer dialog that is neither the sheet nor the reference form. */
export const findingDialog = (page: Page): Locator =>
page.locator('dialog[open][data-layer]').filter({
hasNot: page.locator('[data-place="citations"], #reference-form-citation'),
})
/** The open reference dialog (R2F-5): the layer dialog that holds the reference form. */
export const referenceDialog = (page: Page): Locator =>
page
.locator('dialog[open][data-layer]')
.filter({ hasNot: page.locator('[data-place="citations"]') })
.filter({ has: page.locator('#reference-form-citation') })
/**
* Waits for the history to settle on a view without the reference layer (or, with
* `keepDialog`, with one): a close pops its entry from an effect, and a move made before
* the pop lands would be undone by it (a user cannot be that quick, a script can).
*/
export async function referenceSettled(page: Page, keepDialog = false) {
await page.waitForFunction((stays) => {
const view = history.state?.usr?.editorEntry?.view
if (!view) return true
return stays ? view.reference !== null : view.reference === null
}, keepDialog)
}
/** Opens « Ajouter une référence » (the References tab is shown): the form is ready. */
export async function startReference(page: Page, dict: Dict) {
await libraryRoot(page)
.getByRole('button', { name: dict['editor.references.add'] })
.click()
await expect(referenceDialog(page)).toBeVisible()
}
/**
* Creates a reference through the dialog and waits for every layer to be gone. The list
* does not move and the focus goes back to « Ajouter » (R2F-5): nothing is focused on the
* new tile.
*/
export async function addReference(
page: Page,
dict: Dict,
citation: string,
type = 'book',
) {
await startReference(page, dict)
const form = referenceDialog(page)
await form.locator('#reference-form-type').selectOption(type)
await form.locator('#reference-form-citation').fill(citation)
await form.getByRole('button', { name: dict['editor.reference.add'] }).click()
await expectNoDialog(page)
await referenceSettled(page)
}
/** Waits until no modal dialog is open: nothing is typed or pressed before (LRN-111/116). */
export const expectNoDialog = (page: Page) =>