Annotations of the view move from under the drawing to the overview card (grouped by category, name filter, all rows); side column from lg. Properties panel gains « Toutes les annotations ». E2E mapping (R-24): after a creation the card is hidden (the new annotation is selected), so list(...).getByText(name) became selectionTag toContainText (annotations, geometry, journey); row clicks go through pickAnnotation (annotations, geometry, journey, structures); geometry's list count 0 while a creation is pending became selectionTag count 0.
481 lines
17 KiB
TypeScript
481 lines
17 KiB
TypeScript
import { fr } from '@/i18n/fr'
|
|
import type { Page, TestInfo } from '@playwright/test'
|
|
import { expect, expectAccessible, test } from '../support/browser'
|
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
|
import {
|
|
place,
|
|
clickDrawing,
|
|
clientOf,
|
|
editorActor,
|
|
geometryField,
|
|
openEditor,
|
|
openSection,
|
|
pickAnnotation,
|
|
pointOf,
|
|
saveDraft,
|
|
seedDraft,
|
|
selectionTag,
|
|
selectTab,
|
|
serverDocument,
|
|
shapeWith,
|
|
standardShape,
|
|
} from '../support/editor'
|
|
|
|
// V1-2.6 geometry and adversarial cases (contract C7, C8, C21; owner 2026-11-04): a click
|
|
// near the edge of a frame (the corrected position shown, confirmed and cancelled), a
|
|
// point inherited out of its frame repaired through the geometry group, a crop change
|
|
// refused when it would invalidate a point, an unmeasured view with its tools disabled,
|
|
// and the touch path (touch-action, pointer capture) in a real browser.
|
|
|
|
const dict = fr
|
|
|
|
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
|
const creation = (page: Page) => page.getByTestId('annotation-creation')
|
|
const notice = (page: Page) => page.getByTestId('correction-notice')
|
|
|
|
const tool = (page: Page, id: string) =>
|
|
page.getByRole('button', {
|
|
name: dict[`editor.annotations.tool.${id}`],
|
|
exact: true,
|
|
})
|
|
|
|
const viewChip = (page: Page, name: string) =>
|
|
page
|
|
.getByRole('group', { name: dict['editor.annotations.views'] })
|
|
.getByRole('button', { name })
|
|
|
|
/** The x and y a correction notice proposes, read from its sentence. */
|
|
async function proposed(page: Page): Promise<{ x: string; y: string }> {
|
|
const text = (await notice(page).innerText()).replace(/\s+/g, ' ')
|
|
const found = /x = (-?\d+(?:\.\d+)?), y = (-?\d+(?:\.\d+)?)/.exec(text)
|
|
if (!found) throw new Error('no proposed position in the notice')
|
|
return { x: found[1], y: found[2] }
|
|
}
|
|
|
|
async function fillNames(page: Page, fr: string, en: string) {
|
|
await creation(page).getByLabel(dict['editor.annotations.name_fr']).fill(fr)
|
|
await creation(page).getByLabel(dict['editor.annotations.name_en']).fill(en)
|
|
await creation(page)
|
|
.getByLabel(dict['editor.annotations.laterality'])
|
|
.selectOption('unpaired')
|
|
}
|
|
|
|
async function open(page: Page, ...annotations: unknown[]) {
|
|
const actor = await editorActor('fr')
|
|
const seed = await seedDraft(actor, { shape: shapeWith(...annotations) })
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
await expect(tool(page, 'point')).toBeEnabled()
|
|
return { actor, seed }
|
|
}
|
|
|
|
test.describe('editor geometry (adversarial)', () => {
|
|
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('a click near the edge: corrected position shown, cancelled, then confirmed', async ({
|
|
page,
|
|
requests,
|
|
}) => {
|
|
const { actor } = await open(page)
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
await tool(page, 'point').click()
|
|
await clickDrawing(page, 3, 3)
|
|
await fillNames(page, 'Bord', 'Edge')
|
|
await creation(page)
|
|
.getByRole('button', { name: dict['editor.annotations.create'] })
|
|
.click()
|
|
await expect(notice(page)).toBeVisible()
|
|
await expect(page.getByTestId('overlay-click-cross')).toBeAttached()
|
|
const shown = await proposed(page)
|
|
await expect(selectionTag(page)).toHaveCount(0) // an insertion selects it
|
|
|
|
// Cancelled: the notice goes, nothing was inserted.
|
|
await notice(page)
|
|
.getByRole('button', {
|
|
name: dict['editor.annotations.correction_cancel'],
|
|
})
|
|
.click()
|
|
await expect(notice(page)).toHaveCount(0)
|
|
await expect(selectionTag(page)).toHaveCount(0) // an insertion selects it
|
|
|
|
// Confirmed: the same attempt again, the corrected position inserted.
|
|
await creation(page)
|
|
.getByRole('button', { name: dict['editor.annotations.create'] })
|
|
.click()
|
|
await expect(notice(page)).toBeVisible()
|
|
expect(await proposed(page)).toEqual(shown)
|
|
await notice(page)
|
|
.getByRole('button', { name: dict['editor.annotations.correction_use'] })
|
|
.click()
|
|
await expect(creation(page)).toHaveCount(0)
|
|
await expect(selectionTag(page)).toContainText('Bord')
|
|
await expect(geometryField(page, dict, 'cx')).toHaveValue(shown.x)
|
|
await expect(geometryField(page, dict, 'cy')).toHaveValue(shown.y)
|
|
})
|
|
|
|
test('a click near the edge of a detail crop is corrected inside the crop', async ({
|
|
page,
|
|
requests,
|
|
}) => {
|
|
const { actor } = await open(page)
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
await viewChip(page, 'Détail A').click()
|
|
await tool(page, 'point').click()
|
|
await clickDrawing(page, 102, 102)
|
|
await fillNames(page, 'Bord détail', 'Detail edge')
|
|
await creation(page)
|
|
.getByRole('button', { name: dict['editor.annotations.create'] })
|
|
.click()
|
|
await expect(notice(page)).toBeVisible()
|
|
const shown = await proposed(page)
|
|
expect(Number(shown.x)).toBeGreaterThan(100)
|
|
expect(Number(shown.y)).toBeGreaterThan(100)
|
|
// Cancelled first: nothing is added to the crop's view.
|
|
await notice(page)
|
|
.getByRole('button', {
|
|
name: dict['editor.annotations.correction_cancel'],
|
|
})
|
|
.click()
|
|
await expect(notice(page)).toHaveCount(0)
|
|
await expect(selectionTag(page)).toHaveCount(0) // an insertion selects it
|
|
// Then confirmed: the same attempt again inserts the corrected position.
|
|
await creation(page)
|
|
.getByRole('button', { name: dict['editor.annotations.create'] })
|
|
.click()
|
|
expect(await proposed(page)).toEqual(shown)
|
|
await notice(page)
|
|
.getByRole('button', { name: dict['editor.annotations.correction_use'] })
|
|
.click()
|
|
await expect(selectionTag(page)).toContainText('Bord détail')
|
|
})
|
|
|
|
test('a point inherited out of its frame is repaired through the geometry group', async ({
|
|
page,
|
|
requests,
|
|
}) => {
|
|
const { actor } = await open(
|
|
page,
|
|
pointOf('out', 'detail-a', { cx: 110, cy: 110, r: 30 }, 'Hors cadre'),
|
|
)
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
await viewChip(page, 'Détail A').click()
|
|
await pickAnnotation(page, dict, /Hors cadre/)
|
|
const issues = page.getByTestId('annotation-geometry-issues')
|
|
await expect(issues).toBeVisible()
|
|
const verification = page.getByRole('tab', {
|
|
name: dict['editor.tab.verification'],
|
|
})
|
|
const errorsBefore = Number(
|
|
(await verification.innerText()).replace(/\D/g, ''),
|
|
)
|
|
expect(errorsBefore).toBeGreaterThan(0)
|
|
|
|
const cx = geometryField(page, dict, 'cx')
|
|
await cx.fill('200')
|
|
await cx.press('Enter')
|
|
const cy = geometryField(page, dict, 'cy')
|
|
await cy.fill('200')
|
|
await cy.press('Enter')
|
|
await expect(issues).toHaveCount(0)
|
|
const after = (await verification.innerText()).replace(/\D/g, '')
|
|
expect(Number(after || 0)).toBeLessThan(errorsBefore)
|
|
})
|
|
|
|
test('a crop change that would invalidate a point is refused, then reverted', async ({
|
|
page,
|
|
requests,
|
|
}) => {
|
|
const { actor } = await open(
|
|
page,
|
|
pointOf(
|
|
'inside',
|
|
'detail-a',
|
|
{ cx: 350, cy: 300, r: 20 },
|
|
'Dans le cadre',
|
|
),
|
|
)
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
await openSection(page, dict, 'views')
|
|
const detail = page.getByRole('listitem', { name: 'Détail A' })
|
|
await detail
|
|
.getByRole('button', { name: dict['editor.views.crop.toggle'] })
|
|
.click()
|
|
const width = detail.getByLabel(dict['editor.views.crop.width'], {
|
|
exact: true,
|
|
})
|
|
await expect(width).toHaveValue('300')
|
|
await width.fill('100')
|
|
await width.press('Enter')
|
|
const refusal = detail.getByRole('alert')
|
|
await expect(
|
|
refusal.getByText(dict['editor.views.crop.not_applied']),
|
|
).toBeVisible()
|
|
await expect(refusal).toContainText('Dans le cadre')
|
|
await refusal
|
|
.getByRole('button', { name: dict['editor.views.crop.revert'] })
|
|
.click()
|
|
await expect(width).toHaveValue('300')
|
|
})
|
|
|
|
test('attaching a drawing to an unmeasured view repairs the annotations outside its frame', async ({
|
|
page,
|
|
requests,
|
|
}) => {
|
|
const zone = {
|
|
...pointOf('out-zone', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone hors cadre'),
|
|
kind: 'zone',
|
|
geometry: {
|
|
type: 'polygon',
|
|
points: [
|
|
[10, 10],
|
|
[400, 10],
|
|
[400, 400],
|
|
],
|
|
},
|
|
}
|
|
const point = pointOf(
|
|
'out-point',
|
|
'main',
|
|
{ cx: 500, cy: 400, r: 20 },
|
|
'Point hors cadre',
|
|
)
|
|
const actor = await editorActor('fr')
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
const seed = await seedDraft(actor, {
|
|
drawing: null,
|
|
shape: (document) => {
|
|
standardShape(document)
|
|
const views = document.views as { id: string }[]
|
|
document.views = views.filter((view) => view.id === 'main')
|
|
document.annotations = [point, zone]
|
|
},
|
|
})
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
await openSection(page, dict, 'views')
|
|
await page.getByTestId('view-main-file').setInputFiles({
|
|
name: 'petit.svg',
|
|
mimeType: 'image/svg+xml',
|
|
buffer: Buffer.from(
|
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">' +
|
|
'<rect x="2" y="2" width="96" height="96" fill="#eee"/></svg>',
|
|
),
|
|
})
|
|
const dialog = page.getByRole('dialog', {
|
|
name: dict['editor.views.repair.title'],
|
|
})
|
|
await expect(dialog).toBeVisible()
|
|
const row = dialog.getByTestId('repair-out-point')
|
|
await expect(
|
|
row.getByLabel(dict['editor.annotations.geometry.cx']),
|
|
).toHaveValue('85')
|
|
await expectAccessible(page, 'the repair dialog')
|
|
|
|
// A value the core refuses: nothing applied, the typed value kept.
|
|
const cx = row.getByLabel(dict['editor.annotations.geometry.cx'])
|
|
await cx.fill('900')
|
|
await cx.press('Enter')
|
|
await dialog
|
|
.getByRole('button', { name: dict['editor.views.repair.apply'] })
|
|
.click()
|
|
await expect(
|
|
dialog.getByText(dict['editor.views.repair.refused']),
|
|
).toBeVisible()
|
|
await expect(cx).toHaveValue('900')
|
|
|
|
await cx.fill('60')
|
|
await cx.press('Enter')
|
|
await dialog
|
|
.getByRole('button', { name: dict['editor.views.repair.apply'] })
|
|
.click()
|
|
await expect(dialog).toBeHidden()
|
|
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
|
|
|
await saveDraft(page, dict, seed.revision + 1)
|
|
const saved = await serverDocument<{
|
|
views: { id: string; svg_asset_id: string | null }[]
|
|
annotations: { id: string; geometry: Record<string, unknown> }[]
|
|
}>(seed.draftId)
|
|
expect(saved.views[0].svg_asset_id).not.toBeNull()
|
|
const byId = Object.fromEntries(saved.annotations.map((a) => [a.id, a]))
|
|
expect(byId['out-point'].geometry).toMatchObject({ type: 'circle', cx: 60 })
|
|
expect(byId['out-zone'].geometry).toEqual({
|
|
type: 'polygon',
|
|
points: [
|
|
[10, 10],
|
|
[100, 10],
|
|
[100, 100],
|
|
],
|
|
})
|
|
})
|
|
|
|
test('a free path outside the new frame blocks the attach, is never reshaped and survives a save', async ({
|
|
page,
|
|
requests,
|
|
}) => {
|
|
const seededPath =
|
|
'M 300 300 l 40 0 C 350 320 380 360 400 400 q 20 -30 -40 -50 ' +
|
|
'A 30 20 0 0 1 320 330 H 310 V 305 Z'
|
|
const path = {
|
|
...pointOf('out-path', 'main', { cx: 0, cy: 0, r: 1 }, 'Tracé libre'),
|
|
kind: 'zone',
|
|
geometry: { type: 'path', d: seededPath },
|
|
}
|
|
const point = pointOf(
|
|
'out-point',
|
|
'main',
|
|
{ cx: 500, cy: 400, r: 20 },
|
|
'Point hors cadre',
|
|
)
|
|
const actor = await editorActor('fr')
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
const seed = await seedDraft(actor, {
|
|
drawing: null,
|
|
shape: (document) => {
|
|
standardShape(document)
|
|
const views = document.views as { id: string }[]
|
|
document.views = views.filter((view) => view.id === 'main')
|
|
document.annotations = [point, path]
|
|
},
|
|
})
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
await openSection(page, dict, 'views')
|
|
await page.getByTestId('view-main-file').setInputFiles({
|
|
name: 'petit.svg',
|
|
mimeType: 'image/svg+xml',
|
|
buffer: Buffer.from(
|
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">' +
|
|
'<rect x="2" y="2" width="96" height="96" fill="#eee"/></svg>',
|
|
),
|
|
})
|
|
const dialog = page.getByRole('dialog', {
|
|
name: dict['editor.views.repair.title'],
|
|
})
|
|
await expect(dialog).toBeVisible()
|
|
const row = dialog.getByTestId('repair-out-path')
|
|
await expect(
|
|
row.getByText(dict['editor.views.repair.path_blocked']),
|
|
).toBeVisible()
|
|
await expect(row.getByRole('button')).toHaveCount(0)
|
|
await expect(
|
|
dialog.getByRole('button', { name: dict['editor.views.repair.apply'] }),
|
|
).toBeDisabled()
|
|
await dialog
|
|
.getByRole('button', { name: dict['editor.views.repair.cancel'] })
|
|
.click()
|
|
await expect(dialog).toBeHidden()
|
|
|
|
// An unrelated change is saved: the path is still the seeded one, byte for byte.
|
|
await selectTab(page, dict, 'general')
|
|
const nameFr = place(page, 'general').getByLabel(
|
|
dict['editor.general.name_fr'],
|
|
{
|
|
exact: true,
|
|
},
|
|
)
|
|
await nameFr.fill('Fiche sans toucher au tracé')
|
|
await nameFr.press('Tab')
|
|
await saveDraft(page, dict, seed.revision + 1)
|
|
const saved = await serverDocument<{
|
|
annotations: { id: string; geometry: Record<string, unknown> }[]
|
|
}>(seed.draftId)
|
|
const kept = saved.annotations.find((a) => a.id === 'out-path')
|
|
expect(kept?.geometry).toEqual({ type: 'path', d: seededPath })
|
|
})
|
|
|
|
test('an unmeasured view: drawing tools and add buttons disabled, the hint shown', async ({
|
|
page,
|
|
requests,
|
|
}) => {
|
|
const actor = await editorActor('fr')
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
const seed = await seedDraft(actor, { drawing: null, shape: standardShape })
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
// No measurable view: the draft opens on Général (C40).
|
|
await selectTab(page, dict, 'annotations')
|
|
await expect(
|
|
page.getByText(dict['editor.annotations.unmeasured.hint'], {
|
|
exact: false,
|
|
}),
|
|
).toBeVisible()
|
|
for (const id of ['point', 'zone', 'link'])
|
|
await expect(tool(page, id)).toBeDisabled()
|
|
for (const kind of ['point', 'zone', 'detail_trigger'])
|
|
await expect(
|
|
page.getByRole('button', {
|
|
name: dict[`editor.annotations.add.${kind}`],
|
|
}),
|
|
).toBeDisabled()
|
|
await expect(tool(page, 'select')).toBeEnabled()
|
|
await expectAccessible(page, 'an unmeasured view with its tools disabled')
|
|
})
|
|
})
|
|
|
|
test.describe('editor touch path (real browser)', () => {
|
|
test.use({
|
|
locale: 'fr-FR',
|
|
actionTimeout: 15_000,
|
|
hasTouch: true,
|
|
viewport: { width: 1280, height: 800 },
|
|
})
|
|
test.beforeEach(async ({ context }, info) => {
|
|
test.skip(isPhone(info), 'touch at 1 024 px runs on desktop') // 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('touch-action follows the tool; a touch drag moves the selected marker', async ({
|
|
page,
|
|
context,
|
|
requests,
|
|
}) => {
|
|
const { actor } = await open(
|
|
page,
|
|
pointOf('moving', 'main', { cx: 500, cy: 400, r: 60 }, 'Tactile'),
|
|
)
|
|
requests.forbid(actor.account.email, actor.account.password)
|
|
const box = page.getByTestId('annotation-canvas')
|
|
const touchAction = () =>
|
|
box.evaluate((el) => getComputedStyle(el).touchAction)
|
|
await expect.poll(touchAction).toBe('pan-x pan-y')
|
|
await tool(page, 'point').click()
|
|
await expect.poll(touchAction).toBe('none')
|
|
await tool(page, 'select').click()
|
|
await expect.poll(touchAction).toBe('pan-x pan-y')
|
|
|
|
// A movable selection needs the touch itself: the browser reads touch-action at
|
|
// touchstart, so a drag of the selected marker must not be left to the pan.
|
|
await pickAnnotation(page, dict, /Tactile/)
|
|
await expect.poll(touchAction).toBe('none')
|
|
const cx = geometryField(page, dict, 'cx')
|
|
await expect(cx).toHaveValue('500')
|
|
const from = await clientOf(page, 500, 400)
|
|
const to = await clientOf(page, 620, 400)
|
|
const cdp = await context.newCDPSession(page)
|
|
const touch = (
|
|
type: 'touchStart' | 'touchMove' | 'touchEnd',
|
|
at: { x: number; y: number } | null,
|
|
) =>
|
|
cdp.send('Input.dispatchTouchEvent', {
|
|
type,
|
|
touchPoints: at ? [{ x: at.x, y: at.y }] : [],
|
|
})
|
|
await touch('touchStart', from)
|
|
for (let step = 1; step <= 8; step++)
|
|
await touch('touchMove', {
|
|
x: from.x + ((to.x - from.x) * step) / 8,
|
|
y: from.y,
|
|
})
|
|
await touch('touchEnd', null)
|
|
await expect(cx).not.toHaveValue('500')
|
|
expect(Math.abs(Number(await cx.inputValue()) - 620)).toBeLessThan(3)
|
|
})
|
|
})
|