Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Jul 10, 2024
1 parent c3d7006 commit 45ea024
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
17 changes: 7 additions & 10 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_primary_logo_is_light_when_no_default_mode(sphinx_build_factory) -> Non
index_html = sphinx_build.html_tree("index.html")
navbar_brand = index_html.select(".navbar-brand")[0]
assert navbar_brand.find("img", class_="only-light") is not None
assert navbar_brand.find("script", string=re.compile("only-dark")) is not None
assert navbar_brand.find("img", class_="only-dark") is not None


def test_primary_logo_is_light_when_default_mode_is_set_to_auto(
Expand All @@ -199,7 +199,7 @@ def test_primary_logo_is_light_when_default_mode_is_set_to_auto(
index_html = sphinx_build.html_tree("index.html")
navbar_brand = index_html.select(".navbar-brand")[0]
assert navbar_brand.find("img", class_="only-light") is not None
assert navbar_brand.find("script", string=re.compile("only-dark")) is not None
assert navbar_brand.find("img", class_="only-dark") is not None


def test_primary_logo_is_light_when_default_mode_is_light(sphinx_build_factory) -> None:
Expand All @@ -212,7 +212,7 @@ def test_primary_logo_is_light_when_default_mode_is_light(sphinx_build_factory)
index_html = sphinx_build.html_tree("index.html")
navbar_brand = index_html.select(".navbar-brand")[0]
assert navbar_brand.find("img", class_="only-light") is not None
assert navbar_brand.find("script", string=re.compile("only-dark")) is not None
assert navbar_brand.find("img", class_="only-dark") is not None


def test_primary_logo_is_dark_when_default_mode_is_dark(sphinx_build_factory) -> None:
Expand All @@ -225,7 +225,7 @@ def test_primary_logo_is_dark_when_default_mode_is_dark(sphinx_build_factory) ->
index_html = sphinx_build.html_tree("index.html")
navbar_brand = index_html.select(".navbar-brand")[0]
assert navbar_brand.find("img", class_="only-dark") is not None
assert navbar_brand.find("script", string=re.compile("only-light")) is not None
assert navbar_brand.find("img", class_="only-light") is not None


def test_logo_missing_image(sphinx_build_factory) -> None:
Expand Down Expand Up @@ -805,8 +805,9 @@ def test_version_switcher_error_states(
if url == "switcher.json": # this should work
index = sphinx_build.html_tree("index.html")
switcher = index.select(".navbar-header-items")[0].find(
"script", string=re.compile(".version-switcher__container")
"div", class_="version-switcher__container"
)
assert switcher is not None
file_regression.check(
switcher.prettify(), basename="navbar_switcher", extension=".html"
)
Expand All @@ -826,11 +827,7 @@ def test_version_switcher_error_states(
def test_theme_switcher(sphinx_build_factory, file_regression) -> None:
"""Regression test for the theme switcher button."""
sphinx_build = sphinx_build_factory("base").build()
switcher = (
sphinx_build.html_tree("index.html")
.find(string=re.compile("theme-switch-button"))
.find_parent("script")
)
switcher = sphinx_build.html_tree("index.html").find(class_="theme-switch-button")
file_regression.check(
switcher.prettify(), basename="navbar_theme", extension=".html"
)
Expand Down
25 changes: 9 additions & 16 deletions tests/test_build/navbar_switcher.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
<div class="version-switcher__container dropdown jsonly">
<button id="pst-version-switcher-button-2"
type="button"
class="version-switcher__button btn btn-sm dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-2"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-2"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-2">
<!-- dropdown will be populated by javascript on page load -->
</div>
<button aria-controls="pst-version-switcher-list-2" aria-haspopup="listbox" aria-label="Version switcher list" class="version-switcher__button btn btn-sm dropdown-toggle" data-bs-toggle="dropdown" id="pst-version-switcher-button-2" type="button">
Choose version
<!-- this text may get changed later by javascript -->
<span class="caret">
</span>
</button>
<div aria-labelledby="pst-version-switcher-button-2" class="version-switcher__menu dropdown-menu list-group-flush py-0" id="pst-version-switcher-list-2" role="listbox">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div>
11 changes: 7 additions & 4 deletions tests/test_build/navbar_theme.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button jsonly" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i>
<button aria-label="light/dark" class="btn btn-sm nav-link pst-navbar-icon theme-switch-button jsonly" data-bs-placement="bottom" data-bs-toggle="tooltip" title="light/dark">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light">
</i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark">
</i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto">
</i>
</button>
11 changes: 7 additions & 4 deletions tests/test_build/sidebar_subpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
</div>
<div class="sidebar-header-items__end">
<div class="navbar-item">
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button jsonly" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i>
<button aria-label="light/dark" class="btn btn-sm nav-link pst-navbar-icon theme-switch-button jsonly" data-bs-placement="bottom" data-bs-toggle="tooltip" title="light/dark">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light">
</i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark">
</i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto">
</i>
</button>
</div>
</div>
Expand Down

0 comments on commit 45ea024

Please sign in to comment.