kindergarten_java/reading-platform-frontend/tests/e2e/teacher/06-tasks.spec.ts

144 lines
4.7 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, waitForSuccess } from './helpers';
test.describe('教师端任务管理功能', () => {
test.beforeEach(async ({ page }) => {
await loginAsTeacher(page);
});
test('验证任务列表页面加载', async ({ page }) => {
// 导航到任务管理页面
await clickSubMenu(page, '任务管理', '任务列表');
// 等待页面加载
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, '任务管理', '任务列表');
// 等待页面加载
await page.waitForTimeout(3000);
// 检查是否有任务数据
const hasTaskList = await page.locator('[class*="task"], table').count() > 0;
const hasEmpty = await page.getByText(/暂无数据 | 暂无任务/).count() > 0;
test.info().annotations.push({
type: 'info',
description: `任务数据:${hasTaskList ? '存在' : hasEmpty ? '空状态' : '未知'}`,
});
});
test('验证创建任务功能', async ({ page }) => {
// 导航到任务管理页面
await clickSubMenu(page, '任务管理', '任务列表');
// 等待页面加载
await page.waitForTimeout(2000);
// 查找创建按钮
const createBtn = page.getByRole('button', { name: /创建 | 新建 | 添加/ });
const hasCreateBtn = await createBtn.count() > 0;
test.info().annotations.push({
type: 'info',
description: `创建按钮:${hasCreateBtn ? '存在' : '不存在'}`,
});
if (hasCreateBtn) {
// 点击创建按钮
await createBtn.click();
await page.waitForTimeout(1000);
// 验证弹窗是否打开
const hasModal = await page.locator('.ant-modal, [class*="modal"]').count() > 0;
test.info().annotations.push({
type: 'info',
description: `创建弹窗:${hasModal ? '打开' : '未打开'}`,
});
if (hasModal) {
// 验证表单字段
const hasTitleInput = await page.locator('[class*="title"] input, input[placeholder*="标题"]').count() > 0;
const hasTypeSelect = await page.locator('[class*="type"] .ant-select, [class*="taskType"]').count() > 0;
test.info().annotations.push({
type: 'info',
description: `标题输入框:${hasTitleInput ? '存在' : '不存在'}`,
});
test.info().annotations.push({
type: 'info',
description: `任务类型选择:${hasTypeSelect ? '存在' : '不存在'}`,
});
}
}
});
test('验证任务筛选功能', async ({ page }) => {
// 导航到任务管理页面
await clickSubMenu(page, '任务管理', '任务列表');
// 等待页面加载
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 ? '存在' : '不存在'}`,
});
// 查找状态筛选
const hasStatusFilter = await page.getByText(/状态 | 全部 | 进行中 | 已完成/).count() > 0;
test.info().annotations.push({
type: 'info',
description: `状态筛选:${hasStatusFilter ? '存在' : '不存在'}`,
});
});
test('验证任务操作按钮', async ({ page }) => {
// 导航到任务管理页面
await clickSubMenu(page, '任务管理', '任务列表');
// 等待页面加载
await page.waitForTimeout(3000);
// 查找操作按钮(编辑、删除等)
const actionBtns = page.locator('button:has-text("编辑"), button:has-text("删除"), button:has-text("详情")');
const hasActionBtns = await actionBtns.count() > 0;
test.info().annotations.push({
type: 'info',
description: `操作按钮:${hasActionBtns ? '存在' : '不存在'}`,
});
});
test('截图保存任务管理状态', async ({ page }) => {
// 导航到任务管理页面
await clickSubMenu(page, '任务管理', '任务列表');
// 等待页面完全加载
await page.waitForTimeout(3000);
// 截图
await page.screenshot({ path: 'test-results/teacher-tasks.png' });
test.info().annotations.push({
type: 'success',
description: '任务管理截图已保存',
});
});
});