269bbc03ca
Refs #122 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
65 lines
2.6 KiB
Python
65 lines
2.6 KiB
Python
"""Controllo del template del wizard DXF: le tre viste sono <tmf-viewer> (#122, prima #113 #119 #121).
|
|
|
|
Legge task_editor.html come testo (come test_vision_panel_fit.py), senza renderlo.
|
|
"""
|
|
import re
|
|
from pathlib import Path
|
|
|
|
TEMPLATE = Path(__file__).resolve().parent.parent / "templates" / "maker" / "task_editor.html"
|
|
|
|
|
|
def _src() -> str:
|
|
# senza commenti Jinja e HTML, che citano <tmf-viewer> e i vecchi nomi
|
|
text = TEMPLATE.read_text(encoding="utf-8")
|
|
text = re.sub(r"\{#.*?#\}", "", text, flags=re.S)
|
|
return re.sub(r"<!--.*?-->", "", text, flags=re.S)
|
|
|
|
|
|
def _tag_of(src: str, marker: str) -> str:
|
|
"""Tag di apertura <tmf-viewer ...> che contiene il marker."""
|
|
i = src.index(marker)
|
|
start = src.rfind("<tmf-viewer", 0, i)
|
|
return src[start:src.index(">", i) + 1]
|
|
|
|
|
|
def test_three_viewers_image_dxf_prova():
|
|
# #122: tre <tmf-viewer>: immagine (src), DXF (modo contenuto, con <svg>), Prova (fit-height)
|
|
src = _src()
|
|
assert src.count("<tmf-viewer") == 3
|
|
img = _tag_of(src, 'save-name="immagine"')
|
|
assert ':src="imagePreviewUrl"' in img
|
|
dxf = _tag_of(src, 'save-name="dxf"')
|
|
assert ":src" not in dxf and ":width=" in dxf and ":height=" in dxf
|
|
prova = _tag_of(src, 'save-name="prova"')
|
|
assert "fit-height" in prova and ':src="imageSrc"' in prova
|
|
assert "result.result.overlay" in prova # overlay delle forme del risultato
|
|
# il DXF contiene lo <svg> da disegnare, dentro il componente
|
|
i = src.index('save-name="dxf"')
|
|
assert src.index("<svg", i) < src.index("</tmf-viewer>", i)
|
|
assert "dxfPreviewD()" in src[i:src.index("</tmf-viewer>", i)]
|
|
|
|
|
|
def test_old_viewports_gone():
|
|
# #122: niente piu' viewport, barre e overlay scritti a mano
|
|
src = _src()
|
|
for old in ('x-ref="vpImg"', 'x-ref="vpDxf"', 'x-ref="overlay"', 'x-ref="viewport"', "tmfSaveImage(",
|
|
"vZoomBy", "vFit(", "zoomPct", "vPct("):
|
|
assert old not in src, old
|
|
|
|
|
|
def test_no_style_string_on_viewers():
|
|
# #122: un :style a stringa sul <tmf-viewer> cancella lo style statico; x-show non sta sul componente
|
|
src = _src()
|
|
for m in re.finditer(r"<tmf-viewer[^>]*>", src):
|
|
tag = m.group(0)
|
|
assert ":style" not in tag and "x-show" not in tag, tag
|
|
|
|
|
|
def test_scripts_loaded_before_wizard():
|
|
# #119 #121 #122: vision_overlay.js e save_image.js prima di image_viewer.js, che sta prima di dxf_recipe_wizard.js
|
|
src = _src()
|
|
viewer = src.index("js/image_viewer.js")
|
|
assert src.index("js/vision_overlay.js") < viewer
|
|
assert src.index("js/save_image.js") < viewer
|
|
assert viewer < src.index("js/dxf_recipe_wizard.js")
|