- e2e:修死选择器与蜜罐误命中、补断言、GA4/security-headers 用例诚实标注 skip 边界;新增 assert-helpers/fixtures/hydrated/primary-nav/touch-targets 等复用桩。 - 集成层:config/test/jest.integration.config.js + tests-integration/ 真库 一次性 SQLite 用例,teardown 守卫开发库指纹。 - 门禁工具链:jest.setup 归位到根、scripts/accessibility 全站 axe 节点计数、 check-brand-text-token/check-motion-constraints 机械守卫、stryker/lighthouse 配置收敛。
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { expect, type Locator, type Page } from '@playwright/test';
|
|
|
|
/**
|
|
* 返回当前视口下真正可用的一级导航容器(桌面顶栏 / 已展开的移动抽屉)。
|
|
*
|
|
* 桌面 project 的 `desktop-navigation` 是 SSR 直出的 `<a>`,无需 hydration;移动 project 的
|
|
* 抽屉只在 `isOpen` 时挂载,而按钮 `onClick` 要等 React hydration 才生效,首屏
|
|
* `waitUntil: 'domcontentloaded'` 之后的首击可能被吞(全量并发跑时 chromium-mobile 实测)。
|
|
* 这里按「未可见才点击」幂等地重试,重复点击不会把抽屉关掉。
|
|
*
|
|
* 返回容器而非链接列表:桌面导航里「产品 / 解决方案」是下拉触发器,文案不一定落在 `<a>` 上。
|
|
*/
|
|
export async function primaryNav(page: Page): Promise<Locator> {
|
|
const desktopNav = page.getByTestId('desktop-navigation');
|
|
if (await desktopNav.isVisible()) {
|
|
return desktopNav;
|
|
}
|
|
|
|
const button = page.getByTestId('mobile-menu-button');
|
|
const drawer = page.getByTestId('mobile-navigation');
|
|
await expect(async () => {
|
|
if (!(await drawer.isVisible())) {
|
|
await button.click();
|
|
}
|
|
await expect(drawer).toBeVisible({ timeout: 1000 });
|
|
}).toPass({ timeout: 15000 });
|
|
|
|
await expect(drawer.locator('a').first()).toBeVisible({ timeout: 5000 });
|
|
return drawer;
|
|
}
|