~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/stream

jetstream v2 in zig · mirror of https://tangled.org/zat.dev/stream

0
0
69 lines · 3.4 KB Raw History
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>homepage layout regression</title>
<p>Serve this page on the same origin as the Caddy-rendered homepage. Checks use the real page and live data.</p>
<pre id="results">running</pre>
<script>
const results = document.getElementById('results');
async function check(width) {
  const frame = document.createElement('iframe');
  frame.style.cssText = `width:${width}px;height:844px;border:0;display:block`;
  const loaded = new Promise(resolve => frame.addEventListener('load', resolve, {once:true}));
  frame.src = '/';
  document.body.append(frame);
  await loaded;
  try {
    const doc = frame.contentDocument;
    const win = frame.contentWindow;
    const river = doc.getElementById('river');
    if (!river) throw new Error('homepage did not render');
    for (let i = 0; i < 30 && !river.textContent.trim(); i++) {
      await new Promise(resolve => setTimeout(resolve, 100));
    }
    if (!river.textContent.trim()) throw new Error('river did not draw');
    if (!doc.querySelector('.ep')) throw new Error('endpoint list did not render');
    for (let i = 0; i < 2; i++) {
      if (doc.documentElement.scrollWidth > doc.documentElement.clientWidth) {
        throw new Error(`page overflows: ${doc.documentElement.scrollWidth} > ${doc.documentElement.clientWidth}`);
      }
      const bounds = river.getBoundingClientRect();
      if (bounds.left < 0 || bounds.right > width) throw new Error('river exceeds viewport');
      const sizes = new Set(Array.from(doc.querySelectorAll('.ep .p, .ep .d, .ep .m'), line => win.getComputedStyle(line).fontSize));
      if (sizes.size !== 1) throw new Error('endpoint text sizes differ');
      for (const line of doc.querySelectorAll('.ep .p, .ep .d, .tag')) {
        if (line.scrollWidth > line.clientWidth + 1) throw new Error(`text overflows: ${line.textContent}`);
        const range = doc.createRange();
        range.selectNodeContents(line);
        const rows = new Set(Array.from(range.getClientRects(), rect => Math.round(rect.top)));
        if (rows.size > 1) throw new Error(`text wraps: ${line.textContent}`);
        if (win.getComputedStyle(line).textOverflow === 'ellipsis') throw new Error('text is truncated');
      }
      win.scrollTo(1000, 0);
      if (win.scrollX !== 0) throw new Error(`horizontal scrolling reached ${win.scrollX}`);
      win.scrollTo(0, doc.documentElement.scrollHeight);
      const atmosphere = doc.getElementById('atmosphere').getBoundingClientRect();
      const surface = doc.getElementById('depth').getBoundingClientRect();
      if (atmosphere.top !== 0 || atmosphere.bottom < win.innerHeight) throw new Error('background does not cover scrolled viewport');
      if (surface.top >= 0 || surface.bottom <= win.innerHeight || surface.left >= 0 || surface.right <= win.innerWidth) {
        throw new Error('background surface ends at a viewport edge');
      }
      win.scrollTo(0, 0);
      await new Promise(resolve => setTimeout(resolve, 1000));
    }
    return `${width}px: PASS`;
  } finally {
    frame.remove();
  }
}
(async () => {
  const lines = [];
  for (const width of [320, 390, 640, 1280]) {
    try { lines.push(await check(width)); }
    catch (error) { lines.push(`${width}px: FAIL — ${error.message}`); }
    results.textContent = lines.join('\n');
  }
  document.title = lines.some(line => line.includes('FAIL')) ? 'FAIL: homepage layout' : 'PASS: homepage layout';
})();
</script>
</html>