const assert=require('node:assert/strict') async function inspectForms(page,scope='body'){ return page.locator(scope+' .el-form-item').evaluateAll(items=>{ const visible=el=>el&&el.getClientRects().length&&getComputedStyle(el).visibility!=='hidden',box=el=>{const r=el.getBoundingClientRect();return {x:r.x,y:r.y,right:r.right,bottom:r.bottom,width:r.width,height:r.height}} return items.filter(visible).map(item=>{ const label=item.querySelector('.el-form-item__label'),content=item.querySelector('.el-form-item__content'),l=visible(label)?box(label):null,c=visible(content)?box(content):null const range=document.createRange();if(l)range.selectNodeContents(label) const textBox=l?range.getBoundingClientRect():null const controls=[...content?.children||[]].filter(el=>el.matches('.el-input,.el-select,.el-input-number,.el-date-editor,.el-cascader,.el-textarea')).filter(visible).map(el=>({...box(el),type:el.className,scroll:el.scrollWidth,client:el.clientWidth})) const error=item.querySelector('.el-form-item__error'),itemBox=box(item),errorBox=visible(error)?box(error):null const next=errorBox?[...item.closest('.el-form').querySelectorAll('.el-form-item')].filter(visible).filter(el=>el!==item).map(box).filter(b=>b.y>=itemBox.bottom-1&&b.xerrorBox.x).sort((a,b)=>a.y-b.y)[0]:null return {label:label?.textContent?.trim(),labelBox:l,labelText:textBox?{height:textBox.height,width:textBox.width}:null,labelOverflow:l?label.scrollWidth-label.clientWidth:0,contentBox:c,controls,error:errorBox?{text:error.textContent,...errorBox,next}:null} }) }) } async function checkForms(page,label,scope='body'){ const forms=await inspectForms(page,scope) for(const item of forms){ if(item.labelBox){assert.ok(item.labelOverflow<=2,label+' overflowing label '+JSON.stringify(item));assert.ok(item.labelText.height<=item.labelBox.height+1,label+' wrapping label '+JSON.stringify(item))} for(const control of item.controls){assert.ok(control.width>=64,label+' collapsed control '+JSON.stringify(item));assert.ok(control.right<=item.contentBox.right+2&&control.x>=item.contentBox.x-2,label+' control outside content '+JSON.stringify(item))} if(item.error?.next)assert.ok(item.error.bottom<=item.error.next.y+1,label+' validation overlaps next field '+JSON.stringify(item)) } return forms } module.exports={inspectForms,checkForms}