library-picturebook-activity/frontend/e2e/admin/users.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

112 lines
3.7 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'
/**
* 用户管理测试
*/
test.describe('用户管理', () => {
test.beforeEach(async ({ adminPage }) => {
const page = adminPage
// 通过 Vue Router 直接导航到用户管理(菜单点击可能因动态路由注册时序问题失效)
await page.evaluate(() => {
const app = document.querySelector('#app')?.__vue_app__
if (app) {
const router = app.config.globalProperties.$router
router.push({ name: 'SystemUsers' })
}
})
// 等待页面内容加载
await page.waitForTimeout(2000)
})
test('U-01 用户列表页正常加载', async ({ adminPage }) => {
const page = adminPage
// 验证页面加载Ant Design 表格或卡片)
await expect(page.locator('.ant-table, .ant-card, .ant-spin').first()).toBeVisible({ timeout: 10_000 })
})
test('U-02 搜索用户', async ({ adminPage }) => {
const page = adminPage
// 查找搜索输入框
const searchInput = page.locator('input[placeholder*="搜索"], input[placeholder*="用户"], input[placeholder*="姓名"], input[placeholder*="手机"]').first()
if (await searchInput.isVisible({ timeout: 5000 }).catch(() => false)) {
await searchInput.fill('管理员')
// 触发搜索
const searchBtn = page.locator('button:has-text("搜索"), button[type="submit"]').first()
if (await searchBtn.isVisible()) {
await searchBtn.click()
} else {
await searchInput.press('Enter')
}
await page.waitForTimeout(1000)
}
})
test('U-03 用户状态筛选', async ({ adminPage }) => {
const page = adminPage
// 查找状态筛选
const statusSelect = page.locator('.ant-select').first()
if (await statusSelect.isVisible({ timeout: 5000 }).catch(() => false)) {
await statusSelect.click()
await page.waitForTimeout(500)
// 选择状态
const option = page.locator('.ant-select-item-option').first()
if (await option.isVisible()) {
await option.click()
await page.waitForTimeout(1000)
}
}
})
test('U-04 创建用户弹窗', async ({ adminPage }) => {
const page = adminPage
// 查找创建用户按钮
const createBtn = page.locator('button:has-text("创建"), button:has-text("新建"), button:has-text("添加用户"), button:has-text("新增")').first()
if (await createBtn.isVisible({ timeout: 5000 }).catch(() => false)) {
await createBtn.click()
// 验证弹窗出现
await expect(page.locator('.ant-modal, .ant-drawer').first()).toBeVisible({ timeout: 5000 })
// 验证表单字段可填写
const usernameInput = page.locator('.ant-modal input, .ant-drawer input').first()
if (await usernameInput.isVisible()) {
await usernameInput.fill('newuser')
await expect(usernameInput).toHaveValue('newuser')
}
}
})
test('U-05 用户操作菜单', async ({ adminPage }) => {
const page = adminPage
// 等待表格加载
await page.waitForTimeout(2000)
// 查找操作列中的按钮
const editBtn = page.locator('button:has-text("编辑"), a:has-text("编辑")').first()
if (await editBtn.isVisible({ timeout: 5000 }).catch(() => false)) {
// 验证编辑按钮可点击
expect(await editBtn.isEnabled()).toBe(true)
}
// 查找更多操作下拉菜单
const moreBtn = page.locator('.ant-table-row button:has-text("更多"), .ant-table-row .ant-dropdown-trigger').first()
if (await moreBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
await moreBtn.click()
await page.waitForTimeout(500)
// 验证下拉菜单选项
await expect(page.locator('.ant-dropdown-menu-item').first()).toBeVisible()
}
})
})