UXInteract / task_020 /tests /validate_ui_behavior.js
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
Raw History Blame Contribute Delete
2.23 kB
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); });