Files
faunosteo/apps/app/e2e/shell/editor-journey.spec.ts
T
bchanot 99b669bf8f feat(editor): header history, save line and Abandonner les modifications
Header Annuler/Retablir on every tab (aria-disabled, commit on pointerdown,
refused blur commit skips the undo). Save line: unsaved count selector
(savedDistance), saveLineState forms, server save time via readSaveTime
(lastSave in the store, never the browser clock). Discard relabelled and
names the stored copy. Tool column pair removed, glyphs in EditorGlyph.

Rewritten or removed assertions (R-24):
- editor-route.test: Revision 3 / unsaved text / Annuler les modifications
  -> save-line testid, Abandonner label, copy sentence in the dialog
- editor-route-conflict, editor-route-recovery: Revision n and copy_cap/
  copy_quota text queries -> save-line testid
- editor-no-loss: discard button label
- editor-annotations-tab: tool column undo/redo test -> no pair left
  (behaviour moved to editor-history-buttons.test)
- e2e journey/annotations/recovery/structures/support saveDraft/lan:
  undo/redo and revision/unsaved text -> historyButton, saveLine helpers;
  structures toHaveCount(0) on old text -> exact Revision n line
- editor-shell clickability: header Annuler/Retablir added
2026-11-08 17:55:49 +01:00

412 lines
16 KiB
TypeScript

import { fr } from '@/i18n/fr'
import type { Locator, Page, TestInfo } from '@playwright/test'
import { sql } from '../../../../packages/supabase/tests/sandbox/stack'
import { stepUpAdmin } from '../support/admin'
import { expect, expectAccessible, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
clickDrawing,
createFromPanel,
creationPanel,
editorActor,
fillCreation,
geometryField,
historyButton,
INKSCAPE_EXPORT,
openDraft,
openSection,
pickAnnotation,
place,
revisionText,
savedLine,
saveDraft,
saveLine,
secondSession,
selectionTag,
selectTab,
serverDocument,
showDrawing,
toolButton,
UNSAVED_LINE,
} from '../support/editor'
import { signIn } from '../support/shell'
// V1-2.6 journey (contract C26 to C30; the steps of docs/development/V1-2-6_OWNER_TRIAL.md
// §4, with two editor accounts): a non-equine sheet created from the administration,
// a drawing, a detail view, findings, categories, points, zones and a link, the save,
// a reload with the beforeunload dialog and the recovery offer, a conflict with the
// other account, the submission and the round read back in SQL.
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const main = (page: Page) => page.getByRole('main')
async function commitText(field: Locator, value: string) {
await field.fill(value)
await field.press('Enter')
}
const clickDialog = (dialog: Locator, name: string) =>
dialog.getByRole('button', { name, exact: true }).click()
const clickButton = (page: Page, name: string) =>
page.getByRole('button', { name, exact: true }).click()
async function createSheetFromAdmin(page: Page, tag: string): Promise<string> {
await page
.locator('section[aria-labelledby="admin-sheets-title"]')
.getByRole('link', { name: dict['admin.home.all_sheets'] })
.click()
await main(page).getByRole('link', { name: dict['admin.sheets.new'] }).click()
// The list page has a species filter with the same label: wait for the form's heading.
await expect(
main(page).getByRole('heading', {
level: 1,
name: dict['admin.sheets.new'],
}),
).toBeVisible()
const species = page.getByLabel(dict['admin.sheet_form.species'], {
exact: true,
})
await expect(species.locator('option[value="canine"]')).toHaveCount(1)
await species.selectOption('canine')
await expect(species).toHaveValue('canine')
await page.getByLabel(dict['admin.sheet_form.name_fr']).fill(`Chien ${tag}`)
await page.getByLabel(dict['admin.sheet_form.name_en']).fill(`Dog ${tag}`)
await page
.getByRole('button', { name: dict['admin.sheet_form.submit'] })
.click()
// The creation opens the new draft in the editor directly (the guide's 4.1 says the
// sheet « apparaît » and is « ouvrable dans l'éditeur »: no overview step).
await expect(page).toHaveURL(/\/app\/admin\/sheets\/[0-9a-f-]{36}\/draft$/)
const id = new URL(page.url()).pathname.split('/')[4] ?? ''
await expect(
page.getByRole('heading', { level: 1, name: 'Brouillon, version 1' }),
).toBeVisible()
return id
}
async function importDrawing(page: Page) {
await openSection(page, dict, 'views')
// The real Inkscape 1.4.3 export, cleaned by the core in the page (viewBox 0 0 200 150).
await page.getByTestId('view-view-main-file').setInputFiles({
name: 'inkscape-1.4.3.svg',
mimeType: 'image/svg+xml',
buffer: INKSCAPE_EXPORT,
})
await clickButton(page, dict['editor.cleaning.confirm'])
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
// The closing modal keeps the page inert until its exit animation ends: text typed
// before that is dropped (the first fields of the new-view form stayed empty).
await expect(
page.getByRole('dialog', { name: dict['editor.cleaning.title'] }),
).toHaveCount(0)
await page.locator('#view-new-fr').fill('Détail essai')
await page.locator('#view-new-en').fill('Trial detail')
const crop = { min_x: '20', min_y: '20', width: '60', height: '45' }
for (const [key, value] of Object.entries(crop))
await page.locator(`#view-new-crop-${key}`).fill(value)
await clickButton(page, dict['editor.views.add'])
await expect(
page.getByRole('listitem', { name: 'Détail essai' }),
).toBeVisible()
}
async function createFindings(page: Page) {
await openSection(page, dict, 'categories')
await page.locator('#category-new-fr').fill('Catégorie essai')
await page.locator('#category-new-en').fill('Trial category')
await clickButton(page, dict['editor.general.category_add'])
await selectTab(page, dict, 'findings')
const create = () => clickButton(page, dict['editor.findings.create'])
const names = async (frName: string, enName: string) => {
await page.locator('#finding-new-name-fr').fill(frName)
await page.locator('#finding-new-name-en').fill(enName)
}
await clickButton(page, dict['editor.findings.add_zone'])
await names('Zone essai', 'Trial zone')
await create()
await clickButton(page, dict['editor.findings.add_category'])
await page.locator('#finding-new-zone').selectOption({ label: 'Zone essai' })
await page.locator('#finding-new-kind').selectOption('dysfunction')
await names('Dysfonction essai', 'Trial dysfunction')
await create()
await clickButton(page, dict['editor.findings.add_node'])
await names('Constat essai', 'Trial finding')
await create()
await expect(
page.getByTestId('finding-item').filter({ hasText: 'Constat essai' }),
).toBeVisible()
}
async function createAnnotations(page: Page) {
await showDrawing(page, dict)
const trace = async (points: number[][]) => {
for (const [x, y] of points) await clickDrawing(page, x, y)
await clickButton(page, dict['editor.annotations.trace_close'])
}
await toolButton(page, dict, 'point').click()
await clickDrawing(page, 60, 56)
await fillCreation(page, dict, { fr: 'Point essai', en: 'Trial point' })
await creationPanel(page)
.getByLabel(dict['editor.annotations.zone'])
.selectOption({ label: 'Zone essai' })
await createFromPanel(page, dict)
await toolButton(page, dict, 'zone').click()
await trace([
[120, 38],
[160, 38],
[140, 75],
])
await fillCreation(page, dict, { fr: 'Zone dessinée', en: 'Drawn zone' })
await creationPanel(page)
.getByLabel(dict['editor.annotations.zone'])
.selectOption({ label: 'Zone essai' })
await createFromPanel(page, dict)
await toolButton(page, dict, 'link').click()
await trace([
[30, 94],
[70, 94],
[50, 131],
])
await fillCreation(page, dict, { fr: 'Accès essai', en: 'Trial access' })
await creationPanel(page)
.getByLabel(dict['editor.annotations.opens'])
.selectOption({ label: 'Détail essai' })
await createFromPanel(page, dict)
}
const MODIFIED = { point: 3, vertex: 4 }
/** Applies (not only refuses) changes to a point, a zone and a link; read back at the save. */
async function modifyAnnotations(page: Page) {
await pickAnnotation(page, dict, /Point essai/)
const cx = geometryField(page, dict, 'cx')
const before = Number(await cx.inputValue())
await commitText(cx, String(before + MODIFIED.point))
await expect(cx).toHaveValue(String(before + MODIFIED.point))
await pickAnnotation(page, dict, /Zone dessinée/)
const vertex = page.getByLabel(
dict['editor.annotations.geometry.vertex_x'].replace('{n}', '1'),
)
const start = Number(await vertex.inputValue())
await commitText(vertex, String(start + MODIFIED.vertex))
await expect(vertex).toHaveValue(String(start + MODIFIED.vertex))
await pickAnnotation(page, dict, /Accès essai/)
await commitText(page.locator('#annotation-name-fr'), 'Accès modifié')
await page.locator('#annotation-laterality').selectOption('bilateral')
await expect(page.locator('#annotation-name-fr')).toHaveValue('Accès modifié')
return { point: before + MODIFIED.point, vertex: start + MODIFIED.vertex }
}
/** Guide 4.4: a click near the edge proposes a position; a far value is refused. */
async function repairGeometry(page: Page) {
await toolButton(page, dict, 'point').click()
// On this 200 x 150 drawing the core keeps a shrunk marker at 1 unit from the edge: the
// proposal of a corrected position needs a click on the edge itself (editor-geometry
// covers it on a 1 000-unit drawing). Here the click is placed at once.
await clickDrawing(page, 1, 1)
await fillCreation(page, dict, { fr: 'Point de bord', en: 'Edge point' })
await createFromPanel(page, dict)
await expect(selectionTag(page)).toContainText('Point de bord')
const cx = geometryField(page, dict, 'cx')
await cx.fill('9999')
await cx.press('Enter')
await expect(
page.getByText(dict['editor.annotations.geometry.unapplied']),
).toBeVisible()
await clickButton(page, dict['editor.annotations.geometry.revert'])
await expect(
page.getByText(dict['editor.annotations.geometry.unapplied']),
).toHaveCount(0)
}
/** Guide 4.5: an unsaved change, a reload (beforeunload accepted), the offer, a restore. */
async function reloadAndRestore(page: Page, sheetId: string) {
const kinds: string[] = []
page.on('dialog', (dialog) => {
kinds.push(dialog.type())
void dialog.accept()
})
await page.reload()
expect(kinds).toContain('beforeunload')
await expect(
page.getByText(dict['editor.draft.recovery.restore'], { exact: true }),
).toBeVisible()
await expect(
page.getByText('Une copie locale temporaire de ce brouillon existe', {
exact: false,
}),
).toBeVisible()
expect(page.url()).toContain(sheetId)
await clickButton(page, dict['editor.draft.recovery.restore'])
await expect(saveLine(page)).toHaveText(UNSAVED_LINE)
}
test.describe('editor journey (owner trial steps)', () => {
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('creation to submission with two editor accounts', async ({
page,
browser,
baseURL,
requests,
}) => {
test.setTimeout(240_000)
const [a, b] = [await editorActor('fr'), await editorActor('fr')]
for (const actor of [a, b])
requests.forbid(actor.account.email, actor.account.password)
const tag = a.account.id.slice(0, 8)
await signIn(page, a.account, dict)
await page.goto('/app/admin')
await stepUpAdmin(page, dict, a.secret)
const sheetId = await createSheetFromAdmin(page, tag)
await importDrawing(page)
await createFindings(page)
await createAnnotations(page)
await repairGeometry(page)
// Undo and redo the numeric repair path's last creation.
await historyButton(page, dict, 'undo').click()
await historyButton(page, dict, 'redo').click()
const modified = await modifyAnnotations(page)
await expectAccessible(page, 'the editor with annotations')
await saveDraft(page, dict, 1)
const draftId = await sql(
`select id from public.anatomical_sheet_versions where sheet_id = '${sheetId}' and status = 'draft'`,
)
const saved = await serverDocument<{
annotations: {
name?: { fr: string }
laterality?: string
geometry: { type: string; cx?: number; points?: number[][] }
}[]
}>(draftId)
const byName = (fr: string) =>
saved.annotations.find((a) => a.name?.fr === fr)
expect(byName('Point essai')?.geometry.cx).toBe(modified.point)
expect(byName('Zone dessinée')?.geometry.points?.[0][0]).toBe(
modified.vertex,
)
expect(byName('Accès modifié')?.laterality).toBe('bilateral')
// 4.5: a rename left unsaved survives a reload through the recovery copy.
await selectTab(page, dict, 'general')
const name = place(page, 'general').getByLabel(
dict['editor.general.name_fr'],
{ exact: true },
)
await commitText(name, `Chien révisé ${tag}`)
await reloadAndRestore(page, sheetId)
await saveDraft(page, dict, 2)
// 4.6: the other account saves first; the conflict names its revision.
const second = await secondSession(browser, baseURL ?? '', 'fr-FR')
await signIn(second.page, b.account, dict)
await second.page.goto('/app/admin')
await stepUpAdmin(second.page, dict, b.secret)
await openDraft(second.page, dict, sheetId)
await selectTab(second.page, dict, 'general')
await commitText(
second.page.getByLabel(dict['editor.general.name_en'], { exact: true }),
`Dog by B ${tag}`,
)
await saveDraft(second.page, dict, 3)
await selectTab(page, dict, 'general')
await commitText(
page.getByLabel(dict['editor.general.name_en'], { exact: true }),
`Dog by A ${tag}`,
)
await clickButton(page, dict['common.save'])
const conflict = page.getByRole('dialog', {
name: dict['editor.draft.conflict.known'].replace('{revision}', '3'),
})
await expect(conflict).toBeVisible()
await expectAccessible(page, 'the conflict dialog')
await clickDialog(conflict, dict['editor.draft.conflict.reload'])
await expect(conflict).toContainText('révision 3')
await clickDialog(conflict, dict['editor.draft.conflict.reload'])
await expect(conflict).toBeHidden()
await expect(saveLine(page)).toHaveText(revisionText(dict, 3))
// The conflict again, resolved by keeping this version after the confirmation.
await commitText(
second.page.getByLabel(dict['editor.general.name_en'], { exact: true }),
`Dog by B again ${tag}`,
)
await saveDraft(second.page, dict, 4)
await commitText(
page.getByLabel(dict['editor.general.name_en'], { exact: true }),
`Dog by A ${tag}`,
)
await clickButton(page, dict['common.save'])
const again = page.getByRole('dialog', {
name: dict['editor.draft.conflict.known'].replace('{revision}', '4'),
})
await clickDialog(again, dict['editor.draft.conflict.keep'])
await expect(again).toContainText('Remplacer la révision 4')
await clickDialog(again, dict['editor.draft.conflict.keep'])
await expect(again).toBeHidden()
await expect(saveLine(page)).toHaveText(savedLine(dict, 5))
await second.context.close()
await selectTab(page, dict, 'verification')
// 4.7: elements to confirm are information, never an error; « Aller à » selects.
const verification = page.getByTestId('editor-tab-verification')
await expect(
verification.getByText(
dict['editor.verification.errors_one'].replace('{count}', '0'),
),
).toBeVisible()
await expect(
verification.getByText(dict['editor.verification.to_confirm_info']),
).toBeVisible()
await expect(
page.getByRole('tab', { name: dict['editor.tab.verification'] }),
).not.toContainText(/\d/)
await expectAccessible(page, 'the verification tab')
await verification
.getByRole('button', {
name: dict['editor.verification.goto'].replace(
'{tab}',
'Point de bord',
),
})
.click()
await expect(page.getByTestId('annotation-selection-tag')).toContainText(
'Point de bord',
)
await selectTab(page, dict, 'verification')
await page
.getByLabel(dict['editor.verification.note'])
.fill('Premier jet complet, éléments à confirmer.')
await clickButton(page, dict['editor.verification.submit'])
await expect(
page.getByText(dict['editor.draft.read_only'], { exact: true }),
).toBeVisible()
await expect(
page.getByText('vérification en cours', { exact: false }),
).toBeVisible()
expect(
await sql(
`select status from public.anatomical_sheet_reviews where version_id = '${draftId}'`,
),
).toBe('verifying')
// The submit button sits at the page's end: back at the header, whose « Références »
// button the sticky top bar covers while the page is scrolled.
await page
.getByRole('heading', { level: 1, name: 'Brouillon, version 1' })
.evaluate((heading) => heading.scrollIntoView({ block: 'center' }))
await expectAccessible(page, 'the frozen draft')
})
})