Spaces:
Running
Running
siddhm11 Claude Opus 5.5 commited on
Commit ·
faf3f76
1
Parent(s): 5866d4e
test(e2e): a self-contained world and browser tests for the paper page
Browse filesscripts/seed_e2e.py builds a tiny metadata sidecar with the six fixture
papers and two made-up ones (maths with an XSS payload; no plain summary),
an app database with each page already parsed, and a stand-in for
arxiv.org/html with generated figures. tests/test_e2e_paper.py drives the
new page in Chromium: tabs by keyboard and remembered, figures from our own
route, lightbox focus, the overflow menu, the outline, Save, console errors
in both themes, layout shift under 0.1, no sideways scrolling from 390 to
1440 px, rendered maths with the payload kept as text, and the fallbacks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- scripts/seed_e2e.py +160 -0
- tests/test_e2e_paper.py +189 -0
scripts/seed_e2e.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Build a self-contained world for the browser tests: no Turso, Qdrant, Groq or
|
| 4 |
+
arXiv involved.
|
| 5 |
+
|
| 6 |
+
python scripts/seed_e2e.py --db /tmp/e2e.db --site /tmp/e2e_arxiv \\
|
| 7 |
+
--sidecar /tmp/e2e_sidecar.sqlite
|
| 8 |
+
|
| 9 |
+
It writes three things:
|
| 10 |
+
|
| 11 |
+
sidecar a tiny metadata sidecar with the six fixture papers from
|
| 12 |
+
tests/fixtures/arxiv_html/, plus two made-up ones: 2609.99001 (an
|
| 13 |
+
abstract full of maths, and a formula carrying an XSS payload, with
|
| 14 |
+
no arXiv HTML) and 2609.99002 (no plain summary seeded, so the page
|
| 15 |
+
must fall back to the abstract);
|
| 16 |
+
db the app database with each fixture page already parsed and saved
|
| 17 |
+
(paper_sources, full text, paragraphs) and plain summaries for three
|
| 18 |
+
papers, so nothing has to be fetched or generated;
|
| 19 |
+
site a stand-in for arxiv.org/html: each page at /<id> and a generated
|
| 20 |
+
PNG at every figure path, served by `python -m http.server`.
|
| 21 |
+
|
| 22 |
+
Then start the app against them with every outside service blanked, so the
|
| 23 |
+
values in .env.local can't leak in (load_dotenv never overrides a set name):
|
| 24 |
+
|
| 25 |
+
DB_PATH=/tmp/e2e.db METADATA_SIDECAR_PATH=/tmp/e2e_sidecar.sqlite \\
|
| 26 |
+
RESEARCHIT_ENV=test ARXIV_HTML_BASE=http://127.0.0.1:8799 \\
|
| 27 |
+
TURSO_URL= TURSO_DB_TOKEN= QDRANT_URL= GROQ_API_KEY= TURSO_SYNC_DISABLED=1 \\
|
| 28 |
+
PAPER_PAGE_V2=on FIGURES=on PAPER_SOURCES=on PORT=7861 python run.py
|
| 29 |
+
"""
|
| 30 |
+
from __future__ import annotations
|
| 31 |
+
|
| 32 |
+
import argparse
|
| 33 |
+
import asyncio
|
| 34 |
+
import importlib.util
|
| 35 |
+
import io
|
| 36 |
+
import os
|
| 37 |
+
import shutil
|
| 38 |
+
import sqlite3
|
| 39 |
+
import sys
|
| 40 |
+
from pathlib import Path
|
| 41 |
+
|
| 42 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 43 |
+
FIXTURES = ROOT / "tests" / "fixtures" / "arxiv_html"
|
| 44 |
+
|
| 45 |
+
PAPERS = {
|
| 46 |
+
"2609.31507": ("cs.CV cs.RO", "Jiajun Jiang, Chunliang Hua, Zichun Chen, Yanxing Wu, Zeyuan Yang, Jie Song, Xiao Hu"),
|
| 47 |
+
"2609.20888": ("cs.LG cs.CL", "Themistoklis Haris, Henry Li, Maryam Karimzadehgan"),
|
| 48 |
+
"2609.27176": ("cs.CL cs.LG", "Divyansh Singh"),
|
| 49 |
+
"2609.29861": ("cs.CV cs.RO", "Guangzhao Dai, Qianru Sun, Qi Wu, Bin Zhu"),
|
| 50 |
+
"2609.30356": ("cs.CV", "Andrew Renninger"),
|
| 51 |
+
"2609.30670": ("cs.CV cs.AI", "Yibo Ma, Qianqian Zhang, Peng Liu, Tiancheng Zhao"),
|
| 52 |
+
}
|
| 53 |
+
MATHS_ID, NO_SUMMARY_ID = "2609.99001", "2609.99002"
|
| 54 |
+
MATHS_ABSTRACT = (
|
| 55 |
+
"We bound the error of attention by $\\epsilon \\le \\frac{1}{\\sqrt{d}}$ and show that "
|
| 56 |
+
"$$\\sum_{i=1}^{n} a_i^2 = 1$$ holds for every head. A formula that tries to inject markup, "
|
| 57 |
+
"$<img src=x onerror=\"window.__xss=1\">$, must stay text.")
|
| 58 |
+
SUMMARIES = {
|
| 59 |
+
"2609.31507": "Testing how well agents follow directions across whole cities has been limited by "
|
| 60 |
+
"the cost of 3D city models. The authors build SatNav from satellite photos instead, "
|
| 61 |
+
"with 118,494 tasks in 18 cities, and find that even strong models struggle.",
|
| 62 |
+
"2609.27176": "Knowing that test questions leaked into training does not say how much they helped. "
|
| 63 |
+
"LeakScale measures that effect directly by planting controlled exposures.",
|
| 64 |
+
MATHS_ID: "The authors prove a bound on attention error that shrinks as the model gets wider.",
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def load_sidecar_schema() -> str:
|
| 69 |
+
spec = importlib.util.spec_from_file_location("build_metadata_sidecar", ROOT / "scripts" / "build_metadata_sidecar.py")
|
| 70 |
+
module = importlib.util.module_from_spec(spec)
|
| 71 |
+
spec.loader.exec_module(module)
|
| 72 |
+
return module.SCHEMA
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def build_sidecar(path: Path, parsed: dict) -> None:
|
| 76 |
+
path.unlink(missing_ok=True)
|
| 77 |
+
conn = sqlite3.connect(path)
|
| 78 |
+
conn.executescript(load_sidecar_schema())
|
| 79 |
+
rows = []
|
| 80 |
+
for aid, (cats, authors) in PAPERS.items():
|
| 81 |
+
p = parsed[aid]
|
| 82 |
+
rows.append((aid, p.title, authors, p.abstract, cats, "AI/ML", "2026-09-25", 3, 0))
|
| 83 |
+
rows.append((MATHS_ID, "Attention error bounds in $O(1/\\sqrt{d})$", "Ada Lovelace, Alan Turing",
|
| 84 |
+
MATHS_ABSTRACT, "cs.LG", "AI/ML", "2026-09-26", 0, 0))
|
| 85 |
+
rows.append((NO_SUMMARY_ID, "A paper with no plain summary", "Grace Hopper",
|
| 86 |
+
"This abstract stands alone because no plain-language summary exists for it.",
|
| 87 |
+
"cs.AI", "AI/ML", "2026-09-26", 0, 0))
|
| 88 |
+
conn.executemany("INSERT INTO papers VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", rows)
|
| 89 |
+
conn.executemany("INSERT INTO paper_categories VALUES (?, ?, ?, ?)",
|
| 90 |
+
[(cats.split()[0], aid, 3, "2026-09-25") for aid, (cats, _) in PAPERS.items()])
|
| 91 |
+
conn.commit()
|
| 92 |
+
conn.close()
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def png_bytes(w: int, h: int, seed: int) -> bytes:
|
| 96 |
+
from PIL import Image, ImageDraw
|
| 97 |
+
im = Image.new("RGB", (max(w, 40), max(h, 30)), (250, 248, 243))
|
| 98 |
+
d = ImageDraw.Draw(im)
|
| 99 |
+
for i in range(6):
|
| 100 |
+
x = (seed * 37 + i * 61) % im.width
|
| 101 |
+
d.rectangle([x, 10 + i * 8, min(im.width - 1, x + im.width // 4), 20 + i * 8 + im.height // 5],
|
| 102 |
+
outline=(40, 80 + i * 20, 120), width=3)
|
| 103 |
+
buf = io.BytesIO()
|
| 104 |
+
im.save(buf, "PNG")
|
| 105 |
+
return buf.getvalue()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def build_site(site: Path, parsed: dict) -> int:
|
| 109 |
+
if site.exists():
|
| 110 |
+
shutil.rmtree(site)
|
| 111 |
+
site.mkdir(parents=True)
|
| 112 |
+
n = 0
|
| 113 |
+
for aid in PAPERS:
|
| 114 |
+
shutil.copy(FIXTURES / f"{aid}.html", site / aid)
|
| 115 |
+
for i, fig in enumerate(parsed[aid].figures):
|
| 116 |
+
for img in fig.images:
|
| 117 |
+
if img.src and not img.missing:
|
| 118 |
+
target = site / img.src
|
| 119 |
+
target.parent.mkdir(parents=True, exist_ok=True)
|
| 120 |
+
target.write_bytes(png_bytes(img.width or 480, img.height or 240, i))
|
| 121 |
+
n += 1
|
| 122 |
+
return n
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
async def seed_db(db_path: Path, parsed: dict) -> None:
|
| 126 |
+
from app import config, db, groq_svc, paper_source_svc
|
| 127 |
+
config.DB_PATH = db.DB_PATH = str(db_path)
|
| 128 |
+
await db.init_db()
|
| 129 |
+
for aid in PAPERS:
|
| 130 |
+
await paper_source_svc._save_parsed(parsed[aid], None)
|
| 131 |
+
await paper_source_svc._save_status(MATHS_ID, "no_html", "", None)
|
| 132 |
+
abstracts = {aid: parsed[aid].abstract for aid in PAPERS}
|
| 133 |
+
abstracts[MATHS_ID] = MATHS_ABSTRACT
|
| 134 |
+
for aid, text in SUMMARIES.items():
|
| 135 |
+
await db.save_explanation(groq_svc.explain_cache_key(aid, abstracts[aid]), aid, text, "seed")
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def main(argv=None) -> int:
|
| 139 |
+
ap = argparse.ArgumentParser()
|
| 140 |
+
ap.add_argument("--db", required=True, type=Path)
|
| 141 |
+
ap.add_argument("--site", required=True, type=Path)
|
| 142 |
+
ap.add_argument("--sidecar", required=True, type=Path)
|
| 143 |
+
args = ap.parse_args(argv)
|
| 144 |
+
|
| 145 |
+
os.environ.setdefault("TURSO_SYNC_DISABLED", "1")
|
| 146 |
+
sys.path.insert(0, str(ROOT))
|
| 147 |
+
from app import arxiv_html
|
| 148 |
+
parsed = {aid: arxiv_html.parse((FIXTURES / f"{aid}.html").read_bytes(), aid) for aid in PAPERS}
|
| 149 |
+
|
| 150 |
+
args.db.unlink(missing_ok=True)
|
| 151 |
+
build_sidecar(args.sidecar, parsed)
|
| 152 |
+
images = build_site(args.site, parsed)
|
| 153 |
+
asyncio.run(seed_db(args.db, parsed))
|
| 154 |
+
print(f"[seed_e2e] sidecar {args.sidecar} ({len(PAPERS) + 2} papers), db {args.db}, "
|
| 155 |
+
f"site {args.site} ({images} images)")
|
| 156 |
+
return 0
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
if __name__ == "__main__":
|
| 160 |
+
raise SystemExit(main())
|
tests/test_e2e_paper.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Browser tests for the redesigned paper page, against the seeded test world.
|
| 3 |
+
|
| 4 |
+
RUNNING
|
| 5 |
+
-------
|
| 6 |
+
Build the world and start a server on it (see scripts/seed_e2e.py for the
|
| 7 |
+
full command, which blanks every outside service):
|
| 8 |
+
|
| 9 |
+
.venv/bin/python scripts/seed_e2e.py --db /tmp/e2e.db --site /tmp/e2e_arxiv \\
|
| 10 |
+
--sidecar /tmp/e2e_sidecar.sqlite
|
| 11 |
+
.venv/bin/python -m http.server 8799 --directory /tmp/e2e_arxiv &
|
| 12 |
+
<the server command from seed_e2e.py> &
|
| 13 |
+
E2E_BASE_URL=http://127.0.0.1:7861 .venv/bin/python -m pytest tests/test_e2e_paper.py -v
|
| 14 |
+
|
| 15 |
+
Skips itself when playwright is missing, no server answers, or the server was
|
| 16 |
+
not started on the seeded world with PAPER_PAGE_V2 and FIGURES on.
|
| 17 |
+
"""
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
import os
|
| 21 |
+
import urllib.error
|
| 22 |
+
import urllib.request
|
| 23 |
+
import uuid
|
| 24 |
+
|
| 25 |
+
import pytest
|
| 26 |
+
|
| 27 |
+
playwright_api = pytest.importorskip("playwright.sync_api", reason="playwright not installed")
|
| 28 |
+
|
| 29 |
+
BASE_URL = os.getenv("E2E_BASE_URL", "http://127.0.0.1:7861").rstrip("/")
|
| 30 |
+
SATNAV, MATHS, NO_SUMMARY, LEAKSCALE = "2609.31507", "2609.99001", "2609.99002", "2609.27176"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _redesign_world() -> bool:
|
| 34 |
+
try:
|
| 35 |
+
html = urllib.request.urlopen(f"{BASE_URL}/p/{SATNAV}", timeout=15).read().decode()
|
| 36 |
+
except (urllib.error.URLError, OSError):
|
| 37 |
+
return False
|
| 38 |
+
return "data-sumbox" in html and "/fig/" in html
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
pytestmark = [
|
| 42 |
+
pytest.mark.browser,
|
| 43 |
+
pytest.mark.skipif(not _redesign_world(),
|
| 44 |
+
reason=f"no seeded redesign server at {BASE_URL} (see scripts/seed_e2e.py)"),
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@pytest.fixture(scope="module")
|
| 49 |
+
def browser():
|
| 50 |
+
with playwright_api.sync_playwright() as p:
|
| 51 |
+
b = p.chromium.launch()
|
| 52 |
+
yield b
|
| 53 |
+
b.close()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def open_page(browser, path, width=1440, height=900, theme="light"):
|
| 57 |
+
ctx = browser.new_context(viewport={"width": width, "height": height}, color_scheme=theme)
|
| 58 |
+
ctx.add_cookies([{"name": "arxiv_user_id", "value": f"e2e-{uuid.uuid4()}", "url": BASE_URL}])
|
| 59 |
+
page = ctx.new_page()
|
| 60 |
+
page.errors = []
|
| 61 |
+
page.on("console", lambda m: page.errors.append(m.text) if m.type == "error" else None)
|
| 62 |
+
page.on("pageerror", lambda e: page.errors.append(str(e)))
|
| 63 |
+
page.goto(BASE_URL + path, wait_until="networkidle")
|
| 64 |
+
return ctx, page
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@pytest.fixture
|
| 68 |
+
def satnav(browser):
|
| 69 |
+
ctx, page = open_page(browser, f"/p/{SATNAV}")
|
| 70 |
+
yield page
|
| 71 |
+
ctx.close()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def test_the_plain_summary_shows_first_and_the_abstract_is_one_keypress_away(satnav):
|
| 75 |
+
satnav.wait_for_selector("#panel-plain .tx-body")
|
| 76 |
+
assert "satellite photos" in satnav.inner_text("#panel-plain")
|
| 77 |
+
satnav.focus("#tab-plain")
|
| 78 |
+
satnav.keyboard.press("ArrowRight")
|
| 79 |
+
assert satnav.evaluate("document.activeElement.id") == "tab-abs"
|
| 80 |
+
assert satnav.is_visible("#panel-abs") and not satnav.is_visible("#panel-plain")
|
| 81 |
+
satnav.keyboard.press("Home")
|
| 82 |
+
assert satnav.is_visible("#panel-plain")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def test_the_tab_choice_is_remembered(browser):
|
| 86 |
+
ctx, page = open_page(browser, f"/p/{SATNAV}")
|
| 87 |
+
page.click("#tab-abs")
|
| 88 |
+
page.goto(f"{BASE_URL}/p/{LEAKSCALE}", wait_until="networkidle")
|
| 89 |
+
assert page.is_visible("#panel-abs")
|
| 90 |
+
ctx.close()
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def test_figures_load_from_our_own_route(satnav):
|
| 94 |
+
sizes = satnav.evaluate("[...document.querySelectorAll('img[src^=\"/fig/\"]')].map(i => i.naturalWidth)")
|
| 95 |
+
assert len(sizes) >= 2 and all(w > 0 for w in sizes)
|
| 96 |
+
assert satnav.evaluate("[...document.images].every(i => !i.src.startsWith('https://arxiv.org'))")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def test_the_lightbox_opens_closes_and_returns_focus(satnav):
|
| 100 |
+
satnav.click("#sec-fig [data-fig]")
|
| 101 |
+
satnav.wait_for_function("document.getElementById('lb').open")
|
| 102 |
+
assert "Figure 1" in satnav.inner_text("#lb-cap")
|
| 103 |
+
assert "CC BY 4.0" in satnav.inner_text("#lb-credit")
|
| 104 |
+
satnav.keyboard.press("Escape")
|
| 105 |
+
satnav.wait_for_function("!document.getElementById('lb').open")
|
| 106 |
+
assert satnav.evaluate("document.activeElement.closest('#sec-fig') !== null")
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def test_the_overflow_menu_works_by_keyboard(satnav):
|
| 110 |
+
satnav.click(".inline-acts [data-menu]")
|
| 111 |
+
assert satnav.is_visible(".inline-acts .menu")
|
| 112 |
+
assert satnav.evaluate("document.activeElement.closest('.menu') !== null")
|
| 113 |
+
satnav.keyboard.press("Escape")
|
| 114 |
+
assert not satnav.is_visible(".inline-acts .menu")
|
| 115 |
+
assert satnav.evaluate("document.activeElement.hasAttribute('data-menu')")
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def test_the_outline_marks_the_section_in_view(satnav):
|
| 119 |
+
def active():
|
| 120 |
+
return satnav.evaluate("[...document.querySelectorAll('.outline nav a.is-active')].map(a => a.dataset.sec)")
|
| 121 |
+
satnav.evaluate("document.getElementById('sec-fig').scrollIntoView()")
|
| 122 |
+
satnav.wait_for_timeout(400)
|
| 123 |
+
assert active() == ["sec-fig"]
|
| 124 |
+
# At the very bottom the last section is the one in view, however short.
|
| 125 |
+
satnav.evaluate("window.scrollTo(0, document.documentElement.scrollHeight)")
|
| 126 |
+
satnav.wait_for_timeout(400)
|
| 127 |
+
last = satnav.evaluate("[...document.querySelectorAll('.outline nav a')].at(-1).dataset.sec")
|
| 128 |
+
assert active() == [last]
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_saving_from_the_new_page_swaps_the_button(satnav):
|
| 132 |
+
satnav.click(".inline-acts .btn-save")
|
| 133 |
+
satnav.wait_for_selector(".inline-acts .btn-saved", timeout=15_000)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_no_console_errors_in_either_theme(browser):
|
| 137 |
+
for theme in ("light", "dark"):
|
| 138 |
+
ctx, page = open_page(browser, f"/p/{SATNAV}", theme=theme)
|
| 139 |
+
page.wait_for_timeout(500)
|
| 140 |
+
assert page.errors == [], page.errors
|
| 141 |
+
ctx.close()
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def test_layout_does_not_jump_while_figures_load(browser):
|
| 145 |
+
ctx = browser.new_context(viewport={"width": 1440, "height": 900})
|
| 146 |
+
page = ctx.new_page()
|
| 147 |
+
page.add_init_script("""
|
| 148 |
+
window.__cls = 0;
|
| 149 |
+
new PerformanceObserver(l => { for (const e of l.getEntries()) if (!e.hadRecentInput) window.__cls += e.value; })
|
| 150 |
+
.observe({type: 'layout-shift', buffered: true});
|
| 151 |
+
""")
|
| 152 |
+
page.goto(f"{BASE_URL}/p/{SATNAV}", wait_until="networkidle")
|
| 153 |
+
page.wait_for_timeout(800)
|
| 154 |
+
assert page.evaluate("window.__cls") < 0.1
|
| 155 |
+
ctx.close()
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
@pytest.mark.parametrize("width", [390, 900, 1180, 1440])
|
| 159 |
+
def test_no_sideways_scrolling_at_any_width(browser, width):
|
| 160 |
+
ctx, page = open_page(browser, f"/p/{SATNAV}", width=width)
|
| 161 |
+
assert not page.evaluate("document.documentElement.scrollWidth > document.documentElement.clientWidth")
|
| 162 |
+
outline_shown = page.is_visible(".outline")
|
| 163 |
+
assert outline_shown == (width >= 1180)
|
| 164 |
+
ctx.close()
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def test_maths_renders_and_a_markup_payload_stays_text(browser):
|
| 168 |
+
ctx, page = open_page(browser, f"/p/{MATHS}")
|
| 169 |
+
page.click("#tab-abs")
|
| 170 |
+
page.wait_for_selector("#panel-abs .katex")
|
| 171 |
+
assert page.locator("#panel-abs .katex-display").count() == 1 # the $$...$$ block
|
| 172 |
+
assert page.locator("h1 .katex").count() == 1 # maths in the title
|
| 173 |
+
assert page.evaluate("window.__xss") is None
|
| 174 |
+
assert page.locator("#panel-abs img").count() == 0
|
| 175 |
+
ctx.close()
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def test_a_paper_with_no_plain_summary_opens_on_its_abstract(browser):
|
| 179 |
+
ctx, page = open_page(browser, f"/p/{NO_SUMMARY}")
|
| 180 |
+
page.wait_for_function("document.getElementById('tab-plain').hidden")
|
| 181 |
+
assert page.is_visible("#panel-abs")
|
| 182 |
+
assert "stands alone" in page.inner_text("#panel-abs")
|
| 183 |
+
ctx.close()
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def test_a_paper_without_arxiv_html_shows_no_figure_sections(browser):
|
| 187 |
+
ctx, page = open_page(browser, f"/p/{MATHS}")
|
| 188 |
+
assert page.locator("#sec-fig").count() == 0 and page.locator("#sec-figs").count() == 0
|
| 189 |
+
ctx.close()
|