Peach: Local-first video metadata scraper and media manager.
fix(test): 列表分页用例在导航前挂上条目 mock
longmeidaoc3f8c06987f1
diff --git a/frontend/e2e/catalog-list.test.ts b/frontend/e2e/catalog-list.test.tsindex 227c688a4..855e51774 100644--- a/frontend/e2e/catalog-list.test.ts+++ b/frontend/e2e/catalog-list.test.ts@@ -3,7 +3,7 @@ import { mkdirSync } from 'node:fs';import { join } from 'node:path';import { after, before, describe, it } from 'node:test';import type { Browser } from 'playwright-core';-import { launch, layout, settle, VIEWPORTS, visit } from './harness.ts';+import { launch, layout, settle, VIEWPORTS, visit, withPageDiagnostics } from './harness.ts';describe('馆藏卡片与列表', () => {let browser: Browser;@@ -88,26 +88,28 @@ describe('馆藏卡片与列表', () => {} finally { await opened.close() }});it(`${viewport.name} 全集排序、每页数量与跨页选择`, { timeout: 90_000 }, async () => {- const opened = await visit(browser, '/?browse=folders&loc=local', viewport);+ const requests: URLSearchParams[] = [];+ const entries = Array.from({ length: 45 }, (_, index) => ({+ id: 9000 + index, name: `条目 ${String(index + 1).padStart(2, '0')}${index === 44 ? '超长文件名'.repeat(60) : ''}.mp4`,+ medium: 'video', location: 'local', duration: 45 - index, size: index * 1024,+ }));+ /* 导航前挂上:首屏网格的请求可能早于 load,挂晚了它会落到真实服务上。 */+ const opened = await visit(browser, '/?browse=folders&loc=local', viewport, page => page.route('**/api/items?*', route => {+ const params = new URL(route.request().url()).searchParams;+ requests.push(params);+ const direction = params.get('dir') === 'asc' ? 1 : -1;+ const sorted = [...entries].sort((a, b) => params.get('sort') === 'dur'+ ? direction * (a.duration - b.duration) : direction * a.name.localeCompare(b.name));+ const offset = Number(params.get('offset') || 0), limit = Number(params.get('limit') || 60);+ return route.fulfill({ json: { items: sorted.slice(offset, offset + limit), total: sorted.length } });+ }));const { page } = opened;try {- const requests: URLSearchParams[] = [];- const entries = Array.from({ length: 45 }, (_, index) => ({- id: 9000 + index, name: `条目 ${String(index + 1).padStart(2, '0')}${index === 44 ? '超长文件名'.repeat(60) : ''}.mp4`,- medium: 'video', location: 'local', duration: 45 - index, size: index * 1024,- }));- await page.route('**/api/items?*', route => {- const params = new URL(route.request().url()).searchParams;- requests.push(params);- const direction = params.get('dir') === 'asc' ? 1 : -1;- const sorted = [...entries].sort((a, b) => params.get('sort') === 'dur'- ? direction * (a.duration - b.duration) : direction * a.name.localeCompare(b.name));- const offset = Number(params.get('offset') || 0), limit = Number(params.get('limit') || 60);- return route.fulfill({ json: { items: sorted.slice(offset, offset + limit), total: sorted.length } });- });+ await page.locator('#grid [data-media-card]').first().waitFor({ state: 'visible' });await page.getByRole('radiogroup', { name: '馆藏显示方式' }).locator('label').filter({ has: page.getByRole('radio', { name: '列表', exact: true }) }).click();- await page.locator('[data-catalog-row][data-id="9044"]').waitFor();+ await withPageDiagnostics(page, '切到列表后第一页没有出现', () =>+ page.locator('[data-catalog-row][data-id="9044"]').waitFor());assert.equal(await page.locator('[data-catalog-row]').count(), 20);assert.equal(requests.at(-1)!.get('limit'), '20');assert.equal(requests.at(-1)!.get('loc'), 'local');