61 lines
5.2 KiB
JavaScript
61 lines
5.2 KiB
JavaScript
|
|
const assert=require('node:assert/strict')
|
||
|
|
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:900}})
|
||
|
|
await context.addCookies([{name:'Admin-Token',value:login.token,url:frontend}])
|
||
|
|
const page=await context.newPage(),errors=[],writes=[],queries=[]
|
||
|
|
page.on('pageerror',e=>errors.push(e.message));page.setDefaultTimeout(12000)
|
||
|
|
const groups=[{dictCode:9100,dictLabel:'机械件',dictValue:'MECH',dictType:'wms_item_category_group',status:'0',dictSort:1}]
|
||
|
|
const leaves=[{dictCode:9200,dictLabel:'紧固件',dictValue:'FASTENER',dictType:'wms_item_category',parentCode:9100,status:'0',dictSort:1},{dictCode:9201,dictLabel:'历史分类',dictValue:'OLD',dictType:'wms_item_category',status:'0',dictSort:2}]
|
||
|
|
await page.route('**/dev-api/**',async route=>{
|
||
|
|
const req=route.request(),url=new URL(req.url()),path=url.pathname.replace('/dev-api','')
|
||
|
|
const ok=data=>route.fulfill({json:{code:200,data}})
|
||
|
|
if(!['GET','HEAD'].includes(req.method())){
|
||
|
|
if(path==='/system/dict/data'&&['POST','PUT'].includes(req.method())){const data=req.postDataJSON();writes.push(data);const collection=data.dictType==='wms_item_category_group'?groups:leaves;if(data.dictCode)Object.assign(collection.find(r=>r.dictCode===data.dictCode),data);else collection.push({...data,dictCode:9300+writes.length});return ok(1)}
|
||
|
|
throw new Error('Unexpected write blocked: '+path)
|
||
|
|
}
|
||
|
|
if(path==='/system/dict/data/list'){const type=url.searchParams.get('dictType');const rows=type==='wms_item_category_group'?groups:type==='wms_item_category'?leaves:[];return route.fulfill({json:{code:200,rows,total:rows.length}})}
|
||
|
|
if(path==='/system/dict/data/type/wms_item_category_group')return ok(groups)
|
||
|
|
if(path==='/system/dict/data/type/wms_item_category')return ok(leaves)
|
||
|
|
if(path==='/warehouse/product/category-options')return ok(leaves.map(c=>({id:c.dictCode,label:c.dictLabel,parentId:c.parentCode,parentLabel:groups.find(g=>g.dictCode===c.parentCode)?.dictLabel})))
|
||
|
|
if(path==='/warehouse/product/category-summary')return ok([{parentId:9100,parentLabel:'机械件',category:'紧固件',itemCount:2},{parentId:null,parentLabel:'未分组',category:'历史分类',itemCount:1}])
|
||
|
|
if(path==='/warehouse/product/list'){queries.push(Object.fromEntries(url.searchParams));return route.fulfill({json:{code:200,total:1,rows:[{id:999001,productName:'测试螺丝',category:'紧固件',categoryGroupName:'机械件',unit:'个'}]}})}
|
||
|
|
return route.continue()
|
||
|
|
})
|
||
|
|
await page.goto(frontend+'/system/dict')
|
||
|
|
await page.locator('.el-table__row').filter({hasText:'紧固件'}).waitFor()
|
||
|
|
assert.match(await page.locator('.desktop-viewport').innerText(),/未分组/)
|
||
|
|
await page.getByRole('button',{name:'新增大类',exact:true}).click()
|
||
|
|
let dialog=page.locator('.el-dialog:visible')
|
||
|
|
await dialog.locator('.el-form-item').filter({hasText:'显示名称'}).locator('input').fill('电子件')
|
||
|
|
await dialog.getByRole('button',{name:'保存',exact:true}).click()
|
||
|
|
await dialog.waitFor({state:'hidden'})
|
||
|
|
assert.equal(writes[0].dictType,'wms_item_category_group');assert.equal(writes[0].dictValue,'电子件')
|
||
|
|
await page.locator('.el-table__row').filter({hasText:'机械件'}).getByRole('button',{name:'新增小类',exact:true}).click()
|
||
|
|
dialog=page.locator('.el-dialog:visible')
|
||
|
|
assert.match(await dialog.innerText(),/机械件/)
|
||
|
|
await dialog.locator('.el-form-item').filter({hasText:'显示名称'}).locator('input').fill('结构件')
|
||
|
|
await dialog.getByRole('button',{name:'保存',exact:true}).click();await dialog.waitFor({state:'hidden'})
|
||
|
|
assert.equal(writes[1].parentCode,9100);assert.equal(writes[1].dictType,'wms_item_category')
|
||
|
|
console.log('PASS tree, ungrouped preservation, new group and child payload; writes mocked')
|
||
|
|
await page.goto(frontend+'/warehouse/product')
|
||
|
|
await page.getByRole('button',{name:'分类统计',exact:true}).click()
|
||
|
|
dialog=page.locator('.el-dialog:visible');await dialog.getByText('紧固件',{exact:true}).waitFor()
|
||
|
|
await dialog.locator('.el-table__row').filter({hasText:'机械件'}).getByRole('button',{name:'查看物品'}).click()
|
||
|
|
await page.waitForFunction(()=>document.querySelector('.query-toolbar')?.textContent.includes('机械件'))
|
||
|
|
await page.waitForTimeout(250);assert.equal(queries.at(-1).categoryGroupId,'9100')
|
||
|
|
await page.getByRole('button',{name:'新增',exact:true}).click();dialog=page.locator('.el-dialog:visible')
|
||
|
|
await dialog.locator('.el-cascader').click()
|
||
|
|
await page.locator('.el-cascader-node:visible').filter({hasText:'机械件'}).click()
|
||
|
|
await page.locator('.el-cascader-node:visible').filter({hasText:'紧固件'}).click()
|
||
|
|
assert.match(await dialog.locator('.el-cascader input').inputValue(),/机械件.*紧固件/)
|
||
|
|
await dialog.getByRole('button',{name:/取\s*消/}).click()
|
||
|
|
assert.deepEqual(errors,[])
|
||
|
|
console.log('PASS summary drilldown sends group ID; choosing leaf displays its parent; no runtime errors')
|
||
|
|
}finally{await browser.close()}
|
||
|
|
})().catch(e=>{console.error(e);process.exit(1)})
|