cmvr-wms/scripts/projectdev/audit-fixes-ui-check.cjs

92 lines
13 KiB
JavaScript
Raw Permalink Normal View History

const assert=require('node:assert/strict')
const {chromium}=require('C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')
;(async()=>{
const login=await(await fetch('http://127.0.0.1:8080/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:'admin',password:'admin123',code:'',uuid:''})})).json();assert.equal(login.code,200)
const browser=await chromium.launch({channel:'chrome',headless:true,args:['--disable-gpu','--js-flags=--max-old-space-size=256']})
try{
const context=await browser.newContext({viewport:{width:1280,height:800}});await context.addCookies([{name:'Admin-Token',value:login.token,url:'http://127.0.0.1:8088'}])
const page=await context.newPage();page.setDefaultTimeout(15000);const errors=[],writes=[],reads=[];let homeFailure=false,acceptFailure=true,arrival=[],fixture
const detail={id:991001,project_id:1,project_name:'验证项目',item_id:101,item_name:'验证机器人',task_no:'SC-test',bom_id:501,status:'OPEN',version:1,planned_quantity:1,good_quantity:1,scrap_quantity:0,current_material_cost:null,children:[{id:991003,item_name:'子任务',good_quantity:0,planned_quantity:1,status:'OPEN'}],openChildCount:1,pendingReceiptCount:101,needs:[],actions:[],settlements:[]}
page.on('pageerror',e=>errors.push(e.message))
await page.route('**/dev-api/**',async route=>{
const req=route.request(),u=new URL(req.url()),p=u.pathname,m=req.method();reads.push(p+'?'+u.searchParams)
if(p==='/dev-api/business/home'){
if(homeFailure)return route.fulfill({json:{code:500,msg:'模拟读取失败'}})
const r=await route.fetch(),j=await r.json();for(const q of j.data.queues)if(['arrival','loan'].includes(q.key)){q.count=17;q.rows=q.rows.slice(0,6)}return route.fulfill({json:j})
}
if(p==='/dev-api/warehouse/purchase/sheet/991010')return route.fulfill({json:{code:200,data:fixture}})
if(p==='/dev-api/warehouse/purchase/arrival/991011')return route.fulfill({json:{code:200,data:arrival}})
if(p==='/dev-api/warehouse/purchase/arrival'&&m==='POST'){writes.push({p,data:req.postDataJSON()});arrival=[{id:991020,arrivalQuantity:req.postDataJSON().arrivalQuantity,acceptanceStatus:0}];return route.fulfill({json:{code:200,data:arrival[0]}})}
if(p==='/dev-api/warehouse/purchase/arrival/991020/accept'){
writes.push({p,data:req.postDataJSON()});if(acceptFailure){acceptFailure=false;return route.fulfill({json:{code:500,msg:'模拟验收失败'}})}
arrival[0].acceptanceStatus=1;return route.fulfill({json:{code:200}})
}
if(p==='/dev-api/warehouse/stock/list'&&u.searchParams.get('productId')==='201')return route.fulfill({json:{code:200,rows:[{id:991100,projectId:2,productId:201,productName:'指定螺丝',stockNum:6,areaId:1,areaName:'库区',unit:'个'}],total:1}})
if(p==='/dev-api/production/tasks/991001')return route.fulfill({json:{code:200,data:detail}})
if(p==='/dev-api/production/tasks/reference')return route.fulfill({json:{code:200,data:{amount:Number(u.searchParams.get('projectId'))*100,complete:true,lines:[]}}})
if(!['GET','HEAD'].includes(m))throw Error('Unexpected real business write '+m+' '+p)
return route.continue()
})
async function navigate(url,selector){await page.goto('http://127.0.0.1:8088'+url,{waitUntil:'domcontentloaded'});await page.locator(selector).waitFor()}
await navigate('/index','.business-home');await page.waitForFunction(()=>document.querySelector('.business-home').__vue__.loadedOnce&&!document.querySelector('.business-home').__vue__.loading)
assert.deepEqual(await page.locator('.home-followups strong').allTextContents(),['17','17'])
homeFailure=true;await page.evaluate(()=>document.querySelector('.business-home').__vue__.reload());assert.ok(await page.getByText(/概览数据加载失败/).count()>0);assert.deepEqual(errors,[]);homeFailure=false
console.log('PASS: homepage true counts above six; error fallback remains usable')
await navigate('/procurement/details','.purchase-sheet');await page.waitForFunction(()=>document.querySelector('.purchase-sheet').__vue__.items.length&&!document.querySelector('.purchase-sheet').__vue__.loading)
fixture=await page.evaluate(()=>{const v=document.querySelector('.purchase-sheet').__vue__,i=v.items.find(i=>i.unit&&i.category),p=v.projects[0],c=v.categories[0];return {batch:{id:991010,batchNo:'CG-test',batchName:'验证采购',businessDate:'2026-10-13'},rows:[{id:991011,projectId:p.id,expenseCategoryId:c.id,materialName:i.productName,materialBrand:i.brand||'',materialParams:i.spec||'',productId:i.id,unit:i.unit,category:i.category,quantity:10,remainingQuantity:10,acceptedQuantity:0,pendingArrivalQuantity:0,receivedQuantity:1,finalUnitPrice:5,priceLocked:true,purchaseStatus:2}],version:'test-v1'}})
await page.evaluate(f=>document.querySelector('.purchase-sheet').__vue__.install(f),fixture)
await page.evaluate(()=>{const v=document.querySelector('.purchase-sheet').__vue__;v.startEditing();v.paste({clipboardData:{getData:()=> '10\t99'},preventDefault(){}},0,'quantity')})
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.sheet.rows[0].finalUnitPrice),5)
await page.evaluate(async()=>{const v=document.querySelector('.purchase-sheet').__vue__;v.editing=false;await v.$refs.arrival.open(v.sheet.rows,'arrival');v.$refs.arrival.rows[0].quantity=2;await v.$refs.arrival.submit()})
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.rows[0].done),false)
await page.getByRole('button',{name:'本次全部到齐',exact:true}).click()
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.rows[0].quantity),2)
await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.submit())
assert.equal(writes.filter(w=>w.p==='/dev-api/warehouse/purchase/arrival').length,1)
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.rows[0].done),true)
assert.equal(writes.filter(w=>w.p.endsWith('/accept')).length,2)
assert.ok((await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.rows[0].result)).includes('2'))
console.log('PASS: locked cell paste blocked atomically; retry preserves registered quantity and does not register again')
arrival=[{id:991020,arrivalQuantity:10,acceptanceStatus:0}];acceptFailure=false
await page.evaluate(async()=>{const v=document.querySelector('.purchase-sheet').__vue__;v.$refs.arrival.visible=false;await v.$refs.arrival.open([{...v.sheet.rows[0],remainingQuantity:0,pendingArrivalQuantity:10}],'acceptance')})
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.rows.length),1)
await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.submit());assert.equal(writes.filter(w=>w.p==='/dev-api/warehouse/purchase/arrival').length,1)
await page.evaluate(async()=>{const v=document.querySelector('.purchase-sheet').__vue__;v.$refs.arrival.visible=false;await v.back()})
await page.getByText('明细搜索',{exact:true}).click();await page.locator('.purchase-lookup').waitFor();assert.equal(await page.getByText('表内维护',{exact:true}).count(),0)
console.log('PASS: fully arrived pending records can be batch accepted; lookup uses the shared purchase sheet')
await navigate('/production/tasks','.production-workspace');await page.waitForFunction(()=>!document.querySelector('.production-workspace').__vue__.loading)
await page.evaluate(async()=>{const v=document.querySelector('.production-workspace').__vue__;v.$store.commit('SET_PERMISSIONS',['project:project:list']);await v.show(991001)})
await page.getByText('关联子任务:',{exact:false}).waitFor();assert.equal(await page.getByRole('tab',{name:'待入库 / 入库记录',exact:true}).count(),0)
assert.ok(await page.getByText('用料未登记,待核对',{exact:false}).count()>0)
const selectable=await page.evaluate(()=>document.querySelector('.production-workspace').__vue__.canSelectTask({status:'OPEN',planned_quantity:1,good_quantity:1,scrap_quantity:0}));assert.equal(selectable,true)
await page.evaluate(async()=>{const v=document.querySelector('.production-workspace').__vue__,loans=v.$refs.loans;v.$store.commit('SET_PERMISSIONS',['*:*:*']);loans.openForNeed({project_id:1,project_name:'验证项目'},{itemId:201,itemName:'螺丝',shortage:5})})
await page.waitForFunction(()=>document.querySelector('.production-workspace').__vue__.$refs.loans.stocks.length>0)
assert.ok(reads.some(r=>r.includes('/warehouse/stock/list?')&&r.includes('productId=201')))
const allocated=await page.evaluate(()=>{const v=document.querySelector('.production-workspace').__vue__,loans=v.$refs.loans,b=loans.$refs.batchReturn;loans.editOpen=false;loans.visible=false;const stocks=[{id:1,stockNum:6,areaId:1},{id:2,stockNum:4,areaId:2}];b.rows=[{id:1,outstandingQuantity:5,stocks,done:false,result:'',quantity:0},{id:2,outstandingQuantity:5,stocks,done:false,result:'',quantity:0}];b.allocate();return {total:b.rows.reduce((n,r)=>n+r.quantity,0),stock1:b.rows.filter(r=>r.stockId===1).reduce((n,r)=>n+r.quantity,0)}})
assert.deepEqual(allocated,{total:10,stock1:6})
console.log('PASS: exact-item borrowing and shared-stock batch return allocation')
console.log('PASS: task details independent of inbound permission and parent pagination; zero-cost warning and completed-plan task access')
await page.evaluate(()=>{const v=document.querySelector('.production-workspace').__vue__;v.detailOpen=false;v.$store.commit('SET_PERMISSIONS',['*:*:*'])})
await navigate('/costManagement/products','.production-workspace');await page.evaluate(async()=>{const v=document.querySelector('.production-workspace').__vue__;v.quoteItem=101;v.quoteBom=501;v.queryProject=1;await v.quote();if(v.quoteResult.amount!==100)throw Error('first cost');v.queryProject=2;await v.search();if(v.quoteResult.amount!==200)throw Error('stale project cost')})
console.log('PASS: project switch refreshes reference cost')
await navigate('/businessBasics/bom','.desktop-viewport .app-container');await page.evaluate(()=>{const root=document.querySelector('.desktop-viewport').firstElementChild.__vue__,find=v=>v.$options.name==='ProductionBom'?v:(v.$children||[]).map(find).find(Boolean),vm=find(root);const current={id:2,snapshot:JSON.stringify({lines:[{itemId:1,itemName:'螺丝',unitQuantity:3},{itemId:3,itemName:'新物品',unitQuantity:1}]})},old={id:1,snapshot:JSON.stringify({lines:[{itemId:1,itemName:'螺丝',unitQuantity:2},{itemId:2,itemName:'旧物品',unitQuantity:1}]})};vm.logRows=[current,old];vm.showSnapshot(current);if(vm.snapshotLines.map(r=>r.change).join(',')!=='修改,新增,删除')throw Error('BOM diff mismatch')})
console.log('PASS: BOM history is a material table with quantity/add/remove differences')
await navigate('/project/info','.desktop-viewport .app-container');await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.projectList?.length>0)
const project=await page.evaluate(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.projectList.find(p=>p.projectCode!=='LEGACY'))
if(project){
await page.evaluate(async id=>{await document.querySelector('.desktop-viewport').firstElementChild.__vue__.$router.push('/project/detail/'+id)},project.id)
await page.locator('.workspace-heading').waitFor();await page.waitForFunction(()=>document.querySelector('.workspace-heading strong').textContent.trim().length>0)
assert.equal((await page.locator('.workspace-heading strong').innerText()).trim(),project.projectName)
await page.getByRole('tab',{name:'采购',exact:true}).click();await page.locator('.purchase-sheet').waitFor();await page.waitForFunction(()=>!document.querySelector('.purchase-sheet').__vue__.loading)
await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.query.materialName='保留的筛选')
await page.getByRole('tab',{name:'总览',exact:true}).click();await page.getByRole('tab',{name:'采购',exact:true}).click()
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.query.materialName),'保留的筛选')
await page.getByRole('button',{name:/返回列表/}).click();await page.waitForURL('**/project/info')
await page.getByText(project.projectName,{exact:true}).first().click();await page.locator('.workspace-heading').waitFor()
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.query.materialName),'保留的筛选')
console.log('PASS: project identity, tab filters and return position retained')
}
assert.deepEqual(errors,[]);console.log('PASS: audit regression; all business mutations mocked:',writes.length)
}finally{await browser.close()}
})().catch(e=>{console.error(e);process.exitCode=1})