cmvr-wms/scripts/projectdev/vue3-cell-overflow-check.cjs

13 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

const assert=require('node:assert/strict')
// Inspect actual rendered controls, not just columns named "状态" or "操作".
module.exports=async function checkControlCells(page,label='page'){
const cells=await page.locator('.el-table td .cell').evaluateAll(nodes=>nodes.filter(el=>el.getClientRects().length&&el.querySelector('.el-button,.el-dropdown,.el-tag,.el-progress,.el-input,.el-input-number,.el-select,.el-checkbox,.el-radio,.el-switch')).map(el=>{
const b=el.getBoundingClientRect(),visible=x=>x.getClientRects().length&&getComputedStyle(x).visibility!=='hidden'
return {text:el.textContent.trim().slice(0,100),overflow:getComputedStyle(el).textOverflow,clippedControls:[...el.querySelectorAll('.el-button,.el-tag,.el-input-number,.el-checkbox,.el-switch')].filter(visible).filter(x=>{const r=x.getBoundingClientRect();return r.width>b.width+2}).map(x=>({text:x.textContent.trim(),width:x.getBoundingClientRect().width,cellWidth:b.width}))}
}))
for(const cell of cells){assert.notEqual(cell.overflow,'ellipsis',label+' control cell ellipsis '+JSON.stringify(cell));assert.deepEqual(cell.clippedControls,[],label+' oversized control '+JSON.stringify(cell))}
const headers=await page.locator('.el-table th.business-status-cell .cell,.el-table th.business-operation-cell .cell,.el-table th.business-control-cell .cell').evaluateAll(nodes=>nodes.filter(el=>el.getClientRects().length).map(el=>({text:el.textContent.trim(),overflow:getComputedStyle(el).textOverflow})))
for(const header of headers)assert.notEqual(header.overflow,'ellipsis',label+' control header ellipsis '+header.text)
return {controlCells:cells.length,controlHeaders:headers.length}
}