|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const ARTICLE = '/docs/langgraph/getting-started/introduction'; |
| 4 | + |
| 5 | +/** |
| 6 | + * The docs shell is one reading pane: a sticky control plane on the left, one |
| 7 | + * prose column, and a sticky TOC rail on the right. These guard the parts of |
| 8 | + * that whose failure mode is silence — a rail that stops tracking, a column |
| 9 | + * that stops sharing its measure — and which jsdom cannot see. |
| 10 | + */ |
| 11 | + |
| 12 | +test.describe('DocsTOC rail', () => { |
| 13 | + test('tracks the reading position on a hard load', async ({ page }) => { |
| 14 | + await page.setViewportSize({ width: 1440, height: 900 }); |
| 15 | + await page.goto(ARTICLE); |
| 16 | + await expect(page.locator('.docs-toc-link').first()).toBeVisible(); |
| 17 | + |
| 18 | + // Nothing is active at the top: the first heading is below the reading line. |
| 19 | + await expect(page.locator('.docs-toc-link[data-active]')).toHaveCount(0); |
| 20 | + |
| 21 | + await page.evaluate(() => window.scrollTo({ top: 4000, behavior: 'instant' })); |
| 22 | + await expect |
| 23 | + .poll(() => |
| 24 | + page |
| 25 | + .locator('.docs-toc-link[data-active]') |
| 26 | + .evaluateAll((els) => els.map((e) => e.getAttribute('href'))), |
| 27 | + ) |
| 28 | + .toEqual(['#connect-with-angular']); |
| 29 | + |
| 30 | + // ...and it follows the scroll rather than latching on the first match. |
| 31 | + await page.evaluate(() => window.scrollTo({ top: 0, behavior: 'instant' })); |
| 32 | + await expect.poll(() => page.locator('.docs-toc-link[data-active]').count()).toBe(0); |
| 33 | + }); |
| 34 | + |
| 35 | + test('every rail link resolves to a heading in the article', async ({ page }) => { |
| 36 | + await page.setViewportSize({ width: 1440, height: 900 }); |
| 37 | + await page.goto(ARTICLE); |
| 38 | + |
| 39 | + const unresolved = await page.evaluate(() => |
| 40 | + [...document.querySelectorAll('.docs-toc-link')] |
| 41 | + .map((a) => (a as HTMLAnchorElement).getAttribute('href') ?? '') |
| 42 | + .filter((href) => !document.getElementById(href.slice(1))), |
| 43 | + ); |
| 44 | + expect(unresolved).toEqual([]); |
| 45 | + }); |
| 46 | + |
| 47 | + test('the library-neutral adapter page gets the same rail', async ({ page }) => { |
| 48 | + await page.setViewportSize({ width: 1440, height: 900 }); |
| 49 | + await page.goto('/docs/choosing-an-adapter'); |
| 50 | + await expect(page.locator('.docs-toc')).toBeVisible(); |
| 51 | + expect(await page.locator('.docs-toc-link').count()).toBeGreaterThan(3); |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +test.describe('docs shell layout', () => { |
| 56 | + test('the sticky rails hold through a full-page scroll', async ({ page }) => { |
| 57 | + await page.setViewportSize({ width: 1440, height: 900 }); |
| 58 | + await page.goto(ARTICLE); |
| 59 | + |
| 60 | + const navH = await page.evaluate(() => |
| 61 | + parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--nav-h')), |
| 62 | + ); |
| 63 | + const tops = async () => ({ |
| 64 | + plane: await page.locator('.docs-control-plane').evaluate((el) => Math.round(el.getBoundingClientRect().top)), |
| 65 | + toc: await page.locator('.docs-toc').evaluate((el) => Math.round(el.getBoundingClientRect().top)), |
| 66 | + }); |
| 67 | + |
| 68 | + expect(await tops()).toEqual({ plane: navH, toc: navH }); |
| 69 | + await page.evaluate(() => window.scrollTo({ top: 4000, behavior: 'instant' })); |
| 70 | + expect(await tops()).toEqual({ plane: navH, toc: navH }); |
| 71 | + await page.evaluate(() => window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' })); |
| 72 | + expect(await tops()).toEqual({ plane: navH, toc: navH }); |
| 73 | + }); |
| 74 | + |
| 75 | + test('breadcrumb, prose and prev/next share one right edge', async ({ page }) => { |
| 76 | + // The header block used to stretch to the full content width while the |
| 77 | + // article and the prev/next rail sat at max-w-3xl, so PageActions floated |
| 78 | + // ~500px right of the column it belongs to. |
| 79 | + await page.setViewportSize({ width: 1920, height: 1000 }); |
| 80 | + await page.goto(ARTICLE); |
| 81 | + |
| 82 | + const right = (selector: string) => |
| 83 | + page.locator(selector).first().evaluate((el) => Math.round(el.getBoundingClientRect().right)); |
| 84 | + |
| 85 | + const header = await right('.docs-page-header'); |
| 86 | + const article = await right('article'); |
| 87 | + const prevNext = await right('.docs-prevnext'); |
| 88 | + |
| 89 | + // The header and prev/next sit inside the article's horizontal padding. |
| 90 | + expect(article - header).toBeLessThanOrEqual(48); |
| 91 | + expect(header).toBe(prevNext); |
| 92 | + }); |
| 93 | +}); |
0 commit comments