1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""Exercise real frontend pages: uv run --with playwright tests/frontend-layout.py [origin]."""
import sys
from pathlib import Path
from playwright.sync_api import sync_playwright
origin = sys.argv[1] if len(sys.argv) > 1 else 'http://127.0.0.1:8789'
artifacts = Path('/tmp/stream-ui-check')
artifacts.mkdir(exist_ok=True)
routes = [('/', 'home', '.ep'), ('/stats', 'stats', '#profile-reading'),
('/status', 'status', '.report dd'), ('/strata/', 'strata', '#crumb')]
with sync_playwright() as p:
for engine in [p.webkit, p.chromium]:
browser = engine.launch()
for width in [320, 390, 768, 1280]:
mobile = width < 768
context = browser.new_context(viewport={'width': width, 'height': 740},
device_scale_factor=3 if mobile else 1, is_mobile=mobile, has_touch=mobile)
page = context.new_page()
errors = []
page.on('pageerror', lambda error: errors.append(str(error)))
for route, name, ready in routes:
page.goto(origin + route, wait_until='domcontentloaded')
page.wait_for_selector(ready, state='attached', timeout=30000)
if name == 'strata':
page.wait_for_function('getComputedStyle(document.querySelector("#loading")).display === "none"')
if name == 'stats':
page.wait_for_function('document.querySelector("#profile-reading").textContent.includes("typically")')
page.wait_for_timeout(250)
assert not errors, errors
page.wait_for_function('''() => { const c=document.querySelector("#depth"), s=Number(c.dataset.scale);
return s>=.6 && s<=Math.min(devicePixelRatio,2) && c.width===Math.round(c.clientWidth*s); }''')
assert page.evaluate('document.documentElement.scrollWidth <= innerWidth'), (engine.name, width, name, 'horizontal overflow')
if name == 'home':
assert page.locator('.ep').count() >= 7
assert page.evaluate('''() => [...document.querySelectorAll('.ep .p,.ep .d,.tag')].every(e => {
const range=document.createRange();range.selectNodeContents(e);
return e.scrollWidth<=e.clientWidth+1 && new Set([...range.getClientRects()].map(r=>Math.round(r.top))).size<=1;
})'''), 'endpoint wraps or clips'
if name == 'status':
assert page.locator('.report dt').count() >= 20
assert page.locator('.report').inner_text().find('historical bootstrap') >= 0
assert page.evaluate('''() => [...document.querySelectorAll('.report dt,.report dd,.report p')].every(e=>{
const r=e.getBoundingClientRect();return r.left>=0 && r.right<=innerWidth && e.scrollWidth<=e.clientWidth+1;
})'''), 'report content escapes its column'
if name == 'stats':
chart=page.locator('#profile')
chart.scroll_into_view_if_needed()
if mobile: chart.tap(position={'x':100,'y':100})
else: chart.click(position={'x':100,'y':100})
assert 'typically' in page.locator('#profile-reading').inner_text()
if engine.name == 'webkit' and width == 390:
page.wait_for_function('document.querySelector("#live").textContent.includes("flowing")')
context.set_offline(True)
page.wait_for_function('document.querySelector("#live").textContent.includes("unreachable")', timeout=15000)
context.set_offline(False)
page.wait_for_function('document.querySelector("#live").textContent.includes("flowing")', timeout=15000)
if name == 'strata':
page.locator('#expand-map').click()
page.wait_for_function('document.querySelector("#map-dialog").open')
page.locator('#map-menu').click()
page.locator('#zoom-in').click()
page.locator('#close-map').click()
page.wait_for_function('!document.querySelector("#map-dialog").open && !document.body.classList.contains("map-open")')
page.locator('#explorer > summary').click()
page.locator('#search').fill('bluesky')
page.wait_for_function('document.querySelector("#list").textContent.toLowerCase().includes("bluesky")')
page.locator('footer').scroll_into_view_if_needed()
assert page.evaluate('scrollY>0 || document.documentElement.scrollHeight<=innerHeight'), 'cannot reach footer'
assert page.evaluate('''() => {
const r=document.querySelector('#atmosphere').getBoundingClientRect();
return r.top<=0 && r.bottom>=innerHeight && r.left<=0 && r.right>=innerWidth;
}'''), 'background does not cover scrolled viewport'
if width in [390,1280]:
page.screenshot(path=str(artifacts / f'{engine.name}-{width}-{name}-bottom.png'))
page.evaluate('scrollTo(0,0)')
if width in [390,1280]:
page.screenshot(path=str(artifacts / f'{engine.name}-{width}-{name}-top.png'))
if engine.name == 'chromium' and mobile:
session=context.new_cdp_session(page)
target=page.locator('#map' if name=='strata' else 'main')
if name=='strata': target.scroll_into_view_if_needed()
box=target.bounding_box(); start=min(620,max(300,box['y']+min(box['height']/2,400)))
before=page.evaluate('scrollY')
session.send('Input.dispatchTouchEvent',{'type':'touchStart','touchPoints':[{'x':width/2,'y':start}]})
for step in range(1,9):
session.send('Input.dispatchTouchEvent',{'type':'touchMove','touchPoints':[{'x':width/2,'y':start-step*25}]})
page.wait_for_timeout(25)
session.send('Input.dispatchTouchEvent',{'type':'touchEnd','touchPoints':[]})
page.wait_for_timeout(250)
assert page.evaluate('scrollY') > before, (name, 'swipe did not scroll')
session.detach()
print(f'{engine.name} {width}px {name}: PASS', flush=True)
context.close()
browser.close()