- 添加移动工作空间对话框全屏样式支持 - 更新应用主视图以支持桌面视口布局 - 重构Excel导入对话框增加预览和校验功能 - 在移动端主页增加生产与交付模块和项目借还功能 - 移动端库存列表显示项目名称和成品标识 - 增加入库记录批量操作和撤销功能 - 优化分页组件在桌面视口中的滚动行为 - 更新路由配置和数据库连接配置 - 调整仓库领域模型移除预期日期字段 - 优化智能代理服务的正则匹配和出库类型处理
196 lines
15 KiB
JavaScript
196 lines
15 KiB
JavaScript
const assert=require('node:assert/strict')
|
|
const path=require('node:path')
|
|
const {chromium}=require('C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')
|
|
;(async()=>{
|
|
const login=await(await fetch('http://127.0.0.1:8080/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:'admin',password:'admin123',code:'',uuid:''})})).json()
|
|
assert.equal(login.code,200)
|
|
const browser=await chromium.launch({channel:'chrome',headless:true,args:['--disable-gpu','--js-flags=--max-old-space-size=256']})
|
|
try{
|
|
const context=await browser.newContext({viewport:{width:1440,height:1000}})
|
|
await context.addCookies([{name:'Admin-Token',value:login.token,url:'http://127.0.0.1:8088'}])
|
|
const page=await context.newPage(),errors=[]
|
|
page.on('dialog',dialog=>dialog.accept())
|
|
page.on('pageerror',e=>errors.push(e.message))
|
|
await page.goto('http://127.0.0.1:8088/procurement/details',{waitUntil:'domcontentloaded'})
|
|
await page.getByRole('button',{name:'新增采购批次'}).waitFor()
|
|
await page.waitForFunction(()=>{const el=document.querySelector('.purchase-sheet');return el&&el.__vue__?.items?.length>0&&!el.__vue__.loading})
|
|
console.log('CHECK: procurement loaded')
|
|
await page.screenshot({path:path.resolve(__dirname,'../../.codex-tmp/purchase-batches.png'),fullPage:true})
|
|
await page.getByRole('button',{name:'新增采购批次'}).click()
|
|
await page.getByRole('button',{name:'保存清单 / 报价'}).waitFor()
|
|
assert.equal(await page.locator('.sheet-grid .el-table__body-wrapper .sheet-cell[data-field="finalUnitPrice"] input').first().inputValue(),'')
|
|
assert.equal(await page.locator('.sheet-grid .el-table__header-wrapper th').filter({hasText:'物品类别'}).count(),1)
|
|
assert.equal(await page.locator('.sheet-grid .el-table__header-wrapper th').filter({hasText:'物品类别'}).locator('.required-mark').count(),1)
|
|
await page.locator('.sheet-cell[data-row="0"][data-field="materialName"] input').first().click()
|
|
await page.waitForTimeout(150)
|
|
assert.ok(await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').count()>10,'open name dropdown must include catalog choices')
|
|
const result=await page.evaluate(()=>{
|
|
const vm=document.querySelector('.purchase-sheet').__vue__
|
|
const first=vm.items.find(i=>i.unit&&vm.items.filter(other=>other.productName===i.productName).length===1)
|
|
if(first){const row=vm.sheet.rows[0];row.materialName=first.productName;vm.nameChanged(row);if(row.productId!==first.id)throw Error('Catalog autofill failed')}
|
|
const grouped=vm.items.find(i=>vm.items.filter(o=>o.productName===i.productName).length>1)
|
|
if(grouped){const row=vm.sheet.rows[1];row.materialName=grouped.productName;vm.nameChanged(row);if(row.productId)throw Error('Ambiguous name picked arbitrarily')}
|
|
return {count:vm.items.length,units:vm.units.length,dirty:vm.dirty}
|
|
})
|
|
assert.ok(result.count>0&&result.units>0&&result.dirty)
|
|
assert.ok(await page.evaluate(()=>{const vm=document.querySelector('.purchase-sheet').__vue__;return vm.nameMenuRow===vm.sheet.rows[0]._key}),'catalog options must open for the focused row')
|
|
console.log('CHECK: catalog dropdown and autofill')
|
|
await page.screenshot({path:path.resolve(__dirname,'../../.codex-tmp/purchase-sheet.png'),fullPage:true})
|
|
// All writes below are intercepted: test explicit editing/saving without changing business data.
|
|
await page.getByRole('button',{name:'批次列表'}).click()
|
|
await page.locator('.el-message-box .el-button--primary').click()
|
|
await page.waitForFunction(()=>{const vm=document.querySelector('.purchase-sheet').__vue__;return !vm.sheet&&!vm.loading})
|
|
const fixture=await page.evaluate(()=>{
|
|
const vm=document.querySelector('.purchase-sheet').__vue__
|
|
const item=vm.items.find(i=>i.unit),project=vm.projects[0],category=vm.categories[0]
|
|
if(!item||!project||!category)throw Error('Reference data required')
|
|
const row={id:987654301,projectId:project.id,expenseCategoryId:category.id,materialName:item.productName,materialBrand:item.brand||'',materialParams:item.spec||'',productId:item.id,productCode:item.productCode,unit:item.unit,quantity:2,finalUnitPrice:10,purchaseLink:'http://127.0.0.1:8088/__purchase_link_test__?ref='+ 'long-link-'.repeat(35),purchaseStatus:0,priceLocked:false,remainingQuantity:2}
|
|
return {batch:{id:987654321,batchNo:'UI-READONLY-CHECK',batchName:'手动编辑验证',supplierId:123,supplierName:'界面测试供应商',businessDate:'2026-10-11'},rows:[row,{...row,id:987654302,priceLocked:true,purchaseStatus:2},{...row,id:987654303,purchaseStatus:5,purchaseLink:'javascript:alert(1)'}],version:'ui-test'}
|
|
})
|
|
let saveCount=0
|
|
await page.route('**/warehouse/purchase/sheet/987654321',route=>route.fulfill({json:{code:200,data:fixture}}))
|
|
await page.route('**/warehouse/purchase/sheet',async route=>{
|
|
assert.equal(route.request().method(),'POST')
|
|
saveCount++
|
|
await route.fulfill({json:{code:200,data:route.request().postDataJSON()}})
|
|
})
|
|
await context.route('**/__purchase_link_test__?*',route=>route.fulfill({contentType:'text/html',body:'<p>Link opened in new window</p>'}))
|
|
await page.evaluate(batch=>{document.querySelector('.purchase-sheet').__vue__.batches=[batch]},fixture.batch)
|
|
await page.getByText('UI-READONLY-CHECK',{exact:true}).first().click()
|
|
const editButton=page.locator('.sheet-toolbar button').filter({hasText:/^\s*编辑\s*$/})
|
|
await editButton.waitFor()
|
|
assert.equal(await page.locator('.sheet-grid .sheet-cell input').count(),0)
|
|
assert.equal(await page.locator('.batch-form .el-date-editor').count(),0)
|
|
assert.equal(await page.getByRole('button',{name:'保存清单 / 报价'}).count(),0)
|
|
assert.equal(await page.getByRole('button',{name:'加一行',exact:true}).count(),0)
|
|
assert.equal(await page.locator('.sheet-grid .el-table__fixed .el-table__fixed-body-wrapper .el-checkbox').count(),3)
|
|
assert.equal((await page.locator('.sheet-grid .el-table__fixed .el-table__fixed-body-wrapper tr').first().locator('td').nth(1).innerText()).trim(),'1')
|
|
assert.equal(await page.locator('.sheet-grid .el-table__header-wrapper th').filter({hasText:/^链接$/}).count(),1)
|
|
const link=page.locator('.sheet-grid .el-table__body-wrapper .sheet-link').first()
|
|
assert.equal(await link.getAttribute('href'),fixture.rows[0].purchaseLink)
|
|
assert.equal(await link.getAttribute('target'),'_blank')
|
|
assert.equal(await link.getAttribute('rel'),'noopener noreferrer')
|
|
assert.equal(await page.locator('.sheet-cell[data-row="2"][data-field="purchaseLink"] a').count(),0)
|
|
const layoutCheck=async()=>page.evaluate(()=>{
|
|
const grid=document.querySelector('.sheet-grid'),body=grid.querySelector('.el-table__body-wrapper'),fixed=grid.querySelector('.el-table__fixed-right')
|
|
const g=grid.getBoundingClientRect(),f=fixed.getBoundingClientRect()
|
|
const normal=body.querySelector('tr').getBoundingClientRect(),clone=fixed.querySelector('.el-table__fixed-body-wrapper tr').getBoundingClientRect()
|
|
return {height:g.height,rightGap:g.right-f.right,rowOffset:Math.abs(normal.top-clone.top),rowHeight:Math.abs(normal.height-clone.height),scroll:body.scrollHeight>body.clientHeight,scrollX:grid.__vue__.layout.scrollX,blankWidth:body.clientWidth-body.querySelector('table').getBoundingClientRect().width,operationOffset:Math.abs(body.querySelector('tr td:last-child').getBoundingClientRect().left-f.left)}
|
|
})
|
|
await page.waitForTimeout(250)
|
|
let geometry=await layoutCheck()
|
|
assert.ok(geometry.height>100&&geometry.height<1000,JSON.stringify(geometry))
|
|
assert.ok(geometry.rightGap<=18&&geometry.rightGap>=0,JSON.stringify(geometry))
|
|
assert.ok(geometry.rowOffset<2&&geometry.rowHeight<2,JSON.stringify(geometry))
|
|
await page.evaluate(()=>{document.querySelector('.sheet-grid .el-table__body-wrapper').scrollLeft=1250})
|
|
await page.waitForTimeout(100)
|
|
assert.ok(await link.evaluate(el=>el.scrollWidth>el.clientWidth&&getComputedStyle(el).textOverflow==='ellipsis'))
|
|
const popupPromise=context.waitForEvent('page')
|
|
await link.click()
|
|
const popup=await popupPromise
|
|
await popup.waitForLoadState()
|
|
assert.equal(popup.url(),fixture.rows[0].purchaseLink)
|
|
assert.ok(page.url().includes('/procurement/details'))
|
|
await popup.close()
|
|
await page.screenshot({path:path.resolve(__dirname,'../../.codex-tmp/purchase-sheet-view.png'),fullPage:true})
|
|
await editButton.click()
|
|
assert.ok(await page.locator('.sheet-cell[data-row="0"] input').count()>0)
|
|
assert.equal(await page.locator('.sheet-cell[data-row="1"] input').count(),0)
|
|
assert.equal(await page.locator('.sheet-cell[data-row="2"] input').count(),0)
|
|
const price=page.locator('.el-table__body-wrapper .sheet-cell[data-row="0"][data-field="finalUnitPrice"] input')
|
|
await price.fill('12.5')
|
|
await price.press('Tab')
|
|
await page.waitForTimeout(350)
|
|
assert.equal(saveCount,0,'Editing must not auto-save')
|
|
await page.getByRole('button',{name:'取消编辑',exact:true}).click()
|
|
await page.locator('.el-message-box .el-button--primary').click()
|
|
await editButton.waitFor()
|
|
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.sheet.rows[0].finalUnitPrice),10)
|
|
assert.equal(saveCount,0,'Cancel must not write')
|
|
await editButton.click()
|
|
await price.fill('12.5')
|
|
await price.press('Tab')
|
|
await page.getByRole('button',{name:'保存清单 / 报价'}).click()
|
|
await editButton.waitFor()
|
|
assert.equal(saveCount,1,'Only explicit save writes')
|
|
assert.equal(await page.locator('.sheet-grid .sheet-cell input').count(),0)
|
|
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.dirty),false)
|
|
console.log('CHECK: explicit view/edit/cancel/save')
|
|
// Many rows, optional columns, resize and both scroll ends must retain fixed-column alignment.
|
|
await page.evaluate(()=>{
|
|
const vm=document.querySelector('.purchase-sheet').__vue__,sheet=JSON.parse(vm.baseline),base=sheet.rows[0]
|
|
sheet.rows=Array.from({length:45},(_,i)=>({...base,id:987650000+i}));vm.install(sheet);vm.extras=true
|
|
})
|
|
for(const width of [1440,1100,1920,3840]){
|
|
console.log('CHECK: fixed columns at width',width)
|
|
await page.setViewportSize({width,height:1000})
|
|
for(const left of [0,99999]){
|
|
await page.evaluate(left=>{document.querySelector('.sheet-grid .el-table__body-wrapper').scrollLeft=left},left)
|
|
await page.waitForTimeout(180)
|
|
geometry=await layoutCheck()
|
|
assert.ok(geometry.scroll,JSON.stringify(geometry))
|
|
assert.ok(geometry.rightGap<=18&&geometry.rightGap>=0,JSON.stringify(geometry))
|
|
assert.ok(geometry.rowOffset<2&&geometry.rowHeight<2,JSON.stringify(geometry))
|
|
if(width===3840){
|
|
assert.equal(geometry.scrollX,false,JSON.stringify(geometry))
|
|
assert.ok(Math.abs(geometry.blankWidth)<2,JSON.stringify(geometry))
|
|
assert.ok(geometry.operationOffset<2,JSON.stringify(geometry))
|
|
}
|
|
}
|
|
}
|
|
for(const editing of [false,true]){
|
|
await page.evaluate(editing=>{const vm=document.querySelector('.purchase-sheet').__vue__;vm.extras=false;vm.editing=editing},editing)
|
|
await page.waitForTimeout(200)
|
|
geometry=await layoutCheck()
|
|
assert.equal(geometry.scrollX,false,JSON.stringify(geometry))
|
|
assert.ok(Math.abs(geometry.blankWidth)<2&&geometry.operationOffset<2,JSON.stringify(geometry))
|
|
}
|
|
await page.screenshot({path:path.resolve(__dirname,'../../.codex-tmp/purchase-sheet-wide.png'),fullPage:true})
|
|
await page.evaluate(()=>{const vm=document.querySelector('.purchase-sheet').__vue__;vm.editing=false;vm.extras=true})
|
|
console.log('CHECK: large-row narrow layout')
|
|
await page.setViewportSize({width:1440,height:1000})
|
|
console.log('CHECK: large-row edit button')
|
|
await editButton.click()
|
|
console.log('CHECK: large-row edit screenshot')
|
|
await page.screenshot({path:path.resolve(__dirname,'../../.codex-tmp/purchase-sheet-edit.png'),fullPage:true})
|
|
// An expanded summary must return its space to the main table when collapsed.
|
|
const tableHeight=await page.locator('.sheet-grid').evaluate(el=>el.getBoundingClientRect().height)
|
|
await page.locator('.project-totals .el-collapse-item__header').click()
|
|
await page.waitForTimeout(700)
|
|
assert.ok(await page.locator('.sheet-grid').evaluate(el=>el.getBoundingClientRect().height)<tableHeight)
|
|
await page.locator('.project-totals .el-collapse-item__header').click()
|
|
await page.waitForTimeout(700)
|
|
assert.ok(Math.abs(await page.locator('.sheet-grid').evaluate(el=>el.getBoundingClientRect().height)-tableHeight)<2,'collapsed summary left a blank flex area')
|
|
await page.getByRole('button',{name:'取消编辑',exact:true}).click()
|
|
await editButton.waitFor()
|
|
assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.dirty),false)
|
|
// New archive rows must supply a category; the failed save never reaches the mocked API.
|
|
await page.evaluate(()=>{const vm=document.querySelector('.purchase-sheet').__vue__;vm.create();Object.assign(vm.sheet.rows[0],{projectId:vm.projects[0].id,expenseCategoryId:vm.categories[0].id,materialName:'类别必填验证',unit:vm.units[0],quantity:1})})
|
|
await page.getByRole('button',{name:'保存清单 / 报价'}).click();await page.waitForTimeout(100)
|
|
assert.equal(saveCount,1);assert.ok((await page.locator('.el-message--error').last().innerText()).includes('请选择物品类别'))
|
|
await page.locator('.sheet-grid .el-table__body-wrapper .sheet-cell[data-row="0"][data-field="category"] input').click()
|
|
await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').first().click()
|
|
await page.getByRole('button',{name:'保存清单 / 报价'}).click();await page.waitForFunction(()=>!document.querySelector('.purchase-sheet').__vue__.saving && !document.querySelector('.purchase-sheet').__vue__.editing)
|
|
assert.equal(saveCount,2);assert.ok(await page.evaluate(()=>!!document.querySelector('.purchase-sheet').__vue__.sheet.rows[0].category))
|
|
await page.evaluate(()=>{const vm=document.querySelector('.purchase-sheet').__vue__;vm.sheet=null;vm.editing=false})
|
|
const batch=await(await fetch('http://127.0.0.1:8080/warehouse/purchase/batch/list',{headers:{Authorization:'Bearer '+login.token}})).json()
|
|
if(batch.rows.length){
|
|
await page.evaluate(batchNo=>{document.querySelector('.purchase-sheet').__vue__.$router.push({path:'/procurement/arrival',query:{purchaseBatchNo:batchNo}})},batch.rows[0].batchNo)
|
|
await page.locator('.el-radio-button').filter({hasText:'部分到货'}).click()
|
|
const state=await page.evaluate(()=>{
|
|
const find=vm=>vm?.$options?.name==='PurchaseRequest'?vm:(vm?.$children||[]).map(find).find(Boolean)
|
|
const vm=find(document.querySelector('#app').__vue__)
|
|
return {batch:vm.queryParams.purchaseBatchNo,status:vm.queryParams.purchaseStatus}
|
|
})
|
|
assert.equal(state.batch,batch.rows[0].batchNo);assert.equal(state.status,3)
|
|
assert.equal(await page.locator('.arrival-queue-card').count(),0)
|
|
}
|
|
assert.deepEqual(errors,[])
|
|
console.log('PASS: default view, explicit edit/cancel/save (no database writes), locked rows, truncated links open new window, fixed columns at 4 widths including 3840px; wide tables fill all space in view/edit with optional columns on/off; catalog and arrival regression passed; screenshots saved')
|
|
}finally{
|
|
const debugPage=browser.contexts()[0]?.pages()[0]
|
|
if(debugPage)await debugPage.screenshot({path:path.resolve(__dirname,'../../.codex-tmp/purchase-sheet-last-check.png'),fullPage:true,timeout:5000}).catch(()=>{})
|
|
await browser.close()
|
|
}
|
|
})().catch(e=>{console.error(e);process.exitCode=1})
|