Wizard DXF: anteprima immagine, anteprima DXF e Prova usano <tmf-viewer>
Refs #122 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,52 +1,64 @@
|
||||
"""Controllo del template del wizard DXF: Salva in due barre zoom e overlay SVG (#119, #121).
|
||||
"""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:
|
||||
return TEMPLATE.read_text(encoding="utf-8")
|
||||
# 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 _bar_of(src: str, marker: str) -> str:
|
||||
"""Testo della barra zoom che contiene il marker (dal div della barra al primo </div>)."""
|
||||
def _tag_of(src: str, marker: str) -> str:
|
||||
"""Tag di apertura <tmf-viewer ...> che contiene il marker."""
|
||||
i = src.index(marker)
|
||||
start = src.rfind('absolute top-2 right-2', 0, i)
|
||||
return src[start:src.index("</div>", i)]
|
||||
start = src.rfind("<tmf-viewer", 0, i)
|
||||
return src[start:src.index(">", i) + 1]
|
||||
|
||||
|
||||
def test_prova_overlay_is_svg_not_canvas():
|
||||
# #121: l'overlay della Prova e' un <svg> con preserveAspectRatio none, non piu' un canvas
|
||||
def test_three_viewers_image_dxf_prova():
|
||||
# #122: tre <tmf-viewer>: immagine (src), DXF (modo contenuto, con <svg>), Prova (fit-height)
|
||||
src = _src()
|
||||
i = src.index('x-ref="overlay"')
|
||||
tag = src[src.rfind("<", 0, i):src.index(">", i) + 1]
|
||||
assert tag.startswith("<svg")
|
||||
assert 'preserveAspectRatio="none"' in tag
|
||||
assert "pointer-events-none" in tag
|
||||
assert "<canvas" not in src[i - 200:i + 200]
|
||||
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_save_button_in_image_and_prova_bars_only():
|
||||
# #119: Salva nella barra dell'immagine e in quella della Prova, non in quella del DXF
|
||||
def test_old_viewports_gone():
|
||||
# #122: niente piu' viewport, barre e overlay scritti a mano
|
||||
src = _src()
|
||||
img_bar = _bar_of(src, "vFit('img')")
|
||||
prova_bar = _bar_of(src, 'zoomBy(1 / 1.25)')
|
||||
dxf_bar = _bar_of(src, "vFit('dxf')")
|
||||
assert "tmfSaveImage(imagePreviewUrl, 'immagine')" in img_bar
|
||||
assert "tmfSaveImage(imageSrc, 'prova')" in prova_bar
|
||||
assert "tmfSaveImage" not in dxf_bar
|
||||
assert src.count("tmfSaveImage(") == 2
|
||||
# il pulsante sta dopo Adatta e prima della percentuale
|
||||
assert img_bar.index("vFit('img')") < img_bar.index("tmfSaveImage") < img_bar.index("vPct('img')")
|
||||
assert prova_bar.index("fit()") < prova_bar.index("tmfSaveImage") < prova_bar.index("zoomPct")
|
||||
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: vision_overlay.js e save_image.js prima di dxf_recipe_wizard.js
|
||||
# #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()
|
||||
wiz = src.index("js/dxf_recipe_wizard.js")
|
||||
assert src.index("js/vision_overlay.js") < wiz
|
||||
assert src.index("js/save_image.js") < wiz
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user