test(editor): V1-2.6 browser journeys on the sandbox, touch drag and findings fixes
This commit is contained in:
1 parent
7bbd096a16
commit
5097fd7484
18 files changed
+3010
-8
No files matched your search
@@ -0,0 +1,303 @@
|
||||
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 {
|
||||
clickDrawing,
|
||||
clientOf,
|
||||
editorActor,
|
||||
geometryField,
|
||||
openEditor,
|
||||
pointOf,
|
||||
seedDraft,
|
||||
selectTab,
|
||||
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 list = (page: Page) =>
|
||||
page.getByRole('list', { name: dict['editor.annotations.list'] })
|
||||
|
||||
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')
|
||||
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(list(page)).toHaveCount(0)
|
||||
|
||||
// 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(list(page)).toHaveCount(0)
|
||||
|
||||
// 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(list(page).getByText('Bord')).toBeVisible()
|
||||
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)
|
||||
await notice(page)
|
||||
.getByRole('button', { name: dict['editor.annotations.correction_use'] })
|
||||
.click()
|
||||
await expect(list(page).getByText('Bord détail')).toBeVisible()
|
||||
})
|
||||
|
||||
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 list(page)
|
||||
.getByRole('button', { name: /Hors cadre/ })
|
||||
.click()
|
||||
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 selectTab(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('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)
|
||||
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),
|
||||
'a 1 024 px touch screen runs on the desktop project',
|
||||
)
|
||||
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)
|
||||
expect(await touchAction()).toBe('pan-x pan-y')
|
||||
await tool(page, 'point').click()
|
||||
expect(await touchAction()).toBe('none')
|
||||
await tool(page, 'select').click()
|
||||
expect(await 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 list(page)
|
||||
.getByRole('button', { name: /Tactile/ })
|
||||
.click()
|
||||
expect(await 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)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user