- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称 - 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配 - 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配 - 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名 - 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试 - 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token - 调整系统角色授权用户页面的表单布局和表格样式类名 - 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
81 lines
6.5 KiB
JavaScript
81 lines
6.5 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(),writes=[],errors=[]
|
|
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();page.setDefaultTimeout(12000)
|
|
page.on('pageerror',e=>errors.push(e.message))
|
|
let failUnit=false,extraUnit=false,delaySave=false
|
|
const categories=Array.from({length:201},(_,i)=>({dictCode:9000+i,dictType:'wms_item_category',dictLabel:'类别'+(i+1),dictValue:'类别'+(i+1),dictSort:i+1,status:'0'}))
|
|
const units=()=>[{dictCode:9901,dictType:'wms_item_unit',dictLabel:'个',dictValue:'个',status:'0',dictSort:1},...(extraUnit?[{dictCode:9902,dictType:'wms_item_unit',dictLabel:'测试单位',dictValue:'测试单位',status:'0',dictSort:2}]:[])]
|
|
await page.route('**/dev-api/**',async route=>{
|
|
const req=route.request(),url=new URL(req.url()),path=url.pathname
|
|
if(!['GET','HEAD'].includes(req.method())){
|
|
if(path==='/dev-api/system/dict/data'&&req.method()==='POST'){
|
|
writes.push(req.postDataJSON());if(delaySave)await new Promise(r=>setTimeout(r,500));extraUnit=true
|
|
return route.fulfill({json:{code:200,msg:'成功'}})
|
|
}
|
|
return route.abort('blockedbyclient')
|
|
}
|
|
if(path==='/dev-api/system/dict/data/list'){
|
|
const type=url.searchParams.get('dictType'),pageNum=Number(url.searchParams.get('pageNum')),size=Number(url.searchParams.get('pageSize'))
|
|
await new Promise(r=>setTimeout(r,type==='wms_item_category'?400:50))
|
|
if(type==='wms_item_unit'&&failUnit)return route.fulfill({json:{code:500,msg:'测试加载失败'}})
|
|
const data=type==='wms_item_category'?categories:type==='wms_item_category_group'?[]:units()
|
|
return route.fulfill({json:{code:200,total:data.length,rows:data.slice((pageNum-1)*size,pageNum*size)}})
|
|
}
|
|
if(path==='/dev-api/system/dict/data/type/wms_item_unit')return route.fulfill({json:{code:200,data:units()}})
|
|
if(path==='/dev-api/project/info/category/list')return route.fulfill({json:{code:200,data:[{id:999,categoryCode:'MATERIAL',categoryName:'材料费',sortOrder:1,status:0},{id:998,categoryCode:'LEGACY',categoryName:'历史待归属',sortOrder:99,status:0}]}})
|
|
return route.continue()
|
|
})
|
|
const tab=name=>page.getByRole('tab',{name,exact:true})
|
|
const rows=()=>page.locator('.desktop-viewport .el-table__body tbody')
|
|
const ready=()=>page.waitForFunction(()=>![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(e=>e.getClientRects().length))
|
|
await page.goto(frontend+'/system/dict')
|
|
await tab('物品单位').click();await ready();await page.waitForTimeout(500)
|
|
assert.match(await rows().innerText(),/个/);assert.doesNotMatch(await rows().innerText(),/类别/)
|
|
await tab('物品类别').click();await tab('费用分类').click();await ready();await page.waitForTimeout(500)
|
|
assert.match(await rows().innerText(),/材料费/);assert.doesNotMatch(await rows().innerText(),/类别|个/)
|
|
console.log('PASS delayed dictionary responses cannot overwrite a newer unit/expense tab')
|
|
const legacy=page.getByRole('row').filter({hasText:'LEGACY'})
|
|
assert.equal(await legacy.getByRole('button').count(),0,'reserved category has no mutation actions')
|
|
await legacy.getByText('系统保留',{exact:true}).waitFor()
|
|
await page.getByRole('row').filter({hasText:'MATERIAL'}).getByRole('button',{name:'修改',exact:true}).click()
|
|
await page.locator('.el-dialog:visible').getByRole('button',{name:'取消',exact:true}).click()
|
|
await page.locator('.el-dialog:visible').waitFor({state:'hidden'})
|
|
await page.locator('.business-list-page').evaluate(async el=>{
|
|
let instance=el.__vueParentComponent
|
|
while(instance&&instance.type.name!=='BusinessDictionaries')instance=instance.parent
|
|
const vm=instance.proxy,row=vm.rows.find(r=>r.categoryCode==='LEGACY')
|
|
vm.edit(row);await vm.remove(row)
|
|
if(vm.open)throw new Error('Reserved category unexpectedly opened an editor')
|
|
vm.form={...row};vm.editTab='expense';await vm.save()
|
|
})
|
|
assert.equal(writes.length,0,'reserved category guards issue no writes')
|
|
console.log('PASS reserved historical category stays visible and read-only; ordinary categories remain editable')
|
|
await tab('物品类别').click();await ready()
|
|
assert.equal(await page.locator('.desktop-viewport .el-table__body tbody tr').count(),202) // 201 leaves plus the ungrouped heading
|
|
console.log('PASS all 201 dictionary entries are loaded, not truncated at one page')
|
|
failUnit=true;await tab('物品单位').click();await page.locator('.desktop-viewport .el-alert').filter({hasText:'测试加载失败'}).waitFor();await ready()
|
|
assert.equal(await page.locator('.desktop-viewport .el-table__body tbody tr').count(),0)
|
|
failUnit=false;await page.getByRole('button',{name:'重试',exact:true}).click();await ready();assert.match(await rows().innerText(),/个/)
|
|
console.log('PASS failed tab query clears stale data and retries correctly')
|
|
await page.evaluate(async()=>{const {default:useDictStore}=await import('/src/store/modules/dict.js');await useDictStore().loadDict('wms_item_unit')})
|
|
await page.getByRole('button',{name:'新增',exact:true}).click()
|
|
const dialog=page.locator('.el-dialog:visible')
|
|
await dialog.locator('.el-form-item').filter({hasText:'显示名称'}).locator('input').fill('测试单位')
|
|
await dialog.locator('.el-form-item').filter({hasText:'数据值'}).locator('input').fill('测试单位')
|
|
delaySave=true;await dialog.getByRole('button',{name:'保存',exact:true}).click();await page.keyboard.press('Escape');assert.equal(await dialog.isVisible(),true)
|
|
await dialog.waitFor({state:'hidden'});await ready()
|
|
assert.equal(writes.length,1);assert.equal(writes[0].dictType,'wms_item_unit')
|
|
const values=await page.evaluate(async()=>{const {default:useDictStore}=await import('/src/store/modules/dict.js');return(await useDictStore().loadDict('wms_item_unit')).map(x=>x.value)})
|
|
assert.ok(values.includes('测试单位'));assert.match(await rows().innerText(),/测试单位/)
|
|
assert.deepEqual(errors,[])
|
|
console.log('PASS save uses the editor dictionary, locks pending dialog, and invalidates shared dropdown cache; all business writes mocked')
|
|
}finally{await browser.close()}
|
|
})().catch(e=>{console.error(e);process.exitCode=1})
|