fix(clazz-e2e): increase role dialog wait from 3s to 15s for CI reliability

In CI the "请选择您的登录身份" role selection dialog may take longer
than 3 seconds to appear. The old `waitForTimeout(3000) + isVisible()`
snapshot check missed it, causing no role to be selected. On subsequent
navigation to /clazz the route guard found multiple active roles and
redirected to / instead, making `.view-toolbar` never appear.

Replaced with `waitFor({ state: 'visible', timeout: 15_000 })` which
waits up to 15s for the dialog.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 03:37:42 +08:00
parent 68780b432a
commit e43b0597a1
3 changed files with 24 additions and 13 deletions
+6 -4
View File
@@ -7,19 +7,21 @@ async function loginAsTeacher(page: any) {
const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' });
await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 });
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
await page.waitForTimeout(3000);
// Wait up to 15s for role selection dialog (may not appear if already logged in)
const rs = page.getByText('请选择您的登录身份');
if (await rs.isVisible().catch(() => false)) {
try {
await rs.waitFor({ state: 'visible', timeout: 15_000 });
const items = page.locator('.van-grid-item');
const count = await items.count();
if (count >= 3) {
await items.nth(2).click(); // TEACHER role
await page.waitForTimeout(3000);
} else {
await items.first().click();
await page.waitForTimeout(3000);
}
await page.waitForTimeout(3000);
} catch {
// No role dialog — proceed with default role
}
}
+13 -7
View File
@@ -15,13 +15,17 @@ async function loginAndGetTokens(page: any) {
const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' });
await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 });
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
await page.waitForTimeout(3000);
// Wait up to 15s for role selection dialog (may not appear if already logged in)
const rs = page.getByText('请选择您的登录身份');
if (await rs.isVisible().catch(() => false)) {
try {
await rs.waitFor({ state: 'visible', timeout: 15_000 });
// Select first role (TESTER) for data seeding
const first = page.locator('.van-grid-item').first();
if (await first.isVisible().catch(() => false)) { await first.click(); await page.waitForTimeout(3000); }
await first.click();
await page.waitForTimeout(3000);
} catch {
// No role dialog — proceed with default role
}
return await getAuthTokens(page);
}
@@ -31,20 +35,22 @@ async function loginAsTeacher(page: any) {
const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' });
await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 });
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
await page.waitForTimeout(3000);
// Wait up to 15s for role selection dialog (may not appear if already logged in)
const rs = page.getByText('请选择您的登录身份');
if (await rs.isVisible().catch(() => false)) {
try {
await rs.waitFor({ state: 'visible', timeout: 15_000 });
// Select TEACHER role (index 2 in the grid: 测试员, 学生, 教师, 管理员, 主管教师)
const items = page.locator('.van-grid-item');
const count = await items.count();
if (count >= 3) {
await items.nth(2).click();
await page.waitForTimeout(3000);
} else {
await items.first().click();
await page.waitForTimeout(3000);
}
await page.waitForTimeout(3000);
} catch {
// No role dialog — proceed with default role
}
return await getAuthTokens(page);
}
+5 -2
View File
@@ -18,10 +18,11 @@ test.describe('主管老师矩阵视图', () => {
const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' });
await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 });
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
await page.waitForTimeout(3000);
// Wait up to 15s for role selection dialog (may not appear if already logged in)
const rs = page.getByText('请选择您的登录身份');
if (await rs.isVisible().catch(() => false)) {
try {
await rs.waitFor({ state: 'visible', timeout: 15_000 });
const items = page.locator('.van-grid-item');
const count = await items.count();
if (count >= 3) {
@@ -30,6 +31,8 @@ test.describe('主管老师矩阵视图', () => {
await items.first().click();
}
await page.waitForTimeout(3000);
} catch {
// No role dialog — proceed with default role
}
}