🐛 fix: 修复仪表盘刷新按钮间距

* 恢复桌面刷新按钮的左右留白和图标文字间距
* 保持手机端图标与加载动画居中,避免挤压和换行
* 验证深浅主题、三种屏宽及刷新请求与加载状态
This commit is contained in:
orion committed 2026-09-19 00:53:48 +08:00
1 parent 4fefcd0f0a
commit fe6d812857
3 files changed
+48 -1

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
const {chromium}=require('playwright');const {expect}=require('playwright/test');const assert=require('node:assert/strict');const fs=require('node:fs');const path=require('node:path');
const site=process.env.FCB_TEST_URL||'https://filetest.orionc.me';
(async()=>{const browser=await chromium.launch({headless:false});try{
const context=await browser.newContext({viewport:{width:1440,height:1000},colorScheme:'dark'});const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
const login=await page.request.post(site+'/admin/login',{data:{password:process.env.FCB_TEST_PASSWORD}});const token=(await login.json()).detail.token;assert.ok(token);
await context.addInitScript(token=>localStorage.setItem('token',token),token);
if(process.env.FCB_FRONTEND_DIST)await page.route(site+'/**',async route=>{const u=new URL(route.request().url());const rel=u.pathname==='/'?'index.html':u.pathname.startsWith('/theme-assets/')?u.pathname.slice(14):null;const file=rel&&path.join(process.env.FCB_FRONTEND_DIST,rel);if(file&&fs.existsSync(file)&&fs.statSync(file).isFile())await route.fulfill({path:file});else await route.continue()});
await page.goto(site+'/#/admin/dashboard');const button=page.getByRole('button',{name:'刷新数据',exact:true});await expect(button).toBeEnabled();
let hold=false;const gates=[];const counts={dashboard:0,analytics:0};
for(const endpoint of Object.keys(counts))await page.route(site+'/admin/'+endpoint+'**',async route=>{counts[endpoint]++;if(hold)await new Promise(r=>gates.push(r));await route.continue()});
const geometry=()=>button.evaluate(b=>{const icon=b.querySelector('svg,.animate-spin'),label=b.querySelector('span'),r=b.getBoundingClientRect(),i=icon.getBoundingClientRect(),l=label.getBoundingClientRect(),s=getComputedStyle(b);return {width:r.width,height:r.height,left:i.left-r.left,right:r.right-l.right,gap:l.left-i.right,centerDelta:(i.left+i.right-r.left-r.right)/2,paddingLeft:parseFloat(s.paddingLeft),paddingRight:parseFloat(s.paddingRight)}});
for(const theme of ['dark','light']){
await page.emulateMedia({colorScheme:theme});
for(const width of [1440,640,390]){
await page.setViewportSize({width,height:1000});await button.scrollIntoViewIfNeeded();const idle=await geometry();
if(width>=640){assert.ok(idle.paddingLeft>=15&&idle.paddingRight>=15,JSON.stringify(idle));assert.ok(idle.gap>=7,JSON.stringify(idle));assert.ok(idle.left>=15&&idle.right>=15,JSON.stringify(idle))}else assert.ok(Math.abs(idle.centerDelta)<1,JSON.stringify(idle));
hold=true;await button.click();await expect(button).toBeDisabled();await expect.poll(()=>gates.length).toBe(2);
const loading=await geometry();if(width>=640)assert.ok(loading.gap>=7,JSON.stringify(loading));else assert.ok(Math.abs(loading.centerDelta)<1,JSON.stringify(loading));
hold=false;gates.splice(0).forEach(r=>r());await expect(button).toBeEnabled();
await page.screenshot({path:`/tmp/fcb-refresh-${theme}-${width}.png`});
}
}
assert.deepEqual(counts,{dashboard:6,analytics:6});assert.deepEqual(errors,[]);console.log('PASS: dark/light at 1440/640/390; desktop padding/gap, mobile icon/spinner centering; both refresh requests and disabled loading state.');
}finally{await browser.close()}})().catch(e=>{console.error(e);process.exitCode=1});