test: always settle on /student/profile after loginAsStudent
Match teacher-switching.spec.ts: navigate to a settled student page even when no org-select page appears, so the route guard fully initializes org context before subsequent test navigation. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -258,12 +258,25 @@ async function loginAsStudent(page: any, moicenUnionid: string) {
|
||||
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 });
|
||||
await page.waitForTimeout(3000);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we're on a settled student page
|
||||
const currentPath = new URL(page.url()).pathname;
|
||||
if (!currentPath.startsWith('/student/')) {
|
||||
await page.goto('/student/profile', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 60_000,
|
||||
});
|
||||
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||
}
|
||||
|
||||
// Skip if session lost
|
||||
if (await page.getByText('请返回微信小程序完成登录').isVisible().catch(() => false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user