Skip to content

test: add Playwright coverage for book-level back-to-top-navigation - #14889

Merged
cderv merged 5 commits into
mainfrom
book-back-to-top-playwright-2
Sep 15, 2026
Merged

cderv merged 5 commits into
mainfrom
book-back-to-top-playwright-2

Conversation

@cderv

@cderv cderv commented Sep 14, 2026

Copy link
Copy Markdown
Member

Companion to #14881, which fixed book projects silently dropping website-level tool options (e.g. back-to-top-navigation) set under the book key. The existing smoke-all fixture only checks that the control is injected into the HTML, not that it behaves correctly in a browser.

Adds a Playwright fixture (tests/docs/playwright/book/back-to-top/) and spec asserting the #quarto-back-to-top control's scroll show/hide behavior and click-to-top reset in a book project.

PR #14881 fixed book projects silently dropping website-level tool
options (e.g. back-to-top-navigation) set under the book key. The
existing smoke-all fixture only checks the control is injected into
the HTML, not that it behaves correctly in a browser.
@posit-snyk-bot

posit-snyk-bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

The scroll-down step and the following scroll-up step both used
page.evaluate(scrollTo) back-to-back with no wait between them. The
nav script's show/hide logic only updates its internal scroll-position
tracker inside the scroll event handler, so if that handler hadn't run
yet before the reversal, the up-scroll direction check compared
against a stale position and the button never showed. Poll scrollY to
confirm the down-scroll's event has been processed before scrolling
back up.
Captures the fix from PR #14889 (book-back-to-top-navigation flaky
test) as a reusable pattern: reversed scrollTo calls can race a
scroll-direction-tracking event handler, and asserting on the
already-hidden UI state doesn't prove the handler ran. Polling
scrollY forces the event-loop turn needed.
…ollY

The prior fix polled window.scrollY between the down- and up-scroll, but
scrollTo({behavior: "instant"}) updates scrollY synchronously, so the poll's
first check passed before the queued "scroll" event even reached the page's
own listener. The race it was meant to close was still there: repeated local
runs (--repeat-each=15, 3 browsers) hit it ~9/45 times.

Switching to an explicit one-shot scroll listener, awaited via a Promise
before reversing direction, closes it for real (45/45, then another 20/20
firefox-only run with zero failures; the earlier single firefox failure was
an unrelated browserContext.close teardown error). Listeners for the same
event fire in registration order, so a listener registered here always runs
after the page's already-registered one has updated its tracked state.

Also drops the now-redundant scrollY poll after the click-to-top step, since
no further scroll follows it there, and updates the best-practices doc that
had documented the ineffective poll pattern.
…ting it

The pattern section repeated the same await-scroll-event Promise block twice
inline. Point at scrollToAndSettle in book-back-to-top.spec.ts instead, kept
local there since it's a single-caller helper (see finishing-a-development
discussion): no second spec needs the same scroll-direction-race handling
yet, so a shared utils.ts helper would be premature.
@cderv
cderv merged commit 85cb762 into main Sep 15, 2026
51 checks passed
@cderv
cderv deleted the book-back-to-top-playwright-2 branch September 15, 2026 09:02
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