cmvr-wms/scripts/projectdev/vue3-legacy-pages-regression.cjs
lixiaolong e78ed25668 refactor(components): 优化组件交互和数据验证逻辑
- 为对话框添加防止意外关闭的安全措施
- 实现表单提交时的数据有效性验证
- 集成远程选择器组件提升用户体验
- 更新表格组件样式适配新设计规范
- 优化列表页面加载和错误处理机制
- 统一组件尺寸设置和存储管理
2026-10-14 09:11:33 +08:00

57 lines
8.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(),errors=[],writes=[]
try{
const c=await browser.newContext({viewport:{width:1366,height:768}});await c.addCookies([{name:'Admin-Token',value:login.token,url:frontend}]);const page=await c.newPage();page.setDefaultTimeout(12000);page.on('pageerror',e=>errors.push(e.message))
let failingPath='',failMonitor=true,keyReads=0,avatarAttempts=0
await page.route('**/dev-api/**',async r=>{
const req=r.request(),p=new URL(req.url()).pathname.replace('/dev-api','')
if(p===failingPath)return r.fulfill({json:{code:500,msg:'回归检查:加载失败'}})
if(p==='/system/user/profile/avatar'){writes.push(p);avatarAttempts++;await new Promise(resolve=>setTimeout(resolve,300));return r.fulfill({json:avatarAttempts===1?{code:500,msg:'模拟上传失败'}:{code:200,imgUrl:'/profile/avatar-test.png'}})}
if(!['GET','HEAD'].includes(req.method())){writes.push(p);return r.abort('blockedbyclient')}
if(p==='/monitor/server')return r.fulfill({json:failMonitor?{code:500,msg:'监控暂时不可用'}:{code:200,data:{}}})
if(p==='/monitor/cache')return r.fulfill({json:failMonitor?{code:500,msg:'监控暂时不可用'}:{code:200,data:{info:{used_memory_human:'12M'},commandStats:[{name:'GET',value:12}]}}})
if(p==='/monitor/cache/getNames')return r.fulfill({json:{code:200,data:[{cacheName:'A:',remark:'测试 A'},{cacheName:'B:',remark:'测试 B'}]}})
if(p.startsWith('/monitor/cache/getKeys/')){keyReads++;const a=p.endsWith('A:');await new Promise(resolve=>setTimeout(resolve,a?250:25));return r.fulfill({json:{code:200,data:[a?'A:key':'B:key']}})}
if(p.startsWith('/monitor/cache/getValue/'))return r.fulfill({json:{code:200,data:{cacheName:'B:',cacheKey:'B:key',cacheValue:'模拟值'}}})
return r.continue()
})
await page.goto(frontend+'/index');await page.waitForLoadState('networkidle')
assert.ok(await page.locator('.home-stat-icon svg').count()>0,'statistics use visible SVG icons');assert.ok(await page.locator('.home-shortcut svg').count()>0)
const lists=[['system/config/index.vue','/system/config/list'],['system/dept/index.vue','/system/dept/list'],['system/menu/index.vue','/system/menu/list'],['system/post/index.vue','/system/post/list'],['system/role/index.vue','/system/role/list'],['system/user/index.vue','/system/user/list'],['system/dict/index.vue','/system/dict/type/list'],['system/dict/data.vue','/system/dict/data/list'],['monitor/logininfor/index.vue','/monitor/logininfor/list'],['monitor/online/index.vue','/monitor/online/list'],['monitor/operlog/index.vue','/monitor/operlog/list'],['monitor/job/index.vue','/monitor/job/list'],['monitor/job/log.vue','/monitor/jobLog/list'],['tool/gen/index.vue','/tool/gen/list']]
await page.evaluate(async lists=>{const router=document.querySelector('#app').__vue_app__.config.globalProperties.$router,{default:Layout}=await import('/src/layout/index.vue');for(let i=0;i<lists.length;i++){const component=(await import('/src/views/'+lists[i][0])).default;router.addRoute({path:'/_legacy/'+i,component:Layout,children:[{path:lists[i][0]==='system/dict/data.vue'?':dictId':'',component,meta:{noCache:true}}]})}},lists)
async function navigate(url){await page.evaluate(async url=>{await document.querySelector('#app').__vue_app__.config.globalProperties.$router.push(url)},url);await page.waitForLoadState('networkidle')}
await navigate('/project/collaboration')
await page.locator('.collaboration-entry').getByText('项目协作功能待接入',{exact:true}).waitFor()
assert.equal(await page.locator('.collaboration-entry .project-workspace').count(),0,'independent entry must not restore the removed replacement business UI')
await page.reload();await page.locator('.collaboration-entry').getByText('项目协作功能待接入',{exact:true}).waitFor()
console.log('PASS independent collaboration menu entry resolves and refreshes without restoring removed business functions')
for(let i=0;i<lists.length;i++){
console.log('CHECK retry',lists[i][0])
failingPath=lists[i][1];await navigate('/_legacy/'+i+(lists[i][0]==='system/dict/data.vue'?'/1':''))
const failure=page.locator('.business-list-page__error');await failure.waitFor();await page.getByRole('button',{name:'重试',exact:true}).waitFor();failingPath=''
await page.getByRole('button',{name:'重试',exact:true}).click();await failure.waitFor({state:'hidden'});await page.waitForFunction(()=>![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(e=>e.getClientRects().length&&Number(getComputedStyle(e).opacity)>.1))
}
console.log('PASS 14 legacy lists release failed loading states and retry; real business writes blocked')
assert.equal(await page.evaluate(()=>document.querySelector('#app').__vue_app__.config.globalProperties.$router.getRoutes().filter(r=>r.path==='/project/collaboration').length),1,'independently maintained project collaboration entry must remain')
for(const url of ['/monitor/server','/monitor/cache']){failMonitor=true;await navigate(url);await page.getByRole('button',{name:'重试',exact:true}).waitFor();failMonitor=false;await page.getByRole('button',{name:'重试',exact:true}).click();await page.waitForFunction(()=>![...document.querySelectorAll('.el-loading-mask')].some(e=>e.getClientRects().length&&Number(getComputedStyle(e).opacity)>.1));await page.getByRole('button',{name:'重试',exact:true}).waitFor({state:'hidden'})}
await page.waitForLoadState('networkidle');await page.locator('.cache-chart-stage canvas').first().waitFor()
const chart=await page.locator('.cache-chart-stage').first().evaluate(e=>({width:e.clientWidth,chart:parseFloat(e.querySelector('canvas')?.style.width)}));assert.ok(chart.width>0&&Math.abs(chart.width-chart.chart)<2,JSON.stringify(chart))
console.log('PASS monitor failures have local retry, no blocking overlay or invalid chart size')
await navigate('/monitor/cacheList');await page.locator('.cache-panel').first().getByText('A',{exact:true}).click();await page.locator('.cache-panel').first().getByText('B',{exact:true}).click();await page.locator('.cache-panel').nth(1).getByText('key',{exact:true}).waitFor();await page.waitForTimeout(300);assert.equal(await page.locator('.cache-panel').nth(1).getByText('key',{exact:true}).count(),1)
await page.setViewportSize({width:1024,height:600});await page.waitForTimeout(200);const tables=await page.locator('.cache-panel .el-table').evaluateAll(es=>es.map(e=>({height:e.getBoundingClientRect().height,bottom:e.getBoundingClientRect().bottom})));tables.forEach(t=>assert.ok(t.height>100&&t.bottom<600))
const count=writes.length;await page.getByRole('button',{name:'清理全部',exact:true}).click();await page.getByRole('button',{name:'取消',exact:true}).click();assert.equal(writes.length,count,'cancel must not clear caches');assert.ok(keyReads>=2)
console.log('PASS latest cache-key selection wins, panels resize and cache clearing requires confirmation')
await page.setViewportSize({width:1366,height:768});await navigate('/user/profile');await page.getByRole('button',{name:'修改头像',exact:true}).click();await page.locator('.el-dialog:visible').getByRole('button',{name:'放大',exact:true}).waitFor()
// Substitute only the cropper output, to avoid depending on avatar image network/CORS in a UI control regression.
await page.locator('.el-dialog:visible .vue-cropper').waitFor()
await page.locator('.user-info-head').evaluate(e=>{const state=e.__vueParentComponent.setupState;state.proxy.$refs.cropper.getCropBlob=callback=>callback(new Blob(['mock'],{type:'image/png'}))})
const dialog=page.locator('.el-dialog:visible');await dialog.getByRole('button',{name:'提交',exact:true}).click();await page.keyboard.press('Escape');await page.waitForTimeout(450);assert.equal(await dialog.count(),1);assert.ok(await dialog.getByRole('button',{name:'提交',exact:true}).isEnabled(),'failed upload stays editable')
await dialog.getByRole('button',{name:'提交',exact:true}).click();await dialog.waitFor({state:'hidden'});assert.equal(avatarAttempts,2);assert.deepEqual(writes,['/system/user/profile/avatar','/system/user/profile/avatar'])
console.log('PASS avatar pending upload blocks close; failure retains editor; retry closes cleanly (uploads mocked)')
assert.deepEqual(errors,[])
}finally{await browser.close()}
})().catch(e=>{console.error(e);process.exitCode=1})