/** * ================================================================ * 场景:活动管理 E2E 测试 * ================================================================ * 目标:管理员通过 cfc-web Element UI 管理后台管理活动 * 部署地址:http://localhost:8082 * * 路由映射: * 活动列表 → /activities * 活动编辑 → /activity-edit * 活动审核 → /activity-review * 报名审核 → /activity-registration-review * ================================================================ * * v11 更新:活动工作流状态机 * draft → submitForReview → pending → published * published → withdraw → withdrawn * rejected → reDraft → draft */ const { test, expect } = require('@playwright/test'); async function ensureLoggedIn(page) { const sidebar = page.locator('.sidebar-container, .el-menu-vertical-demo, .el-aside'); if (await sidebar.isVisible({ timeout: 3000 }).catch(() => false)) { return; } await page.goto('/login'); await page.waitForSelector('.el-input__inner', { timeout: 15000 }); await page.fill('.el-input__inner', 'admin', { timeout: 5000 }); const passwordInputs = page.locator('.el-input__inner').filter({ hasPlaceholder: /密码/ }); if (await passwordInputs.count() > 0) { await passwordInputs.first().fill('admin123'); } else { const inputs = page.locator('.el-input__inner'); const count = await inputs.count(); if (count >= 2) { await inputs.nth(1).fill('admin123'); } } await page.click('.el-button--primary.login-btn, .el-button[type="primary"]:not(.skip)'); await page.waitForURL(/\/dashboard|\/admin\/dashboard/, { timeout: 15000 }); } test.describe('【场景流程】活动管理全流程', () => { test('[场景1] 管理员查看活动列表', async ({ page }) => { await ensureLoggedIn(page); await page.goto('/activities'); await page.waitForLoadState('networkidle'); await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); }); test('[场景2] 管理员查看活动审核', async ({ page }) => { await ensureLoggedIn(page); await page.goto('/activity-review'); await page.waitForLoadState('networkidle'); await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); }); test('[场景3] 管理员查看报名审核', async ({ page }) => { await ensureLoggedIn(page); await page.goto('/activity-registration-review'); await page.waitForLoadState('networkidle'); await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); }); // ================================================================ // v11 新增:活动工作流测试(需前端运行后执行) // ================================================================ test('[场景4] 创建活动草稿 → 提交审核', async ({ page }) => { await ensureLoggedIn(page); await page.goto('/activity-edit'); await page.waitForLoadState('networkidle'); // 填写活动基本信息 const titleInput = page.locator('input').first(); await titleInput.fill('E2E_自动测试活动_' + Date.now()); // 保存草稿 const saveBtn = page.locator('button').filter({ hasText: /保存/ }).first(); await saveBtn.click(); await page.waitForTimeout(1500); // 如果有提交审核按钮 const submitBtn = page.locator('button').filter({ hasText: /提交审核/ }); if (await submitBtn.isVisible({ timeout: 2000 }).catch(() => false)) { await submitBtn.click(); await page.waitForTimeout(1000); } await expect(page.locator('.el-message--error, .el-form-item__error')).not.toBeVisible(); }); test('[场景5] 查看活动审核列表 → 审核操作可用', async ({ page }) => { await ensureLoggedIn(page); await page.goto('/activity-review'); await page.waitForLoadState('networkidle'); // 查找待审核状态的活动 const pendingRows = page.locator('.el-table__row').filter({ hasText: 'pending' }); const count = await pendingRows.count(); if (count > 0) { // 应该有通过/驳回按钮 const approveBtn = page.locator('button').filter({ hasText: /通过|批准/ }); const rejectBtn = page.locator('button').filter({ hasText: /驳回/ }); if (await approveBtn.isVisible({ timeout: 1000 }).catch(() => false)) { out += '[INFO] Activity approve button visible\n'; } } await expect(page.locator('.el-message--error')).not.toBeVisible(); }); });