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/purchase-workbench-check');fs.mkdirSync(out,{recursive:true}) const errors=[],writes=[];let slow=false,fixture,page try{ const context=await browser.newContext({viewport:{width:1440,height:900}});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(),p=new URL(req.url()).pathname if(req.method()==='POST'&&p.endsWith('/warehouse/purchase/sheet')){const body=req.postDataJSON();writes.push(body);fixture={...body,batch:{...body.batch,id:987655321,batchNo:'UI-SUPPLIER-OPTIONAL'},rows:body.rows.map((r,i)=>({...r,id:987655100+i,remainingQuantity:r.quantity})),version:'fixture'};return route.fulfill({json:{code:200,data:fixture}})} assert.ok(['GET','HEAD'].includes(req.method()),'Unexpected business write '+p) if(fixture&&p.endsWith('/warehouse/purchase/sheet/987655321'))return route.fulfill({json:{code:200,data:fixture}}) if(slow&&/\/list$/.test(p)){const response=await route.fetch();await new Promise(r=>setTimeout(r,1100));return route.fulfill({response})} return route.continue() }) async function navigate(url){await page.evaluate(async u=>{await document.querySelector('#app').__vue__.$router.push(u)},url);await page.waitForFunction(u=>location.pathname===u.split('?')[0],url)} const sheetVM=()=>document.querySelector('.purchase-sheet').__vue__ await page.goto('http://127.0.0.1:8088/procurement/details',{waitUntil:'domcontentloaded'}) await page.waitForFunction(()=>document.querySelector('.purchase-sheet')?.__vue__?.items.length>0&&!document.querySelector('.purchase-sheet').__vue__.loading) assert.deepEqual(await page.locator('.purchase-view-switch .el-radio-button').allTextContents(),['按批次','全部明细','未分批']) assert.equal(await page.getByText('明细维护 / 未分批采购',{exact:true}).count(),0) await page.getByRole('button',{name:'新增采购批次'}).click() await page.evaluate(()=>{const v=document.querySelector('.purchase-sheet').__vue__,i=v.items.find(i=>i.unit),p=v.projects[0],c=v.categories[0];v.sheet.rows=[{...v.emptyRow(),projectId:p.id,expenseCategoryId:c.id,materialName:i.productName,materialBrand:i.brand||'',materialParams:i.spec||'',productId:i.id,productCode:i.productCode,unit:i.unit,quantity:2,finalUnitPrice:3}];v.sheet.batch.supplierId=null}) await page.locator('.purchase-view-switch .el-radio-button').filter({hasText:'全部明细'}).click();await page.locator('.el-message-box').waitFor() await page.locator('.el-message-box button').filter({hasText:'取消'}).click() await page.waitForFunction(()=>{const v=document.querySelector('.purchase-workbench').__vue__;return v.purchaseView==='batches'&&!v.switchingView}) assert.equal(await page.evaluate(()=>document.querySelector('.purchase-workbench').__vue__.purchaseView),'batches') assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.sheet.rows.length),1) await page.getByRole('button',{name:'保存清单 / 报价'}).click();await page.waitForFunction(()=>document.querySelector('.purchase-sheet').__vue__.sheet?.batch.id===987655321&&!document.querySelector('.purchase-sheet').__vue__.saving) assert.equal(writes.length,1);assert.equal(writes[0].batch.supplierId,null) await page.getByRole('button',{name:'确认采购'}).click();await page.waitForTimeout(100) assert.equal(await page.locator('.el-message-box:visible').count(),0);assert.equal(writes.length,1) assert.ok((await page.locator('.el-message').last().innerText()).includes('供应商')) await page.locator('.purchase-view-switch .el-radio-button').filter({hasText:'全部明细'}).click();await page.waitForFunction(()=>{const v=document.querySelector('.purchase-workbench').__vue__;return v.legacyMode&&!v.loading}) assert.equal(await page.evaluate(()=>document.querySelector('.purchase-workbench').__vue__.queryParams.unbatched),false) const linked=await page.evaluate(()=>document.querySelector('.purchase-workbench').__vue__.purchaseList.find(r=>r.purchaseBatchId)) if(linked){await page.evaluate(r=>document.querySelector('.purchase-workbench').__vue__.openBatchFromRow(r),linked);await page.waitForFunction(id=>document.querySelector('.purchase-sheet').__vue__.sheet?.batch.id===id,linked.purchaseBatchId);assert.equal(await page.evaluate(()=>document.querySelector('.purchase-workbench').__vue__.purchaseView),'batches')} await page.locator('.purchase-view-switch .el-radio-button').filter({hasText:'未分批'}).click();await page.waitForFunction(()=>{const v=document.querySelector('.purchase-workbench').__vue__;return v.purchaseView==='unbatched'&&!v.loading}) assert.equal(await page.evaluate(()=>document.querySelector('.purchase-workbench').__vue__.queryParams.unbatched),true) assert.ok(await page.evaluate(()=>document.querySelector('.purchase-workbench').__vue__.purchaseList.every(r=>!r.purchaseBatchId))) await page.screenshot({path:path.join(out,'unbatched.png')}) await navigate('/procurement/arrival');await page.waitForFunction(()=>{const v=document.querySelector('.arrival-workbench-page')?.__vue__;return v&&!v.loading}) const headers=await page.locator('.arrival-workbench-page .el-table__header-wrapper').first().locator('th').allTextContents();assert.ok(headers[1].includes('采购批次 / 供应商'));assert.ok(headers[2].includes('物品 / 规格')) const record=await page.evaluate(()=>document.querySelector('.arrival-workbench-page').__vue__.purchaseList.find(r=>r.purchaseBatchNo)) if(record){await page.locator('.arrival-workbench-page .el-table__body-wrapper .el-link').filter({hasText:record.purchaseBatchNo}).first().click();await page.waitForFunction(()=>!document.querySelector('.arrival-workbench-page').__vue__.loading);assert.ok((await page.locator('.arrival-list-summary').innerText()).includes(record.purchaseBatchNo));assert.ok(await page.evaluate(()=>{const v=document.querySelector('.arrival-workbench-page').__vue__;return v.purchaseList.every(r=>r.purchaseBatchNo===v.queryParams.purchaseBatchNo)}));await page.getByRole('button',{name:'清除批次',exact:true}).click();await page.waitForFunction(()=>!document.querySelector('.arrival-workbench-page').__vue__.loading)} const material=await page.evaluate(()=>document.querySelector('.arrival-workbench-page').__vue__.purchaseList[0]?.materialName) if(material){await page.locator('.arrival-workbench-page input[placeholder="名称、规格或品牌"]').fill(material);await page.locator('.arrival-workbench-page button').filter({hasText:/^搜索$/}).click();await page.waitForFunction(()=>!document.querySelector('.arrival-workbench-page').__vue__.loading);assert.ok(await page.evaluate(()=>{const v=document.querySelector('.arrival-workbench-page').__vue__;return v.purchaseList.length>0&&v.purchaseList.every(r=>r.materialName.includes(v.queryParams.materialName))}))} await page.locator('.el-message').first().waitFor({state:'hidden',timeout:6000}).catch(()=>{}) await page.screenshot({path:path.join(out,'arrival-1440.png')});await page.setViewportSize({width:1366,height:768});await page.waitForTimeout(200);await page.screenshot({path:path.join(out,'arrival-1366.png')}) const icon=page.locator('.sidebar-container .el-menu-item').filter({hasText:'借用与归还'}).locator('use');assert.ok(await icon.count());assert.ok(await page.locator('symbol#icon-exchange').count()) // Delay real read responses to compare empty/loading and populated geometry. slow=true for(const [url,list] of [['/warehouse/stock','stockList'],['/businessBasics/product','productList'],['/procurement/details','batches']]){ // A fresh page avoids measuring the previous route during its exit animation. await page.goto('http://127.0.0.1:8088'+url+'?loadingcheck=1',{waitUntil:'domcontentloaded'}) await page.waitForFunction(key=>{const find=v=>v?.$data?.[key]?v:(v?.$children||[]).map(find).find(Boolean);return !!find(document.querySelector('.desktop-viewport')?.firstElementChild?.__vue__)},list) await page.waitForTimeout(200) const rect=()=>page.locator('.desktop-viewport [data-viewport-table]').first().evaluate(e=>({height:e.clientHeight,top:e.getBoundingClientRect().top,bottom:e.getBoundingClientRect().bottom})) const before=await rect();assert.ok(before.height>180,JSON.stringify({url,before})) await page.waitForFunction(key=>{const find=v=>v?.$data?.[key]?v:(v?.$children||[]).map(find).find(Boolean);const v=find(document.querySelector('.desktop-viewport').firstElementChild.__vue__);return v&&!v.loading},list) await page.waitForTimeout(120);const after=await rect();assert.ok(Math.abs(before.height-after.height)<=2,'loading table height changed '+JSON.stringify({url,before,after})) assert.ok(after.bottom<=768+1) } assert.deepEqual(errors,[]) console.log('PASS: supplier-free simulated save, pre-confirm supplier guard, unified 3 views and batch link, actual unbatched filter, arrival batch/material search, exchange icon, stable delayed-list heights. No real 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})