kindergarten_java/lesingle-edu-reading-platform-frontend/tests/e2e/teacher/04-courses.spec.ts

105 lines
3.3 KiB
TypeScript
Raw Normal View History

2026-03-17 10:38:51 +08:00
/**
* E2E -
*/
import { test, expect } from '@playwright/test';
import { loginAsTeacher, clickSubMenu, waitForTable } from './helpers';
test.describe('教师端课程列表功能', () => {
test.beforeEach(async ({ page }) => {
await loginAsTeacher(page);
});
test('验证课程列表页面加载', async ({ page }) => {
// 导航到课程列表页面
await clickSubMenu(page, '', '课程中心');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(2000);
// 验证页面标题
const hasTitle = await page.getByText(/课程 | 教学课程/).count() > 0;
test.info().annotations.push({
type: hasTitle ? 'success' : 'warning',
description: `课程标题:${hasTitle ? '存在' : '不存在'}`,
});
});
test('验证课程数据加载', async ({ page }) => {
// 导航到课程列表页面
await clickSubMenu(page, '', '课程中心');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(3000);
// 检查是否有课程数据
const hasCourseList = await page.locator('[class*="course"], [class*="card"], table').count() > 0;
const hasEmpty = await page.getByText(/暂无数据 | 暂无课程/).count() > 0;
test.info().annotations.push({
type: 'info',
description: `课程数据:${hasCourseList ? '存在' : hasEmpty ? '空状态' : '未知'}`,
});
});
test('验证课程详情查看', async ({ page }) => {
// 导航到课程列表页面
await clickSubMenu(page, '', '课程中心');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(2000);
// 查找第一个课程并点击查看
const firstCourse = page.locator('[class*="course-card"], [class*="course-item"], table tbody tr').first();
const hasCourse = await firstCourse.count() > 0;
if (hasCourse) {
// 尝试点击查看课程详情
await firstCourse.click();
await page.waitForTimeout(2000);
// 验证是否进入课程详情页
const hasDetailPage = await page.locator('[class*="course-detail"], [class*="detail"]').count() > 0;
test.info().annotations.push({
type: 'info',
description: `课程详情页:${hasDetailPage ? '存在' : '不存在'}`,
});
} else {
test.info().annotations.push({
type: 'warning',
description: '没有找到课程数据',
});
}
});
test('验证课程筛选功能', async ({ page }) => {
// 导航到课程列表页面
await clickSubMenu(page, '', '课程中心');
2026-03-17 10:38:51 +08:00
// 等待页面加载
await page.waitForTimeout(2000);
// 查找筛选器
const hasFilter = await page.locator('[class*="filter"], [class*="search"], .ant-input, .ant-select').count() > 0;
test.info().annotations.push({
type: 'info',
description: `筛选功能:${hasFilter ? '存在' : '不存在'}`,
});
});
test('截图保存课程列表状态', async ({ page }) => {
// 导航到课程列表页面(教师端菜单为"课程中心"
await clickSubMenu(page, '', '课程中心');
2026-03-17 10:38:51 +08:00
// 等待页面完全加载
await page.waitForTimeout(3000);
// 截图
await page.screenshot({ path: 'test-results/teacher-courses.png' });
test.info().annotations.push({
type: 'success',
description: '课程列表截图已保存',
});
});
});