Files
orion 3d70f67cf7 ✨ feat: 支持单个、选中及全量手动检测下载状态
* 默认关闭定时检测,取消页面加载、翻页和刷新列表触发检测
* 提供明确的检测可下载状态入口,支持全量跨分页和选中文件
* 逐个读取文件并显示进度,支持取消及过期响应隔离
* 保持检测结果标签与时间展示,验证桌面和移动端交互
* 补充手动范围、失败重试、取消及跨页全量检测的集成验收
2026-09-19 01:24:16 +08:00

97 lines
7.6 KiB
JavaScript

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 page.getByTitle('检测全部文件,包括未显示的分页', {exact:true}).click();
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});