Deterministic scroll-settle wait for the bubble e2e, useDismissal split, precondition for the add-button focus test, CSS comment wrap.
1260 lines
48 KiB
TypeScript
1260 lines
48 KiB
TypeScript
import { fr } from '@/i18n/fr'
|
|
import type { Locator, Page, TestInfo } from '@playwright/test'
|
|
import { expect, expectAccessible, test } from '../support/browser'
|
|
import { expectNoShift } from '../support/layout'
|
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
|
import {
|
|
place,
|
|
clickDrawing,
|
|
clientOf,
|
|
editorActor,
|
|
shownNumber,
|
|
shownShape,
|
|
openEditor,
|
|
openSection,
|
|
pickAnnotation,
|
|
pointOf,
|
|
saveDraft,
|
|
seedDraft,
|
|
selectionTag,
|
|
selectTab,
|
|
annotationList,
|
|
serverDocument,
|
|
shapeWith,
|
|
standardShape,
|
|
openProperties,
|
|
scrollToTop,
|
|
} 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 with the move mode (U2 Task 4), 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 the correction proposes, read from the drawing (R-4: the notice in the
|
|
* creation dialog says it without numbers).
|
|
*/
|
|
async function proposed(page: Page): Promise<{ x: string; y: string }> {
|
|
const circle = page.getByTestId('overlay-correction').locator('circle')
|
|
const x = await circle.getAttribute('cx')
|
|
const y = await circle.getAttribute('cy')
|
|
if (x === null || y === null) throw new Error('no proposed position drawn')
|
|
return { x, y }
|
|
}
|
|
|
|
/** A mouse drag on the drawing in the move mode, between two points in drawing units. */
|
|
async function dragInMode(
|
|
page: Page,
|
|
from: { x: number; y: number },
|
|
to: { x: number; y: number },
|
|
) {
|
|
const start = await clientOf(page, from.x, from.y)
|
|
const end = await clientOf(page, to.x, to.y)
|
|
await page.mouse.move(start.x, start.y)
|
|
await page.mouse.down()
|
|
await page.mouse.move(end.x, end.y, { steps: 6 })
|
|
await page.mouse.up()
|
|
}
|
|
|
|
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()
|
|
// R-4: the notice is in the creation dialog, its text without numbers.
|
|
await expect(
|
|
page.getByRole('dialog', { name: dict['editor.annotations.new.point'] }),
|
|
).toContainText(dict['editor.annotations.correction'])
|
|
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(shownShape(page)).toHaveAttribute('cx', shown.x)
|
|
await expect(shownShape(page)).toHaveAttribute('cy', 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 with the move mode', 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/)
|
|
// The issue: an alert in the properties dialog's read mode, its text in the strip.
|
|
const properties = await openProperties(page, dict)
|
|
const issue = (
|
|
await properties
|
|
.getByTestId('annotation-geometry-issues')
|
|
.locator('li')
|
|
.first()
|
|
.innerText()
|
|
).trim()
|
|
await page.keyboard.press('Escape')
|
|
await expect(page.getByRole('dialog')).toHaveCount(0)
|
|
const notice = page.getByTestId('edit-strip-notice')
|
|
await expect(notice).toContainText(issue)
|
|
const verification = page.getByRole('tab', {
|
|
name: dict['editor.tab.verification'],
|
|
})
|
|
const errorsBefore = Number(
|
|
(await verification.innerText()).replace(/\D/g, ''),
|
|
)
|
|
expect(errorsBefore).toBeGreaterThan(0)
|
|
const move = page.getByRole('button', {
|
|
name: dict['editor.annotations.move.point'],
|
|
})
|
|
const confirm = page.getByRole('button', {
|
|
name: dict['editor.annotations.move.confirm'],
|
|
})
|
|
|
|
// A partial move (still out of the frame): refused by the core, the point restored.
|
|
// Nothing around the drawing moves (A14), from the page's top here.
|
|
await scrollToTop(page)
|
|
await expectNoShift(page, () => move.click())
|
|
await dragInMode(page, { x: 250, y: 250 }, { x: 260, y: 260 })
|
|
await expectNoShift(page, async () => {
|
|
await confirm.click()
|
|
await expect(page.getByTestId('gesture-message')).toBeVisible()
|
|
})
|
|
await expect(page.getByTestId('gesture-message')).toContainText(
|
|
dict['editor.annotations.message.move_refused'].split(' :')[0],
|
|
)
|
|
await expect(page.getByTestId('overlay-refused-place')).toBeAttached()
|
|
await expect(shownShape(page)).toHaveAttribute('cx', '110')
|
|
await expect(verification).toContainText(String(errorsBefore))
|
|
|
|
// M-3: the same refusal again is a new pill, announced again; nothing moves (A14).
|
|
const pill = page.getByTestId('gesture-message')
|
|
await pill.evaluate((element) => element.setAttribute('data-first', ''))
|
|
await expectNoShift(page, () => move.click())
|
|
await dragInMode(page, { x: 250, y: 250 }, { x: 260, y: 260 })
|
|
await expectNoShift(page, async () => {
|
|
await confirm.click()
|
|
await expect(
|
|
page.locator('[data-testid="gesture-message"]:not([data-first])'),
|
|
).toBeVisible()
|
|
})
|
|
await expect(pill).toHaveCount(1)
|
|
await expect(page.getByRole('alert').filter({ has: pill })).toHaveCount(0)
|
|
await expect(pill).toHaveAttribute('role', 'alert')
|
|
await expect(pill).toContainText(
|
|
dict['editor.annotations.message.move_refused'].split(' :')[0],
|
|
)
|
|
await expect(shownShape(page)).toHaveAttribute('cx', '110')
|
|
|
|
// Far enough inside, from the page's end: kept, the issue gone, one error less. The
|
|
// issue leaving no longer shortens the page (it lives in the strip and the dialog, the
|
|
// side column keeps the overview, U2 Task 6), so the scroll clamp moves nothing. The
|
|
// buttons are pressed in place (no scroll into view), the page stays at its end.
|
|
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight))
|
|
const end = await page.evaluate(() => window.scrollY)
|
|
expect(end, 'the page scrolls: its end is not its top').toBeGreaterThan(0)
|
|
await expectNoShift(page, () => move.dispatchEvent('click'))
|
|
await dragInMode(page, { x: 250, y: 250 }, { x: 290, y: 290 })
|
|
await expectNoShift(page, async () => {
|
|
await confirm.dispatchEvent('click')
|
|
await expect(notice).not.toContainText(issue)
|
|
})
|
|
expect(await page.evaluate(() => window.scrollY)).toBe(end)
|
|
expect(Math.abs((await shownNumber(page, 'cx')) - 150)).toBeLessThan(2)
|
|
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')
|
|
await expect(shownShape(page)).toHaveAttribute('cx', '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(shownShape(page)).not.toHaveAttribute('cx', '500')
|
|
expect(Math.abs((await shownNumber(page, 'cx')) - 620)).toBeLessThan(3)
|
|
})
|
|
})
|
|
|
|
// U2 Task 14 (owner point 1): on the editable layout the strip stays right under the sticky
|
|
// top bar at every scroll position, without moving anything in the flow.
|
|
const VIEWPORTS = [
|
|
{ width: 1024, height: 768 },
|
|
{ width: 1180, height: 820 },
|
|
{ width: 1280, height: 800 },
|
|
]
|
|
|
|
const topBar = (page: Page) =>
|
|
page.locator('header:has([data-testid="topbar-account"])')
|
|
|
|
/** Enough annotations for the overview to grow the page well past one screen. */
|
|
const manyPoints = () =>
|
|
Array.from({ length: 14 }, (_, i) =>
|
|
pointOf(`pt-${i}`, 'main', { cx: 100 + i * 40, cy: 100, r: 10 }, `Pt ${i}`),
|
|
)
|
|
|
|
/** The strip's and the bar's boxes, and what is painted at the strip's centre. */
|
|
function stripGeometry(page: Page) {
|
|
return page.evaluate(() => {
|
|
const strip = document.querySelector('[data-testid="edit-strip"]')!
|
|
const bar = document.querySelector(
|
|
'header:has([data-testid="topbar-account"])',
|
|
)!
|
|
const box = strip.getBoundingClientRect()
|
|
const hit = document.elementFromPoint(
|
|
box.x + box.width / 2,
|
|
box.y + box.height / 2,
|
|
)
|
|
return {
|
|
barBottom: bar.getBoundingClientRect().bottom,
|
|
top: box.top,
|
|
bottom: box.bottom,
|
|
covered: !hit || !strip.contains(hit),
|
|
scrollY: window.scrollY,
|
|
limit: document.documentElement.scrollHeight - window.innerHeight,
|
|
innerHeight: window.innerHeight,
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* The pinned drawing column (U2 Task 17): its box, the canvas box, what is painted at the
|
|
* canvas's top centre.
|
|
*/
|
|
function columnGeometry(page: Page) {
|
|
return page.evaluate(() => {
|
|
const rect = (css: string) =>
|
|
document.querySelector(css)!.getBoundingClientRect()
|
|
const box = rect('[data-drawing-column]')
|
|
const drawing = rect('[data-testid="annotation-canvas"]')
|
|
const hit = document.elementFromPoint(
|
|
drawing.x + drawing.width / 2,
|
|
drawing.y + 2,
|
|
)
|
|
return {
|
|
top: box.top,
|
|
bottom: box.bottom,
|
|
canvas: { y: drawing.y, width: drawing.width, height: drawing.height },
|
|
canvasTopPainted: !!hit?.closest('[data-testid="annotation-canvas"]'),
|
|
// Not capped: the canvas box still runs to the column's right edge.
|
|
canvasFills: Math.abs(rect('[data-canvas-box]').right - box.right) < 0.5,
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Whether the page scrolls sideways: a scroll attempt moves it only if something overflows
|
|
* (scrollWidth against clientWidth hides up to the scrollbar gutter's width). It scrolls the
|
|
* page sideways and back, so it fires scroll events.
|
|
*/
|
|
function scrollsSideways(page: Page) {
|
|
return page.evaluate(() => {
|
|
window.scrollTo(100, window.scrollY)
|
|
const moved = window.scrollX > 0
|
|
window.scrollTo(0, window.scrollY)
|
|
return moved
|
|
})
|
|
}
|
|
|
|
/**
|
|
* The focused element's top against the bottom of what covers it (the strip in the drawing
|
|
* place, else the bar); null on the sticky chrome itself, whose focus never scrolls the page.
|
|
*/
|
|
function focusedUnderStrip(page: Page) {
|
|
return page.evaluate(() => {
|
|
const active = document.activeElement as HTMLElement
|
|
const strip = document.querySelector('[data-testid="edit-strip"]')!
|
|
const label = active.getAttribute('aria-label') ?? active.textContent ?? ''
|
|
const bar = document.querySelector(
|
|
'header:has([data-testid="topbar-account"])',
|
|
)!
|
|
const inPlace =
|
|
!!active.closest('[data-place="annotations.drawing"]') &&
|
|
!strip.contains(active)
|
|
// Below the strip in the drawing place, below the bar elsewhere; the sticky chrome
|
|
// itself (the strip's commands, the bar's links) never scrolls the page; the shell's own
|
|
// links, outside the editor page, are not its concern.
|
|
const sticky =
|
|
strip.contains(active) ||
|
|
bar.contains(active) ||
|
|
!active.closest('[data-editor-workspace]')
|
|
return {
|
|
limit: sticky
|
|
? null
|
|
: inPlace
|
|
? strip.getBoundingClientRect().bottom
|
|
: bar.getBoundingClientRect().bottom,
|
|
name: `${active.tagName} « ${label.trim().slice(0, 30)} »`,
|
|
top: active.getBoundingClientRect().top,
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* A window too short for the pinned drawing column (U2 Task 17: pinned from 40.25 rem high):
|
|
* the drawing scrolls under the strip as before, and the strip's margin brings a focus out.
|
|
*/
|
|
const belowPinnedHeight = (page: Page) =>
|
|
page.setViewportSize({ width: page.viewportSize()!.width, height: 600 })
|
|
|
|
// Criterion 25: the header's « Enregistrer » and the tab row's « Défaire » and « Refaire » sit
|
|
// outside the drawing place; a keyboard focus on them, the page scrolled, never lands under the bar.
|
|
const HEADER_WIDTHS = [820, 1024, 1280]
|
|
|
|
/** Focuses the tabbable next to `target` without scrolling, then scrolls it under the bar. */
|
|
function parkBesideTarget(target: Locator, key: 'Tab' | 'Shift+Tab') {
|
|
return target.evaluate((el, step) => {
|
|
const tabbable = [
|
|
...document.querySelectorAll<HTMLElement>(
|
|
'a[href], button, input, select, textarea, [tabindex]',
|
|
),
|
|
].filter((n) => n.tabIndex >= 0 && n.getClientRects().length > 0)
|
|
const beside =
|
|
tabbable[tabbable.indexOf(el as HTMLElement) + (step === 'Tab' ? -1 : 1)]
|
|
beside.focus({ preventScroll: true })
|
|
const bar = document.querySelector(
|
|
'header:has([data-testid="topbar-account"])',
|
|
)!
|
|
const top = el.getBoundingClientRect().top + window.scrollY
|
|
window.scrollTo(0, top - bar.getBoundingClientRect().bottom + 10)
|
|
}, key)
|
|
}
|
|
|
|
for (const width of HEADER_WIDTHS) {
|
|
test.describe(`the editor header's controls under the top bar at ${width} px (criterion 25)`, () => {
|
|
test.use({
|
|
locale: 'fr-FR',
|
|
actionTimeout: 15_000,
|
|
viewport: { width, height: 768 },
|
|
})
|
|
test.beforeEach(async ({ context }, info) => {
|
|
test.skip(isPhone(info), 'the phone project has its own viewport') // floor-guard: allow C16 sticky bar probed at 820, 1 024 and 1 280 px
|
|
await routeToSandbox(context)
|
|
})
|
|
test.afterEach(async ({ context }) => {
|
|
await dropLateReplays(context)
|
|
})
|
|
|
|
test('Tab and Shift+Tab onto « Enregistrer », « Défaire » and « Refaire » end below the bar', async ({
|
|
page,
|
|
}) => {
|
|
const actor = await editorActor('fr')
|
|
const seed = await seedDraft(actor, { shape: shapeWith(...manyPoints()) })
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
// A committed edit enables « Enregistrer » and « Défaire »; back on the annotations tab.
|
|
await selectTab(page, dict, 'general')
|
|
const name = page.getByLabel(dict['editor.general.name_en'], {
|
|
exact: true,
|
|
})
|
|
// Read-only below 1 024 px: the name is text and only the tab row's controls remain.
|
|
const editable = await name.evaluate((el) => el.tagName === 'INPUT')
|
|
if (editable) {
|
|
await name.fill(`Edited ${Date.now()}`)
|
|
await name.press('Enter')
|
|
}
|
|
await selectTab(page, dict, 'annotations')
|
|
const named = (label: string) =>
|
|
page.getByRole('button', { name: label, exact: true })
|
|
const targets = [
|
|
page.getByRole('tab', { name: dict['editor.tab.annotations'] }),
|
|
...(editable
|
|
? [
|
|
named(dict['common.save']),
|
|
named(dict['editor.history.undo_title']),
|
|
named(dict['editor.history.redo_title']),
|
|
]
|
|
: []),
|
|
]
|
|
if (editable) await expect(targets[1]).toBeEnabled()
|
|
for (const target of targets) {
|
|
for (const key of ['Tab', 'Shift+Tab'] as const) {
|
|
await parkBesideTarget(target, key)
|
|
const bar = await topBar(page).boundingBox()
|
|
const before = (await target.boundingBox())!
|
|
expect(before.y, 'precondition: starts under the bar').toBeLessThan(
|
|
bar!.y + bar!.height,
|
|
)
|
|
const label =
|
|
(await target.getAttribute('aria-label')) ??
|
|
(await target.textContent())
|
|
await page.keyboard.press(key)
|
|
await expect(target, `${key} onto ${label}`).toBeFocused()
|
|
const after = (await target.boundingBox())!
|
|
const barBottom = (await topBar(page).boundingBox())!.y + bar!.height
|
|
expect
|
|
.soft(
|
|
after.y,
|
|
`${key} onto ${label}: top ${after.y} vs bar bottom ${barBottom}`,
|
|
)
|
|
.toBeGreaterThanOrEqual(barBottom - 0.5)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
for (const viewport of VIEWPORTS) {
|
|
test.describe(`the strip under the top bar at ${viewport.width} px (U2 Task 14)`, () => {
|
|
test.use({
|
|
locale: 'fr-FR',
|
|
actionTimeout: 15_000,
|
|
hasTouch: true,
|
|
viewport,
|
|
})
|
|
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('at every scroll step the strip is below the bar and visible; nothing shifts', async ({
|
|
page,
|
|
context,
|
|
}) => {
|
|
await open(page, ...manyPoints())
|
|
await pickAnnotation(page, dict, 'Pt 0')
|
|
await expect(selectionTag(page)).toContainText('Pt 0')
|
|
const flowTop = (selector: string) =>
|
|
page.evaluate(
|
|
(css) =>
|
|
document.querySelector(css)!.getBoundingClientRect().top +
|
|
window.scrollY,
|
|
selector,
|
|
)
|
|
const asideTop = await flowTop('[data-annotation-aside="edit"]')
|
|
const start = await stripGeometry(page)
|
|
const { canvas } = await columnGeometry(page)
|
|
expect(start.limit, 'the page must scroll').toBeGreaterThan(300)
|
|
|
|
for (let y = 0; y <= start.limit + 150; y += 150) {
|
|
await page.evaluate((to) => window.scrollTo(0, to), y)
|
|
const now = await stripGeometry(page)
|
|
const at = `scrollY ${now.scrollY}`
|
|
expect(
|
|
now.top,
|
|
`strip top below the bar at ${at}`,
|
|
).toBeGreaterThanOrEqual(now.barBottom - 0.5)
|
|
expect(now.bottom, `strip bottom in view at ${at}`).toBeLessThanOrEqual(
|
|
now.innerHeight,
|
|
)
|
|
expect(now.covered, `strip painted at ${at}`).toBe(false)
|
|
// Task 17: the drawing column (chips to message line) is never under the strip
|
|
// and fits the window; the canvas keeps its size; nothing scrolls sideways.
|
|
const pinned = await columnGeometry(page)
|
|
expect(
|
|
pinned.top,
|
|
`column top below the strip at ${at}`,
|
|
).toBeGreaterThanOrEqual(now.bottom - 0.5)
|
|
// Stuck with the strip, all of it is in view (before, the page top shows its top).
|
|
if (now.top <= now.barBottom + 0.5)
|
|
expect(
|
|
pinned.bottom,
|
|
`column bottom in view at ${at}`,
|
|
).toBeLessThanOrEqual(now.innerHeight + 0.5)
|
|
expect(pinned.canvasTopPainted, `canvas top painted at ${at}`).toBe(
|
|
true,
|
|
)
|
|
expect(pinned.canvas.width, `canvas width at ${at}`).toBe(canvas.width)
|
|
expect(pinned.canvas.height, `canvas height at ${at}`).toBe(
|
|
canvas.height,
|
|
)
|
|
expect(await scrollsSideways(page), `no sideways scroll at ${at}`).toBe(
|
|
false,
|
|
)
|
|
expect(pinned.canvasFills, `canvas not capped at ${at}`).toBe(true)
|
|
}
|
|
// Sticky leaves the flow alone: the aside keeps its place.
|
|
expect(await flowTop('[data-annotation-aside="edit"]')).toBe(asideTop)
|
|
|
|
const bottom = (await stripGeometry(page)).scrollY
|
|
const command = page
|
|
.getByTestId('edit-strip')
|
|
.getByRole('button', { name: dict['editor.annotations.properties'] })
|
|
// A finger on a strip command after the scroll hits it (a hit check that had to
|
|
// scroll again would move the page), and no box moves.
|
|
const cdp = await context.newCDPSession(page)
|
|
const box = (await command.boundingBox())!
|
|
expect(
|
|
box.y,
|
|
'the command is in view, under the bar',
|
|
).toBeGreaterThanOrEqual((await stripGeometry(page)).barBottom)
|
|
await expectNoShift(page, async () => {
|
|
const at = { x: box.x + box.width / 2, y: box.y + box.height / 2 }
|
|
await cdp.send('Input.dispatchTouchEvent', {
|
|
type: 'touchStart',
|
|
touchPoints: [at],
|
|
})
|
|
await cdp.send('Input.dispatchTouchEvent', {
|
|
type: 'touchEnd',
|
|
touchPoints: [],
|
|
})
|
|
await expect(page.getByRole('dialog')).toBeVisible()
|
|
await page.keyboard.press('Escape')
|
|
await expect(page.getByRole('dialog')).toHaveCount(0)
|
|
})
|
|
expect((await stripGeometry(page)).scrollY).toBe(bottom)
|
|
})
|
|
|
|
test('a focus never scrolls onto the bar or the strip, nor lands under them', async ({
|
|
page,
|
|
}) => {
|
|
// A marker large enough on the phone preview for its moves to be accepted.
|
|
const big = pointOf(
|
|
'pt-big',
|
|
'main',
|
|
{ cx: 500, cy: 400, r: 40 },
|
|
'Pt Big',
|
|
)
|
|
await open(page, ...manyPoints(), big)
|
|
await pickAnnotation(page, dict, 'Pt Big')
|
|
// At the page top the add row is below the fold: its focus reveals it with the least
|
|
// scroll, never onto the bar or the strip, and the column stays below the strip.
|
|
await page.evaluate(() => window.scrollTo(0, 0))
|
|
const add = page.locator('[data-add-kind="point"]')
|
|
const unrevealed = (await add.boundingBox())!
|
|
expect(
|
|
unrevealed.y,
|
|
'precondition: the add button is below the fold',
|
|
).toBeGreaterThan(await page.evaluate(() => window.innerHeight))
|
|
await add.focus()
|
|
const revealed = await stripGeometry(page)
|
|
const addBox = (await add.boundingBox())!
|
|
expect(addBox.y, 'the add button below the strip').toBeGreaterThanOrEqual(
|
|
revealed.bottom - 0.5,
|
|
)
|
|
expect(addBox.y + addBox.height).toBeLessThanOrEqual(
|
|
revealed.innerHeight + 0.5,
|
|
)
|
|
expect((await columnGeometry(page)).top).toBeGreaterThanOrEqual(
|
|
revealed.bottom - 0.5,
|
|
)
|
|
await page.evaluate(() => window.scrollTo(0, 300))
|
|
const before = (await stripGeometry(page)).scrollY
|
|
// The keyboard's focus move on the strip's command and on the bar's first control.
|
|
for (const target of [
|
|
page
|
|
.getByTestId('edit-strip')
|
|
.getByRole('button', { name: dict['editor.annotations.properties'] }),
|
|
topBar(page).getByRole('link').first(),
|
|
]) {
|
|
await target.focus()
|
|
expect(
|
|
(await stripGeometry(page)).scrollY,
|
|
'focus on sticky chrome',
|
|
).toBe(before)
|
|
}
|
|
// U2 Task 17: nor on the pinned column's controls (the line's « Défaire », a view
|
|
// chip, the handle, an add button, the canvas box), each below the strip. A commit
|
|
// puts « Défaire » in the message line for 6 s.
|
|
await page.getByTestId('point-handle').focus()
|
|
await page.keyboard.press('ArrowRight')
|
|
await page.keyboard.press('Enter')
|
|
const line = page.getByTestId('gesture-line')
|
|
const undo = line.getByRole('button', {
|
|
name: dict['editor.history.undo_title'],
|
|
})
|
|
await expect(undo).toBeVisible()
|
|
for (const target of [
|
|
undo,
|
|
viewChip(page, 'Vue principale'),
|
|
page.getByTestId('point-handle'),
|
|
page.locator('[data-add-kind="point"]'),
|
|
page.getByTestId('annotation-canvas'),
|
|
]) {
|
|
await target.focus()
|
|
const label = await target.evaluate(
|
|
(el) => el.getAttribute('aria-label') ?? el.textContent,
|
|
)
|
|
expect((await stripGeometry(page)).scrollY, `focus on ${label}`).toBe(
|
|
before,
|
|
)
|
|
expect(
|
|
(await target.boundingBox())!.y,
|
|
`${label} below the strip`,
|
|
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom - 0.5)
|
|
}
|
|
// A row hidden under the strip comes out below it, not under it. The row sits low in the
|
|
// page: a short window lets the page scroll far enough to put it under the strip.
|
|
await page.setViewportSize({
|
|
width: page.viewportSize()!.width,
|
|
height: 400,
|
|
})
|
|
const row = annotationList(page, dict).getByRole('button').first()
|
|
await page.evaluate(
|
|
(el) => {
|
|
const top = el.getBoundingClientRect().top + window.scrollY
|
|
window.scrollTo(0, top - 100)
|
|
},
|
|
await row.elementHandle(),
|
|
)
|
|
const hidden = await stripGeometry(page)
|
|
expect(
|
|
(await row.boundingBox())!.y,
|
|
'precondition: the row starts under the strip',
|
|
).toBeLessThan(hidden.bottom)
|
|
await row.focus()
|
|
const now = await stripGeometry(page)
|
|
const top = (await row.boundingBox())!.y
|
|
expect(top, 'the focused row is below the strip').toBeGreaterThanOrEqual(
|
|
now.bottom,
|
|
)
|
|
})
|
|
|
|
test(
|
|
'a vertex handle (SVG) focused under the strip ends below it ' +
|
|
'(window below the pinned height)',
|
|
async ({ page }) => {
|
|
await belowPinnedHeight(page)
|
|
await open(page, ...manyPoints(), {
|
|
...pointOf('zone-v', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone V'),
|
|
kind: 'zone',
|
|
geometry: {
|
|
type: 'polygon',
|
|
points: [
|
|
[300, 200],
|
|
[600, 200],
|
|
[600, 500],
|
|
[300, 500],
|
|
],
|
|
},
|
|
})
|
|
await pickAnnotation(page, dict, 'Zone V')
|
|
const vertex = page.locator('[data-vertex="0"]')
|
|
await expect(vertex).toBeVisible()
|
|
await page.evaluate(() => {
|
|
const el = document.querySelector('[data-vertex="0"]')!
|
|
window.scrollTo(
|
|
0,
|
|
el.getBoundingClientRect().top + window.scrollY - 80,
|
|
)
|
|
})
|
|
const strip = await stripGeometry(page)
|
|
const before = (await vertex.boundingBox())!
|
|
expect(
|
|
before.y,
|
|
'precondition: the handle starts under the strip',
|
|
).toBeLessThan(strip.bottom)
|
|
await vertex.focus()
|
|
const after = (await vertex.boundingBox())!
|
|
expect(
|
|
after.y,
|
|
'the focused handle is below the strip',
|
|
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom)
|
|
},
|
|
)
|
|
|
|
test(
|
|
"Tab and Shift+Tab onto the drawing place's native controls land below the strip " +
|
|
'(window below the pinned height)',
|
|
async ({ page }) => {
|
|
await belowPinnedHeight(page)
|
|
await open(page, ...manyPoints())
|
|
await pickAnnotation(page, dict, 'Pt 0')
|
|
// A commit puts « Défaire » in the message line under the drawing.
|
|
await page.getByTestId('point-handle').focus()
|
|
await page.keyboard.press('ArrowRight')
|
|
await page.keyboard.press('Enter')
|
|
await expect(page.getByTestId('gesture-message')).toBeVisible()
|
|
// Each walk starts on the canvas box, the page scrolled so the canvas top and the
|
|
// aside's top sit under the strip; the focus starts there without a scroll.
|
|
for (const key of ['Shift+Tab', 'Tab']) {
|
|
await page.evaluate(() => {
|
|
const canvas = document.querySelector<HTMLElement>(
|
|
'[data-testid="annotation-canvas"]',
|
|
)!
|
|
const top = canvas.getBoundingClientRect().top + window.scrollY
|
|
window.scrollTo(0, top - 100)
|
|
canvas.focus({ preventScroll: true })
|
|
})
|
|
for (let step = 0; step < 40; step++) {
|
|
await page.keyboard.press(key)
|
|
const at = await focusedUnderStrip(page)
|
|
if (at.limit === null) continue
|
|
expect(
|
|
at.top,
|
|
`${key} ${step + 1}: ${at.name} below the strip or the bar`,
|
|
).toBeGreaterThanOrEqual(at.limit - 0.5)
|
|
}
|
|
}
|
|
},
|
|
)
|
|
|
|
test(
|
|
'Delete from the keyboard focuses the next vertex below the strip ' +
|
|
'(window below the pinned height)',
|
|
async ({ page }) => {
|
|
await belowPinnedHeight(page)
|
|
await open(page, ...manyPoints(), {
|
|
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
|
|
kind: 'zone',
|
|
geometry: {
|
|
type: 'polygon',
|
|
points: [
|
|
[300, 600],
|
|
[300, 150],
|
|
[600, 150],
|
|
[600, 600],
|
|
],
|
|
},
|
|
})
|
|
await pickAnnotation(page, dict, 'Zone K')
|
|
// The next vertex (drawn higher) starts under the strip, the focused one below it.
|
|
const top = await page.evaluate(() => {
|
|
const next = document.querySelector('[data-vertex="1"]')!
|
|
const y = next.getBoundingClientRect().top + window.scrollY
|
|
window.scrollTo(0, y - 90)
|
|
document
|
|
.querySelector<SVGElement>('[data-vertex="0"]')!
|
|
.focus({ preventScroll: true })
|
|
return next.getBoundingClientRect().top
|
|
})
|
|
const strip = await stripGeometry(page)
|
|
expect(
|
|
top,
|
|
'precondition: the next vertex is under the strip',
|
|
).toBeLessThan(strip.bottom)
|
|
await page.keyboard.press('Delete')
|
|
await expect(page.locator('[data-vertex="3"]')).toHaveCount(0)
|
|
const at = await focusedUnderStrip(page)
|
|
expect(at.name).toContain('Sommet')
|
|
expect(at.top, `${at.name} below the strip`).toBeGreaterThanOrEqual(
|
|
(await stripGeometry(page)).bottom - 0.5,
|
|
)
|
|
},
|
|
)
|
|
|
|
test(
|
|
'pinned: Delete and Insert from the keyboard keep the page still, ' +
|
|
'the vertex below the strip',
|
|
async ({ page }) => {
|
|
await open(page, ...manyPoints(), {
|
|
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
|
|
kind: 'zone',
|
|
geometry: {
|
|
type: 'polygon',
|
|
points: [
|
|
[300, 600],
|
|
[300, 150],
|
|
[600, 150],
|
|
[600, 600],
|
|
],
|
|
},
|
|
})
|
|
await pickAnnotation(page, dict, 'Zone K')
|
|
await page.evaluate(() => window.scrollTo(0, 400))
|
|
// A pinned handle carries no strip margin: its focus does not scroll the page.
|
|
await page.locator('[data-vertex="0"]').focus()
|
|
const before = (await stripGeometry(page)).scrollY
|
|
expect(before, 'the focus on a pinned handle').toBe(400)
|
|
for (const [key, last] of [
|
|
['Delete', 0],
|
|
['Insert', 1],
|
|
] as const) {
|
|
await page.keyboard.press(key)
|
|
await expect(page.locator('[data-vertex="3"]')).toHaveCount(last)
|
|
const at = await focusedUnderStrip(page)
|
|
expect(at.name, key).toContain('Sommet')
|
|
expect(
|
|
at.top,
|
|
`${key}: ${at.name} below the strip`,
|
|
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom - 0.5)
|
|
expect((await stripGeometry(page)).scrollY, `${key}: the page`).toBe(
|
|
before,
|
|
)
|
|
}
|
|
},
|
|
)
|
|
|
|
test('pinned: a row selection moves neither the page nor the drawing on screen', async ({
|
|
page,
|
|
}) => {
|
|
await open(page, ...manyPoints())
|
|
for (const name of ['Pt 3', 'Pt 4']) {
|
|
const row = annotationList(page, dict).getByRole('button', { name })
|
|
// The row at mid-window, the page scrolled past the point where the column sticks.
|
|
await row.evaluate((el) => {
|
|
const top = el.getBoundingClientRect().top + window.scrollY
|
|
window.scrollTo(0, top - window.innerHeight / 2)
|
|
})
|
|
expect((await stripGeometry(page)).scrollY).toBeGreaterThan(300)
|
|
const box = (await row.boundingBox())!
|
|
const strip = await stripGeometry(page)
|
|
expect(box.y, `precondition: ${name} in view`).toBeGreaterThan(
|
|
strip.bottom,
|
|
)
|
|
expect(box.y + box.height).toBeLessThan(strip.innerHeight)
|
|
const before = await columnGeometry(page)
|
|
// A real pointer press on the visible row: no bring-into-view scroll.
|
|
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2)
|
|
await expect(selectionTag(page)).toContainText(name)
|
|
expect((await stripGeometry(page)).scrollY, name).toBe(strip.scrollY)
|
|
expect((await columnGeometry(page)).canvas, name).toEqual(before.canvas)
|
|
}
|
|
})
|
|
|
|
test('with the strip hidden only the bar offset is applied', async ({
|
|
page,
|
|
}) => {
|
|
await open(page, ...manyPoints())
|
|
const margin = () =>
|
|
page.evaluate(
|
|
() =>
|
|
getComputedStyle(
|
|
document.querySelector(
|
|
'[data-place="annotations.drawing"] [data-focus-key]',
|
|
)!,
|
|
).scrollMarginTop,
|
|
)
|
|
expect(parseFloat(await margin()), 'the strip is shown').toBeGreaterThan(
|
|
100,
|
|
)
|
|
await openSection(page, dict, 'categories')
|
|
await expect(page.getByTestId('edit-strip')).toBeHidden()
|
|
// Only the bar's margin (its height and the 0.5 rem gap) remains, not the strip's.
|
|
const bar = (await topBar(page).boundingBox())!
|
|
expect(parseFloat(await margin()), 'the strip is hidden').toBe(
|
|
bar.height + 8,
|
|
)
|
|
})
|
|
})
|
|
}
|
|
|
|
// U2 Task 17 at shorter windows: 1 180 x 700 pins a capped canvas (its size set by the window,
|
|
// never by the scroll); 1 024 x 600 is below the pinned height (nothing pinned or capped).
|
|
const SHORT_WINDOWS = [
|
|
{ width: 1180, height: 700, pinned: true },
|
|
{ width: 1024, height: 600, pinned: false },
|
|
]
|
|
|
|
for (const { pinned, ...viewport } of SHORT_WINDOWS) {
|
|
test.describe(`the drawing column at ${viewport.width} x ${viewport.height} (U2 Task 17)`, () => {
|
|
test.use({ locale: 'fr-FR', actionTimeout: 15_000, viewport })
|
|
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('no sideways scroll at any scroll step; pinned, the column fits the window', async ({
|
|
page,
|
|
}) => {
|
|
await open(page, ...manyPoints())
|
|
const start = await stripGeometry(page)
|
|
const { canvas, canvasFills } = await columnGeometry(page)
|
|
expect(canvasFills, 'the canvas is capped only when pinned').toBe(!pinned)
|
|
for (let y = 0; y <= start.limit + 150; y += 150) {
|
|
await page.evaluate((to) => window.scrollTo(0, to), y)
|
|
const strip = await stripGeometry(page)
|
|
const now = await columnGeometry(page)
|
|
const at = `scrollY ${strip.scrollY}`
|
|
expect(await scrollsSideways(page), `no sideways scroll at ${at}`).toBe(
|
|
false,
|
|
)
|
|
expect(now.canvas.width, `canvas width at ${at}`).toBe(canvas.width)
|
|
if (!pinned) continue
|
|
expect(
|
|
now.top,
|
|
`column below the strip at ${at}`,
|
|
).toBeGreaterThanOrEqual(strip.bottom - 0.5)
|
|
if (strip.top <= strip.barBottom + 0.5)
|
|
expect(now.bottom, `column in view at ${at}`).toBeLessThanOrEqual(
|
|
strip.innerHeight + 0.5,
|
|
)
|
|
}
|
|
})
|
|
})
|
|
}
|