Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

test(web): 侧栏岛的行为进 e2e,外观决定按计算值验收

longmeidao9de2219e470c
diff --git a/docs/FRONTEND.md b/docs/FRONTEND.md
index 7703baa49..e27a09560 100644
--- a/docs/FRONTEND.md
+++ b/docs/FRONTEND.md
@@ -95,7 +95,7 @@ island。原因是那一套一上来就打 `/api/items`,而未配置的机器
- 壳在启动时写一份骨架(`sidebar-skeleton.ts`,与岛画的导航同一份顺序与按下态),随后 `loadSidebar(sidebarHost())` 装载岛,之后 `sidebarApi()` 同步可取,契约在 `sidebar/sidebar-api.ts`。岛接上时调 `attached`,壳把品牌与开合键挪进标题行;覆盖式滚动条仍由壳挂在 `#drawerScroll` 上。
- 内容由壳推:`paintSidebar(patch)` 合并 `content`、`filters`、`latest` 后调 `render`。目录与资料页的聚合在 `buildBars` 里换成 `{kind:'catalog'}`,关注页与关注详情的内容标签由 `renderFollowDrawer` 推 `{kind:'follow'}`;就地改筛选时 `applyFilterStateInPlace` 只推 `filters`,`refreshFacetCounts` 只推 `latest`。点下去的动作回到壳的 `navTo`、`commitContextFilter` 与关注页的筛选。
- 导航顺序读 `appSettings` 这一份 store 的 `sidebarOrder`:拖动排序先落 store 再写 `/api/settings`,设置面板改顺序也写同一份 store,岛按通知当场重排。按下态换了由壳的 `paintNav` 调 `navChanged`。
-- 样式在 `sidebar/sidebar.css`,只认 `data-sidebar-*`;岛里不写 className。行为在 `test/react/sidebar.test.tsx`,量布局的玻璃滑动、拖动、各页计数与窄屏开合在 `e2e/sidebar.test.ts`。
+- 样式在 `sidebar/sidebar.css`,只认 `data-sidebar-*`;岛里不写 className。行为在 `test/react/sidebar.test.tsx`,量布局的玻璃滑动、拖动、各页计数与窄屏开合在 `e2e/sidebar.test.ts`;当前项玻璃、标题行间距、时长拉条与窄屏遮罩的外观在 `e2e/design.test.ts` 读计算值。
### 产物缓存
diff --git a/frontend/e2e/design.test.ts b/frontend/e2e/design.test.ts
index da8201870..6a75324e4 100644
--- a/frontend/e2e/design.test.ts
+++ b/frontend/e2e/design.test.ts
@@ -5895,4 +5895,181 @@ describe('设计决定', () => {
await opened.close();
}
});
+
+ /* ── 侧栏岛(`frontend/src/react/sidebar/sidebar.css`) ── */
+
+ /** 打开首页等侧栏的分组画出来。聚合照演示库真取,只保证时长那一组在(演示库的短片可能凑不出总时长)。 */
+ async function openSidebar(viewport: Viewport): Promise<Visit> {
+ const opened = await visit(browser, '/', viewport);
+ await opened.page.route((url) => url.pathname === '/api/facets', async (route) => {
+ const real = await (await route.fetch()).json() as { stats?: Record<string, unknown> };
+ await route.fulfill({ json: { ...real, stats: { ...real.stats, duration: real.stats?.duration || 540 } } });
+ });
+ await opened.page.reload({ waitUntil: 'load' });
+ await opened.page.locator('#drawer [data-sidebar-group="时长"]').waitFor({ state: 'attached', timeout: 15_000 });
+ await settle(opened.page);
+ return { ...opened, close: async () => {
+ await opened.page.unrouteAll({ behavior: 'ignoreErrors' });
+ await opened.close();
+ } };
+ }
+
+ it('侧栏当前项自己不铺底,由挂在抽屉上的那块玻璃标出;悬停时玻璃跟过去,离开这一列回到当前项', { timeout: 60_000 }, async () => {
+ const opened = await openSidebar(DESKTOP);
+ try {
+ const { page } = opened;
+ const read = (key: string) => page.evaluate((target) => {
+ const glide = document.querySelector<HTMLElement>('[data-sidebar-glide]')!;
+ const button = document.querySelector<HTMLElement>(`#drawer [data-sidebar-nav] [data-nav="${target}"]`)!;
+ const box = (node: Element) => {
+ const rect = node.getBoundingClientRect();
+ return [rect.left, rect.top, rect.width, rect.height].map(Math.round);
+ };
+ const style = getComputedStyle(button);
+ return {
+ glide: box(glide), button: box(button), parent: glide.parentElement?.id,
+ layer: getComputedStyle(glide).zIndex, radius: getComputedStyle(glide).borderRadius,
+ fill: [style.backgroundColor, style.backgroundImage, style.boxShadow], color: style.color,
+ };
+ }, key);
+ const current = await read('');
+ assert.equal(current.parent, 'drawer', '玻璃没有挂在抽屉上,纵滚时会被滚动层切掉');
+ assert.deepEqual([current.layer, current.radius], ['-1', '10px'], '玻璃要压在字底下、圆角照按钮的 10px');
+ assert.deepEqual(current.glide, current.button, '玻璃没有垫在当前项下面');
+ assert.deepEqual(current.fill, ['rgba(0, 0, 0, 0)', 'none', 'none'], '当前项自己铺了底,静止时就是两层底叠着');
+ assert.equal(current.color, await tokenColor(page, '#drawer', '--glass-text'), '当前项的字色不是玻璃上的字色');
+ const idle = await read('studios');
+ assert.equal(idle.color, await tokenColor(page, '#drawer', '--color-text-secondary'), '未选中项的字色不是次要文字色');
+
+ await page.locator('#drawer [data-sidebar-nav] [data-nav="studios"]').hover();
+ const hovered = await read('studios');
+ assert.deepEqual(hovered.glide, hovered.button, '悬停时玻璃没有跟到指着的那一项');
+ assert.deepEqual(hovered.fill, ['rgba(0, 0, 0, 0)', 'none', 'none'], '悬停的那一项自己铺了底');
+ await page.mouse.move(900, 420);
+ const back = await read('');
+ assert.deepEqual(back.glide, back.button, '指针离开这一列之后玻璃没有回到当前项');
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('侧栏标题行:切换器 32px 圆标识、收起键 20px 高,与导航首项相隔 12px;分组箭头展开时转 90°;收起后只剩 60px 宽的图标列', { timeout: 60_000 }, async () => {
+ const opened = await openSidebar(DESKTOP);
+ try {
+ const { page } = opened;
+ const head = await page.evaluate(() => {
+ const drawer = document.querySelector('#drawer')!;
+ const rect = (selector: string) => drawer.querySelector(selector)!.getBoundingClientRect();
+ const mark = drawer.querySelector('#brandHome .mark')!;
+ const rotation = (group: Element) => {
+ const matrix = new DOMMatrix(getComputedStyle(group.querySelector(':scope > [data-sidebar-toggle] svg')!).transform);
+ return Math.round(Math.atan2(matrix.b, matrix.a) * 180 / Math.PI);
+ };
+ const groups = [...drawer.querySelectorAll<HTMLDetailsElement>('[data-sidebar-group]')];
+ return {
+ gap: Math.round(rect('[data-sidebar-nav]').top - rect('[data-sidebar-head]').bottom),
+ mark: [Math.round(rect('#brandHome .mark').width), Math.round(rect('#brandHome .mark').height), getComputedStyle(mark).borderRadius],
+ toggle: Math.round(rect('#filterBtn').height),
+ open: groups.filter((group) => group.open).map(rotation),
+ closed: groups.filter((group) => !group.open).map(rotation),
+ };
+ });
+ assert.equal(head.gap, 12, '切换器与导航首项挨得太近,两块底色读起来像压在一起');
+ assert.deepEqual(head.mark, [32, 32, '50%'], '切换器的标识不是 32px 的圆');
+ assert.equal(head.toggle, 20, '收起键不是 20px 高');
+ assert.ok(head.open.length && head.closed.length, `首页的分组没有一开一合可比:${JSON.stringify(head)}`);
+ assert.ok(head.open.every((angle) => angle === 90), `展开的分组箭头没有转到 90°:${head.open}`);
+ assert.ok(head.closed.every((angle) => angle === 0), `收着的分组箭头没有回到 0°:${head.closed}`);
+
+ await page.locator('#filterBtn').click();
+ await page.waitForFunction(() => Math.round(document.querySelector('#drawer')!.getBoundingClientRect().width) === 60,
+ undefined, { timeout: 5_000 });
+ const rail = await page.evaluate(() => {
+ const drawer = document.querySelector('#drawer')!;
+ const toggle = drawer.querySelector('#filterBtn')!.getBoundingClientRect();
+ return {
+ toggle: [Math.round(toggle.width), Math.round(toggle.height)],
+ groups: [...new Set([...drawer.querySelectorAll('[data-sidebar-group]')].map((group) => getComputedStyle(group).display))],
+ labels: [...new Set([...drawer.querySelectorAll('[data-sidebar-nav] button span')].map((span) => getComputedStyle(span).maxWidth))],
+ };
+ });
+ assert.deepEqual(rail, { toggle: [36, 20], groups: ['none'], labels: ['0px'] }, '收起的窄栏不是一列图标');
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('时长拉条:已选段是 accent 渐变,两端读数常显、推到端点也不越出轨道,刚动过的那枚压在上面', { timeout: 60_000 }, async () => {
+ const opened = await openSidebar(DESKTOP);
+ try {
+ const { page } = opened;
+ await page.locator('#drawer [data-sidebar-group="时长"] > [data-sidebar-toggle]').click();
+ await page.locator('#drawer [data-sidebar-group="时长"] [data-sidebar-collapse]:not([inert])').waitFor({ timeout: 5_000 });
+ const read = () => page.evaluate(() => {
+ const range = document.querySelector('#durationRange')!;
+ const bounds = range.getBoundingClientRect();
+ return {
+ fill: getComputedStyle(range.querySelector('[data-sidebar-range-fill]')!).backgroundImage,
+ tips: [...range.querySelectorAll<HTMLElement>('[data-sidebar-range-tip]')].map((tip) => {
+ const box = tip.getBoundingClientRect();
+ return {
+ end: tip.dataset.rangeEnd, text: tip.textContent, layer: getComputedStyle(tip).zIndex,
+ visible: getComputedStyle(tip).visibility === 'visible' && box.width > 0,
+ inside: box.left >= bounds.left - 1 && box.right <= bounds.right + 1,
+ };
+ }),
+ };
+ });
+ const resting = await read();
+ const accent = await tokenColor(page, '#drawer', '--color-accent-400');
+ assert.ok(resting.fill.startsWith('linear-gradient(90deg') && resting.fill.includes(accent),
+ `已选段不是从 accent-400 起的横向渐变:${resting.fill}`);
+ assert.deepEqual(resting.tips, [
+ { end: 'min', text: '0 分钟', layer: '1', visible: true, inside: true },
+ { end: 'max', text: '不限', layer: '2', visible: true, inside: true },
+ ], '两端读数要常显、贴着轨道两端不越界,没动过时右端那枚在上');
+
+ await page.locator('#durMin').focus();
+ await page.keyboard.press('ArrowRight');
+ await page.waitForFunction(() => document.querySelector('[data-sidebar-range-tip][data-range-end="min"]')?.hasAttribute('data-range-active'),
+ undefined, { timeout: 5_000 });
+ const moved = await read();
+ assert.deepEqual(moved.tips.map((tip) => [tip.end, tip.layer, tip.inside]), [['min', '2', true], ['max', '1', true]],
+ '刚动过的那一端没有压到上面');
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('手机侧栏:抽屉开着时遮罩外壳隐形、暗色画在 ::before 上,层级低于抽屉;收起时遮罩退出渲染树', { timeout: 60_000 }, async () => {
+ const opened = await openSidebar(MOBILE);
+ try {
+ const { page } = opened;
+ const scrim = () => page.evaluate(() => {
+ const node = document.querySelector('#scrim')!, drawer = document.querySelector('#drawer')!;
+ const before = getComputedStyle(node, '::before');
+ return {
+ display: getComputedStyle(node).display, visibility: getComputedStyle(node).visibility,
+ dim: [before.visibility, before.backgroundColor],
+ layers: [Number(getComputedStyle(node).zIndex), Number(getComputedStyle(drawer).zIndex)],
+ fill: getComputedStyle(drawer).getPropertyValue('--glass-fill'),
+ };
+ });
+ assert.equal((await scrim()).display, 'none', '抽屉收着时遮罩还在渲染树里,iOS 的 Safari 会拿它给状态栏取色');
+ await page.locator('#filterBtn').tap();
+ await page.waitForFunction(() => document.querySelector('#drawer')?.classList.contains('open'));
+ const shown = await scrim();
+ assert.deepEqual([shown.display, shown.visibility], ['block', 'hidden'], '遮罩外壳没有隐形,iOS 的 Safari 会拿它给状态栏取色');
+ assert.equal(shown.dim[0], 'visible', '遮罩的暗色没有画在 ::before 上');
+ assert.notEqual(shown.dim[1], 'rgba(0, 0, 0, 0)', '遮罩的 ::before 是透明的,压不暗身后的页面');
+ assert.ok(shown.layers[0] < shown.layers[1], `遮罩压在抽屉上面,抽屉里就点不动了:${shown.layers}`);
+ assert.ok(shown.fill.replace(/\s/g, '').includes('86%'), `窄屏抽屉的填充没有加厚到 86%:${shown.fill}`);
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await opened.close();
+ }
+ });
});
diff --git a/frontend/e2e/sidebar.test.ts b/frontend/e2e/sidebar.test.ts
new file mode 100644
index 000000000..ead2d0cda
--- /dev/null
+++ b/frontend/e2e/sidebar.test.ts
@@ -0,0 +1,323 @@
+/* 侧栏岛(`frontend/src/react/sidebar/`,ADR-0031 第 11f 步)在真浏览器里的行为:拖动排序写回、五处语境的
+ * 筛选分组与计数、切页时那块玻璃一路滑过去、手机宽度下抽屉的开合,以及覆盖式滚动条仍挂在滚动层上。
+ *
+ * 写接口一律落在桩里(`settings-fixture`、`follow-fixture`、`item-fixture`)。聚合接口 `/api/facets` 照演示库
+ * 真取一份,只把内容标签换成按语境可区分的几枚:首页与实体页数字不同,才看得出侧栏是按语境取的。演示库没有
+ * 人物实体,实体页的资料与作品照接口的形状在这里给(同 `entity-filter.test.ts`)。 */
+import assert from 'node:assert/strict';
+import { after, before, describe, it } from 'node:test';
+
+import type { Browser, Page } from 'playwright-core';
+
+import { expectBody, launch, settle, visit, VIEWPORTS } from './harness.ts';
+import { openFollowFeed } from './follow-fixture.ts';
+import { ITEM, openItemPage } from './item-fixture.ts';
+import { openHome, ORDER } from './settings-fixture.ts';
+
+const DESKTOP = VIEWPORTS.find((viewport) => !viewport.mobile)!;
+const PHONE = VIEWPORTS.find((viewport) => viewport.mobile)!;
+const HOME_TAGS = [['演示侧栏甲', 41], ['演示侧栏乙', 7]] as const;
+const ENTITY_TAGS = [['演示侧栏甲', 23], ['演示侧栏乙', 5]] as const;
+const withoutPlayer = (problems: string[]) => problems.filter((line) => !line.includes('VIDEOJS'));
+const PERFORMER = '篠田ゆう';
+const THUMB = '<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360"><rect width="640" height="360" fill="#456"/></svg>';
+
+/** 女优资料页要的资料、作品、照片与图。 */
+async function serveEntity(page: Page): Promise<void> {
+ const entity = {
+ id: 90_101, kind: 'performer', canonical_name: PERFORMER, aliases: [], display_aliases: [], user_aliases: [],
+ asset_count: 6, tags: [], related_performers: [], links: [], metadata: {}, has_image: false, has_avatar: false,
+ avatar_focus: null, representative_asset_id: null, entry_links: [], feed: null,
+ };
+ const items = Array.from({ length: 6 }, (_, at) => ({
+ id: 91_000 + at, name: `SSIS-${100 + at} 演示作品 ${at + 1}`, code: `SSIS-${100 + at}`, is_jav: true, has_thumb: true,
+ duration: 7200, studio: 'S1 NO.1 STYLE', tags: [],
+ }));
+ await page.route(/\/api\/entity\?/, (route) => route.fulfill({ json: entity }));
+ await page.route((url) => url.pathname === '/api/items', (route) => route.fulfill({ json: {
+ items: Number(new URL(route.request().url()).searchParams.get('offset') || 0) ? [] : items, total: items.length, has_more: false,
+ } }));
+ await page.route((url) => url.pathname === '/api/photos', (route) =>
+ route.fulfill({ json: { total: 0, sample_total: 0, sets: [], items: [], has_more: false, seed: '' } }));
+ await page.route((url) => url.pathname === '/api/feeds/discoveries', (route) =>
+ route.fulfill({ json: { ok: true, more: false, items: [] } }));
+ await page.route(/\/(?:thumb|poster|photo-thumb|cover)\?/, (route) =>
+ route.fulfill({ contentType: 'image/svg+xml', body: THUMB }));
+}
+
+/** 把 `/api/facets` 的内容标签换成按语境给的那一份;交回收到的查询串,好看实体页是不是按实体口径取的。 */
+async function scopeFacets(page: Page): Promise<string[]> {
+ const seen: string[] = [];
+ await page.route((url) => url.pathname === '/api/facets', async (route) => {
+ const url = new URL(route.request().url());
+ seen.push(url.search);
+ const real = await (await route.fetch()).json() as Record<string, unknown>;
+ const rows = url.searchParams.get('scope_kind') ? ENTITY_TAGS : HOME_TAGS;
+ await route.fulfill({ json: { ...real, tags: rows.map(([k, n]) => ({ k, n, cat: 'general' })) } });
+ });
+ return seen;
+}
+
+/** 抽屉里某一组的 chip:值与计数徽标的数字,按画出来的先后。 */
+const chips = (page: Page, group: string) =>
+ page.locator(`#drawer [data-sidebar-group="${group}"] [data-sidebar-chip]`).evaluateAll((nodes) =>
+ nodes.map((node) => [node.getAttribute('data-val') ?? node.getAttribute('data-follow-drawer-tag'),
+ node.querySelector('[data-sidebar-count]')?.textContent ?? null]));
+
+const navKeys = (page: Page) =>
+ page.locator('#drawer [data-sidebar-nav] [data-nav]').evaluateAll((nodes) => nodes.map((node) => node.getAttribute('data-nav')));
+
+/** 点开一组(初始只有正在生效的组展开,收着的组 `inert`,点不到里面的 chip)。 */
+async function openGroup(page: Page, group: string): Promise<void> {
+ const toggle = page.locator(`#drawer [data-sidebar-group="${group}"] > [data-sidebar-toggle]`);
+ if (await toggle.getAttribute('aria-expanded') !== 'true') await toggle.click();
+ await page.locator(`#drawer [data-sidebar-group="${group}"] [data-sidebar-collapse]:not([inert])`).waitFor({ timeout: 5_000 });
+}
+
+describe('侧栏岛', () => {
+ let browser: Browser;
+
+ before(async () => {
+ browser = await launch();
+ });
+
+ after(async () => {
+ await browser.close();
+ });
+
+ it('拖动一项改导航顺序:当场重排、写进设置,刷新之后照新顺序', { timeout: 60_000 }, async () => {
+ const opened = await openHome(browser);
+ const { page, server } = opened;
+ try {
+ assert.deepEqual(await navKeys(page), ORDER, '侧栏没有按设置里的顺序画');
+ const from = (await page.locator('#drawer [data-nav="tags"]').boundingBox())!;
+ const to = (await page.locator('#drawer [data-nav="follow"]').boundingBox())!;
+ await page.mouse.move(from.x + 40, from.y + from.height / 2);
+ await page.mouse.down();
+ await page.mouse.move(from.x + 44, from.y + from.height / 2 - 6, { steps: 4 });
+ await page.mouse.move(to.x + 40, to.y + 6, { steps: 8 });
+ await page.mouse.move(to.x + 42, to.y + 7, { steps: 2 });
+ assert.equal(await page.locator('#drawer [data-nav="tags"]').getAttribute('data-dragging'), '', '被拖的那一项没有标出来');
+ assert.equal(await page.locator('#drawer [data-nav="follow"]').getAttribute('data-drop'), 'before', '落点没有画在目标上沿');
+ await page.mouse.up();
+ const moved = ['', 'tags', 'follow', 'jav', 'performers', 'studios', 'flagged', 'manage'];
+ await page.waitForFunction((want) => JSON.stringify([...document.querySelectorAll('#drawer [data-sidebar-nav] [data-nav]')]
+ .map((node) => node.getAttribute('data-nav'))) === want, JSON.stringify(moved), { timeout: 5_000 });
+ const posts = server.posts.filter((post) => post.path === '/api/settings' && 'sidebarOrder' in post.body);
+ assert.deepEqual(posts.at(-1)?.body.sidebarOrder, moved, '新顺序没有写进设置');
+ assert.equal(await page.locator('#drawer [data-dragging], #drawer [data-drop]').count(), 0, '松手后拖动标记没有清掉');
+
+ await page.reload({ waitUntil: 'load' });
+ await page.locator('#drawer [data-sidebar-nav] [data-nav]').first().waitFor({ timeout: 15_000 });
+ await settle(page);
+ assert.deepEqual(await navKeys(page), moved, '刷新之后侧栏回到了旧顺序');
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('首页与实体页各按自己的口径列内容标签与计数;点一枚 chip 就按下并进地址', { timeout: 60_000 }, async () => {
+ const opened = await visit(browser, '/', DESKTOP);
+ const { page } = opened;
+ try {
+ const seen = await scopeFacets(page);
+ await page.reload({ waitUntil: 'load' });
+ await page.locator('#drawer [data-sidebar-group="内容标签"]').waitFor({ state: 'attached', timeout: 15_000 });
+ await settle(page);
+ assert.deepEqual(await chips(page, '内容标签'), HOME_TAGS.map(([k, n]) => [k, String(n)]), '首页的内容标签不是全库那一份');
+ assert.ok((await chips(page, '来源')).some(([value, count]) => value === 'local' && Number(count) > 0), '来源那一组没有本机的计数');
+
+ await openGroup(page, '内容标签');
+ const chip = page.locator(`#drawer [data-sidebar-chip][data-key="tag"][data-val="${HOME_TAGS[0][0]}"]`);
+ await chip.click();
+ await page.waitForFunction((tag) => new URL(location.href).searchParams.get('tag') === tag, HOME_TAGS[0][0], { timeout: 5_000 });
+ await page.locator(`#drawer [data-sidebar-chip][data-val="${HOME_TAGS[0][0]}"][aria-pressed="true"]`).waitFor({ timeout: 5_000 });
+ assert.ok(seen.some((query) => new URLSearchParams(query).get('tag') === HOME_TAGS[0][0]), '按下 chip 之后聚合没有按这条筛选重取');
+
+ await serveEntity(page);
+ await page.goto(new URL(`/performers/${encodeURIComponent(PERFORMER)}`, page.url()).toString(), { waitUntil: 'load' });
+ await page.locator('#drawer [data-sidebar-group="内容标签"]').waitFor({ state: 'attached', timeout: 15_000 });
+ await settle(page);
+ assert.ok(seen.some((query) => {
+ const params = new URLSearchParams(query);
+ return params.get('scope_kind') === 'performer' && params.get('scope_name') === PERFORMER;
+ }), `实体页没有按实体口径取聚合:${seen.join(' | ')}`);
+ assert.deepEqual(await chips(page, '内容标签'), ENTITY_TAGS.map(([k, n]) => [k, String(n)]), '实体页列的不是这个实体的计数');
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await page.unrouteAll({ behavior: 'ignoreErrors' });
+ await opened.close();
+ }
+ });
+
+ it('关注页按这一版条目数标签,关注详情只列这一条的标签、每枚计 1', { timeout: 60_000 }, async () => {
+ const opened = await openFollowFeed(browser, '/follow', DESKTOP);
+ const { page } = opened;
+ try {
+ await page.locator('#drawer [data-sidebar-group="内容标签"] [data-follow-drawer-tag]').first().waitFor({ state: 'attached', timeout: 10_000 });
+ const listed = await chips(page, '内容标签');
+ const shown = await page.locator('[data-follow-list] > [data-follow-item]').count();
+ assert.ok(listed.length > 1, '关注页的标签组是空的');
+ assert.ok(listed.every(([, count]) => Number(count) >= 1), `关注页有标签没带计数:${JSON.stringify(listed)}`);
+ assert.equal(listed.reduce((sum, [, count]) => sum + Number(count), 0), shown * 2,
+ '每条更新两枚标签,计数之和应是条目数的两倍');
+
+ await page.locator('[data-follow-item="1002"] [data-follow-open]').click();
+ await page.locator('#stage[open] [data-follow-detail-side]').waitFor({ timeout: 10_000 });
+ await page.waitForFunction(() => document.querySelectorAll('#drawer [data-follow-drawer-tag]').length === 2, undefined, { timeout: 5_000 });
+ assert.deepEqual((await chips(page, '内容标签')).sort(), [['3d', '1'], ['outdoor', '1']], '关注详情列的不是这一条的标签');
+ await page.locator('#closeStage').click();
+ await page.waitForFunction((count) => document.querySelectorAll('#drawer [data-follow-drawer-tag]').length === count,
+ listed.length, { timeout: 5_000 });
+ assert.deepEqual(await chips(page, '内容标签'), listed, '关掉详情之后关注页的标签计数变了');
+
+ /* 抽屉里的关注标签是单选:点一枚就只按这一枚筛,抽屉随之收起,让出来的是筛过的列表。 */
+ await openGroup(page, '内容标签');
+ const [tag] = listed[0]!;
+ await page.locator(`#drawer [data-follow-drawer-tag="${tag}"]`).click();
+ await page.waitForFunction((want) => new URL(location.href).searchParams.get('tag') === want
+ && !document.querySelector('#drawer')?.classList.contains('open'), tag, { timeout: 5_000 });
+ await page.locator('#filterBtn').click();
+ await page.locator(`#drawer.open [data-follow-drawer-tag="${tag}"][aria-pressed="true"]`).waitFor({ timeout: 5_000 });
+ const pressed = await page.locator('#drawer [data-follow-drawer-tag][aria-pressed="true"]').count();
+ assert.equal(pressed, 1, '关注标签按下了不止一枚');
+ assert.deepEqual(withoutPlayer(opened.problems), []);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('作品详情开着时侧栏只剩导航,关掉之后列表那几组原样回来', { timeout: 60_000 }, async () => {
+ const opened = await openItemPage(browser, '/', DESKTOP, { ready: `#grid [data-media-card][data-id="${ITEM.plain}"]` });
+ const { page } = opened;
+ try {
+ await page.locator('#drawer [data-sidebar-group]').first().waitFor({ state: 'attached', timeout: 10_000 });
+ const groups = () => page.locator('#drawer [data-sidebar-group]').evaluateAll((nodes) => nodes.map((node) => node.getAttribute('data-sidebar-group')));
+ const before = await groups();
+ const sources = await chips(page, '来源');
+ assert.ok(before.length > 1, `首页的分组不全:${before.join('、')}`);
+ await page.locator(`#grid [data-media-card][data-id="${ITEM.plain}"] [data-media-title]`).first().click();
+ await page.locator('#stage[open] [data-item-side]').waitFor({ timeout: 10_000 });
+ assert.deepEqual(await groups(), [], '详情开着时侧栏还挂着列表的筛选分组');
+ assert.ok((await navKeys(page)).includes(''), '详情开着时导航那一列不在了');
+ await page.locator('#closeStage').click();
+ await page.waitForFunction((want) => JSON.stringify([...document.querySelectorAll('#drawer [data-sidebar-group]')]
+ .map((node) => node.getAttribute('data-sidebar-group'))) === want, JSON.stringify(before), { timeout: 10_000 });
+ assert.deepEqual(await chips(page, '来源'), sources, '关掉详情之后来源那一组的计数变了');
+ assert.deepEqual(withoutPlayer(opened.problems), []);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('切页时当前项底下那块玻璃是同一个节点,从旧项一路滑到新项,中途不被打断', { timeout: 60_000 }, async () => {
+ const opened = await visit(browser, '/', DESKTOP);
+ const { page } = opened;
+ try {
+ await expectBody(page, '首页', [page.locator('#drawer.open [data-sidebar-nav] [aria-pressed="true"]')]);
+ await page.locator('#drawer [data-sidebar-group]').first().waitFor({ state: 'attached', timeout: 15_000 });
+ await settle(page);
+ await page.emulateMedia({ reducedMotion: 'no-preference' });
+ for (const key of ['performers', 'tags', '']) {
+ const run = await page.evaluate(async (target) => {
+ const glide = document.querySelector<HTMLElement>('#drawer > [data-sidebar-glide]')!;
+ (glide as unknown as { __mark: boolean }).__mark = true;
+ const seen = new Set<Animation>();
+ let cancelled = 0;
+ const watch = () => glide.getAnimations().forEach((animation) => {
+ if (seen.has(animation)) return;
+ seen.add(animation);
+ animation.addEventListener('cancel', () => { cancelled += 1 });
+ });
+ const from = glide.getBoundingClientRect().top;
+ document.querySelector<HTMLElement>(`#drawer [data-sidebar-nav] [data-nav="${target}"]`)!.click();
+ watch();
+ const started = seen.size;
+ const tops: number[] = [];
+ await new Promise<void>((done) => {
+ const begin = performance.now();
+ const tick = () => {
+ watch();
+ tops.push(glide.getBoundingClientRect().top);
+ if (performance.now() - begin < 900) requestAnimationFrame(tick); else done();
+ };
+ requestAnimationFrame(tick);
+ });
+ const now = document.querySelector('#drawer > [data-sidebar-glide]') as (HTMLElement & { __mark?: boolean }) | null;
+ const pressed = document.querySelector<HTMLElement>('#drawer [data-sidebar-nav] [aria-pressed="true"]')!;
+ return {
+ same: !!now?.__mark, started, cancelled, from, to: now!.getBoundingClientRect().top,
+ pressedKey: pressed.dataset.nav, pressedTop: pressed.getBoundingClientRect().top,
+ between: tops.some((top) => Math.min(from, pressed.getBoundingClientRect().top) + 4 < top
+ && top < Math.max(from, pressed.getBoundingClientRect().top) - 4),
+ };
+ }, key);
+ assert.equal(run.pressedKey, key, `点了 ${key || '首页'} 之后按下的不是它`);
+ assert.ok(run.same, '切页之后那块玻璃换了节点,位移会从头起跑');
+ assert.ok(run.started > 0, `切到 ${key || '首页'} 时玻璃没有起动画`);
+ assert.equal(run.cancelled, 0, `切到 ${key || '首页'} 的途中玻璃的动画被掐断了`);
+ assert.ok(run.between, `切到 ${key || '首页'} 时玻璃没有经过中间的位置,是瞬移过去的`);
+ assert.ok(Math.abs(run.to - run.pressedTop) <= 1, `玻璃停在 ${run.to},当前项在 ${run.pressedTop}`);
+ }
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('手机宽度下抽屉收着、点开盖在页面上,点遮罩或点导航都收回去;滚动层仍挂着覆盖式滚动条', { timeout: 60_000 }, async () => {
+ const opened = await visit(browser, '/', PHONE);
+ const { page } = opened;
+ try {
+ await page.locator('#drawer [data-sidebar-nav] [data-nav]').first().waitFor({ state: 'attached', timeout: 15_000 });
+ await settle(page);
+ const state = () => page.evaluate(() => {
+ const drawer = document.querySelector<HTMLElement>('#drawer')!;
+ return {
+ open: drawer.classList.contains('open'), inert: drawer.inert,
+ expanded: document.querySelector('#filterBtn')!.getAttribute('aria-expanded'),
+ scrim: getComputedStyle(document.querySelector('#scrim')!).display,
+ left: Math.round(drawer.getBoundingClientRect().left),
+ };
+ });
+ const closed = await state();
+ assert.equal(closed.open, false, '手机上一进来抽屉就开着');
+ assert.equal(closed.inert, true, '收着的抽屉没有 inert,Tab 会走进屏幕外面');
+ assert.equal(closed.scrim, 'none', '抽屉收着时遮罩还在渲染树里');
+ assert.ok(closed.left < 0, '收着的抽屉没有移出屏幕');
+
+ await page.locator('#filterBtn').tap();
+ await page.waitForFunction(() => document.querySelector('#drawer')?.classList.contains('open'));
+ const shown = await state();
+ assert.deepEqual([shown.inert, shown.expanded, shown.scrim, shown.left], [false, 'true', 'block', 12], '点开之后抽屉没有盖进来');
+
+ assert.equal(await page.evaluate(() => document.elementFromPoint(370, 420)?.id), 'scrim', '抽屉右边那一截点到的不是遮罩');
+ await page.mouse.click(370, 420);
+ await page.waitForFunction(() => !document.querySelector('#drawer')?.classList.contains('open'));
+ assert.deepEqual((await state()).scrim, 'none', '点遮罩收起之后遮罩没退出渲染树');
+
+ await page.locator('#filterBtn').tap();
+ await page.waitForFunction(() => document.querySelector('#drawer')?.classList.contains('open'));
+ await page.locator('#drawer [data-sidebar-nav] [data-nav="tags"]').tap();
+ await page.waitForFunction(() => location.pathname === '/tags' && !document.querySelector('#drawer')?.classList.contains('open'),
+ undefined, { timeout: 5_000 });
+
+ const scroller = await page.evaluate(() => {
+ const scroll = document.querySelector<HTMLElement>('#drawerScroll')!;
+ const drawer = document.querySelector<HTMLElement>('#drawer')!;
+ return {
+ parent: scroll.parentElement?.id, overflow: getComputedStyle(scroll).overflowY,
+ drawerOverflow: getComputedStyle(drawer).overflowY,
+ nav: !!scroll.querySelector(':scope > [data-sidebar-nav]'),
+ tracks: drawer.querySelectorAll(':scope > .ovtrack').length,
+ };
+ });
+ assert.deepEqual(scroller, { parent: 'drawer', overflow: 'auto', drawerOverflow: 'hidden', nav: true, tracks: 2 },
+ '滚的不是抽屉里那一层,或覆盖式滚动条没有接在它上面');
+ assert.deepEqual(opened.problems, []);
+ } finally {
+ await opened.close();
+ }
+ });
+});