Przeglądaj źródła

✅ test(activity): 增强活动管理页面的E2E测试稳定性

- 为确认对话框添加data-testid属性,提高选择器可靠性
- 更新E2E测试代码,使用data-testid定位删除和状态确认对话框
- 优化活动状态检查逻辑,直接从表格单元格读取状态文本
- 移除删除操作后的强制页面刷新,改为等待网络状态稳定
yourname 4 miesięcy temu
rodzic
commit
7e5ea42beb

+ 2 - 2
src/client/admin/pages/Activities.tsx

@@ -429,7 +429,7 @@ export const ActivitiesPage: React.FC = () => {
 
       {/* 删除确认对话框 */}
       <AlertDialog open={deleteConfirmOpen} onOpenChange={setDeleteConfirmOpen}>
-        <AlertDialogContent>
+        <AlertDialogContent data-testid="delete-confirm-dialog">
           <AlertDialogHeader>
             <AlertDialogTitle>确认删除</AlertDialogTitle>
             <AlertDialogDescription>
@@ -456,7 +456,7 @@ export const ActivitiesPage: React.FC = () => {
 
       {/* 启用/禁用确认对话框 */}
       <AlertDialog open={statusConfirmOpen} onOpenChange={setStatusConfirmOpen}>
-        <AlertDialogContent>
+        <AlertDialogContent data-testid="status-confirm-dialog">
           <AlertDialogHeader>
             <AlertDialogTitle>确认状态切换</AlertDialogTitle>
             <AlertDialogDescription>

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

@@ -200,11 +200,11 @@ export class ActivityManagementPage {
     await deleteButton.waitFor({ state: 'visible', timeout: 10000 });
     await deleteButton.click();
 
-    // 等待删除确认对话框出现
-    await this.page.waitForSelector('[role="dialog"]', { state: 'visible', timeout: 10000 });
+    // 等待删除确认对话框出现 - 使用data-testid
+    await this.page.waitForSelector('[data-testid="delete-confirm-dialog"]', { state: 'visible', timeout: 10000 });
 
     // 确认删除 - 点击删除按钮
-    await this.page.locator('[role="dialog"]').getByRole('button', { name: '删除' }).click();
+    await this.page.locator('[data-testid="delete-confirm-dialog"]').getByRole('button', { name: '删除' }).click();
 
     // 等待删除操作完成
     try {
@@ -221,8 +221,7 @@ export class ActivityManagementPage {
       console.log('删除操作没有显示提示信息,继续执行');
     }
 
-    // 刷新页面确认活动是否被删除
-    await this.page.reload();
+    // 等待页面状态稳定,不需要强制刷新
     await this.page.waitForLoadState('networkidle');
     await this.expectToBeVisible();
   }
@@ -238,12 +237,12 @@ export class ActivityManagementPage {
     const currentStatus = await statusButton.textContent();
     await statusButton.click();
 
-    // 等待状态切换确认对话框出现
-    await this.page.waitForSelector('[role="dialog"]', { state: 'visible', timeout: 10000 });
+    // 等待状态切换确认对话框出现 - 使用data-testid
+    await this.page.waitForSelector('[data-testid="status-confirm-dialog"]', { state: 'visible', timeout: 10000 });
 
     // 确认状态切换 - 点击禁用或启用按钮
     const actionText = currentStatus === '禁用' ? '启用' : '禁用';
-    await this.page.locator('[role="dialog"]').getByRole('button', { name: actionText }).click();
+    await this.page.locator('[data-testid="status-confirm-dialog"]').getByRole('button', { name: actionText }).click();
 
     // 等待操作完成
     await this.page.waitForLoadState('networkidle');
@@ -266,7 +265,8 @@ export class ActivityManagementPage {
     const activityRow = await this.getActivityByName(name);
     if (!activityRow) return null;
 
-    const statusButton = activityRow.locator('button').nth(2);
-    return await statusButton.textContent();
+    // 状态文本在第五列(索引4)
+    const statusCell = activityRow.locator('td').nth(4);
+    return await statusCell.textContent();
   }
 }