fix(anatomy): V1-2.2 marker layer and halo outside the drawing's group
Owner-approved lot B (brief 2026-11-01). The composition root is the engine's (namespaces and frame); the drawing's root becomes a group and the marker layer and halo are its siblings, so no root property reaches a marker. Point hitboxes declare stroke none and visibleFill. Census over the reader's whole allowlist; R3 references compared under the declared transform; click proofs in three engines.
This commit is contained in:
1 parent
f1bb19b30b
commit
4f52f5e1c4
23 files changed
+933
-112
No files matched your search
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Canvas harness</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="./canvas.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Test page for the editor canvas in a real browser (e2e/ui/canvas-clicks.spec.ts): the
|
||||
* bundled equine sheet in AnatomyCanvas, its drawing's root given the attributes of the
|
||||
* chosen `?drawing=` case, every click recorded. Served by the Vite dev server only
|
||||
* (`/e2e/harness/canvas.html`); the build has a single entry, index.html, so this page
|
||||
* never ships.
|
||||
*/
|
||||
import { StrictMode, useState } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import '@/styles/index.css'
|
||||
import AnatomyCanvas from '@/components/canvas/AnatomyCanvas'
|
||||
import { bundledSheetProvider } from '@/sheets/provider'
|
||||
import { setSheetProvider, useSheet } from '@/sheets/useSheet'
|
||||
|
||||
/**
|
||||
* Root attributes of the drawing per case (V1-2.2 owner brief 2026-10-30, defect 2): the
|
||||
* reported giant stroke, the same width with no stroke paint (an invisible enlarged
|
||||
* surface), and the hiding stroke properties.
|
||||
*/
|
||||
const DRAWINGS: Record<string, string> = {
|
||||
plain: '',
|
||||
'giant-stroke': 'stroke="#ff00ff" stroke-width="2000"',
|
||||
'invisible-stroke': 'stroke-width="2000"',
|
||||
'hidden-stroke': 'stroke="#ff00ff" stroke-width="2000" stroke-opacity="0"',
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(location.search)
|
||||
const rootAttrs = DRAWINGS[params.get('drawing') ?? 'plain'] ?? ''
|
||||
const viewId = params.get('view') ?? 'main'
|
||||
|
||||
setSheetProvider({
|
||||
async getReferenceSheet(speciesId) {
|
||||
const sheet = await bundledSheetProvider.getReferenceSheet(speciesId)
|
||||
if (!sheet || rootAttrs === '') return sheet
|
||||
const assets = Object.fromEntries(
|
||||
Object.entries(sheet.assets).map(([id, text]) => [
|
||||
id,
|
||||
text.replace('<svg ', `<svg ${rootAttrs} `),
|
||||
]),
|
||||
)
|
||||
return { ...sheet, assets }
|
||||
},
|
||||
})
|
||||
|
||||
function Harness() {
|
||||
const sheet = useSheet('equine')
|
||||
const [clicks, setClicks] = useState<string[]>([])
|
||||
return (
|
||||
<main className="p-4">
|
||||
<h1 className="text-xl font-semibold">Canvas harness</h1>
|
||||
{/* A fixed height: the canvas never moves when the first click is listed. */}
|
||||
<output data-testid="clicks" className="block h-6 overflow-hidden">
|
||||
{clicks.join(' ')}
|
||||
</output>
|
||||
<div style={{ width: 'min(1000px, 100%)', aspectRatio: '2073.4 / 1629.4' }}>
|
||||
{sheet.status === 'ready' && (
|
||||
<AnatomyCanvas
|
||||
index={sheet.index}
|
||||
viewId={viewId}
|
||||
states={new Map()}
|
||||
onZoneClick={(id) => setClicks((all) => [...all, id])}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root') as HTMLElement).render(
|
||||
<StrictMode>
|
||||
<Harness />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* `pnpm e2e:ui`: Chromium against a Vite dev server with no backend, on a
|
||||
* loopback port of its own (never the owner's `pnpm dev` on 5173, never
|
||||
* reused): the Dialog test page and the local tool. docs/development/BROWSER_TESTS.md.
|
||||
* reused): the Dialog test page, the local tool and the canvas click proof (also on
|
||||
* Firefox and WebKit when installed). docs/development/BROWSER_TESTS.md.
|
||||
*/
|
||||
import { defineConfig } from '@playwright/test'
|
||||
import type { GuardOptions } from './support/browser'
|
||||
import { PROJECTS } from './support/browser'
|
||||
import { CLICK_PROJECTS, PROJECTS } from './support/browser'
|
||||
|
||||
const ORIGIN = 'http://127.0.0.1:5191'
|
||||
|
||||
@@ -27,7 +28,7 @@ export default defineConfig<GuardOptions>({
|
||||
trace: 'retain-on-failure',
|
||||
screenshot: 'only-on-failure',
|
||||
},
|
||||
projects: PROJECTS,
|
||||
projects: [...PROJECTS, ...CLICK_PROJECTS],
|
||||
webServer: {
|
||||
command: 'node_modules/.bin/vite --host 127.0.0.1 --port 5191 --strictPort',
|
||||
cwd: '..',
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
* the two Chromium projects, the request guard every test runs under, the axe
|
||||
* gate, and the focus and layout probes.
|
||||
*/
|
||||
import { existsSync } from 'node:fs'
|
||||
import AxeBuilder from '@axe-core/playwright'
|
||||
import {
|
||||
devices,
|
||||
expect,
|
||||
firefox,
|
||||
test as base,
|
||||
webkit,
|
||||
type Page,
|
||||
type Project,
|
||||
} from '@playwright/test'
|
||||
@@ -37,6 +40,51 @@ export const PROJECTS: Project[] = [
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* The canvas click proof (V1-2.2, e2e/ui/canvas-clicks.spec.ts) also runs on Firefox and
|
||||
* WebKit, desktop, and on the WebKit phone, when the pinned engine is installed
|
||||
* (`playwright install firefox webkit`, no sudo, never `--with-deps`). A missing engine is
|
||||
* named in the run's output, never passed silently.
|
||||
*/
|
||||
const CANVAS_CLICKS = /canvas-clicks\.spec\.ts$/
|
||||
|
||||
function installed(name: string, executable: string): boolean {
|
||||
const present = existsSync(executable)
|
||||
if (!present) console.warn(`canvas clicks: ${name} is not installed, its projects do not run`)
|
||||
return present
|
||||
}
|
||||
|
||||
export const CLICK_PROJECTS: Project[] = [
|
||||
...(installed('firefox', firefox.executablePath())
|
||||
? [
|
||||
{
|
||||
name: 'firefox-desktop',
|
||||
testMatch: CANVAS_CLICKS,
|
||||
grepInvert: /@phone/,
|
||||
use: { ...devices['Desktop Firefox'], viewport: { width: 1280, height: 800 } },
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(installed('webkit', webkit.executablePath())
|
||||
? [
|
||||
{
|
||||
name: 'webkit-desktop',
|
||||
testMatch: CANVAS_CLICKS,
|
||||
grepInvert: /@phone/,
|
||||
use: { ...devices['Desktop Safari'], viewport: { width: 1280, height: 800 } },
|
||||
},
|
||||
{
|
||||
name: 'webkit-375',
|
||||
testMatch: CANVAS_CLICKS,
|
||||
use: {
|
||||
...devices['iPhone SE'],
|
||||
viewport: { width: 375, height: 667 },
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]
|
||||
|
||||
export interface GuardOptions {
|
||||
/** Origins the page may reach; every other request is aborted and fails the test. */
|
||||
allowedOrigins: string[]
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["."]
|
||||
"include": [".", "../src/sheets/virtual-sheet.d.ts"]
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import { expect, test } from '../support/browser'
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
// V1-2.2 owner brief 2026-10-30, defect 2: a click on the editor canvas records the marker
|
||||
// under the pointer, never another one, whatever stroke the drawing's root sets. Real
|
||||
// clicks (taps on the phone project) on the bundled equine sheet in AnatomyCanvas
|
||||
// (e2e/harness/canvas.tsx); run on Chromium, Firefox and WebKit when installed.
|
||||
|
||||
/**
|
||||
* The points of the equine main view whose visible disc no other marker covers, in document
|
||||
* order. The three vertebral junctions sit on the edge of a zone painted after them: part of
|
||||
* their disc records the zone (pre-existing, owner decision, see the fixme below).
|
||||
*/
|
||||
const POINTS = [
|
||||
'hind-fetlock',
|
||||
'hock',
|
||||
'stifle',
|
||||
'hip',
|
||||
'sacroiliac',
|
||||
'shoulder',
|
||||
'elbow',
|
||||
'carpus',
|
||||
'fore-fetlock',
|
||||
'fore-sesamoids',
|
||||
]
|
||||
const JUNCTIONS = ['l6-s1', 't18-l1', 'c7-t1']
|
||||
const DRAWINGS = ['plain', 'giant-stroke', 'invisible-stroke', 'hidden-stroke']
|
||||
|
||||
type Point = { x: number; y: number }
|
||||
|
||||
async function open(page: Page, drawing: string) {
|
||||
await page.goto(`/e2e/harness/canvas.html?drawing=${drawing}`)
|
||||
await expect(
|
||||
page.locator('[data-testid="anatomy-canvas"] [data-anno-id="hock"]').first(),
|
||||
).toBeAttached()
|
||||
}
|
||||
|
||||
/** The centre of a marker's visible shape on screen (a point's twin shares its hitbox's). */
|
||||
async function centreOf(page: Page, id: string): Promise<Point> {
|
||||
const box = await page
|
||||
.locator(`[data-testid="anatomy-canvas"] [data-anno-id="${id}"]`)
|
||||
.last()
|
||||
.boundingBox()
|
||||
if (!box) throw new Error(`${id} has no box`)
|
||||
return { x: box.x + box.width / 2, y: box.y + box.height / 2 }
|
||||
}
|
||||
|
||||
async function press(page: Page, at: Point, touch: boolean) {
|
||||
if (touch) await page.touchscreen.tap(at.x, at.y)
|
||||
else await page.mouse.click(at.x, at.y)
|
||||
}
|
||||
|
||||
/** The ids recorded by the clicks so far. */
|
||||
async function recorded(page: Page): Promise<string[]> {
|
||||
const text = (await page.getByTestId('clicks').textContent()) ?? ''
|
||||
return text.split(' ').filter(Boolean)
|
||||
}
|
||||
|
||||
async function clickRecords(page: Page, at: Point, touch = false) {
|
||||
const before = (await recorded(page)).length
|
||||
await press(page, at, touch)
|
||||
// A click that records nothing leaves the list as it was; wait out the handler.
|
||||
await page.waitForTimeout(50)
|
||||
return (await recorded(page)).slice(before)
|
||||
}
|
||||
|
||||
test.describe('canvas clicks', () => {
|
||||
for (const drawing of DRAWINGS) {
|
||||
test(`a click on the hock records the hock (${drawing})`, async ({ page }, info) => {
|
||||
await open(page, drawing)
|
||||
const touch = info.project.use.hasTouch === true
|
||||
expect(await clickRecords(page, await centreOf(page, 'hock'), touch)).toEqual(['hock'])
|
||||
})
|
||||
|
||||
test(`every point clear of the zones records itself (${drawing})`, async ({ page }) => {
|
||||
await open(page, drawing)
|
||||
for (const id of POINTS) {
|
||||
expect(await clickRecords(page, await centreOf(page, id)), id).toEqual([id])
|
||||
}
|
||||
})
|
||||
|
||||
test(`a click on the drawing away from the markers records nothing (${drawing})`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page, drawing)
|
||||
const box = await page.getByTestId('anatomy-canvas').boundingBox()
|
||||
if (!box) throw new Error('no canvas')
|
||||
// The top left corner and the middle of the belly hold no marker.
|
||||
for (const [fx, fy] of [
|
||||
[0.03, 0.05],
|
||||
[0.5, 0.55],
|
||||
] as const) {
|
||||
const at = { x: box.x + box.width * fx, y: box.y + box.height * fy }
|
||||
expect(await clickRecords(page, at), `${fx},${fy}`).toEqual([])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
test('two close points each record themselves, their shared edge goes to the later one', async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page, 'giant-stroke')
|
||||
const fetlock = await centreOf(page, 'fore-fetlock')
|
||||
const sesamoids = await centreOf(page, 'fore-sesamoids')
|
||||
expect(await clickRecords(page, fetlock)).toEqual(['fore-fetlock'])
|
||||
expect(await clickRecords(page, sesamoids)).toEqual(['fore-sesamoids'])
|
||||
// Halfway, outside both visible discs and inside both hitboxes: document order, the
|
||||
// later marker is on top. One id, never two.
|
||||
const half = { x: (fetlock.x + sesamoids.x) / 2, y: (fetlock.y + sesamoids.y) / 2 }
|
||||
expect(await clickRecords(page, half)).toEqual(['fore-sesamoids'])
|
||||
})
|
||||
|
||||
test('a click on a vertebral junction records the junction', async ({ page }) => {
|
||||
test.fixme(
|
||||
true,
|
||||
'V1-2.2 finding: the zones are painted and hit after the points; c7-t1 records « thoracic » at its centre in Firefox and WebKit, and up to half of each junction disc records a zone in every engine (owner decision on the capture order)',
|
||||
)
|
||||
await open(page, 'plain')
|
||||
for (const id of JUNCTIONS) {
|
||||
expect(await clickRecords(page, await centreOf(page, id)), id).toEqual([id])
|
||||
}
|
||||
})
|
||||
|
||||
// @phone: the desktop projects leave it out (grepInvert), the touch projects run it.
|
||||
test('a tap on the hock records the hock @phone', async ({ page }) => {
|
||||
for (const drawing of DRAWINGS) {
|
||||
await open(page, drawing)
|
||||
expect(await clickRecords(page, await centreOf(page, 'hock'), true), drawing).toEqual([
|
||||
'hock',
|
||||
])
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -126,3 +126,49 @@ export function withIdsScopedPerView(tree: unknown, viewId: string): unknown {
|
||||
visit(copy)
|
||||
return copy
|
||||
}
|
||||
|
||||
const HITBOX_DECLARED = { stroke: 'none', 'pointer-events': 'visibleFill' }
|
||||
|
||||
/** A point hitbox of the R3 layer: a circle capturing on `all` with no stroke of its own. */
|
||||
function isR3Hitbox(node: unknown): node is { name: string; attrs: Record<string, string> } {
|
||||
const n = node as { name?: string; attrs?: Record<string, string> }
|
||||
return n.name === 'circle' && n.attrs?.['pointer-events'] === 'all' && !('stroke' in n.attrs)
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner brief 2026-10-30 (V1-2.2, three MEDIUM): each point hitbox the composers draw declares
|
||||
* `stroke="none"` and `pointer-events="visibleFill"`. Applied to a frozen layer (a deep copy).
|
||||
* Mirrors `crates/core/tests/common/svg_tree.rs`.
|
||||
*/
|
||||
export function withDeclaredHitboxes(layer: unknown): unknown {
|
||||
const copy = structuredClone(layer) as { children?: unknown[] }
|
||||
for (const child of copy.children ?? []) {
|
||||
if (isR3Hitbox(child)) Object.assign(child.attrs, HITBOX_DECLARED)
|
||||
}
|
||||
return copy
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner brief 2026-10-30 (V1-2.2, three MEDIUM): the composition root is the engine's. Applied
|
||||
* to a frozen canvas tree (a deep copy): the root keeps its namespaces and `viewBox`; its other
|
||||
* attributes and every child before the layer go into a `<g>` of the drawing; the layer's
|
||||
* hitboxes are declared (`withDeclaredHitboxes`). Mirrors `crates/core/tests/common/svg_tree.rs`.
|
||||
*/
|
||||
export function withIsolatedLayer(tree: unknown): unknown {
|
||||
const root = structuredClone(tree) as {
|
||||
ns: string
|
||||
attrs: Record<string, string>
|
||||
children: unknown[]
|
||||
}
|
||||
const layer = root.children.pop()
|
||||
const kept: Record<string, string> = {}
|
||||
const moved: Record<string, string> = {}
|
||||
for (const [name, value] of Object.entries(root.attrs)) {
|
||||
if (name === 'xmlns' || name === 'xmlns:xlink' || name === 'viewBox') kept[name] = value
|
||||
else moved[name] = value
|
||||
}
|
||||
const group = { ns: root.ns, name: 'g', attrs: moved, children: root.children }
|
||||
root.attrs = kept
|
||||
root.children = [group, withDeclaredHitboxes(layer)]
|
||||
return root
|
||||
}
|
||||
@@ -21,7 +21,9 @@ import {
|
||||
import {
|
||||
checkR3Golden,
|
||||
treeOf,
|
||||
withDeclaredHitboxes,
|
||||
withIdsScopedPerView,
|
||||
withIsolatedLayer,
|
||||
withTriggerNamesPerLanguage,
|
||||
type TreeNode,
|
||||
} from '../helpers/svgTree'
|
||||
@@ -82,9 +84,10 @@ describe.each(VIEWS)('the %s canvas', (viewId) => {
|
||||
it('builds the frozen tree with no state', () => {
|
||||
const build = buildViewSvg(sheet, viewId)
|
||||
if (!build.ok) throw new Error(`canvas ${viewId}: ${build.failure}`)
|
||||
// and the owner's decision 2026-10-29: the drawing's ids scoped to the view
|
||||
// and the owner's decision 2026-10-29: the drawing's ids scoped to the view; the brief
|
||||
// 2026-10-30: the composition root is the engine's, the hitboxes declared
|
||||
checkR3Golden(`canvas.${viewId}.json`, treeOf(build.svg), (frozen) =>
|
||||
withIdsScopedPerView(declared(frozen), viewId),
|
||||
withIsolatedLayer(withIdsScopedPerView(declared(frozen), viewId)),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -94,6 +97,13 @@ describe.each(VIEWS)('the %s canvas', (viewId) => {
|
||||
layers[name] = await mountedLayer(viewId, states)
|
||||
}
|
||||
expect(Object.keys(layers).length).toBeGreaterThan(8)
|
||||
checkR3Golden(`canvas.${viewId}.layers.json`, layers, declared)
|
||||
checkR3Golden(`canvas.${viewId}.layers.json`, layers, (frozen) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(declared(frozen) as Record<string, unknown>).map(([name, layer]) => [
|
||||
name,
|
||||
withDeclaredHitboxes(layer),
|
||||
]),
|
||||
),
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user