cmvr-wms/scripts/projectdev/vue3-header-layout-regression.cjs
lixiaolong e78ed25668 refactor(components): 优化组件交互和数据验证逻辑
- 为对话框添加防止意外关闭的安全措施
- 实现表单提交时的数据有效性验证
- 集成远程选择器组件提升用户体验
- 更新表格组件样式适配新设计规范
- 优化列表页面加载和错误处理机制
- 统一组件尺寸设置和存储管理
2026-10-14 09:11:33 +08:00

57 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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-actions .top-right-btn button').count(),1,'one refresh, 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-actions .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})