cmvr-wms/scripts/projectdev/vue3-header-layout-regression.cjs

57 lines
4.4 KiB
JavaScript
Raw Normal View History

const assert = require('node:assert/strict')
const { chromium, frontend, backend, username, password } = require('./vue3-test-runtime.cjs')
;(async () => {
const login=await(await fetch(backend+'/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username,password})})).json()
assert.equal(login.code,200)
const browser=await chromium.launch(), errors=[]
try {
const context=await browser.newContext({viewport:{width:1366,height:900}})
await context.addCookies([{name:'Admin-Token',value:login.token,url:frontend}])
const page=await context.newPage();page.setDefaultTimeout(12000)
page.on('pageerror',e=>errors.push(e.message))
await page.route('**/dev-api/**',r=>['GET','HEAD'].includes(r.request().method())?r.continue():r.abort('blockedbyclient'))
const ready=()=>page.waitForFunction(()=>document.querySelector('.desktop-viewport')&&![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(e=>e.getClientRects().length))
async function fit(label) {
await page.waitForTimeout(120)
const geometry=await page.evaluate(()=>{
const stage=document.querySelector('.desktop-viewport'), visible=e=>e.getClientRects().length&&getComputedStyle(e).visibility!=='hidden'
const blocks=[...stage.querySelectorAll('.business-list-page__header,.el-form--inline,.el-row.mb8,.list-actions,.query-toolbar')].filter(e=>visible(e)&&!e.closest('.el-dialog,.el-table'))
const controls=[...new Set(blocks.flatMap(e=>[...e.querySelectorAll('.el-input,.el-select,.el-date-editor')]))].filter(e=>visible(e)&&!e.parentElement.closest('.el-select,.el-date-editor'))
return {overflow:blocks.filter(e=>e.scrollWidth>e.clientWidth+2).map(e=>e.className),document:document.documentElement.scrollWidth>innerWidth+2,controls:controls.filter(e=>e.getBoundingClientRect().width<130).map(e=>({class:e.className,width:e.getBoundingClientRect().width}))}
})
assert.deepEqual(geometry.overflow,[],label)
assert.equal(geometry.document,false,label)
assert.deepEqual(geometry.controls,[],label+' squeezed controls')
}
for(const route of ['/project/info','/procurement/details','/procurement/arrival','/warehouse/stock','/production/tasks','/production/operations']) {
await page.goto(frontend+route);await ready()
for(const width of [1366,1920,2560]) {
await page.setViewportSize({width,height:900})
for(const density of ['紧凑','标准','宽松']) {
await page.locator('#size-select').click();await page.getByRole('menuitem',{name:density,exact:true}).click()
await fit(route+'/'+width+'/'+density)
}
}
const more=page.getByRole('button',{name:/更多筛选/}).first()
if(await more.count()) {await more.click();await fit(route+'/expanded');await page.getByRole('button',{name:/收起/}).first().click()}
console.log('PASS '+route+' header: 3 widths × 3 densities and advanced filters')
}
await page.goto(frontend+'/procurement/arrival');await ready()
assert.equal(await page.locator('.arrival-workbench-page .el-form--inline .top-right-btn button').count(),1,'one refresh in filter bar, no duplicate search toggle')
assert.equal(await page.getByRole('button',{name:'刷新任务',exact:true}).count(),0)
const checkbox=page.locator('.el-table__body tr .el-checkbox:not(.is-disabled)').first()
if(await checkbox.count()) {
await checkbox.click()
await page.locator('.arrival-list-summary').getByText(/已选 1 项/).waitFor()
await page.locator('.arrival-list-summary').getByRole('button',{name:'清空',exact:true}).click()
await page.waitForFunction(()=>!document.querySelector('.arrival-list-summary')?.textContent.includes('已选'))
}
await page.locator('.arrival-workbench-page .el-form--inline .top-right-btn button').click();await ready()
console.log('PASS arrival selection/clear/refresh and single processing row')
await page.goto(frontend+'/procurement/details');await ready()
for(const name of ['明细搜索','待组批']) {await page.getByText(name,{exact:true}).click();await page.locator('.purchase-lookup').waitFor();await ready();await page.setViewportSize({width:1366,height:900});await fit('purchase/'+name)}
assert.deepEqual(errors,[])
console.log('HEADER LAYOUT PASS; business writes blocked')
} finally {await browser.close()}
})().catch(e=>{console.error(e);process.exitCode=1})