release: Евномия, новая версия, линейка юристов
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
"""Smoke, overflow and contrast checks for the Pantheon tricolor UI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = os.environ.get("EUNOMIA_URL", "http://127.0.0.1:18765")
|
||||
OUT = Path(__file__).parents[1] / "qa" / "tricolor"
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
ROUTES = {
|
||||
"home": "#view=home",
|
||||
"reader": "#doc=legal-corpus%3Acode%3Agpk-rf&fragment=doc%3Alegal-corpus%3Acode%3Agpk-rf_article_131",
|
||||
"plenum": "#view=category&kind=plenum",
|
||||
"history": "#view=history",
|
||||
"search": "#view=search&q=395",
|
||||
}
|
||||
SELECTORS = {"home": ".p-catalog", "reader": ".p-document", "plenum": ".p-catalog", "history": ".p-editions", "search": ".p-research"}
|
||||
|
||||
|
||||
def check(report: dict[str, Any], name: str, ok: bool, detail: Any = "") -> None:
|
||||
report["checks"].append({"name": name, "ok": bool(ok), "detail": detail})
|
||||
|
||||
|
||||
def main() -> int:
|
||||
report: dict[str, Any] = {"base": BASE, "checks": [], "screens": {}, "contrast": {}}
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport={"width": 1440, "height": 900}, device_scale_factor=1)
|
||||
for width, label in ((390, "390"), (1440, "1440")):
|
||||
page.set_viewport_size({"width": width, "height": 900})
|
||||
for name, route in ROUTES.items():
|
||||
errors: list[str] = []
|
||||
page_errors: list[str] = []
|
||||
page.on("console", lambda message: errors.append(message.text) if message.type == "error" else None)
|
||||
page.on("pageerror", lambda error: page_errors.append(str(error)))
|
||||
page.goto(BASE + "/" + route, wait_until="domcontentloaded")
|
||||
page.locator(SELECTORS[name]).wait_for(timeout=120000)
|
||||
page.wait_for_timeout(700)
|
||||
overflow = page.evaluate("document.documentElement.scrollWidth - document.documentElement.clientWidth")
|
||||
check(report, f"{name} {label}px renders", page.locator(SELECTORS[name]).count() == 1, page.title())
|
||||
check(report, f"{name} {label}px has no horizontal overflow", overflow == 0, overflow)
|
||||
check(report, f"{name} {label}px has no JavaScript errors", not errors and not page_errors, {"console": errors, "page": page_errors})
|
||||
screen = OUT / f"{name}-{label}.png"
|
||||
page.screenshot(path=str(screen), full_page=True)
|
||||
report["screens"][f"{name}-{label}"] = str(screen.relative_to(OUT.parent.parent))
|
||||
|
||||
if label == "1440":
|
||||
contrast = page.evaluate(
|
||||
"""() => {
|
||||
const parse = value => { const m=value.match(/rgba?\\(([^)]+)\\)/); if(!m)return null; const p=m[1].split(',').map(Number); return {r:p[0],g:p[1],b:p[2],a:p[3]===undefined?1:p[3]}; };
|
||||
const lum = c => { const f=v=>{v/=255;return v<=.03928?v/12.92:Math.pow((v+.055)/1.055,2.4)}; return .2126*f(c.r)+.7152*f(c.g)+.0722*f(c.b); };
|
||||
const ratio=(fg,bg)=>{const a=lum(fg),b=lum(bg);return (Math.max(a,b)+.05)/(Math.min(a,b)+.05)};
|
||||
const bgFor=el=>{for(let n=el;n;n=n.parentElement){const c=parse(getComputedStyle(n).backgroundColor);if(c&&c.a>.95)return c}return {r:247,g:245,b:240,a:1}};
|
||||
const out={};
|
||||
for(const [name,selector] of Object.entries({bodyText:'.p-main',control:'.p-button-primary',input:'.p-field input',search:'.p-search-field',warning:'.p-warning',notice:'.p-notice'})){const el=document.querySelector(selector);if(!el)continue;const s=getComputedStyle(el),fg=parse(s.color),bg=bgFor(el);if(fg)out[name]={ratio:ratio(fg,bg),foreground:s.color,background:`rgb(${bg.r},${bg.g},${bg.b})`};}
|
||||
return out;
|
||||
}"""
|
||||
)
|
||||
report["contrast"][name] = contrast
|
||||
for sample, values in contrast.items():
|
||||
check(report, f"{name} contrast {sample} >= 3", values["ratio"] >= 3, values)
|
||||
if "bodyText" in contrast:
|
||||
check(report, f"{name} body text contrast >= 4.5", contrast["bodyText"]["ratio"] >= 4.5, contrast["bodyText"])
|
||||
browser.close()
|
||||
(OUT / "tricolor-check.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n")
|
||||
failures = [item for item in report["checks"] if not item["ok"]]
|
||||
print(json.dumps({"checks": len(report["checks"]), "failures": failures}, ensure_ascii=False, indent=2))
|
||||
return 1 if failures else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user