test_musehub_ui_htmx_infra.py
python
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226
Merge branch 'fix/two-column-scroll-layout' into dev
Human
9 days ago
| 1 | """Tests for HTMX infrastructure — static assets, base.html wiring, and helpers. |
| 2 | |
| 3 | Verifies that: |
| 4 | - htmx.min.js and alpinejs.min.js are present in the static directory. |
| 5 | - base.html includes the correct <script> tags and hx-boost attribute. |
| 6 | - app.js contains the HTMX after-swap hook. |
| 7 | - The is_htmx() / is_htmx_boosted() helpers return the correct values. |
| 8 | - The static files are reachable via the /static/ HTTP endpoint. |
| 9 | """ |
| 10 | |
| 11 | from __future__ import annotations |
| 12 | |
| 13 | from pathlib import Path |
| 14 | |
| 15 | import pytest |
| 16 | from httpx import AsyncClient |
| 17 | |
| 18 | STATIC_DIR = Path(__file__).parent.parent / "musehub" / "templates" / "musehub" / "static" |
| 19 | BASE_HTML = Path(__file__).parent.parent / "musehub" / "templates" / "musehub" / "base.html" |
| 20 | APP_JS = STATIC_DIR / "app.js" |
| 21 | |
| 22 | |
| 23 | # ── Static asset presence ──────────────────────────────────────────────────── |
| 24 | |
| 25 | def test_htmx_min_js_static_file_exists() -> None: |
| 26 | """htmx.min.js must be present in the MuseHub static directory.""" |
| 27 | assert (STATIC_DIR / "htmx.min.js").exists(), "htmx.min.js not found in static dir" |
| 28 | |
| 29 | |
| 30 | def test_alpinejs_min_js_static_file_exists() -> None: |
| 31 | """alpinejs.min.js must be present in the MuseHub static directory.""" |
| 32 | assert (STATIC_DIR / "alpinejs.min.js").exists(), "alpinejs.min.js not found in static dir" |
| 33 | |
| 34 | |
| 35 | # ── base.html wiring ───────────────────────────────────────────────────────── |
| 36 | |
| 37 | def test_base_html_includes_htmx_script() -> None: |
| 38 | """base.html must reference htmx.min.js so HTMX is available on every page.""" |
| 39 | content = BASE_HTML.read_text() |
| 40 | assert "htmx.min.js" in content, "htmx.min.js script tag missing from base.html" |
| 41 | |
| 42 | |
| 43 | def test_base_html_includes_alpinejs_script() -> None: |
| 44 | """base.html must reference alpinejs.min.js so Alpine.js is available on every page.""" |
| 45 | content = BASE_HTML.read_text() |
| 46 | assert "alpinejs.min.js" in content, "alpinejs.min.js script tag missing from base.html" |
| 47 | |
| 48 | |
| 49 | def test_base_html_hx_boost_on_container() -> None: |
| 50 | """The main container div must carry hx-boost so navigation links get SPA-feel transitions.""" |
| 51 | content = BASE_HTML.read_text() |
| 52 | assert 'hx-boost="true"' in content, 'hx-boost="true" missing from container div in base.html' |
| 53 | |
| 54 | |
| 55 | def test_base_html_htmx_loading_indicator() -> None: |
| 56 | """base.html must include the #htmx-loading progress bar element.""" |
| 57 | content = BASE_HTML.read_text() |
| 58 | assert 'id="htmx-loading"' in content, "#htmx-loading element missing from base.html" |
| 59 | |
| 60 | |
| 61 | # ── app.js HTMX hooks ──────────────────────────────────────────────────────── |
| 62 | |
| 63 | |
| 64 | def test_musehub_js_has_htmx_after_swap_hook() -> None: |
| 65 | """app.js must register an htmx:afterSwap listener to re-run initRepoNav after fragments swap.""" |
| 66 | content = APP_JS.read_text() |
| 67 | assert "htmx:afterSwap" in content, "htmx:afterSwap listener missing from app.js" |
| 68 | |
| 69 | |
| 70 | # ── is_htmx() / is_htmx_boosted() helpers ─────────────────────────────────── |
| 71 | |
| 72 | def test_is_htmx_helper_true() -> None: |
| 73 | """is_htmx() must return True when the HX-Request: true header is present.""" |
| 74 | from unittest.mock import MagicMock |
| 75 | |
| 76 | from musehub.api.routes.musehub.htmx_helpers import is_htmx |
| 77 | |
| 78 | request = MagicMock() |
| 79 | request.headers = {"HX-Request": "true"} |
| 80 | assert is_htmx(request) is True |
| 81 | |
| 82 | |
| 83 | def test_is_htmx_helper_false() -> None: |
| 84 | """is_htmx() must return False when the HX-Request header is absent.""" |
| 85 | from unittest.mock import MagicMock |
| 86 | |
| 87 | from musehub.api.routes.musehub.htmx_helpers import is_htmx |
| 88 | |
| 89 | request = MagicMock() |
| 90 | request.headers = {} |
| 91 | assert is_htmx(request) is False |
| 92 | |
| 93 | |
| 94 | def test_is_htmx_boosted_helper_true() -> None: |
| 95 | """is_htmx_boosted() must return True when HX-Boosted: true is present.""" |
| 96 | from unittest.mock import MagicMock |
| 97 | |
| 98 | from musehub.api.routes.musehub.htmx_helpers import is_htmx_boosted |
| 99 | |
| 100 | request = MagicMock() |
| 101 | request.headers = {"HX-Boosted": "true"} |
| 102 | assert is_htmx_boosted(request) is True |
| 103 | |
| 104 | |
| 105 | def test_is_htmx_boosted_helper_false() -> None: |
| 106 | """is_htmx_boosted() must return False when the HX-Boosted header is absent.""" |
| 107 | from unittest.mock import MagicMock |
| 108 | |
| 109 | from musehub.api.routes.musehub.htmx_helpers import is_htmx_boosted |
| 110 | |
| 111 | request = MagicMock() |
| 112 | request.headers = {} |
| 113 | assert is_htmx_boosted(request) is False |
| 114 | |
| 115 | |
| 116 | # ── HTTP endpoint reachability ─────────────────────────────────────────────── |
| 117 | |
| 118 | async def test_htmx_min_js_served_over_http(client: AsyncClient) -> None: |
| 119 | """GET /static/htmx.min.js must return 200.""" |
| 120 | resp = await client.get("/static/htmx.min.js") |
| 121 | assert resp.status_code == 200, f"Expected 200, got {resp.status_code}" |
| 122 | |
| 123 | |
| 124 | async def test_alpinejs_min_js_served_over_http(client: AsyncClient) -> None: |
| 125 | """GET /static/alpinejs.min.js must return 200.""" |
| 126 | resp = await client.get("/static/alpinejs.min.js") |
| 127 | assert resp.status_code == 200, f"Expected 200, got {resp.status_code}" |
File History
13 commits
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226
Merge branch 'fix/two-column-scroll-layout' into dev
Human
9 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454
chore: bump version to 0.2.0.dev2 — nightly.2, matching muse
Sonnet 4.6
patch
12 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2
chore: bump version to 0.2.0rc15 for musehub#113 fix release
Sonnet 4.6
patch
15 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352
Merge branch 'task/version-tags-phase3-server' into dev
Human
18 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53
merge: rescue snapshot-recovery hardening (c00aa21d) into d…
Opus 4.8
minor
⚠
30 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a
fix: remove false-positive proposal_comments index drop fro…
Sonnet 4.6
patch
34 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3
feat: render markdown mists as HTML with heading anchor links
Sonnet 4.6
patch
35 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6
Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump …
Human
36 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee
Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump …
Human
36 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c
Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo…
Human
36 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd
Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop…
Human
36 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f
fix: use wire_bytes not mpack_bytes_raw in compute_object_b…
Sonnet 4.6
patch
49 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583
rename: delta_add → delta_upsert across wire format, models…
Sonnet 4.6
patch
51 days ago