fix(user-management): 修复用户管理测试 - 添加用户创建API和模态框等待逻辑

问题:
- 用户管理页面输入框缺少name属性
- API缺少POST方法处理用户创建
- 测试未等待模态框打开

修复:
1. 应用代码:为创建/编辑模态框的输入框添加name属性
2. API:添加POST方法处理用户创建请求
3. 测试:增加模态框等待逻辑和详细日志

测试结果:
- Chromium: ✓ 通过
- Firefox: ✓ 通过
This commit is contained in:
2026-04-12 08:50:48 +08:00
parent 5226249264
commit c0599fd7b1
3 changed files with 95 additions and 5 deletions
+47 -4
View File
@@ -17,15 +17,30 @@ export class AdminUserPage {
}
async createUser(data: UserData) {
await this.goto();
console.log('开始创建用户:', data.email);
await this.goto();
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForTimeout(1000);
console.log('页面加载完成,准备点击添加用户按钮');
const addButton = this.page.locator('button:has-text("添加用户")');
await addButton.waitFor({ timeout: 10000, state: 'visible' });
await addButton.click();
console.log('已点击添加用户按钮,等待模态框打开');
await this.page.waitForTimeout(500);
await this.page.waitForSelector('.fixed.inset-0.bg-black.bg-opacity-50', {
timeout: 5000,
state: 'visible'
});
console.log('模态框已打开,等待表单加载');
await this.page.waitForTimeout(300);
await this.page.waitForSelector('input[name="email"]', { timeout: 5000, state: 'visible' });
await this.page.fill('input[name="email"]', data.email);
await this.page.fill('input[name="password"]', data.password);
@@ -38,12 +53,40 @@ export class AdminUserPage {
await this.page.selectOption('select[name="role"]', data.role);
}
console.log('表单填写完成,准备提交');
await this.page.click('button:has-text("创建")');
console.log('用户创建请求已提交');
}
async expectUserInList(email: string) {
console.log(`检查用户是否在列表中: ${email}`);
await this.goto();
const row = this.page.locator(`tr:has-text("${email}")`);
await expect(row).toBeVisible();
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForTimeout(1000);
let row = this.page.locator(`tr:has-text("${email}")`);
let isVisible = await row.count() > 0;
if (!isVisible) {
console.log('用户不在列表中,尝试刷新页面');
await this.page.reload({ waitUntil: 'domcontentloaded' });
await this.page.waitForSelector('table tbody tr', { timeout: 5000 });
await this.page.waitForTimeout(1000);
row = this.page.locator(`tr:has-text("${email}")`);
isVisible = await row.count() > 0;
}
if (!isVisible) {
const allRows = await this.page.locator('table tbody tr').allTextContents();
console.log('当前列表中的用户:');
allRows.forEach((text, i) => console.log(`${i + 1}: ${text}`));
}
await expect(row).toBeVisible({ timeout: 10000 });
console.log(`✅ 用户已在列表中: ${email}`);
}
}