test: add verifyStickyBar helper for sticky-element tests - #1618
Open
eran132 wants to merge 1 commit into
Open
Conversation
A test helper that captures a sticky bar's background in BOTH at-rest and scrolled states and returns the metrics, so callers can write the exact assertions they need: - atRestBg / scrolledBg (computed background-color) - conditionallyOpaque (background differs between states - proves a bar that's transparent at rest but opaque when stuck, like #1528's StickyInputs) - stuckAtTop (still pinned to viewport top after scrolling) This directly prevents the bug pattern hit twice during #1528 review: - Original 'transparent bar lets content bleed through' bug - caught by asserting scrolledBg !== 'rgba(0, 0, 0, 0)' - 'Always-opaque bar shows as a visible box on pages where the surrounding container color doesn't match' regression - caught by asserting atRestBg === 'rgba(0, 0, 0, 0)' Wheels-scrolls (not window.scrollTo) so it works with apps that use an inner scroll container like this codebase. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Playwright test helper intended for future position: sticky UI tests by capturing a sticky bar’s computed background color in both at-rest and scrolled states, and returning simple metrics for assertions.
Changes:
- Introduces
verifyStickyBar(page, opts)helper to read computedbackground-colorbefore/after scrolling. - Implements wheel-based scrolling to support inner scroll containers and returns
conditionallyOpaque+stuckAtTopsignals.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,78 @@ | |||
| import { expect, type Page } from '@playwright/test' | |||
Comment on lines
+68
to
+70
| const stuckAtTop = await el.evaluate( | ||
| (node) => (node as HTMLElement).getBoundingClientRect().top <= 100, | ||
| ) |
Comment on lines
+60
to
+64
| const ticks = Math.max(1, Math.round(scrollBy / 90)) | ||
| for (let i = 0; i < ticks; i++) { | ||
| await page.mouse.wheel(0, 90) | ||
| await page.waitForTimeout(80) | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a single test helper,
verifyStickyBar(page, opts), that captures aposition: stickyelement's background in both at-rest and scrolled states, and returns the metrics so callers write the exact assertions they want.Returned shape:
atRestBg,scrolledBg— computedbackground-colorin each stateconditionallyOpaque— convenience boolean: the bg differs between states (i.e. transparent at rest, opaque when stuck)stuckAtTop— the bar is still pinned within the top 100px after scrollingMotivation
This directly prevents the bug pattern we hit twice during the #1528 (sticky inputs) review:
Both could have been one line each:
Implementation notes
Uses
page.mouse.wheel, notwindow.scrollTo— this codebase has an inner scroll container, sowindow.scrollTois a no-op (a lesson from #1528).Test plan
tests/timeline.spec.ts) is one line. I'd rather ship the helper now so future sticky-bar work can pick it up, than block on PR ordering.Closes nothing; this is pure infrastructure to make future visual reviews faster.
🤖 Generated with Claude Code