Skip to content

Commit 26d6b3f

Browse files
committed
Add a test of the scrollspy
1 parent 2046203 commit 26d6b3f

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-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

+34
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,37 @@ 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+
# Wait until at least one of these gets activated by the js
161+
page.wait_for_function(
162+
"document.querySelector('#pst-page-toc-nav a.active') !== null"
163+
)
164+
165+
toclinks = page.locator("#pst-page-toc-nav a.nav-link").element_handles()
166+
headings = []
167+
for handle in toclinks:
168+
headings.append(
169+
page.locator(handle.get_attribute("href")).first.element_handle()
170+
)
171+
172+
# Upon first page load, the first element should be active
173+
assert "active" in toclinks[0].get_attribute("class")
174+
page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
175+
176+
# After scrolling down, the first element shouldn't be active anymore
177+
assert "active" not in toclinks[0].get_attribute("class")
178+
179+
_check_test_site(site_name, site_path, check_toc)

0 commit comments

Comments
 (0)