Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/Stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,6 @@ export function Stage({
style={pixelGridLines(1)}
ref={pixelGridRef}
/>
{/* the selected frame's size badge, in screen px (FrameLabelLayer) */}
<div className="pointer-events-none absolute inset-0" ref={setLabelLayer} />
{/* `world` is likewise a behaviour hook: pan hit-testing checks
classList.contains('world') to tell background from frame */}
<div
Expand All @@ -1224,6 +1222,9 @@ export function Stage({
/>
)}
</div>
{/* the selected frame's size badge, in screen px (FrameLabelLayer); after
the world so no frame, however it stacks, covers it */}
<div className="pointer-events-none absolute inset-0" ref={setLabelLayer} />
Comment on lines +1225 to +1227

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge stacking goes untested

frameResizeBrowser.test.ts uses a separate fixture that still places its label layer before the world. It only checks the badge's text, so it passes with either version of this change and cannot catch the badge being hidden again.

Add a browser test that mounts Stage with a neighboring frame overlapping the selected frame's badge. Check that the badge paints above that frame at a zoomed-out level.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests/frameSizeBadgeBrowser.test.ts: it mounts the real Stage (rulers fixture) at 25% with a second frame under the selected one's badge, and checks the badge is the topmost element at its centre with a frame underneath. It fails against the previous Stage.tsx and passes with this change.

{showRulers && <Rulers stage={ref} />}
</div>
</ContextMenuTrigger>
Expand Down
82 changes: 82 additions & 0 deletions tests/frameSizeBadgeBrowser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import type { Page } from 'puppeteer-core'
import { findBrowserPath } from '../server/screenshot'
import { fixtureUrl, openBrowser, type TestBrowser } from './browser'
import type { Frame } from '../shared/types'

/* the rulers fixture mounts the real Stage; its harness is declared in
rulersBrowser.test.ts */

const HTML = '<!doctype html><html><body style="margin:0;background:#eee"></body></html>'
const frame = (id: string, y: number, height: number): Frame => ({
id,
canvasId: 'c',
pageId: 'first',
name: id,
x: 0,
y,
width: 400,
height,
html: HTML,
createdAt: 0,
updatedAt: 0,
updatedBy: 'Tester',
})

describe.skipIf(!findBrowserPath())('frame size badge', { timeout: 30_000 }, () => {
let browser: TestBrowser
let page: Page
const errors: string[] = []

beforeAll(async () => {
browser = await openBrowser()
page = await browser.newPage()
page.setDefaultTimeout(10_000)
page.on('pageerror', (err) => errors.push(String(err)))
await page.setViewport({ width: 1200, height: 800 })
await page.goto(fixtureUrl('rulers.html'))
await page.waitForFunction(() => !!window.rulersHarness)
/* `below` starts just under `above`, where the badge lands when zoomed out */
await page.evaluate(
(frames) => {
window.rulersHarness.seed({
id: 'c',
name: 'Badge',
frames,
pages: [{ id: 'first', name: 'Main' }],
createdAt: 0,
updatedAt: 0,
})
},
[frame('above', 0, 200), frame('below', 220, 400)],
)
await page.waitForSelector('[aria-label="Canvas tools"]')
await page.evaluate(() => window.rulersHarness.viewport({ x: 100, y: 100, zoom: 0.25 }))
}, 60_000)

afterAll(async () => {
await page?.close()
await browser?.close()
expect(errors).toEqual([])
})

it('paints above a later frame it overlaps', async () => {
await page.evaluate(() => window.rulersHarness.select(['above']))
const badge = await page.waitForSelector('[data-frame-size]')
/* the badge never takes the pointer, so hit-testing skips it; let it for
the probe, so the topmost painted element at its centre is found */
const top = await badge!.evaluate((el) => {
const node = el as HTMLElement
node.style.pointerEvents = 'auto'
const r = node.getBoundingClientRect()
const hit = () => document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2)
const onBadge = hit() === node
node.style.visibility = 'hidden'
const underneath = !!hit()?.closest('[data-frame-surface]')
node.style.visibility = ''
node.style.pointerEvents = ''
return { onBadge, underneath }
})
expect(top).toEqual({ onBadge: true, underneath: true })
})
})
Loading