Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/pydata_sphinx_theme/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ def suppress_sidebar_toctree(startdepth: int = 1, **kwargs):
)
if ancestorname is None:
return True # suppress
if kwargs.get("includehidden", False):
# if ancestor is found and `includehidden=True` we're guaranteed there's a
# TocTree to be shown, so don't suppress
return False

# we've found an ancestor page, but `includehidden=False` so we can't be sure if
# there's a TocTree fragment that should be shown on this page; unfortunately we
Expand Down
18 changes: 18 additions & 0 deletions tests/sites/test_primary_sidebar_toc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Test conf file."""

# -- Project information -----------------------------------------------------

project = "PyData Tests"
copyright = "2020, Pydata community"
author = "Pydata community"

root_doc = "index"

# -- General configuration ---------------------------------------------------

html_theme = "pydata_sphinx_theme"

html_copy_source = True
html_sourcelink_suffix = ""

html_theme_options = {"navigation_with_keys": False}
7 changes: 7 additions & 0 deletions tests/sites/test_primary_sidebar_toc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test-primary-sidebar-toc
========================

.. toctree::

page
sec/index
5 changes: 5 additions & 0 deletions tests/sites/test_primary_sidebar_toc/page.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
============
Page at Root
============

Some text.
10 changes: 10 additions & 0 deletions tests/sites/test_primary_sidebar_toc/sec/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
===============
Section at Root
===============

Some text.

.. toctree::
:hidden:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this test case is at all dependent on the change made in this PR, but it seems like a nice test case to have in the test suite. 😄


subpage
15 changes: 15 additions & 0 deletions tests/sites/test_primary_sidebar_toc/sec/subpage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
===============
Page in Section
===============

Some text.

Subsection
==========

Some text.

Subsubsection
-------------

Some text.
20 changes: 20 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,3 +1173,23 @@ def test_role_main_for_search_highlights(sphinx_build_factory):
"""
sphinx_build = sphinx_build_factory("base").build()
assert sphinx_build.html_tree("index.html").select_one('[role="main"]')


def test_primary_sidebar_hidden_when_empty(sphinx_build_factory) -> None:
"""Test that the primary sidebar does not show up if it is empty."""
sphinx_build = sphinx_build_factory("test_primary_sidebar_toc").build()
sidebar_primary = sphinx_build.html_tree("page.html").select(
"div.bd-sidebar-primary"
)[0]
assert "hide-on-wide" in sidebar_primary.attrs["class"]


def test_primary_sidebar_exist_when_hidden_toctree(sphinx_build_factory) -> None:
"""Test that the primary sidebar shows up if there are hidden toctrees."""
sphinx_build = sphinx_build_factory("test_primary_sidebar_toc").build()
for page in ("sec/index.html", "sec/subpage.html"):
sidebar_primary = sphinx_build.html_tree(page).select("div.bd-sidebar-primary")[
0
]
assert "hide-on-wide" not in sidebar_primary.attrs["class"]
assert "Page in Section" in str(sidebar_primary)