library-picturebook-activity/frontend/e2e/admin/contest-create.spec.ts
En f03991819d feat: 管理端全功能 E2E 测试——40 用例覆盖登录、仪表盘、活动、报名、作品、评审、用户、导航
新增 10 个管理端 E2E 测试文件和 1 个 Mock fixture:
- admin.fixture.ts: Mock 数据 + 登录注入 + 组件预热 + 兜底 API 拦截
- login/contests/dashboard/navigation/registrations/works/reviews/users 等 9 个 spec

关键修复:route.fallback() 替代 route.continue() 修正 Mock 链式传递;
review-rules/select Mock + 兜底拦截器防止未 mock 请求到达真实后端。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 12:52:39 +08:00

102 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, expect } from '../fixtures/admin.fixture'
import { TENANT_CODE } from '../fixtures/admin.fixture'
/**
* 创建活动测试
*/
test.describe('创建活动', () => {
test.beforeEach(async ({ adminPage }) => {
const page = adminPage
// 导航到活动列表页
const submenu = page.locator('.ant-menu-submenu').filter({ hasText: '活动管理' }).first()
await submenu.click()
await page.waitForTimeout(500)
await submenu.locator('.ant-menu-item').filter({ hasText: '活动列表' }).first().click()
await page.waitForURL(/contests\/list/, { timeout: 15_000 })
})
test('CC-01 创建活动页表单渲染', async ({ adminPage }) => {
const page = adminPage
// 点击创建活动按钮
await page.locator('button:has-text("创建活动")').click()
// 验证跳转到创建活动页面
await page.waitForURL(/contests\/create/, { timeout: 10_000 })
// 验证表单区域可见
await expect(page.locator('form')).toBeVisible({ timeout: 10_000 })
// 验证关键表单字段
await expect(page.locator('input, textarea, .ant-select').first()).toBeVisible()
})
test('CC-02 必填字段校验', async ({ adminPage }) => {
const page = adminPage
// 进入创建活动页
await page.locator('button:has-text("创建活动")').click()
await page.waitForURL(/contests\/create/, { timeout: 10_000 })
// 直接点击保存/提交按钮(不填写任何内容)
const submitBtn = page.locator('button:has-text("保存"), button:has-text("提交"), button[type="submit"]').first()
if (await submitBtn.isVisible()) {
await submitBtn.click()
// 验证校验错误提示
await page.waitForTimeout(1000)
const errors = page.locator('.ant-form-item-explain-error')
const errorCount = await errors.count()
expect(errorCount).toBeGreaterThan(0)
}
})
test('CC-03 填写活动信息', async ({ adminPage }) => {
const page = adminPage
// 进入创建活动页
await page.locator('button:has-text("创建活动")').click()
await page.waitForURL(/contests\/create/, { timeout: 10_000 })
await page.waitForTimeout(1000)
// 填写活动名称
const nameInput = page.locator('input[placeholder*="活动名称"], input[placeholder*="名称"]').first()
if (await nameInput.isVisible()) {
await nameInput.fill('E2E测试活动')
await expect(nameInput).toHaveValue('E2E测试活动')
}
})
test('CC-04 时间范围选择器可见', async ({ adminPage }) => {
const page = adminPage
// 进入创建活动页
await page.locator('button:has-text("创建活动")').click()
await page.waitForURL(/contests\/create/, { timeout: 10_000 })
await page.waitForTimeout(1000)
// 验证时间选择器存在Ant Design RangePicker
const datePickers = page.locator('.ant-picker')
const pickerCount = await datePickers.count()
expect(pickerCount).toBeGreaterThan(0)
})
test('CC-05 返回按钮功能', async ({ adminPage }) => {
const page = adminPage
// 进入创建活动页
await page.locator('button:has-text("创建活动")').click()
await page.waitForURL(/contests\/create/, { timeout: 10_000 })
// 查找返回按钮
const backBtn = page.locator('button:has-text("返回"), button:has-text("取消"), .ant-page-header-back, [aria-label="返回"]').first()
if (await backBtn.isVisible()) {
await backBtn.click()
// 验证返回活动列表页
await page.waitForURL(/contests\/list/, { timeout: 10_000 })
}
})
})