84fc1a08f7
Refs #122 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
88 lines
4.2 KiB
Python
88 lines
4.2 KiB
Python
"""Test della pagina Acquisizione camera (#87): contenuto statico di PAGINA, senza servizio."""
|
|
|
|
|
|
|
|
import importlib.util
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
_FILE = Path(__file__).resolve().parents[1] / "calibrazione_pagina.py"
|
|
|
|
_spec = importlib.util.spec_from_file_location("calibrazione_pagina", _FILE)
|
|
|
|
_mod = importlib.util.module_from_spec(_spec)
|
|
|
|
_spec.loader.exec_module(_mod)
|
|
|
|
PAGINA = _mod.PAGINA
|
|
|
|
|
|
|
|
|
|
|
|
def test_titolo_e_stile_scuro():
|
|
|
|
assert "<title>Acquisizione camera</title>" in PAGINA
|
|
|
|
assert "#0f172a" in PAGINA and "#1e293b" in PAGINA and "#3b82f6" in PAGINA
|
|
|
|
|
|
|
|
|
|
|
|
def test_rotte_usate():
|
|
|
|
for rotta in ("/camera/sources", "/camera/anteprima", "/camera/parametri",
|
|
|
|
"/camera/parametri/salva", "/camera/calibrate", "/camera/calibration"):
|
|
|
|
assert '"' + rotta in PAGINA, rotta
|
|
|
|
|
|
|
|
|
|
|
|
def test_offline_e_senza_finestre_del_browser():
|
|
|
|
for vietato in ("alert(", "confirm(", "prompt(", "http://", "https://"):
|
|
|
|
assert vietato not in PAGINA, vietato
|
|
|
|
|
|
|
|
|
|
|
|
def test_id_principali():
|
|
|
|
ids = set(re.findall(r'id="([^"]+)"', PAGINA))
|
|
|
|
attesi = {"sorgente", "avvia", "ferma", "scatta", "mirinoCasella", "immagine",
|
|
|
|
"nitidezza", "nitidezzaMax", "saturati", "media", "dimensioni",
|
|
|
|
"parametri", "salvaParametri", "quadrato", "acquisisci", "caricaImmagine", "fileImmagine",
|
|
|
|
"mostraCal", "salva", "stato", "statoSorgente"} # #91: carica/elimina sono ora per riga; #92: file e calibrata nell'Acquisizione
|
|
|
|
assert attesi <= ids, attesi - ids
|
|
|
|
# ogni id usato dal JS con $("...") esiste nel markup
|
|
|
|
usati = set(re.findall(r'\$\("([^"]+)"\)', PAGINA))
|
|
|
|
assert usati <= ids, usati - ids
|
|
|
|
|
|
|
|
|
|
|
|
def test_sezioni_e_testi_italiani():
|
|
|
|
for testo in ("Sorgente", "Anteprima", "Parametri camera", "Calibrazione",
|
|
|
|
"Salva come predefiniti", "Carica immagine da file...", "Questa sorgente non ha parametri regolabili",
|
|
|
|
"Attiva calibrazione"): # #92 #93
|
|
|
|
assert testo in PAGINA, testo
|
|
|
|
assert "it-IT" in PAGINA # numeri con la virgola
|
|
|
|
assert "Choose File" not in PAGINA
|
|
|
|
|
|
|
|
|
|
|
|
def test_localstorage_protetto():
|
|
|
|
# ogni uso di localStorage sta dentro un try
|
|
|
|
for m in re.finditer(r"localStorage[.]", PAGINA):
|
|
|
|
assert "try {" in PAGINA[max(0, m.start() - 200):m.start()]
|
|
|
|
|
|
|
|
|
|
|
|
def test_specchiatura_per_sorgente(): # #110
|
|
|
|
ids = set(re.findall(r'id="([^"]+)"', PAGINA))
|
|
|
|
assert {"specchiaO", "specchiaV", "msgSpecchia"} <= ids
|
|
|
|
assert '"/camera/orientamento' in PAGINA
|
|
|
|
assert "Specchia orizzontale" in PAGINA and "Specchia verticale" in PAGINA
|
|
|
|
|
|
|
|
|
|
|
|
def test_zoom_visori(): # #111, #122: i visori sono <tmf-viewer>, la barra e lo zoom vengono dal componente
|
|
ids = set(re.findall(r'id="([^"]+)"', PAGINA))
|
|
for i in ("immagine", "immagineCal", "immagineCalTab", "overlay"): # grezza, calibrata, tab Calibrazione, angoli
|
|
assert re.search(r'<tmf-viewer id="%s"' % i, PAGINA), i
|
|
assert PAGINA.count("<tmf-viewer") == 4
|
|
for nome in ("grezza", "calibrata", "calibrazione", "angoli"):
|
|
assert 'save-name="%s"' % nome in PAGINA, nome
|
|
assert "zoomAdatta" not in PAGINA and "barraZoom" not in PAGINA and "creaVisore(" in PAGINA
|
|
assert not {"zoomMeno", "zoomPiu", "zoomPct"} & ids
|
|
assert "latoAnteprima()" in PAGINA and "unaAnteprima(1280)" not in PAGINA # lato_max segue lo zoom
|
|
assert '"viewer-zoom"' in PAGINA # lo zoom si legge dall'evento del componente
|
|
|
|
|
|
def test_script_del_visore_in_ordine(): # #122: i JS arrivano da /visore/ (offline), prima dello script di pagina
|
|
src = re.findall(r'<script src="([^"]+)"', PAGINA)
|
|
assert src == ["/visore/vision_overlay.js", "/visore/save_image.js", "/visore/image_viewer.js"]
|
|
assert PAGINA.index("/visore/image_viewer.js") < PAGINA.index("<script>")
|
|
|
|
|
|
def test_nessuna_funzione_dichiarata_due_volte(): # #111: in JS vince l'ultima dichiarazione, in silenzio
|
|
|
|
script = re.search(r"<script>(.*?)</script>", PAGINA, re.S).group(1)
|
|
|
|
nomi = re.findall(r"function\s+([A-Za-z0-9_$]+)\s*\(", script)
|
|
|
|
doppi = sorted({n for n in nomi if nomi.count(n) > 1})
|
|
|
|
assert not doppi, "funzioni dichiarate piu' volte: " + ", ".join(doppi)
|
|
|