File size: 2,228 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 27 28 29 30 31 32 33 | 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({ viewport: { width: 1200, height: 800 } });
await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' });
let boxes = await page.evaluate(() => {
const sidebar = document.querySelector('[data-testid="sidebar"]').getBoundingClientRect();
const shell = document.querySelector('[data-testid="content-shell"]').getBoundingClientRect();
const content = document.querySelector('[data-testid="main-content"]').getBoundingClientRect();
const style = getComputedStyle(document.querySelector('[data-testid="main-content"]'));
return { gap: shell.left - sidebar.right, paddingLeft: parseFloat(style.paddingLeft), contentLeft: content.left };
});
if (Math.abs(boxes.gap) > 2) throw new Error(`sidebar/content gap should be removed, got ${boxes.gap}`);
if (boxes.paddingLeft > 2) throw new Error(`content left padding should be removed, got ${boxes.paddingLeft}`);
await page.locator('[data-testid="collapse-sidebar"]').click();
await page.waitForFunction(() => {
const el = document.querySelector('[data-testid=sidebar]');
const rect = el.getBoundingClientRect(), style = getComputedStyle(el);
return style.display === 'none' || style.visibility === 'hidden' || Math.max(0, Math.min(innerWidth, rect.right) - Math.max(0, rect.left)) <= 2;
}, null, {timeout:5000});
await page.waitForTimeout(250);
await page.locator('[data-testid="show-prompt"]').click();
await page.waitForTimeout(150);
const sidebarWidth = await page.locator('[data-testid="sidebar"]').evaluate(el => {
const rect = el.getBoundingClientRect(), style = getComputedStyle(el);
return style.display === 'none' || style.visibility === 'hidden' ? 0 : Math.max(0, Math.min(innerWidth, rect.right) - Math.max(0, rect.left));
});
if (sidebarWidth > 2) throw new Error('showing prompt should not re-open a collapsed sidebar');
await browser.close();
})().catch(err => { console.error(err && err.stack || err); process.exit(1); });
|