From d470e2e95e83f3adfb52973441379d4011ac1978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=94=B7?= Date: Sun, 3 May 2026 07:57:54 +0800 Subject: [PATCH] fix(department-e2e): use waitFor for role selector to avoid race condition Replace one-shot isVisible() with waitFor() to handle the timing gap where the SPA route guard is still resolving roles asynchronously. The role selector renders after the route guard's read() call completes, and isVisible() may return false if called before that. Co-Authored-By: Claude Opus 4.7 --- tests/department-single-transparent.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/department-single-transparent.spec.ts b/tests/department-single-transparent.spec.ts index 5fb361b..4945403 100644 --- a/tests/department-single-transparent.spec.ts +++ b/tests/department-single-transparent.spec.ts @@ -45,12 +45,14 @@ async function loginAndDismissSelectors(page: any) { console.log('[DeptTest] clicked org cell'); await page.waitForTimeout(3_000); } else if (path === '/') { + // 用 waitFor 避免 SPA 路由守卫异步加载角色时的竞态(isVisible 可能返回 false) const rs = page.getByText('请选择您的登录身份'); - if (await rs.isVisible().catch(() => false)) { + try { + await rs.waitFor({ state: 'visible', timeout: 10_000 }); await page.locator('.van-grid-item').first().click(); console.log('[DeptTest] clicked role'); await page.waitForTimeout(3_000); - } else { + } catch { console.log('[DeptTest] at / but no role selector'); // 无角色选择器 → 当前用户角色已自动选中(1个活跃角色)。 // chooseRole 内部调用 router.push('/role/profile') 是异步的,