library-picturebook-activity/lesingle-creation-frontend/e2e/admin/contest-create.spec.ts
En 98e9ad1d28 feat(前端): 测试环境登录框支持自动填充测试账号
通过 VITE_AUTO_FILL_TEST 环境变量控制,在 .env.test 中启用,
使测试环境构建后登录框也能自动填充测试账号,方便测试人员使用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 17:03:22 +08:00

102 lines
3.5 KiB
TypeScript
Raw Permalink 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 })
}
})
})