Files
scadaproj/components/ui-theme/validation/theme-1.0.0/canary/overview_stale.py
T

60 lines
3.0 KiB
Python

"""Frozen five-minute-old real Overview card; no poller or external services."""
import json
from pathlib import Path
from urllib.request import Request, urlopen
from playwright.sync_api import sync_playwright
from browser_zoom import zoom_browser, set_browser_zoom
BASE = "http://127.0.0.1:5200"
OUT = Path(__file__).resolve().parent / "overview-stale"
OUT.mkdir(exist_ok=True)
urlopen(Request(BASE + "/canary/scene/stale", method="POST")).read()
def current_state(page):
# Select and measure the CURRENT node in the same synchronous JS turn.
# A locator-bound SSR node can detach during hydration and yield empty styles.
return page.evaluate("""() => {
const e=document.querySelector('.inst.stale');
return {class:e.className,text:e.textContent,
bodyOpacity:getComputedStyle(e.querySelector('.inst-body')).opacity,
hostOpacity:getComputedStyle(e.querySelector('.inst-host')).opacity,
hostColor:getComputedStyle(e.querySelector('.inst-host')).color,
background:getComputedStyle(e).backgroundColor,
width:innerWidth,devicePixelRatio,scrollWidth:document.documentElement.scrollWidth};
}""")
samples=[]
with sync_playwright() as p:
with zoom_browser(p) as (context, worker):
page=context.pages[0]
page.emulate_media(reduced_motion="reduce")
session=context.new_cdp_session(page)
for width,height in [(1440,900),(390,844)]:
page.set_viewport_size({"width":width,"height":height})
page.goto(BASE)
page.evaluate("document.fonts.ready")
data=current_state(page)
assert data["bodyOpacity"]==data["hostOpacity"]=="1",data
assert "up" in data["class"] and "Stale" in data["text"]
assert data["width"]==data["scrollWidth"],data
session.send("Emulation.setEmulatedVisionDeficiency",{"type":"achromatopsia"})
page.screenshot(path=str(OUT/f"stale-{width}-grayscale.png"),full_page=True)
session.send("Emulation.setEmulatedVisionDeficiency",{"type":"none"})
samples.append(data)
page.set_viewport_size({"width":1440,"height":900})
page.goto(BASE)
page.evaluate("document.fonts.ready")
assert set_browser_zoom(worker,page,2)==2
zoom=current_state(page)
assert zoom["width"]==zoom["scrollWidth"]==720 and zoom["devicePixelRatio"]==2
page.screenshot(path=str(OUT/"stale-200-percent.png"),full_page=False)
session.detach()
(OUT/"results.json").write_text(json.dumps({
"fixture":"Frozen synthetic healthy reading five minutes old; actual Overview components, no polling",
"samples":samples,"actualZoom":zoom,
"initialHarnessFailure":"Locator-bound SSR element detached during hydration and yielded empty styles; original observations retained. Synchronous current-node confirmation fixes the measurement without UI change.",
},indent=2)+"\n")
print("Stale text remains fully opaque and bounded at both viewports and real 200% browser zoom.")