Criterion 18: « Sommet {n} de {nom} », « Ajouter un sommet après le sommet
{n} de {nom} », « Retirer le sommet {n} de {nom} » (EN « Vertex {n} of
{name} » …), {nom} the zone's display name in the current locale; the
handle group is a role="group" named « Sommets de {nom} ».
Tests: no assertion removed; every unit and e2e locator that read the old
names now reads the same handle with the zone name appended (fixtures: N,
Vertèbres thoraciques, Zone dessinée, Zone clavier). New unit tests in
editor-zone-edit cover the FR names, the group and the EN locale.
466 lines
18 KiB
TypeScript
466 lines
18 KiB
TypeScript
import { fr } from '@/i18n/fr'
|
|
import type { Locator, Page, TestInfo } from '@playwright/test'
|
|
import { sql } from '../../../../packages/supabase/tests/sandbox/stack'
|
|
import { allSheetsLink, stepUpAdmin } from '../support/admin'
|
|
import { expect, expectAccessible, test } from '../support/browser'
|
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
|
import {
|
|
clickDrawing,
|
|
clientOf,
|
|
closeFinding,
|
|
createFromPanel,
|
|
creationPanel,
|
|
editorActor,
|
|
fillCreation,
|
|
round2,
|
|
shownNumber,
|
|
shownPoints,
|
|
shownShape,
|
|
historyButton,
|
|
INKSCAPE_EXPORT,
|
|
openDraft,
|
|
openSection,
|
|
pickAnnotation,
|
|
place,
|
|
revisionText,
|
|
savedLine,
|
|
saveDraft,
|
|
saveLine,
|
|
closeSecondSession,
|
|
secondSession,
|
|
selectionTag,
|
|
selectTab,
|
|
serverDocument,
|
|
showDrawing,
|
|
toolButton,
|
|
UNSAVED_LINE,
|
|
openProperties,
|
|
} 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 allSheetsLink(
|
|
page.locator('section[aria-labelledby="admin-sheets-title"]'),
|
|
dict,
|
|
).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')
|
|
// « Créer » turns the dialog into the new element's view: close it before the next add.
|
|
const create = async () => {
|
|
await clickButton(page, dict['editor.findings.create'])
|
|
await closeFinding(page, dict)
|
|
}
|
|
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 }
|
|
|
|
/**
|
|
* `steps` arrow presses on the focused handle (one unit each on this 200-unit drawing,
|
|
* R-11), then Enter: one commit. Returns where `from` lands, rounded as the page does.
|
|
*/
|
|
async function stepRight(
|
|
page: Page,
|
|
handle: Locator,
|
|
from: number,
|
|
steps: number,
|
|
) {
|
|
await handle.focus()
|
|
let to = from
|
|
for (let step = 0; step < steps; step++) {
|
|
await page.keyboard.press('ArrowRight')
|
|
to = round2(to + 1)
|
|
}
|
|
await page.keyboard.press('Enter')
|
|
return to
|
|
}
|
|
|
|
/**
|
|
* Applies (not only refuses) changes to a point, a zone and a link; read back at the save.
|
|
* U2 Task 5: the point and the vertex move by their handle keys (no coordinate field).
|
|
*/
|
|
async function modifyAnnotations(page: Page) {
|
|
await pickAnnotation(page, dict, /Point essai/)
|
|
const before = await shownNumber(page, 'cx')
|
|
const handle = page.getByTestId('point-handle')
|
|
const point = await stepRight(page, handle, before, MODIFIED.point)
|
|
await expect(shownShape(page)).toHaveAttribute('cx', String(point))
|
|
await pickAnnotation(page, dict, /Zone dessinée/)
|
|
const [[start]] = await shownPoints(page)
|
|
const first = page.getByRole('button', {
|
|
name: 'Sommet 1 de Zone dessinée',
|
|
exact: true,
|
|
})
|
|
const vertex = await stepRight(page, first, start, MODIFIED.vertex)
|
|
await expect.poll(async () => (await shownPoints(page))[0][0]).toBe(vertex)
|
|
await pickAnnotation(page, dict, /Accès essai/)
|
|
// U2 Task 6: the properties dialog's form, one save for both fields.
|
|
const properties = await openProperties(page, dict)
|
|
await properties
|
|
.getByRole('button', { name: dict['editor.findings.edit'], exact: true })
|
|
.click()
|
|
await properties.locator('#annotation-edit-fr').fill('Accès modifié')
|
|
await properties
|
|
.locator('#annotation-edit-laterality')
|
|
.selectOption('bilateral')
|
|
await properties
|
|
.getByRole('button', { name: dict['editor.findings.save'] })
|
|
.click()
|
|
await expect(properties.getByTestId('annotation-read')).toContainText(
|
|
'Accès modifié',
|
|
)
|
|
await page.keyboard.press('Escape')
|
|
await expect(page.getByRole('dialog')).toHaveCount(0)
|
|
return { point, vertex }
|
|
}
|
|
|
|
/**
|
|
* Guide 4.4: a click near the edge proposes a position; a far place is refused (U2 Task
|
|
* 5: dragged by the handle, the coordinate fields left the panel).
|
|
*/
|
|
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')
|
|
// The point tool stays on after « Créer » (A7 lands with Task 7): the handle needs select.
|
|
await toolButton(page, dict, 'select').click()
|
|
const cx = String(await shownNumber(page, 'cx'))
|
|
const cy = await shownNumber(page, 'cy')
|
|
const from = await clientOf(page, Number(cx), cy)
|
|
const to = await clientOf(page, 260, cy)
|
|
await page.mouse.move(from.x, from.y)
|
|
await page.mouse.down()
|
|
await page.mouse.move(to.x, to.y, { steps: 6 })
|
|
await page.mouse.up()
|
|
await expect(page.getByTestId('gesture-message')).toContainText(
|
|
dict['editor.annotations.message.move_refused'].split(' :')[0],
|
|
)
|
|
await expect(shownShape(page)).toHaveAttribute('cx', cx)
|
|
}
|
|
|
|
/** 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 closeSecondSession(second)
|
|
|
|
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(selectionTag(page)).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')
|
|
})
|
|
})
|