Files
hermes-webui/tests/test_issue4075_mermaid_lightbox.py
T
nesquena-hermesandRod Boev a875bcbb9e feat(ux): enlarge Mermaid diagrams in chat (#4075) + workspace CSV table preview (#4025)
Combined light-UX release NW. Both rebased onto current master (were 96 and
247 behind; net 3-dot diffs applied, byte-identical to PR heads). Both reuse
existing renderers (chat image lightbox / chat CSV table renderer).

Review fix (#4025, Codex): the CSV table preview previously stripped the
workspace Edit affordance .csv had when it fell through to the code preview.
Restored: csv mode is editable, renderCsvPreviewContent caches raw content for
the edit textarea, and saving an edited CSV re-renders the table (not markdown).
Verified the full edit round-trip live + regression test.

Co-authored-by: Rod Boev <rod.boev@gmail.com>
2026-06-14 06:12:24 +00:00

83 lines
2.9 KiB
Python

"""Static regression coverage for Mermaid diagram lightbox wiring."""
from pathlib import Path
import re
ROOT = Path(__file__).resolve().parent.parent
UI = ROOT / "static" / "ui.js"
STYLE = ROOT / "static" / "style.css"
def _ui_js() -> str:
return UI.read_text(encoding="utf-8")
def _style_css() -> str:
return STYLE.read_text(encoding="utf-8")
class TestMermaidLightboxHelper:
def test_mermaid_lightbox_has_dedicated_helper(self):
src = _ui_js()
assert re.search(r"function\s+_openMermaidLightbox\(svgEl\)\s*\{", src)
assert "svgEl.cloneNode(true)" in src
assert "mermaid-lightbox-svg" in src
def test_mermaid_lightbox_reuses_existing_modal_chrome(self):
src = _ui_js()
assert "img-lightbox" in src
assert "img-lightbox-close" in src
assert "_closeImgLightbox(lb)" in src
def test_mermaid_lightbox_rewrites_cloned_svg_ids(self):
src = _ui_js()
assert "const idMap = new Map();" in src
assert "const idPrefix = 'mermaid-lightbox-'" in src
assert "replace(/url\\(#([^)]+)\\)/g" in src
def test_mermaid_lightbox_rewrites_embedded_style_selectors(self):
src = _ui_js()
assert "clone.querySelectorAll('style').forEach(styleEl => {" in src
assert "styleText = styleText.replace(new RegExp(`url\\\\(#${escapedId}\\\\)`" in src
assert "styleText = styleText.replace(new RegExp(`(^|[^\\\\w-])#${escapedId}(?=$|[^\\\\w-])`" in src
class TestDocumentClickDelegate:
def test_delegate_routes_rendered_mermaid_svgs_before_attach_thumb(self):
src = _ui_js()
mermaid_branch = (
" const mermaidSvg = e.target.closest('.mermaid-rendered svg');\n"
" if(mermaidSvg){ _openMermaidLightbox(mermaidSvg); return; }\n"
)
attach_branch = (
" img = e.target.closest('.attach-thumb');\n"
" if(img && img.tagName === 'IMG'){\n"
)
assert mermaid_branch in src
assert attach_branch in src
assert src.index(mermaid_branch) < src.index(attach_branch)
def test_delegate_still_handles_message_images(self):
src = _ui_js()
msg_branch = "let img = e.target.closest('.msg-media-img');\n if(img){ _openImgLightbox(img); return; }"
assert msg_branch in src
class TestMermaidLightboxCss:
def test_rendered_mermaid_svg_advertises_zoom(self):
src = _style_css()
assert ".mermaid-rendered svg{max-width:100%;height:auto;cursor:zoom-in;}" in src
def test_lightbox_svg_uses_modal_viewport_limits(self):
src = _style_css()
rule = ".img-lightbox .mermaid-lightbox-svg{max-width:90vw;max-height:90vh;"
assert rule in src
assert "background:var(--code-bg);" in src
class TestLightboxAria:
def test_lightboxes_set_aria_modal(self):
src = _ui_js()
assert src.count("setAttribute('aria-modal', 'true')") >= 2