import { expect, type Locator, type Page } from '@playwright/test'; /** * 返回当前视口下真正可用的一级导航容器(桌面顶栏 / 已展开的移动抽屉)。 * * 桌面 project 的 `desktop-navigation` 是 SSR 直出的 ``,无需 hydration;移动 project 的 * 抽屉只在 `isOpen` 时挂载,而按钮 `onClick` 要等 React hydration 才生效,首屏 * `waitUntil: 'domcontentloaded'` 之后的首击可能被吞(全量并发跑时 chromium-mobile 实测)。 * 这里按「未可见才点击」幂等地重试,重复点击不会把抽屉关掉。 * * 返回容器而非链接列表:桌面导航里「产品 / 解决方案」是下拉触发器,文案不一定落在 `` 上。 */ export async function primaryNav(page: Page): Promise { 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; }