cmvr-wms/scripts/projectdev/production-operations-ux-check.cjs

78 lines
15 KiB
JavaScript
Raw Permalink Normal View History

const assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path')
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']})
const out=path.resolve(__dirname,'../../.codex-tmp/production-operations-ux');fs.mkdirSync(out,{recursive:true})
const writes=[],errors=[],calls=[];let page
const need={itemId:201,itemName:'任务螺丝',required:10,issued:4,returned:0,scrapped:0,available:20,shortage:0}
const issue={id:301,kind:'ISSUE',active:1,task_id:701,project_id:1,project_name:'验证项目',item_id:201,item_name:'任务螺丝',area_id:1,area_name:'验证库区',quantity:4,handled_quantity:1}
const task={id:701,project_id:1,project_name:'验证项目',item_id:101,item_name:'验证机器人',task_no:'UX-701',bom_id:501,status:'OPEN',version:2,planned_quantity:10,good_quantity:2,scrap_quantity:0,current_material_cost:40,needs:[need],actions:[issue],settlements:[]}
const ended={...task,id:702,task_no:'UX-702',status:'SETTLED',version:5}
const products=[{id:991,itemId:101,itemName:'验证机器人',brand:'测试品牌',spec:'标准',unit:'台'}]
const stocks=[...Array.from({length:100},(_,i)=>({id:i+1,projectId:1,productId:900+i,productName:'非任务物品'+i,stockNum:20,areaId:1,areaName:'验证库区',unit:'件',finishedProduct:i===0})),{id:201,projectId:1,productId:201,productName:'任务螺丝',stockNum:20,areaId:1,areaName:'验证库区',unit:'个',finishedProduct:false}]
try {
const context=await browser.newContext({viewport:{width:1366,height:768}});await context.addCookies([{name:'Admin-Token',value:login.token,url:'http://127.0.0.1:8088'}]);page=await context.newPage();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;calls.push(p);const ok=data=>route.fulfill({json:{code:200,data}}),rows=items=>route.fulfill({json:{code:200,rows:items,total:items.length}})
if(p.endsWith('/production/tasks/actions') && req.method()==='GET')return ok([issue])
if(p.endsWith('/production/tasks') && req.method()==='GET')return ok([task,ended])
if(/\/production\/tasks\/70[12]$/.test(p))return ok(p.endsWith('701')?task:ended)
if(/\/production\/tasks\/701\/(settle|reopen)$/.test(p)) { const body=req.postDataJSON();assert.equal(body.version,task.version);writes.push({path:p,body});task.status=p.endsWith('settle')?'SETTLED':'OPEN';task.version++;return ok(task) }
if(p.endsWith('/production/tasks/actions') && req.method()==='POST'){writes.push({path:p,body:req.postDataJSON()});return ok({id:401})}
if(p.endsWith('/warehouse/stock/list')) { const q=u.searchParams,items=stocks.filter(s=>(!q.get('projectId') || s.projectId===Number(q.get('projectId'))) && (!q.get('productId') || s.productId===Number(q.get('productId'))) && (!q.get('productName') || s.productName.includes(q.get('productName')))),n=Number(q.get('pageNum')||1),size=Number(q.get('pageSize')||100);return route.fulfill({json:{code:200,rows:items.slice((n-1)*size,n*size),total:items.length}}) }
if(p.endsWith('/project/info/options'))return ok([{id:1,projectName:'验证项目'}])
if(p.endsWith('/warehouse/area/optionselect'))return ok([{id:1,areaName:'验证库区'}])
if(p.endsWith('/warehouse/inRecord/list'))return rows([])
if(p.endsWith('/production/product/options'))return ok(products)
if(p.endsWith('/production/product/project/1'))return ok([])
if(p.endsWith('/production/bom/options'))return ok([{id:501,itemId:101,versionTag:'V1',isDefault:true}])
assert.ok(['GET','HEAD'].includes(req.method()),'Blocked unexpected real mutation '+p);return route.continue()
})
await page.goto('http://127.0.0.1:8088/production/tasks',{waitUntil:'domcontentloaded'})
await page.waitForFunction(()=>document.querySelector('.desktop-viewport')?.firstElementChild?.__vue__?.rows?.[0]?.id===701)
const root=page.locator('.desktop-viewport'),dialog=page.locator('.production-task-dialog:visible'),vm=()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__
await page.evaluate(async()=>{await document.querySelector('.desktop-viewport').firstElementChild.__vue__.show(701)})
await dialog.waitFor();await page.waitForTimeout(350);const bounds=await dialog.boundingBox();assert.ok(bounds.height>650 && bounds.y>=0 && bounds.y+bounds.height<=768,JSON.stringify(bounds))
await dialog.getByRole('button',{name:'结束生产并结算',exact:true}).click();await page.locator('.el-message-box').getByRole('button',{name:'取消',exact:true}).click();await page.waitForTimeout(100);assert.equal(writes.length,0)
await dialog.getByRole('button',{name:'结束生产并结算',exact:true}).click();assert.ok((await page.locator('.el-message-box').innerText()).includes('停止新增领料'));await page.locator('.el-message-box').getByRole('button',{name:'结束并结算',exact:true}).click()
await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.detail.status==='SETTLED');assert.equal(writes.length,1);assert.equal(await dialog.getByRole('button',{name:'领料 / 补料',exact:true}).count(),0)
await dialog.getByRole('button',{name:'继续生产',exact:true}).click();await page.locator('.el-message-box').getByRole('button',{name:'取消',exact:true}).click();await page.waitForTimeout(100);assert.equal(writes.length,1)
await dialog.getByRole('button',{name:'继续生产',exact:true}).click();await page.locator('.el-message-box').getByRole('button',{name:'继续生产',exact:true}).click();await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.detail.status==='OPEN');assert.equal(writes.length,2)
await dialog.getByRole('button',{name:'领料 / 补料',exact:true}).click();await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.stocks.length===1)
const selected=await page.evaluate(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.stocks.map(s=>s.productId));assert.deepEqual(selected,[201]);assert.ok(calls.filter(p=>p.endsWith('/warehouse/stock/list')).length>=2)
const operation=page.locator('.el-dialog:visible').filter({has:page.locator('.el-dialog__title').filter({hasText:'生产领料'})})
await operation.locator('.el-form-item').filter({hasText:'任务用料'}).locator('input').click();await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').first().waitFor();assert.equal(await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').count(),1);await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').click()
const allowed=await page.evaluate(()=>{const a=document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action;return {id:a.form.itemId,outsider:a.stockMatchesKind({projectId:1,productId:999,stockNum:1}),otherProject:a.stockMatchesKind({projectId:2,productId:201,stockNum:1})}});assert.deepEqual(allowed,{id:201,outsider:false,otherProject:false})
await operation.getByRole('button',{name:'取消',exact:true}).click();await page.waitForTimeout(350)
await page.evaluate(async()=>{const v=document.querySelector('.desktop-viewport').firstElementChild.__vue__;v.detail.needs=Array.from({length:80},(_,i)=>({itemId:2000+i,itemName:'长用料行'+i,required:1,available:0}));await v.$nextTick()})
const geometry=await dialog.evaluate(d=>{const pane=d.querySelector('.el-tab-pane:not([style*="display: none"])'),b=pane.querySelector('.el-table__body-wrapper');return {outer:d.scrollHeight-d.clientHeight,scroll:b.scrollHeight>b.clientHeight,bodyBottom:b.getBoundingClientRect().bottom,dialogBottom:d.getBoundingClientRect().bottom}});assert.ok(geometry.outer<=2);assert.ok(geometry.scroll);assert.ok(geometry.bodyBottom<=geometry.dialogBottom+1)
await page.screenshot({path:path.join(out,'fixture-task-large-dialog.png')})
await page.evaluate(async()=>{const v=document.querySelector('.desktop-viewport').firstElementChild.__vue__;v.detail.needs=[];await v.$nextTick()});assert.equal(Math.round((await dialog.boundingBox()).height),Math.round(bounds.height))
await page.evaluate(()=>{document.querySelector('.desktop-viewport').firstElementChild.__vue__.detailOpen=false})
// The same global dialog supplies all scrap entries; no extra records are created for these selection checks.
await page.evaluate(async()=>{await document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.open('SCRAP_STOCK',{projectId:1})})
const scrap=page.locator('.el-dialog:visible');await scrap.locator('label.el-radio-button').filter({hasText:'已领到生产'}).click();await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.tasks.length===2)
await scrap.locator('.el-form-item').filter({hasText:'生产任务'}).locator('input').click();await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').filter({hasText:'UX-701'}).click();await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.sources.length===1)
await scrap.locator('.el-form-item').filter({hasText:'领料记录'}).locator('input').click();await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').filter({hasText:'任务螺丝'}).click()
assert.deepEqual(await page.evaluate(()=>{const a=document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action;return {kind:a.form.kind,task:a.form.taskId,source:a.form.sourceId,item:a.form.itemId,max:a.maximum}}),{kind:'SCRAP_ISSUED',task:701,source:301,item:201,max:3});await page.waitForTimeout(350);await page.screenshot({path:path.join(out,'fixture-issued-scrap.png')});await scrap.getByRole('button',{name:'取消',exact:true}).click()
await page.evaluate(async()=>{await document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.open('SCRAP_ASSEMBLY',{projectId:1})});await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.tasks.length===1);assert.equal(await page.evaluate(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.tasks[0].status),'OPEN');await scrap.getByRole('button',{name:'取消',exact:true}).click()
await page.evaluate(async()=>{await document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.open('SCRAP_FINISHED',{projectId:1})});await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.stocks.length===1);assert.equal(await page.evaluate(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.action.stocks[0].finishedProduct),true);await scrap.getByRole('button',{name:'取消',exact:true}).click()
// Actual project association and BOM root both query product archives, not the material catalog.
await page.evaluate(async()=>{await document.querySelector('#app').__vue__.$router.push('/businessBasics/bom')});await page.waitForTimeout(350);await root.getByRole('button',{name:'新增'}).click();await page.locator('.el-dialog:visible .el-form-item').filter({has:page.locator('label').filter({hasText:/^产品$/})}).locator('input').click();await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').filter({hasText:'验证机器人'}).click();assert.equal(await page.evaluate(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.editor.form.itemId),101);await page.locator('.el-dialog:visible').getByRole('button',{name:'关闭',exact:true}).click()
await page.evaluate(async()=>{await document.querySelector('#app').__vue__.$router.push('/project/info')});await page.waitForTimeout(350)
const projectComponent=await page.evaluate(()=>{const v=document.querySelector('.desktop-viewport').firstElementChild.__vue__;return !!v.$refs.projectProducts});assert.ok(projectComponent)
await page.evaluate(async()=>{const v=document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.projectProducts;v.open({id:1,projectName:'验证项目'})});await page.waitForTimeout(350);await page.locator('.el-dialog:visible').getByRole('button',{name:'关联产品'}).click();const association=page.locator('.el-dialog:visible').filter({has:page.locator('.el-dialog__title').filter({hasText:'关联项目产品'})});await association.locator('.el-form-item').filter({has:page.locator('label').filter({hasText:/^产品$/})}).locator('input').click();await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').filter({hasText:'验证机器人'}).click();await page.waitForFunction(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.$refs.projectProducts.versions.length===1)
assert.equal(calls.filter(p=>p.endsWith('/production/bom/items')).length,0)
await association.getByRole('button',{name:'取消',exact:true}).click();await page.locator('.el-dialog:visible').filter({has:page.locator('.el-dialog__title').filter({hasText:'项目产品与用料'})}).getByRole('button',{name:'关闭',exact:true}).click();await page.waitForTimeout(350)
await page.evaluate(async()=>{await document.querySelector('#app').__vue__.$router.push('/production/operations')});await page.waitForTimeout(350)
await root.locator('.business-action-bar .el-dropdown').getByRole('button',{name:'报废'}).click()
await page.locator('.el-dropdown-menu:visible .el-dropdown-menu__item').first().waitFor()
for(const label of ['零件报废','组装报废','成品报废'])assert.equal(await page.locator('.el-dropdown-menu:visible .el-dropdown-menu__item').filter({hasText:label}).count(),1)
assert.equal(await root.getByRole('button',{name:'交付'}).count(),1)
await page.locator('.el-dropdown-menu:visible .el-dropdown-menu__item').filter({hasText:'零件报废'}).click();await page.waitForTimeout(350);await page.screenshot({path:path.join(out,'fixture-global-scrap-entry.png')})
assert.equal(writes.length,2);assert.deepEqual(errors,[])
console.log('PASS: product-only BOM/project selectors; confirmation cancel/settle/resume; BOM-only stock across pagination; large stable dialog and inner scroll; issued/assembly/finished scrap source selection. All UI mutations intercepted; no business writes.')
} finally {if(page)await page.screenshot({path:path.join(out,'last.png')}).catch(()=>{});await browser.close()}
})().catch(e=>{console.error(e);process.exitCode=1})