- 在 .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 组件的对话框尺寸、表单验证和分页功能
30 lines
6.8 KiB
JavaScript
30 lines
6.8 KiB
JavaScript
const assert=require('node:assert/strict'),path=require('node:path'),fs=require('node:fs')
|
|
const {chromium}=require('./vue3-test-runtime.cjs')
|
|
const base=process.env.VUE3_URL||'http://127.0.0.1:8088'
|
|
;(async()=>{
|
|
const browser=await chromium.launch({headless:true})
|
|
const out=path.resolve(__dirname,'../../.codex-tmp/vue3-interactions-check');fs.mkdirSync(out,{recursive:true})
|
|
try{
|
|
const c=await browser.newContext({viewport:{width:1366,height:768}}),p=await c.newPage();p.setDefaultTimeout(15000)
|
|
const errors=[],writes=[];p.on('pageerror',e=>{errors.push(e.message);console.log('ERROR',e.message)})
|
|
// Login is real; every business mutation below is intercepted.
|
|
await p.goto(base+'/login?redirect=/index');await p.getByPlaceholder('账号').fill(process.env.TEST_USERNAME || 'admin');await p.getByPlaceholder('密码',{exact:true}).fill(process.env.TEST_PASSWORD || 'admin123');await p.waitForFunction(()=>!document.querySelector('input[placeholder="验证码"]'));await p.getByRole('button',{name:/登\s*录/}).click();try{await p.locator('.business-home').waitFor()}catch(e){console.log('LOGIN_STATE',p.url(),await p.locator('body').innerText());await p.screenshot({path:path.join(out,'login-failure.png')});throw e}console.log('PASS Vue3 login and Pinia session')
|
|
await p.route('**/dev-api/**',async r=>{const q=r.request(),u=new URL(q.url());if(q.method()==='GET'&&u.pathname==='/dev-api/production/product/options-page')return r.fulfill({json:{code:200,total:1,rows:[{itemId:991111,itemName:'交互模拟产品'}]}});if(q.method()==='POST'&&u.pathname==='/dev-api/warehouse/purchase/sheet'){const data=q.postDataJSON();writes.push(data);return r.fulfill({json:{code:200,data:{...data,rows:data.rows.map((row,i)=>({...row,id:row.id||991010+i})),version:'vue3-saved'}}})}if(!['GET','HEAD'].includes(q.method()))return r.abort('blockedbyclient');return r.continue()})
|
|
async function visit(url,selector){await p.goto(base+url,{waitUntil:'domcontentloaded'});await p.locator(selector).waitFor()}
|
|
async function vm(selector,code,args){return p.locator(selector).first().evaluate((el,{code,args})=>{let instance=el.__vueParentComponent;const v=instance.proxy;return Function('v','args','return ('+code+')(v,args)')(v,args)},{code,args})}
|
|
await visit('/procurement/details','.purchase-sheet');await p.waitForFunction(()=>{const v=document.querySelector('.purchase-sheet').__vueParentComponent.proxy;return v.items.length>0&&!v.loading&&v._routeStamp===v.$route.fullPath})
|
|
await vm('.purchase-sheet',`v=>{const item=v.items.find(i=>i.unit&&i.category),project=v.projects[0],category=v.categories[0];v.install({batch:{id:991000,batchNo:'CG-VUE3',businessDate:'2026-10-13'},version:'vue3-test',rows:[{id:991001,projectId:project.id,expenseCategoryId:category.id,productId:item.id,materialName:item.productName,materialBrand:item.brand||'',materialParams:item.spec||'',unit:item.unit,category:item.category,quantity:1,finalUnitPrice:2,purchaseStatus:0,priceLocked:false}]})}`)
|
|
await p.screenshot({path:path.join(out,'before-edit.png')})
|
|
assert.equal(await p.locator('.sheet-cell input:not([disabled])').count(),0)
|
|
await p.getByRole('button',{name:'编辑',exact:true}).click();await p.locator('.sheet-cell[data-field="quantity"]').first().click();const quantity=p.locator('.sheet-cell[data-field="quantity"] input').first();await quantity.fill('12');await quantity.blur();assert.equal(await vm('.purchase-sheet','v=>v.sheet.rows[0].quantity'),12)
|
|
const date=p.locator('.batch-form .el-form-item').filter({hasText:'日期'}).locator('input');await date.fill('2026-10-14');await date.press('Enter');await date.blur();assert.equal(await vm('.purchase-sheet','v=>v.sheet.batch.businessDate'),'2026-10-14')
|
|
await p.getByRole('button',{name:'保存清单',exact:true}).click();await p.waitForFunction(()=>document.querySelector('.purchase-sheet').__vueParentComponent.proxy.sheet?.version==='vue3-saved');assert.equal(writes.length,1);assert.equal(writes[0].rows[0].quantity,12);assert.equal(writes[0].batch.businessDate,'2026-10-14');assert.equal(await p.locator('.sheet-cell input:not([disabled])').count(),0);console.log('PASS explicit edit/save, native quantity/date v-model; one mocked business save')
|
|
await p.waitForFunction(()=>!document.querySelector('.purchase-sheet').__vueParentComponent.proxy.saving);await vm('.purchase-sheet','v=>v.startEditing()');const picker=p.locator('.batch-form .el-form-item').filter({hasText:'供应商'}).locator('.el-select');await picker.click();await p.locator('.el-select-dropdown:visible .el-select-dropdown__item').first().click();assert.ok(await vm('.purchase-sheet','v=>v.sheet.batch.supplierId'));await vm('.purchase-sheet','v=>{v.editing=false;v.baseline=v.serialize(v.sheet)}');console.log('PASS supplier modelValue binding')
|
|
await visit('/production/tasks','.production-workspace');await p.getByRole('button',{name:'新建生产任务',exact:true}).click();const dialog=p.locator('.el-dialog:visible').last();await dialog.locator('.el-form-item').filter({hasText:'产品'}).locator('.el-select').click();await p.locator('.el-select-dropdown:visible .el-select-dropdown__item').first().click();assert.ok(await vm('.production-workspace','v=>v.form.itemId'));await dialog.getByRole('button',{name:'取消',exact:true}).click();console.log('PASS product picker and dialog modelValue')
|
|
await visit('/project/info','.desktop-viewport');await p.locator('.desktop-viewport .el-table__body tr').first().getByRole('button').first().click();await p.locator('.workspace-heading').waitFor();for(const tab of ['总览','分类预算','产品与BOM','采购','库存','借用与归还','生产','成本与损耗']){await p.getByRole('tab',{name:tab,exact:true}).click();await p.waitForTimeout(400)}await p.screenshot({path:path.join(out,'project.png')});console.log('PASS eight project tabs and nested component mounted hooks')
|
|
await visit('/businessBasics/product','.desktop-viewport');await p.getByRole('button',{name:'新增',exact:true}).first().click();await p.locator('.el-dialog:visible').last().getByRole('button',{name:/确\s*定/}).click();await p.locator('.el-form-item__error').first().waitFor();await p.locator('.el-dialog:visible').last().getByRole('button',{name:/取\s*消/}).click();console.log('PASS native form validation')
|
|
await p.setViewportSize({width:412,height:860});await visit('/mobile','.mobile-app');await p.waitForTimeout(400);await vm('.mobile-app','v=>v.switchTab("stock")');await p.waitForTimeout(300);assert.ok(await p.getByRole('button',{name:'返回上一页'}).count());await p.getByRole('button',{name:'返回上一页'}).click();assert.equal(await vm('.mobile-app','v=>v.activeTab'),'home');await p.screenshot({path:path.join(out,'mobile.png')});console.log('PASS mobile web inventory and back navigation')
|
|
assert.deepEqual(errors,[]);console.log('PASS all interactions; no real business writes')
|
|
}finally{await browser.close()}
|
|
})().catch(e=>{console.error(e);process.exitCode=1})
|