Skip to content

armgit / peach

Public Imported from GitHub
0

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

test(navigation): 等待当前页面的可见骨架状态

longmeidaoac73b8062013
diff --git a/frontend/e2e/design-cards.test.ts b/frontend/e2e/design-cards.test.ts
index fe13afa63..6698afc62 100644
--- a/frontend/e2e/design-cards.test.ts
+++ b/frontend/e2e/design-cards.test.ts
@@ -268,8 +268,10 @@ describe('设计决定:作品卡、管理页与复核', () => {
return [Math.round(rect.top), Math.round(rect.height)];
};
const lede = document.querySelector<HTMLElement>('[data-manage-lede]');
- const card = document.querySelector('#grid .catalog-skeleton .skeletoncard')
- || document.querySelector('#grid [data-media-card][data-variant="resource"]');
+ const card = [...document.querySelectorAll(
+ '#grid .catalog-skeleton .skeletoncard, #grid [data-media-card][data-variant="resource"]',
+ )].find(node => !node.closest('[data-content-skeleton][aria-hidden="true"], [data-content-current][aria-hidden="true"]')
+ && getComputedStyle(node).visibility === 'visible') ?? null;
/* 读数与「清空回收站」各自的竖直中线:两者说的是同一批文件,同在说明行一行里。 */
const middle = (element: Element | null | undefined) => {
if (!element) return null;
diff --git a/frontend/e2e/follow-feed.test.ts b/frontend/e2e/follow-feed.test.ts
index e64a47f45..22e2a23f9 100644
--- a/frontend/e2e/follow-feed.test.ts
+++ b/frontend/e2e/follow-feed.test.ts
@@ -400,11 +400,12 @@ describe('关注页岛', () => {
authors: document.querySelectorAll('button[data-follow-author]').length,
glass: !!document.querySelector('[data-follow-filter-glass]'),
wholePage: !!document.querySelector('#stats .followauthors'),
- skeletons: document.querySelectorAll('[data-skeleton]').length,
+ skeletons: [...document.querySelectorAll('[data-skeleton]')]
+ .filter(node => !node.closest('[data-content-skeleton][aria-hidden="true"]')).length,
}));
assert.deepEqual(during, { head: true, authors: 6, glass: true, wholePage: false, skeletons: 1 });
await opened.stub.release();
- await page.locator('[data-follow-list-body] [data-skeleton]').waitFor({ state: 'detached', timeout: 10_000 });
+ await page.locator('[data-follow-list-body] [data-skeleton]').waitFor({ state: 'hidden', timeout: 10_000 });
await page.locator(CARDS).first().waitFor();
assert.deepEqual(opened.problems, []);
} finally {
diff --git a/frontend/e2e/harness.ts b/frontend/e2e/harness.ts
index 16bbe5da4..3819a6292 100644
--- a/frontend/e2e/harness.ts
+++ b/frontend/e2e/harness.ts
@@ -92,6 +92,7 @@ export async function withPageDiagnostics<T>(page: Page, where: string | (() =>
expanded: node.getAttribute('aria-expanded'), text: node.textContent?.slice(0, 600),
})),
busy: [...document.querySelectorAll('[aria-busy="true"],[data-skeleton]')]
+ .filter(node => !node.closest('[data-content-skeleton][aria-hidden="true"]'))
.slice(0, 12).map(node => ({ tag: node.tagName, id: node.id, label: node.getAttribute('aria-label') })),
})).catch(() => '未取得');
const tree = await page.locator('body').ariaSnapshot({ timeout: 2000 }).catch(() => '未取得');
@@ -115,7 +116,8 @@ export async function settle(page: Page, scope = 'body', { except = '' }: { exce
await page.waitForFunction(
({ selector, except }) => {
const root = document.querySelector(selector);
- const waiting = (node: Element) => node.matches('[aria-busy="true"],[data-skeleton]') && !(except && node.matches(except));
+ const waiting = (node: Element) => node.matches('[aria-busy="true"],[data-skeleton]')
+ && !node.closest('[data-content-skeleton][aria-hidden="true"]') && !(except && node.matches(except));
return !!root && !waiting(root) && ![...root.querySelectorAll('[aria-busy="true"],[data-skeleton]')].some(waiting);
},
{ selector: scope, except }, { timeout: 15_000 });
@@ -123,9 +125,10 @@ export async function settle(page: Page, scope = 'body', { except = '' }: { exce
const pending = await page.evaluate(({ selector, except }) => {
const root = document.querySelector(selector);
if (!root) return { missing_scope: selector };
- const nodes = [...root.querySelectorAll('[aria-busy="true"],[data-skeleton]')]
- .filter(node => !(except && node.matches(except)));
- if (root.matches('[aria-busy="true"],[data-skeleton]')) nodes.unshift(root);
+ const waiting = (node: Element) => node.matches('[aria-busy="true"],[data-skeleton]')
+ && !node.closest('[data-content-skeleton][aria-hidden="true"]') && !(except && node.matches(except));
+ const nodes = [...root.querySelectorAll('[aria-busy="true"],[data-skeleton]')].filter(waiting);
+ if (waiting(root)) nodes.unshift(root);
return nodes.slice(0, 12).map(node => {
const box = node.getBoundingClientRect();
return { tag: node.tagName, id: node.id, skeleton: node.getAttribute('data-skeleton'),