const { chromium } = require('playwright'); const assert = require('node:assert/strict'); const widths = [360, 390, 412, 800, 1440]; const longName = 'The unexpectedly long journey across the northern mountains and beyond the distant sea'; (async () => { const browser = await chromium.launch({ headless: true, executablePath: process.env.CHROMIUM_PATH }); try { const page = await browser.newPage(); const standalone = process.env.PD_RESPONSIVE_STANDALONE === '1'; await page.addInitScript(standalone => { if (standalone) Object.defineProperty(navigator, 'standalone', { get: () => true }); }, standalone); for (const width of widths) { await page.setViewportSize({ width, height: 900 }); for (const theme of ['modern-dark', 'warm-dark', 'modern-light']) { const mobile = width < 768; for (const [kind, url] of [['chapters', '/fixture?desktop=Books'], ['timeline', '/fixture?page=timeline-render'], ['plot', '/plot-map-fixture']]) { await page.goto('http://127.0.0.1:5238' + url); await page.evaluate(theme => { document.documentElement.dataset.appTheme = theme; document.documentElement.dataset.theme = theme.endsWith('dark') ? 'dark' : 'light'; }, theme); // The isolated map host does not have a viewport meta tag; desktop Playwright // uses CSS pixels, just as the full application with its viewport meta does. if (kind === 'chapters') { assert.equal(await page.locator('.chapter-table').count(), 1); assert.equal(await page.locator('.chapter-title').count(), 2); const titles = await page.locator('.chapter-title').evaluateAll(els => els.map(el => ({ width: el.clientWidth, scroll: el.scrollWidth, height: el.clientHeight }))); assert.ok(titles.every(t => t.width > (mobile ? 200 : 100) && t.scroll <= t.width + 1), JSON.stringify(titles)); assert.equal(await page.locator('.chapter-table tbody tr').first().evaluate(el => getComputedStyle(el).display), mobile ? 'grid' : 'table-row'); for (const selector of ['.chapter-status', '.chapter-manuscript', '.chapter-summary', '.chapter-actions a', '.chapter-actions button']) { for (const el of await page.locator(selector).all()) assert.ok(await el.isVisible(), selector); } if (mobile) assert.ok(await page.locator('.chapter-actions button').first().evaluate(el => el.clientHeight >= 42)); } else { const rail = page.locator(kind === 'timeline' ? '.timeline-project-title' : '.plot-lane-label').first(); const name = rail.locator('.responsive-rail-text'); if (kind === 'timeline') await page.locator('.timeline-book-title strong').first().evaluate((el, text) => { el.textContent = text; }, longName); await name.evaluate((el, text) => { const title = el.querySelector('strong'); (title || el).textContent = text; }, longName); const box = await rail.boundingBox(); assert.equal(Math.round(box.width), mobile ? 52 : kind === 'timeline' ? 180 : 204); if (mobile) { assert.notEqual(await name.evaluate(el => getComputedStyle(el).transform), 'none'); const bounds = await name.boundingBox(); assert.ok(bounds.x >= box.x - 1 && bounds.x + bounds.width <= box.x + box.width + 1, JSON.stringify({box, bounds})); await name.focus(); await name.evaluate(el => { el.scrollLeft = 100; }); assert.ok(await name.evaluate(el => el.scrollLeft > 0), 'Long text remains scrollable'); } const scroll = page.locator(kind === 'timeline' ? '.timeline-shell' : '.plot-map-scroll').first(); const scrollable = await scroll.evaluate(el => el.scrollWidth > el.clientWidth); if (mobile) assert.ok(scrollable, 'mobile workspace must keep horizontal scrolling'); await scroll.evaluate(el => { el.scrollLeft = 180; }); if (scrollable) assert.ok(await scroll.evaluate(el => el.scrollLeft > 0)); const after = await rail.boundingBox(); assert.ok(Math.abs(after.x - box.x) < 1, `sticky rail moved: ${JSON.stringify({ box, after })}`); if (kind === 'plot') { await page.locator('[data-map-mode="associate"]').click(); for (const el of await page.locator('.plot-lane-label .plot-associate-action').all()) { assert.ok(await el.isVisible()); if (mobile) assert.ok((await el.boundingBox()).height >= 44); } // Zoom and breakpoint changes must update scene markers and SVG dependencies together. await page.locator('#plot-map-zoom').selectOption('180'); const coords = await page.evaluate(() => { const map = document.querySelector('.plot-narrative-map'); const path = map.querySelector('[data-source-column]'); const offset = parseFloat(getComputedStyle(map).getPropertyValue('--plot-map-origin')) || 260; return { d: path?.getAttribute('d'), expected: offset + Number(path?.dataset.sourceColumn) * 180 }; }); if (coords.d) assert.ok(coords.d.startsWith(`M ${coords.expected} `)); } } const overflow = await page.evaluate(() => document.documentElement.scrollWidth - innerWidth); assert.ok(overflow <= 1, `${kind} ${width} ${theme}: page overflow ${overflow}px`); if (theme === 'modern-dark' && [390, 1440].includes(width)) await page.screenshot({ path: `/tmp/responsive-${kind}-${width}${standalone ? "-standalone" : ""}.png`, fullPage: true }); } } console.log(`PASS responsive content: ${width}px, three themes`); } } finally { await browser.close(); } })().catch(error => { console.error(error); process.exitCode = 1; });