File size: 1,806 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const path = require('path');
const { pathToFileURL } = require('url');
const { chromium } = require('playwright');
(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage();
  await page.setViewportSize({ width: 500, height: 700 });
  await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' });
  let small = await page.locator('[data-testid="placeholder"]').boundingBox();
  if (!small || small.x < 63) throw new Error(`small-window placeholder should keep 64px left margin, x=${small && small.x}`);
  await page.setViewportSize({ width: 1200, height: 800 });
  await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' });
  let expanded = await page.evaluate(() => {
    const sidebar = document.querySelector('[data-testid="sidebar"]').getBoundingClientRect();
    const content = document.querySelector('[data-testid="main-content"]').getBoundingClientRect();
    return { gap: content.left - sidebar.right, contentLeft: content.left, contentWidth: content.width, viewport: innerWidth, sidebarRight: sidebar.right };
  });
  if (expanded.gap < 63) throw new Error(`expanded sidebar/content gap should be at least 64px, got ${expanded.gap}`);
  const expandedCenter = expanded.contentLeft + expanded.contentWidth / 2;
  await page.locator('[data-testid="toggle-sidebar"]').click();
  await page.waitForTimeout(150);
  let collapsed = await page.locator('[data-testid="main-content"]').boundingBox();
  if (!collapsed || collapsed.x < 63) throw new Error(`collapsed content should keep 64px left margin, x=${collapsed && collapsed.x}`);
  await browser.close();
})().catch(err => { console.error(err && err.stack || err); process.exit(1); });