fix(gallery): preserve mobile preview height (#135)

* fix(gallery): preserve mobile preview height

* test(gallery): report routing failures directly
This commit is contained in:
Cathryn Lavery
2026-08-20 12:42:26 -07:00
committed by GitHub
parent b827385a17
commit 5538b35116
5 changed files with 82 additions and 3 deletions
+66
View File
@@ -667,6 +667,49 @@ def network_isolation_failures(context):
return []
def gallery_mobile_failures(context, gallery_path=None):
"""Keep the wrapped gallery controls from collapsing its mobile preview."""
gallery_path = gallery_path or ASSET_DIR / "index.html"
failures = []
page = context.new_page()
page.set_viewport_size({"width": 390, "height": 844})
try:
page.goto(gallery_path.as_uri(), wait_until="load")
page.locator('[data-type="polar"]').click()
routed_source = page.locator("#preview").get_attribute("src")
if routed_source != "example-polar.html":
failures.append(
"gallery-mobile-routing: Polar routed to "
f"{routed_source!r}, expected 'example-polar.html'"
)
facts = page.evaluate(
"""
() => {
const doc = document.documentElement;
const preview = document.querySelector('#preview');
const rect = preview.getBoundingClientRect();
return {
previewHeight: rect.height,
pageOverflow: doc.scrollWidth - doc.clientWidth,
};
}
"""
)
if facts["previewHeight"] < 400:
failures.append(
"gallery-mobile-preview: iframe height "
f"{facts['previewHeight']:.1f}px is below the 400px minimum"
)
if facts["pageOverflow"] > TOLERANCE:
failures.append(
"gallery-mobile-overflow: page extends "
f"{facts['pageOverflow']:.1f}px past the mobile viewport"
)
finally:
page.close()
return failures
def self_test(context):
page = context.new_page()
failures = []
@@ -736,6 +779,29 @@ def self_test(context):
checks += 1
failures += network_isolation_failures(context)
checks += 1
failures += gallery_mobile_failures(context)
# A broken route should be a targeted failure, not a delayed Playwright
# timeout or traceback that escapes the self-test report.
checks += 1
with tempfile.TemporaryDirectory() as directory:
broken_gallery = Path(directory) / "index.html"
gallery_source = (ASSET_DIR / "index.html").read_text(encoding="utf-8")
route_line = "const src = `example-${state.type}${state.variant}.html`;"
if gallery_source.count(route_line) != 1:
failures.append("gallery-mobile-routing-fixture: route source changed unexpectedly")
else:
broken_gallery.write_text(
gallery_source.replace(route_line, 'const src = "wrong-example.html";'),
encoding="utf-8",
)
route_failures = gallery_mobile_failures(context, broken_gallery)
if not any(
failure.startswith("gallery-mobile-routing:") for failure in route_failures
):
failures.append("gallery-mobile-routing: broken route was not reported")
if failures:
print("self-test FAILED:")
for failure in failures: