Skip to content

test: add verifyStickyBar helper for sticky-element tests - #1618

Open
eran132 wants to merge 1 commit into
mainfrom
chore/test-helpers-sticky-visual
Open

test: add verifyStickyBar helper for sticky-element tests#1618
eran132 wants to merge 1 commit into
mainfrom
chore/test-helpers-sticky-visual

Conversation

@eran132

@eran132 eran132 commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a single test helper, verifyStickyBar(page, opts), that captures a position: sticky element'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 — computed background-color in each state
  • conditionallyOpaque — 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 scrolling

Motivation

This directly prevents the bug pattern we hit twice during the #1528 (sticky inputs) review:

  1. Original 'transparent bar lets content bleed through' — automated lint/tsc/unit all green; only a scrolled screenshot revealed the timeline timestamps showing through the sticky bar.
  2. 'Always-opaque bar shows as a visible box on pages whose surrounding container color doesn't match' — the regression NoamGaash flagged; again invisible to all automated gates, only visible at rest on the gaps page.

Both could have been one line each:

const m = await verifyStickyBar(page, { selector: '[data-sticky-inputs]' })
expect(m.atRestBg).toBe('rgba(0, 0, 0, 0)')         // would have caught the box regression
expect(m.scrolledBg).not.toBe('rgba(0, 0, 0, 0)')   // would have caught the bleed-through
expect(m.stuckAtTop).toBe(true)                      // confirms it actually stuck

Implementation notes

Uses page.mouse.wheel, not window.scrollTo — this codebase has an inner scroll container, so window.scrollTo is a no-op (a lesson from #1528).

Test plan

  • TypeScript / ESLint / Prettier clean
  • Helper not exercised by an existing spec in this PR — the only sticky bar currently in the codebase arrives with feat: add sticky inputs section to gaps and timeline pages #1528, which isn't merged yet. Once it merges, applying it (e.g. inside 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

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>
@eran132
eran132 requested a review from AvivAbachi as a code owner June 6, 2026 11:09
Copilot AI review requested due to automatic review settings June 6, 2026 11:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 computed background-color before/after scrolling.
  • Implements wheel-based scrolling to support inner scroll containers and returns conditionallyOpaque + stuckAtTop signals.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/stickyHelpers.ts
@@ -0,0 +1,78 @@
import { expect, type Page } from '@playwright/test'
Comment thread tests/stickyHelpers.ts
Comment on lines +68 to +70
const stuckAtTop = await el.evaluate(
(node) => (node as HTMLElement).getBoundingClientRect().top <= 100,
)
Comment thread tests/stickyHelpers.ts
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants