Skip to content

Commit 4ea7c00

Browse files
committed
Update test_page_status.py
1 parent 052ceab commit 4ea7c00

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎tests/test_page_status.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ def test_default_definitions(self, tmp_path: Path):
100100
assert defs["new"]["label"] == "New"
101101
assert defs["deprecated"]["icon"] == "triangle-alert"
102102

103+
def test_shorthand_true_preserves_default_definitions(self, tmp_path: Path):
104+
"""Regression: `page_status: true` must not replace definitions with bool."""
105+
cfg = _make_config(tmp_path, "page_status: true\n")
106+
defs = cfg.page_status_definitions
107+
assert isinstance(defs, dict)
108+
assert len(defs) >= 5
109+
assert "new" in defs
110+
assert "experimental" in defs
111+
assert defs["new"]["label"] == "New"
112+
103113
def test_custom_definitions_merge(self, tmp_path: Path):
104114
cfg = _make_config(
105115
tmp_path,
@@ -237,3 +247,40 @@ def test_with_pages_returns_true(self, tmp_path: Path):
237247
# Verify JSON file was created
238248
json_path = gd.project_path / "_page_status.json"
239249
assert json_path.exists()
250+
251+
252+
# ── Asset Correctness Tests ─────────────────────────────────────────────────
253+
254+
255+
class TestStatusBadgeAssets:
256+
"""Verify the SCSS and JS assets contain correct selectors and logic."""
257+
258+
def test_scss_sidebar_flex_uses_compound_selector(self):
259+
"""Regression: .sidebar-navigation is ON #quarto-sidebar, not inside it.
260+
261+
#quarto-sidebar.sidebar-navigation (compound) must be used, NOT
262+
#quarto-sidebar .sidebar-navigation (descendant).
263+
"""
264+
scss_path = Path(__file__).parent.parent / "great_docs" / "assets" / "great-docs.scss"
265+
content = scss_path.read_text(encoding="utf-8")
266+
assert "#quarto-sidebar.sidebar-navigation .sidebar-item .sidebar-link" in content
267+
assert "#quarto-sidebar .sidebar-navigation .sidebar-item .sidebar-link" not in content
268+
269+
def test_js_uses_url_api_for_href_parsing(self):
270+
"""Regression: browsers resolve getAttribute('href') to absolute URLs.
271+
272+
The JS must use new URL() to extract the pathname for matching.
273+
"""
274+
js_path = Path(__file__).parent.parent / "great_docs" / "assets" / "page-status-badges.js"
275+
content = js_path.read_text(encoding="utf-8")
276+
assert "new URL(href, window.location.href)" in content
277+
278+
def test_js_progressive_subpath_matching(self):
279+
"""Regression: subdirectory deployments add a prefix to the pathname.
280+
281+
e.g. /great-docs/user-guide/foo.qmd must match key user-guide/foo.qmd.
282+
The JS must try progressively shorter subpaths.
283+
"""
284+
js_path = Path(__file__).parent.parent / "great_docs" / "assets" / "page-status-badges.js"
285+
content = js_path.read_text(encoding="utf-8")
286+
assert "segments.slice(i).join" in content

0 commit comments

Comments
 (0)