Skip to content

Commit 9eb31e1

Browse files
committed
Add a test of the scrollspy
1 parent 2046203 commit 9eb31e1

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tests/sites/colors/index.rst

+20
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ Heading 3
2121

2222
Some text with a |code link|_.
2323

24+
Heading 4
25+
---------
26+
27+
Some other text
28+
29+
Heading 5
30+
---------
31+
32+
Some other text
33+
34+
Heading 6
35+
---------
36+
37+
Some other text
38+
39+
Heading 7
40+
---------
41+
42+
Some other text
43+
2444

2545
.. the below replacement is included to emulate what intersphinx / autodoc / numpydoc generate (links on text formatted as code), which (sadly) can't be done using nesting of standard rST markup.
2646

tests/test_playwright.py

+35
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,38 @@ def check_colors():
143143
expect(el).to_have_css("color", hover_color)
144144

145145
_check_test_site(site_name, site_path, check_colors)
146+
147+
148+
def test_secondary_sidebar_toc_scrollspy(
149+
sphinx_build_factory: Callable,
150+
page: Page,
151+
url_base: str,
152+
) -> None:
153+
"""Test that the secondary sidebar TOC highlights the correct item upon scroll."""
154+
site_name = "colors"
155+
site_path = _build_test_site(site_name, sphinx_build_factory=sphinx_build_factory)
156+
157+
def check_toc():
158+
page.goto(urljoin(url_base, f"playwright_tests/{site_name}/index.html"))
159+
160+
toclinks = page.locator("#pst-page-toc-nav a.nav-link").all()
161+
headings = []
162+
for link in toclinks:
163+
headings.append(page.locator(link.get_attribute("href")).first)
164+
165+
# Upon click, the first element should be active
166+
toclinks[0].click()
167+
expect(page.locator("p.copyright")).not_to_be_in_viewport()
168+
assert "active" in toclinks[0].get_attribute("class")
169+
page.locator("p.copyright").scroll_into_view_if_needed()
170+
171+
# After scrolling down, the first element shouldn't be active anymore
172+
page.wait_for_function(
173+
"""() => !document
174+
.querySelector('#pst-page-toc-nav a.nav-link')
175+
.classList
176+
.contains('active')
177+
"""
178+
)
179+
180+
_check_test_site(site_name, site_path, check_toc)

0 commit comments

Comments
 (0)