93 lines
4.7 KiB
Python
Executable File
93 lines
4.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Responsive regression for the Overview toolbar modal.
|
|
|
|
0.33.7 repurposed the former visual layout editor as Dashboard presets. Keep
|
|
this older viewport regression focused on modal fit/no horizontal overflow.
|
|
"""
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
HTML = (ROOT / "src/admin/web/index.html").read_text(encoding="utf-8")
|
|
CSS = (ROOT / "src/admin/web/style.css").read_text(encoding="utf-8")
|
|
ROUTER = (ROOT / "src/admin/router.rs").read_text(encoding="utf-8")
|
|
PACKS = {
|
|
name: {"id": name, **json.loads((ROOT / "langs" / f"{name}.json").read_text(encoding="utf-8"))}
|
|
for name in ("en_US", "pl_pl")
|
|
}
|
|
|
|
|
|
def app_bundle():
|
|
match = re.search(r"fn admin_app_javascript\([^)]*\)[^{]*\{", ROUTER)
|
|
assert match
|
|
body = ROUTER[match.end():]
|
|
body = body[:re.search(r'\]\s*\.join\("\\n"\)', body).start()]
|
|
result = []
|
|
for line in body.splitlines():
|
|
line = line.strip()
|
|
include = re.search(r'include_str!\("([^"]+)"\)', line)
|
|
if include:
|
|
result.append((ROOT / "src/admin" / include.group(1)).read_text(encoding="utf-8"))
|
|
elif line == "admin_vhosts_javascript(),":
|
|
result.append("(() => {\n" + "\n".join(
|
|
(ROOT / "src/admin/web/vhosts" / f"{name}.js").read_text(encoding="utf-8")
|
|
for name in ("core", "protocol", "health", "rates", "editor", "render")) + "\n})();")
|
|
elif line.startswith('"') and line.endswith('",'):
|
|
result.append(json.loads(line[:-1]))
|
|
return "\n".join(result)
|
|
|
|
|
|
BUNDLE = app_bundle()
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True, executable_path="/usr/bin/chromium", args=["--no-sandbox"])
|
|
for width in (320, 375, 550, 620, 800, 900, 960, 1158, 1440, 1920):
|
|
page = browser.new_page(viewport={"width": width, "height": 823})
|
|
errors = []
|
|
page.on("pageerror", lambda error: errors.append(str(error)))
|
|
page.set_content(HTML.replace("/assets/app___RUSTPROXY_ASSET_ID__.js", "")
|
|
.replace("/assets/style___RUSTPROXY_ASSET_ID__.css", ""))
|
|
page.add_style_tag(content=CSS)
|
|
page.add_script_tag(content=BUNDLE)
|
|
page.wait_for_function("window.rustProxyPreferences && window.rustProxyDashboardLayout")
|
|
page.evaluate("""packs => {
|
|
languagePacks = new Map(Object.entries(packs)); defaultLanguage = 'en_US';
|
|
language = 'pl_pl'; languagePreference = 'pl_pl';
|
|
document.documentElement.classList.remove('app-loading', 'app-startup-failed');
|
|
document.getElementById('workspace').hidden = false;
|
|
document.getElementById('panel-overview').hidden = false;
|
|
document.getElementById('overview-layout-open').hidden = false;
|
|
currentPanel = 'overview';
|
|
window.__savedDashboard = {...structuredClone(ADMIN_APPEARANCE_DEFAULTS), language:'pl_pl'};
|
|
window.rustProxyPreferences.load = async () => window.__savedDashboard;
|
|
window.rustProxyPreferences.current = () => window.__savedDashboard;
|
|
window.rustProxyPreferences.update = async patch => {
|
|
window.__savedDashboard = {...window.__savedDashboard, ...patch};
|
|
applyAdminPreferences(window.__savedDashboard); return window.__savedDashboard;
|
|
};
|
|
applyAdminPreferences(window.__savedDashboard); language = 'pl_pl'; languagePreference = 'pl_pl';
|
|
for (const node of document.querySelectorAll('#overview-layout-dialog [data-i18n]'))
|
|
node.textContent = t(node.dataset.i18n);
|
|
}""", PACKS)
|
|
page.locator("#overview-layout-open").click()
|
|
page.wait_for_function("document.getElementById('overview-layout-dialog').open")
|
|
check = page.locator("#overview-layout-dialog").evaluate("""d => {
|
|
const r = d.getBoundingClientRect();
|
|
const rows = [...d.querySelectorAll('.dashboard-preset-save,.dashboard-preset-row')];
|
|
return {
|
|
left:r.left, right:r.right, client:d.clientWidth, scroll:d.scrollWidth,
|
|
overflow: rows.some(row => row.scrollWidth > row.clientWidth + 2),
|
|
};
|
|
}""")
|
|
assert check["left"] >= -1 and check["right"] <= width + 1, (width, check)
|
|
assert check["scroll"] <= check["client"] + 2 and not check["overflow"], (width, check)
|
|
assert page.locator("#overview-preset-name").is_visible()
|
|
assert page.locator("#overview-preset-save").is_visible()
|
|
assert not errors, (width, errors)
|
|
page.close()
|
|
print(f"PASS responsive Dashboard preset modal at {width}px")
|
|
browser.close()
|
|
print("PASS modal responsive regression after 0.33.7 preset conversion")
|