File size: 2,406 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 34 35 36 37 38 39 40 41 42 | 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: 900, height: 700 } });
const errors = [];
page.on('pageerror', err => errors.push(err.message));
await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' });
await page.locator('[data-testid="block-1"]').click();
await page.locator('[data-testid="active-input"]').fill('333');
await page.locator('h1').click();
await page.waitForTimeout(100);
const kept = await page.locator('[data-testid="block-1"]').evaluate(el => ({
text: el.textContent.trim(),
empty: el.classList.contains('empty'),
editing: [...el.querySelectorAll('textarea,input,[contenteditable="true"]')].some(e=>{const r=e.getBoundingClientRect(),s=getComputedStyle(e);return r.width>0&&r.height>0&&s.display!=='none'&&s.visibility!=='hidden'})
}));
if (kept.text !== '333' || kept.editing) {
throw new Error('non-empty block should close editor but keep typed text visible');
}
await page.locator('[data-testid="block-2"]').click();
await page.locator('h1').click();
await page.waitForTimeout(100);
const empty = await page.locator('[data-testid="block-2"]').evaluate(el => ({
text: el.textContent.trim(),
empty: el.classList.contains('empty'),
editing: [...el.querySelectorAll('textarea,input,[contenteditable="true"]')].some(e=>{const r=e.getBoundingClientRect(),s=getComputedStyle(e);return r.width>0&&r.height>0&&s.display!=='none'&&s.visibility!=='hidden'})
}));
if (empty.text || empty.editing) {
throw new Error('empty block should return to default empty state after outside click');
}
await page.locator('[data-testid="block-3"]').click();
await page.locator('[data-testid="active-input"]').fill('abc');
await page.locator('[data-testid="block-1"]').click();
await page.waitForTimeout(100);
const third = await page.locator('[data-testid="block-3"]').evaluate(el => el.textContent.trim());
if (third !== 'abc') throw new Error('click-outside behavior must work for every paragraph block');
if (errors.length) throw new Error(errors.join(' | '));
await browser.close();
})().catch(err => { console.error(err && err.stack || err); process.exit(1); });
|