test: settle SPA state after org selection in loginAsStudent

The previous loginAsStudent only waited 2s after org switch, but
on subsequent page.goto the route guard re-evaluated and could
redirect away. Navigate to a known student page to settle the
Vue app state, matching the pattern in teacher-switching.spec.ts.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 17:06:48 +08:00
parent df645b70a7
commit 593869e939
+7 -4
View File
@@ -255,10 +255,13 @@ async function loginAsStudent(page: any, moicenUnionid: string) {
if (await page.locator('.course-package-store').isVisible().catch(() => false)) {
return false; // session not usable
}
const orgCell = page.locator('#app .van-cell-group .van-cell').first();
if (await orgCell.isVisible({ timeout: 5000 }).catch(() => false)) {
await orgCell.click();
await page.waitForTimeout(2000);
const firstOrgCell = page.locator('#app .van-cell-group .van-cell').first();
if (await firstOrgCell.isVisible({ timeout: 10_000 }).catch(() => false)) {
await firstOrgCell.click();
// Navigate to a known student page to settle SPA state after org switch
await page.waitForURL(/\/student\/|\//, { timeout: 15_000 });
await page.goto('/student/profile', { waitUntil: 'domcontentloaded', timeout: 60_000 });
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
}
}
return true;