39 lines
5.8 KiB
JavaScript
39 lines
5.8 KiB
JavaScript
|
|
const assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path')
|
|||
|
|
const {chromium,frontend,backend,username,password}=require('./vue3-test-runtime.cjs')
|
|||
|
|
const checkControlCells=require('./vue3-cell-overflow-check.cjs')
|
|||
|
|
const output=path.resolve(__dirname,'../../.codex-tmp/stock-dialogs-regression');fs.mkdirSync(output,{recursive:true})
|
|||
|
|
;(async()=>{
|
|||
|
|
const browser=await chromium.launch(),writes=[],errors=[];let page
|
|||
|
|
try{
|
|||
|
|
const context=await browser.newContext({viewport:{width:1440,height:900}}),login=await(await context.request.post(backend+'/login',{data:{username,password}})).json();assert.equal(login.code,200)
|
|||
|
|
await context.addCookies([{name:'Admin-Token',value:login.token,url:frontend}])
|
|||
|
|
const stocks=await(await context.request.get(backend+'/warehouse/stock/list',{headers:{Authorization:'Bearer '+login.token},params:{pageNum:1,pageSize:100}})).json(),stock=stocks.rows.find(r=>Number(r.stockNum)>0);assert.ok(stock)
|
|||
|
|
await context.route('**/dev-api/**',route=>{
|
|||
|
|
const req=route.request(),endpoint=new URL(req.url()).pathname.replace('/dev-api',''),ok=data=>route.fulfill({json:{code:200,data}})
|
|||
|
|
if(!['GET','HEAD'].includes(req.method())){writes.push(endpoint);return route.abort('blockedbyclient')}
|
|||
|
|
if(endpoint==='/warehouse/stock/list')return route.fulfill({json:{code:200,total:1,rows:[stock]}})
|
|||
|
|
if(endpoint==='/warehouse/stock/events')return ok([{eventNo:'LS-TEST',eventKey:'TEST',eventType:'RECEIPT',active:true,areaId:stock.areaId,quantity:1,originalCost:10,effectiveCost:10,businessDate:'2026-10-14',createTime:'2026-10-14 12:00:00'}])
|
|||
|
|
if(endpoint==='/warehouse/stock/adjustments')return ok([])
|
|||
|
|
return route.continue()
|
|||
|
|
})
|
|||
|
|
page=await context.newPage();page.setDefaultTimeout(15000);page.on('pageerror',e=>errors.push(e.message))
|
|||
|
|
await page.goto(frontend+'/warehouse/stock',{waitUntil:'domcontentloaded'});await page.locator('.business-list-page__table .el-table__body tr').first().waitFor()
|
|||
|
|
const command=async name=>{await page.locator('.business-list-page__table .el-dropdown').getByRole('button',{name:'操作',exact:true}).click();await page.getByRole('menuitem',{name,exact:true}).click()}
|
|||
|
|
await command('移库');const batch=page.getByRole('dialog',{name:'移库',exact:true});await batch.waitFor();await page.waitForTimeout(400)
|
|||
|
|
assert.equal(await batch.locator('.el-form-item').filter({hasText:'操作'}).count(),0,'row action kind must be fixed')
|
|||
|
|
const input=await batch.locator('.el-table__body .el-input-number').evaluate(el=>{const cell=el.closest('.cell');return {width:el.getBoundingClientRect().width,cell:cell.clientWidth,padding:parseFloat(getComputedStyle(cell).paddingLeft)+parseFloat(getComputedStyle(cell).paddingRight),ellipsis:getComputedStyle(cell).textOverflow}})
|
|||
|
|
assert.notEqual(input.ellipsis,'ellipsis');assert.ok(input.width<=input.cell-input.padding+2,JSON.stringify(input));await checkControlCells(page,'移库弹窗');await page.screenshot({path:path.join(output,'move.png'),animations:'disabled'});await batch.getByRole('button',{name:'关闭',exact:true}).click();await batch.waitFor({state:'hidden'})
|
|||
|
|
await command('盘点');const check=page.getByRole('dialog',{name:'库存盘点',exact:true});await check.waitFor();await page.waitForTimeout(400)
|
|||
|
|
assert.ok(page.url().endsWith('/warehouse/stock'));assert.equal(await page.locator('.el-dialog:visible').count(),1)
|
|||
|
|
const labelMetrics=await check.locator('.el-form-item__label').evaluateAll(labels=>labels.map(el=>({text:el.textContent,w:el.clientWidth,sw:el.scrollWidth,whiteSpace:getComputedStyle(el).whiteSpace})))
|
|||
|
|
labelMetrics.forEach(m=>{assert.equal(m.whiteSpace,'nowrap');assert.ok(m.sw<=m.w+2,JSON.stringify(m))});assert.equal(await check.locator('.el-select__wrapper.is-disabled').count(),3)
|
|||
|
|
await page.screenshot({path:path.join(output,'check.png'),animations:'disabled'});await check.getByRole('button',{name:/取\s*消/}).click();await check.waitFor({state:'hidden'})
|
|||
|
|
await command('借出');const loan=page.getByRole('dialog',{name:'借用库存',exact:true});await loan.waitFor();assert.ok(page.url().endsWith('/warehouse/stock'));assert.equal(await page.locator('.el-dialog:visible').count(),1,'borrow must not open a parent loans list dialog')
|
|||
|
|
assert.ok(await loan.locator('.el-form-item').filter({hasText:'取料库存'}).locator('.item-summary').isVisible());assert.equal(await loan.locator('.el-form-item').filter({hasText:'取料库存'}).locator('.el-select').count(),0);await page.screenshot({path:path.join(output,'borrow.png'),animations:'disabled'});await loan.locator('.el-dialog__headerbtn').click();await loan.waitFor({state:'hidden'})
|
|||
|
|
await page.locator('.business-list-page__table').getByRole('button',{name:'流水',exact:true}).click();const ledger=page.getByRole('dialog',{name:'库存流水',exact:true});await ledger.waitFor();await ledger.getByRole('tab',{name:'成本调整(0)',exact:true}).click();assert.equal(await page.locator('.el-dialog:visible').count(),1)
|
|||
|
|
await page.screenshot({path:path.join(output,'cost-tab.png'),animations:'disabled'});await ledger.getByRole('button',{name:'关闭',exact:true}).click();await ledger.waitFor({state:'hidden'})
|
|||
|
|
for(const width of [1366,1920]){await page.setViewportSize({width,height:900});const m=await page.evaluate(()=>({x:document.documentElement.scrollWidth-innerWidth,y:document.documentElement.scrollHeight-innerHeight}));assert.ok(m.x<=2&&m.y<=2,JSON.stringify(m))}
|
|||
|
|
assert.deepEqual(writes,[]);assert.deepEqual(errors,[]);console.log(JSON.stringify({passed:true,realBusinessWrites:0,scenarios:['move input fits','stock check in place','labels auto-fit','borrow in place without parent modal','ledger/cost tabs without nested modal','two viewport sizes']}))
|
|||
|
|
}catch(error){await page?.screenshot({path:path.join(output,'failure.png')}).catch(()=>{});throw error}finally{await browser.close()}
|
|||
|
|
})().catch(e=>{console.error(e);process.exitCode=1})
|