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 }) } }) })