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

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