activity-registration.spec.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * ================================================================
  3. * 场景:活动管理 E2E 测试
  4. * ================================================================
  5. * 目标:管理员通过 cfc-web Element UI 管理后台管理活动
  6. * 部署地址:http://localhost:8082
  7. *
  8. * 路由映射:
  9. * 活动列表 → /activities
  10. * 活动编辑 → /activity-edit
  11. * 活动审核 → /activity-review
  12. * 报名审核 → /activity-registration-review
  13. * ================================================================
  14. *
  15. * v11 更新:活动工作流状态机
  16. * draft → submitForReview → pending → published
  17. * published → withdraw → withdrawn
  18. * rejected → reDraft → draft
  19. */
  20. const { test, expect } = require('@playwright/test');
  21. async function ensureLoggedIn(page) {
  22. const sidebar = page.locator('.sidebar-container, .el-menu-vertical-demo, .el-aside');
  23. if (await sidebar.isVisible({ timeout: 3000 }).catch(() => false)) {
  24. return;
  25. }
  26. await page.goto('/login');
  27. await page.waitForSelector('.el-input__inner', { timeout: 15000 });
  28. await page.fill('.el-input__inner', 'admin', { timeout: 5000 });
  29. const passwordInputs = page.locator('.el-input__inner').filter({ hasPlaceholder: /密码/ });
  30. if (await passwordInputs.count() > 0) {
  31. await passwordInputs.first().fill('admin123');
  32. } else {
  33. const inputs = page.locator('.el-input__inner');
  34. const count = await inputs.count();
  35. if (count >= 2) {
  36. await inputs.nth(1).fill('admin123');
  37. }
  38. }
  39. await page.click('.el-button--primary.login-btn, .el-button[type="primary"]:not(.skip)');
  40. await page.waitForURL(/\/dashboard|\/admin\/dashboard/, { timeout: 15000 });
  41. }
  42. test.describe('【场景流程】活动管理全流程', () => {
  43. test('[场景1] 管理员查看活动列表', async ({ page }) => {
  44. await ensureLoggedIn(page);
  45. await page.goto('/activities');
  46. await page.waitForLoadState('networkidle');
  47. await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
  48. });
  49. test('[场景2] 管理员查看活动审核', async ({ page }) => {
  50. await ensureLoggedIn(page);
  51. await page.goto('/activity-review');
  52. await page.waitForLoadState('networkidle');
  53. await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
  54. });
  55. test('[场景3] 管理员查看报名审核', async ({ page }) => {
  56. await ensureLoggedIn(page);
  57. await page.goto('/activity-registration-review');
  58. await page.waitForLoadState('networkidle');
  59. await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
  60. });
  61. // ================================================================
  62. // v11 新增:活动工作流测试(需前端运行后执行)
  63. // ================================================================
  64. test('[场景4] 创建活动草稿 → 提交审核', async ({ page }) => {
  65. await ensureLoggedIn(page);
  66. await page.goto('/activity-edit');
  67. await page.waitForLoadState('networkidle');
  68. // 填写活动基本信息
  69. const titleInput = page.locator('input').first();
  70. await titleInput.fill('E2E_自动测试活动_' + Date.now());
  71. // 保存草稿
  72. const saveBtn = page.locator('button').filter({ hasText: /保存/ }).first();
  73. await saveBtn.click();
  74. await page.waitForTimeout(1500);
  75. // 如果有提交审核按钮
  76. const submitBtn = page.locator('button').filter({ hasText: /提交审核/ });
  77. if (await submitBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
  78. await submitBtn.click();
  79. await page.waitForTimeout(1000);
  80. }
  81. await expect(page.locator('.el-message--error, .el-form-item__error')).not.toBeVisible();
  82. });
  83. test('[场景5] 查看活动审核列表 → 审核操作可用', async ({ page }) => {
  84. await ensureLoggedIn(page);
  85. await page.goto('/activity-review');
  86. await page.waitForLoadState('networkidle');
  87. // 查找待审核状态的活动
  88. const pendingRows = page.locator('.el-table__row').filter({ hasText: 'pending' });
  89. const count = await pendingRows.count();
  90. if (count > 0) {
  91. // 应该有通过/驳回按钮
  92. const approveBtn = page.locator('button').filter({ hasText: /通过|批准/ });
  93. const rejectBtn = page.locator('button').filter({ hasText: /驳回/ });
  94. if (await approveBtn.isVisible({ timeout: 1000 }).catch(() => false)) {
  95. out += '[INFO] Activity approve button visible\n';
  96. }
  97. }
  98. await expect(page.locator('.el-message--error')).not.toBeVisible();
  99. });
  100. });