Files
faunosteo/apps/app/e2e/shell/editor-touch.spec.ts
T
bchanot 9522eb72aa test(tests): probe mode entry and exit for shifts at three widths
Criterion 5: « Déplacer le point », « Déplacer la zone », « Valider la
position », and « Redessiner » entered then cancelled, each under
expectNoShift at 1 024, 1 180 and 1 280 px (seeded point and zone, the
existing multi-width pattern). The editor-touch « Déplacer la zone » entry
joins the probe; its button is centred first, since below xl the sticky top
bar can cover the strip and Playwright would scroll inside the probe.

No assertion removed. No product shift found.
2026-11-18 14:13:53 +01:00

441 lines
17 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fr } from '@/i18n/fr'
import type { CDPSession, Page, TestInfo } from '@playwright/test'
import { expect, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
clientOf,
creationPanel,
editorActor,
historyButton,
openEditor,
pickAnnotation,
pointOf,
seedDraft,
selectionTag,
shapeWith,
shownNumber,
shownPoints,
toolButton,
} from '../support/editor'
import { expectNoShift } from '../support/layout'
// V1-2.6 U2 Task 8: the editor by finger (A13, board 13) at 1 024, 1 180 and 1 280 px, with
// CDP touch points: a finger drags what it holds (a vertex, the point) under the loupe and
// nothing else (the two-finger hint, R-1, shown once, nothing moving), two fingers zoom and
// pan, a second finger cancels a vertex drag (Review Focus 1), the move mode, a tap on the
// selection (A1), the tracing closed within 22 px (R-11), the page scroll over the drawing
// without a selection, and every handle reached within 44 px (R-9).
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const WIDTHS = [1024, 1180, 1280]
const HINT = dict['editor.annotations.message.two_fingers']
const POINT = 'Pt Alpha'
const ZONE = 'Zone Beta'
const SQUARE = [
[300, 200],
[600, 200],
[600, 500],
[300, 500],
]
// Away from every annotation and handle (drawing units of the 1000 × 800 fixture).
const EMPTY = { x: 150, y: 150 }
const INSIDE = { x: 450, y: 330 }
const zone = {
...pointOf('zone-b', 'main', { cx: 0, cy: 0, r: 1 }, ZONE),
kind: 'zone',
geometry: { type: 'polygon', points: SQUARE },
}
type XY = { x: number; y: number }
const touch = (
cdp: CDPSession,
type: 'touchStart' | 'touchMove' | 'touchEnd',
points: XY[],
) =>
cdp.send('Input.dispatchTouchEvent', {
type,
touchPoints: points.map((p, id) => ({ x: p.x, y: p.y, id })),
})
const between = (from: XY, to: XY, step: number, steps: number) => ({
x: from.x + ((to.x - from.x) * step) / steps,
y: from.y + ((to.y - from.y) * step) / steps,
})
/** Fingers moved together from `from` to `to` in `steps` moves (no touchEnd). */
async function move(cdp: CDPSession, from: XY[], to: XY[], steps = 6) {
for (let step = 1; step <= steps; step++)
await touch(
cdp,
'touchMove',
from.map((f, i) => between(f, to[i], step, steps)),
)
}
async function tap(cdp: CDPSession, at: XY) {
await touch(cdp, 'touchStart', [at])
await touch(cdp, 'touchEnd', [])
}
/** One finger pressed at `from`, dragged to `to`, released. */
async function drag(cdp: CDPSession, from: XY, to: XY) {
await touch(cdp, 'touchStart', [from])
await move(cdp, [from], [to])
await touch(cdp, 'touchEnd', [])
}
/** Two fingers 60 px apart around `at`, spread to 240 px: the drawing zooms in. */
async function pinchOut(cdp: CDPSession, at: XY) {
const start = [
{ x: at.x - 30, y: at.y },
{ x: at.x + 30, y: at.y },
]
const end = [
{ x: at.x - 120, y: at.y },
{ x: at.x + 120, y: at.y },
]
await touch(cdp, 'touchStart', start)
await move(cdp, start, end)
await touch(cdp, 'touchEnd', [])
}
const canvas = (page: Page) => page.getByTestId('annotation-canvas')
const loupe = (page: Page) => page.getByTestId('loupe')
const message = (page: Page) => page.getByTestId('gesture-message')
const button = (page: Page, key: string) =>
page.getByRole('button', { name: dict[key], exact: true })
/** The framing of the drawing layer: `translate(x, y) scale(s)`. */
async function framing(page: Page) {
const transform = await page
.getByTestId('annotation-canvas-drawing')
.evaluate((el) => (el.parentElement as HTMLElement).style.transform)
const [x, y, scale] = (transform.match(/-?[\d.]+/g) ?? []).map(Number)
return { x, y, scale }
}
async function open(page: Page) {
const actor = await editorActor('fr')
const seed = await seedDraft(actor, {
shape: shapeWith(
pointOf('pt-a', 'main', { cx: 750, cy: 600, r: 30 }, POINT),
zone,
),
})
const saves: string[] = []
page.on('request', (request) => {
if (request.url().includes('save_sheet_draft')) saves.push(request.url())
})
await openEditor(page, dict, actor, seed.sheetId)
await expect(toolButton(page, dict, 'point')).toBeEnabled()
return { actor, saves }
}
/** Selects from the overview, then brings the whole drawing into view. */
async function select(page: Page, name: string) {
await pickAnnotation(page, dict, name)
await expect(selectionTag(page)).toContainText(name)
await canvas(page).scrollIntoViewIfNeeded()
}
/** R-9 on a finger: every hit circle at least 44 px, the « − » bubble 44 × 36 px. */
async function expectFingerSizedHandles(page: Page) {
const shapes = await page
.locator('[data-testid="handle-layer"] [data-handle]')
.evaluateAll((elements) =>
elements.map((el) => {
const box = el.getBoundingClientRect()
return { tag: el.tagName, w: box.width, h: box.height }
}),
)
expect(shapes.length).toBeGreaterThan(0)
for (const shape of shapes) {
if (shape.tag === 'circle') {
expect(Math.min(shape.w, shape.h), 'hit circle').toBeGreaterThanOrEqual(
43.5,
)
} else {
expect(shape.w, '« − » width').toBeGreaterThanOrEqual(43.5)
expect(shape.h, '« − » height').toBeGreaterThanOrEqual(35.5)
}
}
return shapes
}
/** The loupe while a finger moves: shown, round, inside the canvas box. */
async function expectLoupeInBox(page: Page) {
await expect(loupe(page)).toBeVisible()
const disc = (await loupe(page).boundingBox())!
const box = (await canvas(page).boundingBox())!
expect(disc.width).toBeCloseTo(120, 0)
expect(disc.x).toBeGreaterThanOrEqual(box.x - 1)
expect(disc.y).toBeGreaterThanOrEqual(box.y - 1)
expect(disc.x + disc.width).toBeLessThanOrEqual(box.x + box.width + 1)
expect(disc.y + disc.height).toBeLessThanOrEqual(box.y + box.height + 1)
await expect(loupe(page).locator('[data-anno-id]')).toHaveCount(0)
}
/** One finger from `from` to `to`, the loupe checked halfway. */
async function dragWithLoupe(page: Page, cdp: CDPSession, from: XY, to: XY) {
await touch(cdp, 'touchStart', [from])
await move(cdp, [from], [between(from, to, 1, 2)], 3)
await expectLoupeInBox(page)
await move(cdp, [between(from, to, 1, 2)], [to], 3)
await touch(cdp, 'touchEnd', [])
await expect(loupe(page)).toHaveCount(0)
}
for (const width of WIDTHS) {
test.describe(`the editor by finger at ${width} px (U2 Task 8)`, () => {
test.use({
locale: 'fr-FR',
actionTimeout: 15_000,
hasTouch: true,
viewport: { width, height: 800 },
})
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 finger drags a vertex and the point under the loupe; handles answer within 44 px', async ({
page,
context,
requests,
}) => {
const { actor } = await open(page)
requests.forbid(actor.account.email, actor.account.password)
const cdp = await context.newCDPSession(page)
await select(page, ZONE)
await expectFingerSizedHandles(page)
const from = await clientOf(page, 600, 200)
// The loupe comes and goes, the message shows: no box moves (A14).
await expectNoShift(page, async () => {
await dragWithLoupe(page, cdp, from, { x: from.x + 40, y: from.y + 30 })
await expect(message(page)).toContainText(
dict['editor.annotations.message.vertex_moved'],
)
})
const [, moved] = await shownPoints(page)
expect(moved).not.toEqual(SQUARE[1])
// The chosen vertex shows its « − » bubble: finger-sized too.
await expect(
page.getByRole('button', { name: /^Retirer le sommet/ }),
).toHaveCount(1)
await expectFingerSizedHandles(page)
await select(page, POINT)
const centre = await clientOf(page, 750, 600)
await dragWithLoupe(page, cdp, centre, {
x: centre.x - 40,
y: centre.y - 20,
})
await expect(message(page)).toContainText(
dict['editor.annotations.message.moved.point'],
)
expect(await shownNumber(page, 'cx')).toBeLessThan(750)
// Zoomed in, the handles keep their CSS px size.
await pinchOut(cdp, await clientOf(page, EMPTY.x, EMPTY.y))
expect((await framing(page)).scale).toBeGreaterThan(1)
await select(page, ZONE)
await expectFingerSizedHandles(page)
})
test('a finger off the handles moves nothing and shows the hint once; no hint over a scroll', async ({
page,
context,
requests,
}) => {
const { actor, saves } = await open(page)
requests.forbid(actor.account.email, actor.account.password)
const cdp = await context.newCDPSession(page)
// No selection at the fit: a finger scrolls the page over the drawing.
await page.evaluate(() => window.scrollTo(0, 0))
const room = await page.evaluate(
() => document.documentElement.scrollHeight - window.innerHeight,
)
expect(room, 'the page can scroll').toBeGreaterThan(40)
const box = (await canvas(page).boundingBox())!
const low = {
x: box.x + box.width / 2,
y: Math.min(box.y + box.height, 790) - 20,
}
await drag(cdp, low, { x: low.x, y: low.y - 200 })
await expect
.poll(() => page.evaluate(() => window.scrollY))
.toBeGreaterThan(0)
await expect(message(page)).toHaveCount(0)
await select(page, ZONE)
const empty = await clientOf(page, EMPTY.x, EMPTY.y)
await expectNoShift(page, async () => {
await drag(cdp, empty, { x: empty.x + 60, y: empty.y + 40 })
await expect(message(page)).toHaveText(HINT)
})
expect(await shownPoints(page)).toEqual(SQUARE)
expect((await framing(page)).scale).toBe(1)
// The hint leaves after 4 s; the line is free again.
await expect(message(page)).toHaveCount(0, { timeout: 6_000 })
// Two fingers worked: never again in this visit.
await pinchOut(cdp, await clientOf(page, INSIDE.x, INSIDE.y))
expect((await framing(page)).scale).toBeGreaterThan(1)
const again = await clientOf(page, 320, 220)
await drag(cdp, again, { x: again.x + 50, y: again.y })
await page.waitForTimeout(300)
await expect(message(page)).toHaveCount(0)
expect(saves).toEqual([])
})
test('two fingers zoom and pan; a second finger cancels a vertex drag and pinches (Review Focus 1)', async ({
page,
context,
requests,
}) => {
const { actor, saves } = await open(page)
requests.forbid(actor.account.email, actor.account.password)
const cdp = await context.newCDPSession(page)
// Nothing selected, at the fit (`touch-action: pan-x pan-y`): a pinch still zooms.
await canvas(page).scrollIntoViewIfNeeded()
await pinchOut(cdp, await clientOf(page, INSIDE.x, INSIDE.y))
expect((await framing(page)).scale).toBeGreaterThan(1)
await button(page, 'catalogue.zoom.fit').click()
await expect.poll(async () => (await framing(page)).scale).toBe(1)
await select(page, ZONE)
const undo = historyButton(page, dict, 'undo')
await expect(undo).toBeDisabled()
// Finger 1 drags vertex 2 under the loupe, then finger 2 lands.
const vertex = await clientOf(page, 600, 200)
const held = { x: vertex.x + 30, y: vertex.y + 30 }
await touch(cdp, 'touchStart', [vertex])
await move(cdp, [vertex], [held], 3)
await expect(loupe(page)).toBeVisible()
expect(await shownPoints(page)).not.toEqual(SQUARE)
const other = await clientOf(page, EMPTY.x, EMPTY.y)
await touch(cdp, 'touchStart', [held, other])
await expect(loupe(page)).toHaveCount(0)
expect(await shownPoints(page)).toEqual(SQUARE)
// The pinch goes on: the drawing zooms, the shape stays where it was.
const spread = { x: other.x - 80, y: other.y - 40 }
await move(
cdp,
[held, other],
[{ x: held.x + 40, y: held.y + 20 }, spread],
)
await touch(cdp, 'touchEnd', [])
expect((await framing(page)).scale).toBeGreaterThan(1)
expect(await shownPoints(page)).toEqual(SQUARE)
await expect(page.getByRole('dialog')).toHaveCount(0)
await expect(selectionTag(page)).toContainText(ZONE)
await expect(undo).toBeDisabled()
// Two fingers zoom further, then pan together without scaling.
await pinchOut(cdp, await clientOf(page, INSIDE.x, INSIDE.y))
const zoomed = await framing(page)
const centre = await clientOf(page, INSIDE.x, INSIDE.y)
const pair = [
{ x: centre.x - 60, y: centre.y },
{ x: centre.x + 60, y: centre.y },
]
await touch(cdp, 'touchStart', pair)
await move(
cdp,
pair,
pair.map((p) => ({ x: p.x + 50, y: p.y + 30 })),
)
await touch(cdp, 'touchEnd', [])
const panned = await framing(page)
expect(panned.scale).toBeCloseTo(zoomed.scale, 2)
expect(Math.abs(panned.x - zoomed.x - 50)).toBeLessThan(1.5)
expect(Math.abs(panned.y - zoomed.y - 30)).toBeLessThan(1.5)
expect(await shownPoints(page)).toEqual(SQUARE)
await expect(undo).toBeDisabled()
expect(saves).toEqual([])
})
test('the move mode by a finger; a tap opens the selection or unchooses; a trace closes within 22 px', async ({
page,
context,
requests,
}) => {
const { actor } = await open(page)
requests.forbid(actor.account.email, actor.account.password)
const cdp = await context.newCDPSession(page)
await select(page, ZONE)
// « Déplacer la zone »: a finger anywhere moves it, « Valider la position » commits.
// Its entry moves nothing around the drawing (A14). The button is centred first: below
// xl the sticky top bar may cover it, and Playwright would scroll inside the probe.
const entry = button(page, 'editor.annotations.move.zone')
await entry.evaluate((element) =>
element.scrollIntoView({ block: 'center' }),
)
await expectNoShift(page, async () => {
await entry.click()
await expect(
button(page, 'editor.annotations.move.confirm'),
).toBeVisible()
})
await canvas(page).scrollIntoViewIfNeeded()
const empty = await clientOf(page, EMPTY.x, EMPTY.y)
await drag(cdp, empty, { x: empty.x + 40, y: empty.y + 40 })
const previewed = await shownPoints(page)
expect(previewed).not.toEqual(SQUARE)
await button(page, 'editor.annotations.move.confirm').click()
await expect.poll(() => shownPoints(page)).toEqual(previewed)
const dx = previewed[0][0] - SQUARE[0][0]
const dy = previewed[0][1] - SQUARE[0][1]
expect(dx).toBeGreaterThan(0)
expect(previewed[2][0]).toBeCloseTo(SQUARE[2][0] + dx, 6)
expect(previewed[2][1]).toBeCloseTo(SQUARE[2][1] + dy, 6)
// A tap on the selected zone opens its properties; the dialog stays.
await canvas(page).scrollIntoViewIfNeeded()
const inside = await clientOf(page, INSIDE.x + dx, INSIDE.y + dy)
await tap(cdp, inside)
const dialog = page.getByRole('dialog')
await expect(dialog).toBeVisible()
await page.waitForTimeout(450)
await expect(dialog).toBeVisible()
await page.keyboard.press('Escape')
await expect(dialog).toHaveCount(0)
// A tap on a vertex chooses it; a tap inside then unchooses, no dialog.
await canvas(page).scrollIntoViewIfNeeded()
const corner = previewed[0]
await tap(cdp, await clientOf(page, corner[0], corner[1]))
const bubble = page.getByRole('button', { name: /^Retirer le sommet/ })
await expect(bubble).toHaveCount(1)
await tap(cdp, await clientOf(page, INSIDE.x + dx, INSIDE.y + dy))
await expect(bubble).toHaveCount(0)
await expect(dialog).toHaveCount(0)
// A new zone traced by finger closes on a tap 18 px from its first vertex (R-11).
await button(page, 'editor.annotations.deselect').click()
await toolButton(page, dict, 'zone').click()
await canvas(page).scrollIntoViewIfNeeded()
const first = await clientOf(page, 150, 600)
// Quick taps, each within the absorber's 400 ms of the last: each one places.
for (const [x, y] of [
[150, 600],
[300, 600],
[300, 700],
]) {
await tap(cdp, await clientOf(page, x, y))
}
await expect(creationPanel(page)).toHaveCount(0)
await tap(cdp, { x: first.x + 18, y: first.y })
await expect(creationPanel(page)).toBeVisible()
})
})
}