cmvr-wms/scripts/projectdev/vue3-modern-workspaces-regression.cjs

81 lines
12 KiB
JavaScript
Raw Normal View History

const assert=require('node:assert/strict'),fs=require('node:fs')
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()
try{
const context=await browser.newContext({viewport:{width:1366,height:768}});await context.addCookies([{name:'Admin-Token',value:login.token,url:frontend}])
const page=await context.newPage(),errors=[],warnings=[];page.setDefaultTimeout(12000);page.on('pageerror',e=>{errors.push(e.message);console.log('PAGEERROR',e.stack)});page.on('console',m=>{if(m.type()==='warning')warnings.push(m.text())})
await page.route('**/dev-api/**',r=>['GET','HEAD'].includes(r.request().method())?r.continue():r.abort('blockedbyclient'))
await page.goto(frontend+'/procurement/details');await page.getByRole('button',{name:'新增未组批',exact:true}).click();await page.locator('.sheet-grid').waitFor()
await page.locator('.purchase-sheet').evaluate(async el=>{const vm=el.__vueParentComponent.proxy,item=vm.items.find(i=>i.unit&&i.category),project=vm.projects[0];vm.sheet.rows=Array.from({length:500},(_,i)=>({...vm.emptyRow(),_key:'regression-'+i,productId:item.id,materialName:item.productName,materialBrand:item.brand,materialParams:item.spec,unit:item.unit,category:item.category,projectId:project.id,quantity:i+1,finalUnitPrice:2}));await vm.$nextTick()})
await page.waitForTimeout(150)
assert.ok(await page.locator('.sheet-grid .el-table__body tbody tr').count()<60)
const vmEvaluate=fn=>page.locator('.purchase-sheet').evaluate(fn)
await vmEvaluate(async el=>{const vm=el.__vueParentComponent.proxy;await vm.activateCell(vm.sheet.rows[450],'quantity')})
const quantity=page.locator('.sheet-cell[data-row="450"][data-field="quantity"] input');await quantity.fill('88');await quantity.blur()
assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.sheet.rows[450].quantity),88)
await page.getByRole('button',{name:'撤销',exact:true}).click();assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.sheet.rows[450].quantity),451)
await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;vm.toggleGridRow(vm.sheet.rows[0],true);vm.toggleGridRow(vm.sheet.rows[499],true)})
assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.selected.length),2)
const wrap=page.locator('.sheet-grid .el-table__body-wrapper .el-scrollbar__wrap')
await wrap.evaluate(e=>{e.scrollTop=e.scrollHeight});await page.waitForTimeout(150)
assert.ok(await page.locator('.sheet-cell[data-row="499"]').count()>0,'last row reachable')
assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.selected.length),2,'selection survives window scroll')
await page.locator('.sheet-grid .el-table__header-wrapper .el-checkbox').click();assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.selected.length),500)
await page.locator('.sheet-grid .el-table__header-wrapper .el-checkbox').click();assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.selected.length),0)
await vmEvaluate(async el=>{const vm=el.__vueParentComponent.proxy,u=vm.sheet.rows[480].unit;await vm.activateCell(vm.sheet.rows[480],'quantity');await vm.paste({clipboardData:{getData:()=>`数量\t单位\t报价单价\n9\t${u}\t12\n10\t${u}\t13`},preventDefault(){}},480,'quantity')})
await page.getByRole('dialog',{name:'Excel 粘贴预览',exact:true}).getByRole('button',{name:'应用到表格',exact:true}).click();await page.getByRole('dialog',{name:'Excel 粘贴预览',exact:true}).waitFor({state:'hidden'})
assert.deepEqual(await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;return vm.sheet.rows.slice(480,482).map(r=>[r.quantity,r.finalUnitPrice])}),[[9,12],[10,13]])
await page.getByRole('button',{name:'撤销',exact:true}).click();assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.sheet.rows[480].quantity),481)
await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;vm.selected=[vm.sheet.rows[10],vm.sheet.rows[11]];vm.remove()});assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.sheet.rows.length),498)
await page.getByRole('button',{name:'撤销',exact:true}).click();assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.sheet.rows.length),500)
await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;vm.sheet.rows[420].quantity=42;vm.persistDraft()})
const key=await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;return vm.draftPrefix()+vm.draftId()})
assert.equal(await page.evaluate(key=>JSON.parse(localStorage.getItem(key)).format,key),3)
await page.locator('.purchase-sheet').evaluate(async(el,key)=>{const vm=el.__vueParentComponent.proxy;vm.sheet=null;vm.editing=false;await vm.restoreDraft(key)},key)
assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.sheet.rows[420].quantity),42)
assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.sheet.rows.length),500)
for(const density of ['紧凑','标准','宽松']){await page.locator('#size-select').click();await page.getByRole('menuitem',{name:density,exact:true}).click();await page.waitForTimeout(100);await vmEvaluate(async el=>{const vm=el.__vueParentComponent.proxy;await vm.activateCell(vm.sheet.rows[499],'quantity')});await page.locator('.sheet-cell[data-row="499"] input:not(.sheet-keyboard-input)').waitFor()}
console.log('PASS virtual scrolling, last-row editing, cross-window selection/select-all, paste/undo/delete/restore and three densities')
const lookupSheet=await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;return {batch:{id:989001,batchNo:'PC26100001'},rows:vm.sheet.rows.map((r,i)=>({...r,id:989000+i,materialName:'同名规格物品'})),version:'lookup-test'}})
await page.route('**/dev-api/warehouse/purchase/sheet/989001',r=>r.fulfill({json:{code:200,data:lookupSheet}}))
await vmEvaluate(async el=>{const vm=el.__vueParentComponent.proxy;await vm.openLookupRow({purchaseBatchId:989001,id:989450,materialName:'同名规格物品'})})
const target=page.locator('.sheet-cell[data-row="450"][data-field="materialName"]');await target.waitFor()
const position=await target.evaluate(e=>{const r=e.getBoundingClientRect(),b=e.closest('.el-table').querySelector('.el-table__body-wrapper').getBoundingClientRect();return {top:r.top,bottom:r.bottom,bodyTop:b.top,bodyBottom:b.bottom}})
assert.ok(position.top>=position.bodyTop&&position.bottom<=position.bodyBottom,'lookup opens the matching row inside the virtual viewport')
assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.editing),false,'lookup must not enter edit mode')
console.log('PASS lookup opens a late matching row in a 500-line read-only batch')
await page.setViewportSize({width:1280,height:600})
await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;vm.install({unbatched:true,batch:{},rows:vm.sheet.rows.slice(0,25),version:null});vm.startEditing();vm.sheet.rows.forEach((r,i)=>{r.projectId=990000+i});vm.projects.push(...vm.sheet.rows.map((r,i)=>({id:r.projectId,projectName:'汇总测试项目 '+(i+1)})))})
const gridLayout=()=>vmEvaluate(el=>{const table=el.querySelector('.sheet-table').getBoundingClientRect(),footer=el.querySelector('.sheet-footer').getBoundingClientRect();return {tableHeight:table.height,footerBottom:footer.bottom,height:innerHeight}})
for(const [name,density]of [['紧凑','small'],['标准','default'],['宽松','large']]){
await page.locator('#size-select').click();await page.getByRole('menuitem',{name,exact:true}).click();await page.waitForTimeout(200)
const layout=await gridLayout();assert.ok(layout.tableHeight>=120&&layout.footerBottom<layout.height,'table and save controls fit a short viewport: '+JSON.stringify(layout))
await vmEvaluate(async el=>{const vm=el.__vueParentComponent.proxy;vm.cellSelection={anchor:{key:vm.sheet.rows[0]._key,field:'quantity'},focus:{key:vm.sheet.rows[24]._key,field:'quantity'}};await vm.$nextTick()});assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.selectionStats.rowCount),25)
const stats=await page.locator('.sheet-selection-stats').boundingBox();assert.ok(stats.y+stats.height<=601,'selection totals remain visible at '+density)
const scroll=page.locator('.sheet-grid .el-table__body-wrapper .el-scrollbar__wrap');await scroll.evaluate(e=>{e.scrollTop=e.scrollHeight});await page.locator('.sheet-cell[data-row="24"]').first().waitFor();await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;vm.selected=[];vm.cellSelection=null})
await page.screenshot({path:'.codex-tmp/function-recheck/multi-project-fixed-'+density+'.png'})
}
await page.setViewportSize({width:1366,height:768})
console.log('PASS 25-project table, selection totals and save controls remain reachable in short viewports at all three densities')
// Saved-sheet change tracking returns clean after undo, without scanning the whole sheet.
await vmEvaluate(async el=>{const vm=el.__vueParentComponent.proxy,rows=vm.sheet.rows.slice(0,2).map((r,i)=>({...r,id:988000+i}));vm.install({unbatched:true,batch:{},rows,deletedIds:[],version:'readonly-test'});vm.startEditing();await vm.activateCell(vm.sheet.rows[0],'quantity')});assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.dirty),false)
await page.locator('.sheet-cell[data-row="0"][data-field="quantity"] input').fill('777');await page.locator('.sheet-cell[data-row="0"][data-field="quantity"] input').blur();assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.dirty),true)
await page.getByRole('button',{name:'撤销',exact:true}).click();assert.equal(await vmEvaluate(el=>el.__vueParentComponent.proxy.dirty),false)
await vmEvaluate(el=>{const vm=el.__vueParentComponent.proxy;vm.clearDraft('unbatched-new');vm.sheet=null;vm.editing=false})
// Deterministic read-only fixtures: the copied data need not contain a BOM.
const bom={id:989100,itemId:989101,itemName:'测试产品',versionTag:'V1',scopeType:'PUBLIC',isDefault:true,version:1,lines:[{itemId:989102,itemName:'测试材料',unit:'个',unitQuantity:2}]}
await page.route('**/dev-api/production/bom/list?*',r=>r.fulfill({json:{code:200,rows:[bom],total:1}}))
await page.route('**/dev-api/production/bom/989100',r=>r.fulfill({json:{code:200,data:bom}}))
await page.route('**/dev-api/production/bom/989100/logs',r=>r.fulfill({json:{code:200,data:[]}}))
await page.goto(frontend+'/businessBasics/bom');await page.locator('.business-list-page').waitFor();await page.getByRole('button',{name:'查看',exact:true}).first().click();const dialog=page.locator('.el-dialog:visible');await dialog.locator('.el-table tbody tr').first().waitFor()
assert.equal(await dialog.locator('input').count(),0,'read-only BOM uses text')
await dialog.getByRole('button',{name:'关闭',exact:true}).click();await page.locator('.el-table__body .el-dropdown').first().click();await page.getByRole('menuitem',{name:'记录',exact:true}).click();await page.locator('.el-dialog:visible').getByText('BOM变更记录',{exact:true}).waitFor();assert.ok(!/\d{4}-\d{2}-\d{2}T/.test(await page.locator('.el-dialog:visible').innerText()))
await page.keyboard.press('Escape');await page.goto(frontend+'/businessBasics/product');await page.getByRole('button',{name:'分类统计',exact:true}).click();await page.setViewportSize({width:600,height:800});await page.waitForTimeout(150)
const box=await page.locator('.el-dialog:visible').boundingBox();assert.ok(box.x>=0&&box.x+box.width<=600)
assert.deepEqual(errors,[]);assert.deepEqual(warnings,[])
console.log('PASS saved-sheet clean tracking, read-only BOM, formatted records and narrow-window dialog; all business writes blocked')
}finally{await browser.close()}
})().catch(e=>{console.error(e);process.exitCode=1})