fix(content): 修复内容ID提取和列表查找逻辑

问题:
- contentId包含下划线和连字符,但正则表达式只匹配字母和数字
- 搜索后列表为空,没有清空搜索框

修复:
1. 正则表达式:增加下划线和连字符匹配
2. 搜索逻辑:搜索无结果时清空搜索框重新显示所有内容
3. 等待时间:增加更长的等待时间确保列表加载完成

测试结果:
- Chromium: ✓ 编辑内容测试通过
This commit was merged in pull request #3.
This commit is contained in:
2026-04-12 09:17:41 +08:00
parent ed2974302a
commit b150ad346b
+16 -6
View File
@@ -66,7 +66,7 @@ export class AdminContentPage {
await this.page.click('button:has-text("发布")');
try {
await this.page.waitForURL(/\/admin\/content\/[a-zA-Z0-9]+/, { timeout: 15000 });
await this.page.waitForURL(/\/admin\/content\/[a-zA-Z0-9_-]+/, { timeout: 15000 });
} catch {
console.log('等待URL跳转失败,当前URL:', this.page.url());
@@ -86,7 +86,7 @@ export class AdminContentPage {
const url = this.page.url();
console.log('最终URL:', url);
const match = url.match(/\/admin\/content\/([a-zA-Z0-9]+)/);
const match = url.match(/\/admin\/content\/([a-zA-Z0-9_-]+)/);
const contentId = match ? match[1] : null;
if (!contentId) {
@@ -152,7 +152,7 @@ export class AdminContentPage {
await this.goto();
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForTimeout(2000);
await this.page.waitForTimeout(3000);
let row = this.page.locator(`tr:has-text("${title}")`);
let isVisible = await row.count() > 0;
@@ -164,10 +164,20 @@ export class AdminContentPage {
if (await searchInput.count() > 0) {
await searchInput.fill(title);
await this.page.keyboard.press('Enter');
await this.page.waitForTimeout(2000);
await this.page.waitForTimeout(3000);
row = this.page.locator(`tr:has-text("${title}")`);
isVisible = await row.count() > 0;
if (!isVisible) {
console.log('搜索无结果,清空搜索框');
await searchInput.fill('');
await this.page.keyboard.press('Enter');
await this.page.waitForTimeout(2000);
row = this.page.locator(`tr:has-text("${title}")`);
isVisible = await row.count() > 0;
}
}
}
@@ -175,7 +185,7 @@ export class AdminContentPage {
console.log('搜索后仍未找到,尝试刷新页面');
await this.page.reload({ waitUntil: 'domcontentloaded' });
await this.page.waitForSelector('table', { timeout: 10000, state: 'visible' });
await this.page.waitForTimeout(2000);
await this.page.waitForTimeout(3000);
row = this.page.locator(`tr:has-text("${title}")`);
isVisible = await row.count() > 0;
@@ -192,7 +202,7 @@ export class AdminContentPage {
}
}
await expect(row.first()).toBeVisible({ timeout: 15000 });
await expect(row.first()).toBeVisible({ timeout: 20000 });
console.log(`✅ 找到内容: ${title}`);
}