Repository navigation
fix(canvas): draw the frame size badge above neighbouring frames #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frameResizeBrowser.test.tsuses 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
Stagewith 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!
There was a problem hiding this comment.
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 realStage(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 previousStage.tsxand passes with this change.