test(app): R1 browser checks assert the touch guards and the margin
This commit is contained in:
1 parent
2327d61d8e
commit
0849e54bc0
1 file changed
+89
-9
@@ -1,5 +1,7 @@
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { CDPSession, Page, TestInfo } from '@playwright/test'
|
||||
import type { CDPSession, Locator, Page, TestInfo } from '@playwright/test'
|
||||
import { expect, test } from '../support/browser'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import {
|
||||
@@ -42,6 +44,18 @@ const liveRegion = (page: Page) =>
|
||||
.locator('p[aria-live="polite"]')
|
||||
.filter({ hasText: dict['editor.annotations.deselected'] })
|
||||
|
||||
const SHOTS =
|
||||
'/tmp/claude-1000/-home-bchanot-Documents-faunosteo/' +
|
||||
'463d8810-0112-4b67-92e4-aa3c30af6089/scratchpad/r1-gates/shots'
|
||||
|
||||
/** A screenshot attached to the report and copied for the design review. */
|
||||
async function shoot(info: TestInfo, name: string, target: Locator) {
|
||||
const png = await target.screenshot()
|
||||
await info.attach(name, { body: png, contentType: 'image/png' })
|
||||
await mkdir(SHOTS, { recursive: true })
|
||||
await writeFile(join(SHOTS, `${name}.png`), png)
|
||||
}
|
||||
|
||||
const POINT = 'Pt Alpha'
|
||||
const ZONE = 'Zone Beta'
|
||||
const LINK = 'Accès Gamma'
|
||||
@@ -156,11 +170,20 @@ test.describe('deselect and D6b (editor, mouse and keyboard)', () => {
|
||||
test('« Désélectionner »: live region, focus on the row, document unchanged', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
}, info) => {
|
||||
const { actor, seed, saves } = await open(page)
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
const before = await serverDocument(seed.draftId)
|
||||
await select(page, POINT)
|
||||
await shoot(info, 'r1-panel-desktop', properties(page))
|
||||
await page.evaluate(() => window.scrollTo(0, 0))
|
||||
await shoot(
|
||||
info,
|
||||
'r1-history-desktop',
|
||||
page
|
||||
.getByTestId('history-buttons')
|
||||
.locator('xpath=ancestor::*[.//*[@role="tablist"]][1]'),
|
||||
)
|
||||
await properties(page)
|
||||
.getByRole('button', { name: dict['editor.annotations.deselect'] })
|
||||
.click()
|
||||
@@ -245,7 +268,19 @@ test.describe('deselect and D6b (editor, mouse and keyboard)', () => {
|
||||
}
|
||||
// The margin of the box beside the drawing (the box is 4:3, the drawing 5:4).
|
||||
const rect = (await box(page).boundingBox())!
|
||||
await page.mouse.click(rect.x + 3, rect.y + rect.height / 2)
|
||||
const content = [
|
||||
await clientOf(page, 0, 0),
|
||||
await clientOf(page, 1000, 800),
|
||||
]
|
||||
const band = (rect.x + content[0].x) / 2
|
||||
expect(
|
||||
content[0].x - rect.x,
|
||||
'a letterbox band left of the drawing',
|
||||
).toBeGreaterThan(8)
|
||||
expect(band).toBeGreaterThan(rect.x)
|
||||
expect(band).toBeLessThan(content[0].x)
|
||||
expect(content[1].x).toBeLessThan(rect.x + rect.width)
|
||||
await page.mouse.click(band, rect.y + rect.height / 2)
|
||||
await expectDeselected(page)
|
||||
|
||||
// Selecting: point, zone interior, link.
|
||||
@@ -370,6 +405,8 @@ interface Recorded {
|
||||
primary: boolean
|
||||
pointerType: string
|
||||
anno: string | null
|
||||
/** Distance a pointermove covered since the previous one of the same pointer. */
|
||||
dist: number
|
||||
}
|
||||
|
||||
/** A capture-phase recorder: what the page really received for each gesture. */
|
||||
@@ -383,16 +420,31 @@ async function startRecorder(page: Page) {
|
||||
? (target.closest('[data-anno-id]')?.getAttribute('data-anno-id') ??
|
||||
null)
|
||||
: null
|
||||
for (const type of ['pointerdown', 'pointerup', 'pointercancel', 'click'])
|
||||
const last = new Map<number, { x: number; y: number }>()
|
||||
const types = ['pointerdown', 'pointermove', 'pointerup', 'pointercancel']
|
||||
for (const type of [...types, 'click'])
|
||||
document.addEventListener(
|
||||
type,
|
||||
(event) => {
|
||||
const pointer = event as PointerEvent
|
||||
const before = last.get(pointer.pointerId)
|
||||
const dist =
|
||||
type === 'pointermove' && before
|
||||
? Math.hypot(
|
||||
pointer.clientX - before.x,
|
||||
pointer.clientY - before.y,
|
||||
)
|
||||
: 0
|
||||
last.set(pointer.pointerId, {
|
||||
x: pointer.clientX,
|
||||
y: pointer.clientY,
|
||||
})
|
||||
w.__rec.push({
|
||||
type,
|
||||
primary: pointer.isPrimary,
|
||||
pointerType: pointer.pointerType ?? '',
|
||||
anno: anno(event.target),
|
||||
dist,
|
||||
})
|
||||
},
|
||||
true,
|
||||
@@ -412,6 +464,17 @@ async function takeRecord(page: Page) {
|
||||
})
|
||||
}
|
||||
|
||||
/** The numbers the guard assertions read from a step's events. */
|
||||
function guards(events: Recorded[]) {
|
||||
const of = (type: string) => events.filter((e) => e.type === type)
|
||||
return {
|
||||
nonPrimary: of('pointerdown').filter((e) => !e.primary).length,
|
||||
clicks: of('click').length,
|
||||
cancels: of('pointercancel').length,
|
||||
moved: of('pointermove').reduce((sum, e) => sum + e.dist, 0),
|
||||
}
|
||||
}
|
||||
|
||||
function summary(events: Recorded[]): string {
|
||||
const count = (pick: (e: Recorded) => boolean) => events.filter(pick).length
|
||||
const clicks = events.filter((e) => e.type === 'click')
|
||||
@@ -420,6 +483,7 @@ function summary(events: Recorded[]): string {
|
||||
`pointerdown non-primary ${count((e) => e.type === 'pointerdown' && !e.primary)}`,
|
||||
`pointerup ${count((e) => e.type === 'pointerup')}`,
|
||||
`pointercancel ${count((e) => e.type === 'pointercancel')}`,
|
||||
`pointermove ${count((e) => e.type === 'pointermove')} (moved ${Math.round(guards(events).moved)} px)`,
|
||||
`click ${clicks.length}`,
|
||||
`click targets [${clicks.map((c) => c.anno ?? 'none').join(', ')}]`,
|
||||
].join('; ')
|
||||
@@ -559,7 +623,9 @@ test.describe('deselect and D6b (touch, editor at 1 280 px)', () => {
|
||||
const dragFrom = await clientOf(page, IN_CIRCLE.x, IN_CIRCLE.y)
|
||||
await drag(cdp, dragFrom, { x: dragFrom.x + 40, y: dragFrom.y + 20 })
|
||||
await expectKept(page, POINT)
|
||||
await report('e one-finger drag')
|
||||
const e = guards((await report('e one-finger drag')).events)
|
||||
expect(e.clicks, 'e: no click after a drag').toBe(0)
|
||||
expect(e.moved, 'e: moved more than the 4 px slop').toBeGreaterThan(4)
|
||||
|
||||
// f. Two-finger tap on empty drawing.
|
||||
await takeRecord(page)
|
||||
@@ -568,7 +634,9 @@ test.describe('deselect and D6b (touch, editor at 1 280 px)', () => {
|
||||
await touch(cdp, 'touchStart', pair)
|
||||
await touch(cdp, 'touchEnd', [])
|
||||
await expectKept(page, POINT)
|
||||
await report('f two-finger tap')
|
||||
const f = guards((await report('f two-finger tap')).events)
|
||||
expect(f.nonPrimary, 'f: a non-primary pointerdown').toBeGreaterThan(0)
|
||||
expect(f.clicks, 'f: no click').toBe(0)
|
||||
|
||||
// g. Pinch on empty drawing.
|
||||
await takeRecord(page)
|
||||
@@ -584,7 +652,9 @@ test.describe('deselect and D6b (touch, editor at 1 280 px)', () => {
|
||||
])
|
||||
await touch(cdp, 'touchEnd', [])
|
||||
await expectKept(page, POINT)
|
||||
await report('g pinch')
|
||||
const g = guards((await report('g pinch')).events)
|
||||
expect(g.nonPrimary, 'g: a non-primary pointerdown').toBeGreaterThan(0)
|
||||
expect(g.clicks, 'g: no click').toBe(0)
|
||||
|
||||
expect(saves).toEqual([])
|
||||
})
|
||||
@@ -652,6 +722,7 @@ test.describe('deselect and D6b (read-only twin at 375 px)', () => {
|
||||
await takeRecord(page)
|
||||
await tap(cdp, await markerAt())
|
||||
await expect(selectionTag(page)).toContainText(POINT)
|
||||
await shoot(info, 'r1-panel-375', properties(page))
|
||||
await report('twin tap on a marker')
|
||||
|
||||
await takeRecord(page)
|
||||
@@ -667,7 +738,12 @@ test.describe('deselect and D6b (read-only twin at 375 px)', () => {
|
||||
await drag(cdp, from, { x: from.x + 30, y: from.y + 10 })
|
||||
await frames(page)
|
||||
await expect(selectionTag(page)).toContainText(POINT)
|
||||
await report('twin one-finger drag')
|
||||
const drag1 = guards(await report('twin one-finger drag'))
|
||||
expect(drag1.clicks, 'twin drag: no click').toBe(0)
|
||||
expect(
|
||||
drag1.cancels > 0 || drag1.moved > 4,
|
||||
'twin drag: pointercancel, or movement recorded',
|
||||
).toBe(true)
|
||||
|
||||
await takeRecord(page)
|
||||
const two = await twinAt(IN_CIRCLE.x, IN_CIRCLE.y)
|
||||
@@ -675,7 +751,11 @@ test.describe('deselect and D6b (read-only twin at 375 px)', () => {
|
||||
await touch(cdp, 'touchEnd', [])
|
||||
await frames(page)
|
||||
await expect(selectionTag(page)).toContainText(POINT)
|
||||
await report('twin two-finger tap')
|
||||
const pair = guards(await report('twin two-finger tap'))
|
||||
expect(pair.nonPrimary, 'twin: a non-primary pointerdown').toBeGreaterThan(
|
||||
0,
|
||||
)
|
||||
expect(pair.clicks, 'twin two-finger: no click').toBe(0)
|
||||
expect(saves).toEqual([])
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user