2026-04-30 23:50:46 +08:00
|
|
|
import { expect, test } from './fixtures';
|
|
|
|
|
|
|
|
|
|
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
|
|
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
test.describe('学生老师切换', () => {
|
2026-04-30 23:50:46 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
async function loginAsStudent(page: import('@playwright/test').Page) {
|
|
|
|
|
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 });
|
|
|
|
|
// Wait for SPA to settle and login/role resolution to complete
|
|
|
|
|
await page.waitForTimeout(5000);
|
|
|
|
|
|
|
|
|
|
// Pick STUDENT role explicitly
|
|
|
|
|
const roleSelect = page.getByText('请选择您的登录身份');
|
|
|
|
|
if (await roleSelect.isVisible().catch(() => false)) {
|
|
|
|
|
const studentRole = page.locator('.van-grid-item').filter({ hasText: '学生' });
|
|
|
|
|
if (await studentRole.isVisible().catch(() => false)) {
|
|
|
|
|
await studentRole.click();
|
|
|
|
|
await page.waitForTimeout(5000);
|
|
|
|
|
}
|
2026-04-30 23:55:49 +08:00
|
|
|
}
|
2026-04-30 23:50:46 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
// Handle org select if needed
|
|
|
|
|
if (page.url().includes('/org/select')) {
|
|
|
|
|
const guest = page.getByText('请返回微信小程序完成登录');
|
|
|
|
|
if (await guest.isVisible().catch(() => false)) {
|
|
|
|
|
test.skip(true, '会话不可用');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const orgCells = page.locator('#app .van-cell-group .van-cell');
|
|
|
|
|
const n = await orgCells.count();
|
|
|
|
|
expect(n).toBeGreaterThan(0);
|
|
|
|
|
await orgCells.first().click();
|
|
|
|
|
await page.waitForTimeout(5000);
|
|
|
|
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
2026-04-30 23:50:46 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
if (await guest.isVisible().catch(() => false)) {
|
|
|
|
|
test.skip(true, 'org switch 后会话不可用');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-04-30 23:50:46 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
await page.goto('/student/profile', {
|
|
|
|
|
waitUntil: 'domcontentloaded',
|
|
|
|
|
timeout: 60_000,
|
|
|
|
|
});
|
|
|
|
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure we're on a 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 });
|
2026-04-30 23:55:49 +08:00
|
|
|
}
|
2026-04-30 23:50:46 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
// Skip if session lost
|
2026-04-30 23:50:46 +08:00
|
|
|
if (
|
|
|
|
|
await page
|
2026-04-30 23:55:49 +08:00
|
|
|
.getByText('请返回微信小程序完成登录')
|
2026-04-30 23:50:46 +08:00
|
|
|
.isVisible()
|
|
|
|
|
.catch(() => false)
|
|
|
|
|
) {
|
2026-05-01 00:39:22 +08:00
|
|
|
test.skip(true, '无法以学生身份访问 profile');
|
|
|
|
|
return;
|
2026-04-30 23:50:46 +08:00
|
|
|
}
|
2026-05-01 00:39:22 +08:00
|
|
|
}
|
2026-04-30 23:50:46 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
test('profile 页显示当前老师且可切换', async ({ page }) => {
|
|
|
|
|
test.setTimeout(180_000);
|
2026-04-30 23:55:49 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
await loginAsStudent(page);
|
2026-04-30 23:55:49 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
// Navigate to student profile
|
2026-04-30 23:50:46 +08:00
|
|
|
await page.goto('/student/profile', {
|
|
|
|
|
waitUntil: 'domcontentloaded',
|
|
|
|
|
timeout: 60_000,
|
|
|
|
|
});
|
|
|
|
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
2026-05-01 00:39:22 +08:00
|
|
|
await page.waitForTimeout(3000);
|
2026-04-30 23:55:49 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
// Find the teacher section
|
2026-04-30 23:50:46 +08:00
|
|
|
const teacherSection = page.locator('.current-teacher');
|
2026-05-01 00:39:22 +08:00
|
|
|
const teacherVisible = await teacherSection
|
|
|
|
|
.isVisible()
|
|
|
|
|
.catch(() => false);
|
2026-04-30 23:50:46 +08:00
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
if (!teacherVisible) {
|
|
|
|
|
const profileHeader = page.locator('.info');
|
|
|
|
|
const profileVisible = await profileHeader.isVisible().catch(() => false);
|
|
|
|
|
if (!profileVisible) {
|
|
|
|
|
test.skip(true, '未到 profile 页');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
test.skip(true, '学生角色无老师信息');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const teacherText = await teacherSection.locator('span').first().textContent();
|
2026-04-30 23:50:46 +08:00
|
|
|
expect(teacherText).toContain('当前老师');
|
|
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
// Check switch button
|
2026-04-30 23:50:46 +08:00
|
|
|
const switchBtn = teacherSection.locator('.van-button');
|
|
|
|
|
await expect(switchBtn).toBeVisible({ timeout: 10_000 });
|
|
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
// Click switch and verify teacher list
|
2026-04-30 23:50:46 +08:00
|
|
|
await switchBtn.click();
|
|
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
|
|
|
|
|
|
const teacherCells = page.locator('.van-cell');
|
|
|
|
|
const teacherCount = await teacherCells.count();
|
|
|
|
|
expect(teacherCount).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
|
|
if (teacherCount > 1) {
|
|
|
|
|
await teacherCells.nth(1).click();
|
|
|
|
|
await page.waitForTimeout(1500);
|
|
|
|
|
|
2026-05-01 00:39:22 +08:00
|
|
|
const updatedSection = page.locator('.current-teacher');
|
|
|
|
|
await expect(updatedSection).toBeVisible({ timeout: 15_000 });
|
|
|
|
|
const newText = await updatedSection.locator('span').first().textContent();
|
|
|
|
|
expect(newText).not.toContain('未选择老师');
|
2026-04-30 23:50:46 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('「我的老师」列表显示本机构老师', async ({ page }) => {
|
|
|
|
|
test.setTimeout(180_000);
|
|
|
|
|
|
2026-04-30 23:55:49 +08:00
|
|
|
await loginAsStudent(page);
|
2026-04-30 23:50:46 +08:00
|
|
|
|
|
|
|
|
// Navigate to my teachers page
|
|
|
|
|
await page.goto('/student/teachers', {
|
|
|
|
|
waitUntil: 'domcontentloaded',
|
|
|
|
|
timeout: 60_000,
|
|
|
|
|
});
|
|
|
|
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
2026-05-01 00:39:22 +08:00
|
|
|
await page.waitForTimeout(3000);
|
2026-04-30 23:50:46 +08:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
await page
|
|
|
|
|
.getByText('请返回微信小程序完成登录')
|
|
|
|
|
.isVisible()
|
|
|
|
|
.catch(() => false)
|
|
|
|
|
) {
|
2026-05-01 00:39:22 +08:00
|
|
|
test.skip(true, '会话已过期');
|
2026-04-30 23:50:46 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const teacherCells = page.locator('.van-cell');
|
|
|
|
|
const teacherCount = await teacherCells.count();
|
|
|
|
|
expect(teacherCount).toBeGreaterThan(0);
|
|
|
|
|
});
|
|
|
|
|
});
|