✨ feat: 完善文件状态、取件记录与表格交互
* 支持当前页下载状态的手动和定时检测,仅显示标签与检测时间 * 区分查件时间和下载点击时间,保留重复查件前的取件时间 * 将查件事件按时间并入现有取件记录,共用展开与收起 * 统一表头居中,支持拖拽和键盘调整列宽并限制最小宽度 * 修复筛选面板收起结束时顶部间距突然消失的顿挫 * 补充单元、集成与浏览器验证,覆盖查询下载、列宽和动画行为
This commit is contained in:
1 parent
272741ee49
commit
4fefcd0f0a
29 files changed
+765
-41
No files matched your search
@@ -0,0 +1,95 @@
|
||||
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}});
|
||||
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 body=await login.json();assert.ok(body.detail?.token,'Test login must succeed');
|
||||
await context.addInitScript(token=>localStorage.setItem('token',token),body.detail.token);
|
||||
if(process.env.FCB_FRONTEND_DIST){
|
||||
await page.route(site+'/**',async route=>{
|
||||
const url=new URL(route.request().url());
|
||||
const relative=url.pathname==='/'?'index.html':url.pathname.startsWith('/theme-assets/')?url.pathname.slice('/theme-assets/'.length):null;
|
||||
const file=relative&&path.join(process.env.FCB_FRONTEND_DIST,relative);
|
||||
if(file&&fs.existsSync(file)&&fs.statSync(file).isFile())await route.fulfill({path:file});else await route.continue();
|
||||
});
|
||||
}
|
||||
await page.goto(site+'/#/admin/files');
|
||||
const all=page.locator('.data-table-2026 table');
|
||||
await all.getByRole('status').first().waitFor();
|
||||
await all.getByRole('status').filter({hasText:'可下载'}).first().waitFor();
|
||||
const statuses=await all.getByRole('status').evaluateAll(nodes=>nodes.map(n=>({children:n.children.length,title:n.getAttribute('title'),text:n.textContent})));
|
||||
statuses.forEach(s=>{assert.ok(s.children<=2,JSON.stringify(s));assert.equal(s.title,null)});
|
||||
async function verifyTable(table,name) {
|
||||
await table.scrollIntoViewIfNeeded();
|
||||
const headers=table.locator('th');const handles=table.getByRole('separator');
|
||||
assert.equal(await handles.count(),await headers.count());
|
||||
for(const style of await headers.evaluateAll(hs=>hs.map(h=>({align:getComputedStyle(h).textAlign,whiteSpace:getComputedStyle(h).whiteSpace})))){
|
||||
assert.equal(style.align,'center');assert.equal(style.whiteSpace,'nowrap');
|
||||
}
|
||||
const widths=()=>headers.evaluateAll(hs=>hs.map(h=>h.getBoundingClientRect().width));
|
||||
const index=1;const handle=handles.nth(index);await handle.scrollIntoViewIfNeeded();
|
||||
const before=await widths();const box=await handle.boundingBox();
|
||||
await page.mouse.move(box.x+box.width/2,box.y+box.height/2);await page.mouse.down();
|
||||
await page.mouse.move(box.x+box.width/2+90,box.y+box.height/2,{steps:12});await page.mouse.up();
|
||||
const after=await widths();assert.ok(Math.abs(after[index]-before[index]-90)<2,`${name}: ${before} -> ${after}`);
|
||||
before.forEach((w,i)=>{if(i!==index)assert.ok(Math.abs(w-after[i])<2,`${name} other column changed`)})
|
||||
// Continued widening and keyboard narrowing must agree with the actual geometry.
|
||||
await handle.focus();await page.keyboard.press('ArrowRight');assert.ok(Math.abs((await widths())[index]-after[index]-16)<2);
|
||||
await page.keyboard.press('ArrowLeft');assert.ok(Math.abs((await widths())[index]-after[index])<2);
|
||||
const b=await handle.boundingBox();await page.mouse.move(b.x+4,b.y+b.height/2);await page.mouse.down();
|
||||
await page.mouse.move(b.x-500,b.y+b.height/2,{steps:10});await page.mouse.up();
|
||||
assert.ok((await widths())[index]>=72);assert.equal(await table.evaluate(t=>t.classList.contains('columns-resizing')),false);
|
||||
const frozen=await widths();await page.mouse.move(900,500);assert.deepEqual(await widths(),frozen);
|
||||
console.log(name+': centered, drag +/- and minimum, keyboard, other columns stable, release cleanup OK');
|
||||
}
|
||||
|
||||
const toggle=page.locator('[aria-controls="file-filter-panel"]');
|
||||
await toggle.scrollIntoViewIfNeeded();await toggle.click();
|
||||
await page.waitForFunction(()=>{const p=document.querySelector('#file-filter-panel');return getComputedStyle(p).display!=='none'&&!p.style.height});
|
||||
const samples=await page.evaluate(async()=>{
|
||||
const panel=document.querySelector('#file-filter-panel'),card=panel.closest('section'),samples=[];
|
||||
const start=performance.now();document.querySelector('[aria-controls="file-filter-panel"]').click();
|
||||
await new Promise(resolve=>{const frame=()=>{const elapsed=performance.now()-start;samples.push({t:elapsed,height:card.getBoundingClientRect().height});if(elapsed<650)requestAnimationFrame(frame);else resolve()};requestAnimationFrame(frame)});
|
||||
return samples;
|
||||
});
|
||||
let lateJump=0;for(let i=1;i<samples.length;i++)if(samples[i-1].t>=300)lateJump=Math.max(lateJump,Math.abs(samples[i].height-samples[i-1].height));
|
||||
fs.writeFileSync('/tmp/fcb-filter-animation-samples.json',JSON.stringify(samples));
|
||||
assert.ok(lateJump<5,'Filter final collapse jump: '+lateJump);
|
||||
await page.evaluate(async()=>{const b=document.querySelector('[aria-controls="file-filter-panel"]');b.click();await new Promise(r=>setTimeout(r,80));b.click();await new Promise(r=>setTimeout(r,80));b.click()});
|
||||
await page.waitForFunction(()=>{const p=document.querySelector('#file-filter-panel');return getComputedStyle(p).display!=='none'&&!p.style.height});
|
||||
await page.emulateMedia({reducedMotion:'reduce'});await toggle.click();
|
||||
await page.waitForFunction(()=>getComputedStyle(document.querySelector('#file-filter-panel')).display==='none');
|
||||
await page.emulateMedia({reducedMotion:'no-preference'});
|
||||
console.log('Filter collapse final frame delta '+lateJump.toFixed(2)+'px; rapid reversal and reduced motion PASS');
|
||||
|
||||
await verifyTable(all,'All files');
|
||||
const history=page.locator('table').filter({has:page.getByRole('columnheader',{name:'流量',exact:true})});
|
||||
await verifyTable(history,'History');
|
||||
await all.scrollIntoViewIfNeeded();await page.screenshot({path:'/tmp/fcb-columns-light.png'});
|
||||
await page.goto(site+'/#/admin/dashboard');
|
||||
const dashboard=page.locator('table');await expect(dashboard).toHaveCount(1);await dashboard.getByRole('separator').first().waitFor();
|
||||
await verifyTable(dashboard,'Download ranking');
|
||||
await page.goto(site+'/#/admin/files');await expect(page.locator('table')).toHaveCount(2);await all.getByRole('separator').first().waitFor();
|
||||
// Cancel the active drag through page blur, then navigate away during another drag.
|
||||
const h=all.getByRole('separator').nth(1);await h.scrollIntoViewIfNeeded();let b=await h.boundingBox();
|
||||
await page.mouse.move(b.x+4,b.y+b.height/2);await page.mouse.down();await page.evaluate(()=>window.dispatchEvent(new Event('blur')));await page.mouse.up();
|
||||
assert.equal(await all.evaluate(t=>t.classList.contains('columns-resizing')),false);
|
||||
b=await h.boundingBox();await page.mouse.move(b.x+4,b.y+b.height/2);await page.mouse.down();
|
||||
await page.goto(site+'/#/admin/dashboard');await page.mouse.up();
|
||||
await page.goto(site+'/#/admin/files');await expect(page.locator('table')).toHaveCount(2);await all.getByRole('separator').first().waitFor();
|
||||
for(const width of [1024,800,390]){
|
||||
await page.setViewportSize({width,height:1000});
|
||||
assert.ok(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1),'No document horizontal overflow '+width);
|
||||
}
|
||||
await page.setViewportSize({width:1440,height:1000});await page.emulateMedia({colorScheme:'dark'});await page.reload();
|
||||
await all.getByRole('separator').first().waitFor();await all.scrollIntoViewIfNeeded();await page.screenshot({path:'/tmp/fcb-columns-dark.png'});
|
||||
assert.deepEqual(errors,[]);console.log('Compact status, responsive widths, navigation/blur cleanup: PASS');
|
||||
}finally{await browser.close()}
|
||||
})().catch(e=>{console.error(e);process.exitCode=1});
|
||||
Reference in new issue
Block a user