96 lines
9.6 KiB
JavaScript
96 lines
9.6 KiB
JavaScript
|
|
const assert=require('node:assert/strict'),fs=require('node:fs'),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']})
|
||
|
|
const out=path.resolve(__dirname,'../../.codex-tmp/home-dashboard-check');fs.mkdirSync(out,{recursive:true})
|
||
|
|
const errors=[],failures=[]
|
||
|
|
try{
|
||
|
|
const context=await browser.newContext({viewport:{width:1440,height:900}})
|
||
|
|
await context.addCookies([{name:'Admin-Token',value:login.token,url:'http://127.0.0.1:8088'}])
|
||
|
|
const page=await context.newPage()
|
||
|
|
page.on('pageerror',e=>errors.push(e.message))
|
||
|
|
page.on('response',r=>{if(r.url().includes('/dev-api/')&&r.status()>=400)failures.push(r.status()+' '+new URL(r.url()).pathname)})
|
||
|
|
await page.route('**/dev-api/**',async route=>{assert.ok(['GET','HEAD'].includes(route.request().method()),'unexpected business write');await route.continue()})
|
||
|
|
await page.goto('http://127.0.0.1:8088/index',{waitUntil:'domcontentloaded'})
|
||
|
|
await page.waitForFunction(()=>{const vm=document.querySelector('.business-home')?.__vue__;return vm?.loadedOnce&&!vm.loading})
|
||
|
|
assert.equal(await page.locator('.business-home .el-table').count(),0)
|
||
|
|
assert.equal(await page.locator('.home-stat').count(),4)
|
||
|
|
assert.equal(await page.locator('.home-todo').count(),5)
|
||
|
|
assert.equal(await page.locator('.home-followups button').count(),2)
|
||
|
|
assert.ok(!(await page.locator('.home-todo-tabs').innerText()).includes('未到齐'))
|
||
|
|
assert.ok(!(await page.locator('.home-todo-tabs').innerText()).includes('未归还'))
|
||
|
|
assert.equal(await page.locator('.home-shortcut').count(),8)
|
||
|
|
assert.ok(await page.locator('.home-todo-row').count()<=6)
|
||
|
|
assert.deepEqual(await page.evaluate(()=>document.querySelector('.business-home').__vue__.failures),[])
|
||
|
|
const actual=await page.evaluate(()=>document.querySelector('.business-home').__vue__.overview)
|
||
|
|
assert.equal(await page.locator('.inventory-assistant').count(),1)
|
||
|
|
assert.deepEqual(await page.locator('.home-stat-text>span').allTextContents(),['库存品项','待入库','待盘库确认','出库记录'])
|
||
|
|
await page.locator('.home-projects .el-radio-button').filter({hasText:'状态'}).click()
|
||
|
|
assert.equal(await page.locator('.home-status-overview>div').count(),4)
|
||
|
|
await page.locator('.home-projects .el-radio-button').filter({hasText:'经费'}).click()
|
||
|
|
assert.equal(await page.locator('.home-funds').count(),1)
|
||
|
|
async function geometry(width,height,tag='home'){
|
||
|
|
await page.setViewportSize({width,height});await page.waitForTimeout(300)
|
||
|
|
const s=await page.evaluate(()=>{const root=document.querySelector('.business-home'),r=root.getBoundingClientRect();return {doc:document.documentElement.scrollHeight-innerHeight,root:root.scrollHeight-root.clientHeight,bottom:r.bottom,screen:innerHeight,panels:[...root.querySelectorAll('.home-panel')].map(e=>({bottom:e.getBoundingClientRect().bottom,scroll:e.scrollHeight-e.clientHeight})),text:root.innerText}})
|
||
|
|
assert.ok(s.doc<=2,'document overflow '+JSON.stringify(s))
|
||
|
|
assert.ok(s.root<=2,'homepage outer overflow '+JSON.stringify(s))
|
||
|
|
assert.ok(s.bottom<=s.screen+1)
|
||
|
|
for(const p of s.panels)assert.ok(p.bottom<=s.screen+1,'panel escaped viewport '+JSON.stringify(s))
|
||
|
|
for(const title of ['首页概览','待办事项','快速入口','项目概况'])assert.ok(s.text.includes(title))
|
||
|
|
await page.screenshot({path:path.join(out,`${tag}-${width}x${height}.png`)})
|
||
|
|
}
|
||
|
|
for(const size of [[1440,900],[1366,768],[1920,1080],[1024,768]])await geometry(...size)
|
||
|
|
const queue=await page.evaluate(()=>{const vm=document.querySelector('.business-home').__vue__;return vm.todoQueues.find(q=>q.rows.length)?.key})
|
||
|
|
if(queue){await page.evaluate(key=>document.querySelector('.business-home').__vue__.selectQueue(key),queue);await page.locator('.home-record-action').first().click();await page.waitForTimeout(500);assert.notEqual(new URL(page.url()).pathname,'/index')}
|
||
|
|
async function home(){await page.evaluate(async()=>{await document.querySelector('#app').__vue__.$router.push('/index').catch(e=>{if(e.name!=='NavigationDuplicated')throw e})});await page.waitForFunction(()=>{const vm=document.querySelector('.business-home')?.__vue__;return vm&&!vm.loading})}
|
||
|
|
await home()
|
||
|
|
const entries=await page.evaluate(()=>document.querySelector('.business-home').__vue__.shortcuts.map(e=>({key:e.key,path:e.target.path})))
|
||
|
|
for(const e of entries.filter(e=>e.key!=='mobile')){await page.locator('.home-shortcut').filter({hasText:e.key==='product'?'产品档案':({purchase:'采购清单',arrival:'到货验收',receipt:'待入库',stock:'库存操作',production:'生产任务',project:'项目管理'})[e.key]}).click();await page.waitForFunction(path=>location.pathname===path,e.path);await home()}
|
||
|
|
const projectId=await page.evaluate(()=>document.querySelector('.business-home').__vue__.projects[0]?.id)
|
||
|
|
if(projectId){
|
||
|
|
// Statistic links apply the same project scope, including cached-page returns.
|
||
|
|
for(const [label,view,field,pathname] of [['待盘库确认','StockCheck','projectId','/warehouse/stockCheck'],['出库记录','OutRecord','usageProjectId','/warehouse/outRecord']]){
|
||
|
|
for(const scope of [projectId,undefined]){
|
||
|
|
await page.evaluate(async id=>{const vm=document.querySelector('.business-home').__vue__;vm.projectId=id;await vm.reload()},scope)
|
||
|
|
await page.locator('.home-stat').filter({hasText:label}).click()
|
||
|
|
await page.waitForFunction(({field,scope})=>{const params=document.querySelector('.desktop-viewport')?.firstElementChild?.__vue__?.queryParams;return params && params[field]===scope},{field,scope})
|
||
|
|
assert.equal(new URL(page.url()).pathname,pathname)
|
||
|
|
if(view==='StockCheck')assert.equal(await page.evaluate(()=>document.querySelector('.desktop-viewport').firstElementChild.__vue__.queryParams.checkStatus),0)
|
||
|
|
await home()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
await page.evaluate(async id=>{const vm=document.querySelector('.business-home').__vue__;vm.projectId=id;await vm.reload()},projectId)
|
||
|
|
await page.locator('.home-shortcut').filter({hasText:'库存操作'}).click()
|
||
|
|
await page.waitForFunction(id=>document.querySelector('.desktop-viewport')?.firstElementChild?.__vue__?.queryParams?.projectId===id,projectId)
|
||
|
|
await home();await page.evaluate(async()=>{const vm=document.querySelector('.business-home').__vue__;vm.projectId=undefined;await vm.reload()})
|
||
|
|
await page.locator('.home-shortcut').filter({hasText:'库存操作'}).click()
|
||
|
|
await page.waitForFunction(()=>{const params=document.querySelector('.desktop-viewport')?.firstElementChild?.__vue__?.queryParams;return params && params.projectId===undefined})
|
||
|
|
await home()
|
||
|
|
}
|
||
|
|
await page.route('**/warehouse/purchase/filtered*',route=>route.fulfill({json:{code:500,msg:'Intentional dashboard source failure'}}))
|
||
|
|
await page.evaluate(()=>{document.querySelector('.business-home').__vue__.metricView='project'})
|
||
|
|
await page.evaluate(async()=>{await document.querySelector('.business-home').__vue__.reload()})
|
||
|
|
assert.equal(await page.evaluate(()=>document.querySelector('.business-home').__vue__.overview.purchaseCount),null)
|
||
|
|
assert.ok((await page.locator('.home-stat').filter({hasText:'采购处理中'}).innerText()).includes('—'))
|
||
|
|
await page.unroute('**/warehouse/purchase/filtered*')
|
||
|
|
const calls=[];const capture=r=>{if(r.url().includes('/dev-api/'))calls.push(new URL(r.url()).pathname)}
|
||
|
|
page.on('request',capture)
|
||
|
|
await page.evaluate(async()=>{const vm=document.querySelector('.business-home').__vue__;vm.$store.commit('SET_PERMISSIONS',['warehouse:purchase:list']);await vm.$nextTick();await vm.reload()})
|
||
|
|
assert.equal(await page.locator('.home-stat').count(),1);assert.equal(await page.locator('.home-shortcut').count(),3);assert.equal(await page.locator('.home-projects').count(),0)
|
||
|
|
assert.equal(await page.locator('.inventory-assistant').count(),0)
|
||
|
|
assert.ok(calls.every(p=>p.endsWith('/warehouse/purchase/filtered')))
|
||
|
|
page.off('request',capture)
|
||
|
|
await page.evaluate(async()=>{const vm=document.querySelector('.business-home').__vue__;vm.$store.commit('SET_PERMISSIONS',['*:*:*']);vm.metricView='warehouse';await vm.$nextTick();await vm.reload()})
|
||
|
|
await page.locator('.el-message').waitFor({state:'hidden',timeout:6000}).catch(()=>{})
|
||
|
|
await page.setViewportSize({width:1440,height:900});await page.waitForTimeout(250);await page.screenshot({path:path.join(out,'home-final.png')})
|
||
|
|
// Presentation fixture only: exercise over-budget/project status geometry, never save it.
|
||
|
|
await page.evaluate(()=>{const vm=document.querySelector('.business-home').__vue__;vm.projects=Array.from({length:12},(_,i)=>({id:900000+i,projectCode:'QA-'+i,projectName:'布局验证项目',projectStatus:i%4,totalAmount:10000,spentAmount:i===0?12000:4000,availableAmount:i===0?-2000:6000,currency:'CNY'}))})
|
||
|
|
await geometry(1366,768,'fixture')
|
||
|
|
assert.equal(await page.locator('.home-budget-warning').count(),1)
|
||
|
|
assert.deepEqual(errors,[]);assert.deepEqual(failures,[])
|
||
|
|
console.log('PASS: dashboard statistics, 6-record preview, 8 shortcuts, project/fund overview; 4 desktop sizes, real deep link, shortcut navigation, failure stays unknown, permission-scoped sources. No business writes. Actual counts:',JSON.stringify({projects:actual.projectCount,purchases:actual.purchaseCount,production:actual.productionCount}))
|
||
|
|
}finally{await browser.close()}
|
||
|
|
})().catch(e=>{console.error(e);process.exitCode=1})
|