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 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 07:57:54 +08:00
parent 20be1e6df7
commit d470e2e95e
+4 -2
View File
@@ -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') 是异步的,