Преглед изворни кода

🐛 fix(e2e): 修复活动管理页面测试方法问题

- 搜索活动时添加防抖等待时间,确保搜索结果准确加载
- 修正filterByType方法参数类型,将"去程活动"/"返程活动"改为"去程"/"返程"
- 优化getActivityCount方法,当表格显示"暂无活动数据"时返回0而非1

✅ test(e2e): 更新活动筛选测试用例

- 调整活动类型筛选测试参数,匹配修改后的filterByType方法
yourname пре 4 месеци
родитељ
комит
45604c0163

+ 10 - 2
tests/e2e/pages/admin/activity-management.page.ts

@@ -54,11 +54,12 @@ export class ActivityManagementPage {
 
   async searchActivities(keyword: string) {
     await this.searchInput.fill(keyword);
-    await this.searchButton.click();
+    // 等待防抖搜索完成(300ms + 网络请求时间)
+    await this.page.waitForTimeout(500);
     await this.page.waitForLoadState('networkidle');
   }
 
-  async filterByType(type: '去程活动' | '返程活动') {
+  async filterByType(type: '去程' | '返程') {
     await this.typeFilter.click();
     await this.page.getByRole('option', { name: type }).click();
     await this.page.waitForLoadState('networkidle');
@@ -121,6 +122,13 @@ export class ActivityManagementPage {
 
   async getActivityCount(): Promise<number> {
     const rows = await this.activityTable.locator('tbody tr').count();
+    // 如果只有一行且显示"暂无活动数据",则返回0
+    if (rows === 1) {
+      const firstRowText = await this.activityTable.locator('tbody tr').first().textContent();
+      if (firstRowText?.includes('暂无活动数据')) {
+        return 0;
+      }
+    }
     return rows;
   }
 

+ 2 - 2
tests/e2e/specs/admin/activities.spec.ts

@@ -37,12 +37,12 @@ test.describe.serial('活动管理 E2E 测试', () => {
 
   test('按活动类型筛选', async ({ activityManagementPage }) => {
     // 筛选去程活动
-    await activityManagementPage.filterByType('去程活动');
+    await activityManagementPage.filterByType('去程');
     const departureCount = await activityManagementPage.getActivityCount();
     expect(departureCount).toBeGreaterThan(0);
 
     // 筛选返程活动
-    await activityManagementPage.filterByType('返程活动');
+    await activityManagementPage.filterByType('返程');
     const returnCount = await activityManagementPage.getActivityCount();
     expect(returnCount).toBeGreaterThan(0);