2026-10-13 09:41:46 +08:00
const assert = require ( 'node:assert/strict' ) , path = require ( 'node:path' ) , fs = require ( 'node:fs' )
2026-10-14 09:11:33 +08:00
const { chromium } = require ( './vue3-test-runtime.cjs' )
const base = process . env . VUE3 _URL || 'http://127.0.0.1:8088'
2026-10-13 09:41:46 +08:00
; ( async ( ) => {
2026-10-14 09:11:33 +08:00
const browser = await chromium . launch ( { headless : true } )
2026-10-13 09:41:46 +08:00
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.
2026-10-14 09:11:33 +08:00
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' )
2026-10-15 11:30:55 +08:00
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 ( ) } )
2026-10-13 09:41:46 +08:00
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 )
2026-10-14 09:11:33 +08:00
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 )
2026-10-13 09:41:46 +08:00
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' )
2026-10-15 11:30:55 +08:00
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' )
2026-10-13 09:41:46 +08:00
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' )
2026-10-15 11:30:55 +08:00
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' )
2026-10-13 09:41:46 +08:00
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 } )