test: add E2E tests for teacher selection flow and role switch
- Add test: switching from teacher to student auto-selects teacher - Add test: teacher selection doesn't loop back to org select - Update existing tests to verify auto-select behavior - Verify teacher name displayed (not "未选择老师") on profile Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,9 @@ test.describe('学生老师切换', () => {
|
|||||||
const teacherText = await teacherSection.locator('span').first().textContent();
|
const teacherText = await teacherSection.locator('span').first().textContent();
|
||||||
expect(teacherText).toContain('当前老师');
|
expect(teacherText).toContain('当前老师');
|
||||||
|
|
||||||
|
// Verify auto-select: teacher name should be displayed (not "未选择老师")
|
||||||
|
expect(teacherText).not.toContain('未选择老师');
|
||||||
|
|
||||||
// Check switch button
|
// Check switch button
|
||||||
const switchBtn = teacherSection.locator('.van-button');
|
const switchBtn = teacherSection.locator('.van-button');
|
||||||
await expect(switchBtn).toBeVisible({ timeout: 10_000 });
|
await expect(switchBtn).toBeVisible({ timeout: 10_000 });
|
||||||
@@ -155,4 +158,150 @@ test.describe('学生老师切换', () => {
|
|||||||
const teacherCount = await teacherCells.count();
|
const teacherCount = await teacherCells.count();
|
||||||
expect(teacherCount).toBeGreaterThan(0);
|
expect(teacherCount).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('从老师切换到学生角色后显示老师选择页面', async ({ page }) => {
|
||||||
|
test.setTimeout(180_000);
|
||||||
|
|
||||||
|
// Login as student to establish session
|
||||||
|
await loginAsStudent(page);
|
||||||
|
|
||||||
|
// Navigate to profile
|
||||||
|
await page.goto('/student/profile', {
|
||||||
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 60_000,
|
||||||
|
});
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
|
// Click the role switcher icon
|
||||||
|
const roleSwitcher = page.locator('.van-icon-exchange');
|
||||||
|
if (!(await roleSwitcher.isVisible().catch(() => false))) {
|
||||||
|
test.skip(true, '未找到角色切换按钮');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await roleSwitcher.click();
|
||||||
|
await page.waitForTimeout(1000);
|
||||||
|
|
||||||
|
// Select TEACHER role
|
||||||
|
const teacherRoleBtn = page.locator('.van-action-sheet__item').filter({ hasText: '老师' });
|
||||||
|
if (!(await teacherRoleBtn.isVisible().catch(() => false))) {
|
||||||
|
test.skip(true, '未找到老师角色选项');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await teacherRoleBtn.click();
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
|
||||||
|
// Handle confirm dialog if shown
|
||||||
|
const confirmDialog = page.locator('.van-dialog__confirm');
|
||||||
|
if (await confirmDialog.isVisible().catch(() => false)) {
|
||||||
|
await confirmDialog.click();
|
||||||
|
await page.waitForTimeout(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for role switch to complete
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
|
// Navigate to teacher profile to ensure we're in teacher context
|
||||||
|
await page.goto('/teacher/profile', {
|
||||||
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 60_000,
|
||||||
|
});
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
|
if (await page.getByText('请返回微信小程序完成登录').isVisible().catch(() => false)) {
|
||||||
|
test.skip(true, '老师会话不可用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now switch back to STUDENT role
|
||||||
|
const roleSwitcher2 = page.locator('.van-icon-exchange');
|
||||||
|
if (!(await roleSwitcher2.isVisible().catch(() => false))) {
|
||||||
|
test.skip(true, '未找到角色切换按钮');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await roleSwitcher2.click();
|
||||||
|
await page.waitForTimeout(1000);
|
||||||
|
|
||||||
|
// Select STUDENT role
|
||||||
|
const studentRoleBtn = page.locator('.van-action-sheet__item').filter({ hasText: '学生' });
|
||||||
|
if (!(await studentRoleBtn.isVisible().catch(() => false))) {
|
||||||
|
test.skip(true, '未找到学生角色选项');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await studentRoleBtn.click();
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
|
||||||
|
// Handle confirm dialog
|
||||||
|
const confirmDialog2 = page.locator('.van-dialog__confirm');
|
||||||
|
if (await confirmDialog2.isVisible().catch(() => false)) {
|
||||||
|
await confirmDialog2.click();
|
||||||
|
await page.waitForTimeout(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for role switch to complete
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
await page.waitForTimeout(5000);
|
||||||
|
|
||||||
|
// We should be on teacher-select page or index page (both show teacher selection)
|
||||||
|
const currentPath = new URL(page.url()).pathname;
|
||||||
|
const validPaths = ['/student/teacher-select', '/'];
|
||||||
|
expect(validPaths).toContain(currentPath);
|
||||||
|
|
||||||
|
// Verify we did NOT end up on org-select page
|
||||||
|
expect(currentPath).not.toBe('/org/select');
|
||||||
|
|
||||||
|
// Verify teacher selection UI is present
|
||||||
|
if (currentPath === '/student/teacher-select') {
|
||||||
|
await expect(page.locator('.van-cell').first()).toBeVisible({ timeout: 10_000 });
|
||||||
|
// Select a teacher
|
||||||
|
await page.locator('.van-cell').first().click();
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
|
// After selection, verify we're NOT on org-select
|
||||||
|
const afterPath = new URL(page.url()).pathname;
|
||||||
|
expect(afterPath).not.toBe('/org/select');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('老师选择后不会回到机构选择页面', async ({ page }) => {
|
||||||
|
test.setTimeout(180_000);
|
||||||
|
|
||||||
|
// Login as student
|
||||||
|
await loginAsStudent(page);
|
||||||
|
|
||||||
|
// Navigate to profile and find teacher section
|
||||||
|
await page.goto('/student/profile', {
|
||||||
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 60_000,
|
||||||
|
});
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
|
// Click switch teacher button
|
||||||
|
const switchBtn = page.locator('.current-teacher .van-button');
|
||||||
|
if (!(await switchBtn.isVisible().catch(() => false))) {
|
||||||
|
test.skip(true, '未找到切换老师按钮');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await switchBtn.click();
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
|
// Verify teacher list shows
|
||||||
|
const teacherCells = page.locator('.van-cell');
|
||||||
|
const teacherCount = await teacherCells.count();
|
||||||
|
expect(teacherCount).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// Select a teacher
|
||||||
|
await teacherCells.first().click();
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
|
// Verify we didn't end up on org-select
|
||||||
|
const afterUrl = page.url();
|
||||||
|
expect(afterUrl).not.toContain('/org/select');
|
||||||
|
|
||||||
|
// Should still be on a valid student page
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user