Forráskód Böngészése

📝 test(admin): add mobile menu support for E2E tests

- add data-testid to mobile menu button for reliable testing
- implement mobile detection logic in dashboard page navigation methods
- add mobile menu opening steps for user management and system settings navigation
- increase timeout for critical element interactions to improve test stability
- add waiting time for menu expansion to ensure elements are clickable
yourname 2 hónapja
szülő
commit
7a19297f22

+ 1 - 0
src/client/admin/layouts/MainLayout.tsx

@@ -171,6 +171,7 @@ export const MainLayout = () => {
               size="icon"
               className="md:hidden"
               onClick={() => setIsMobileMenuOpen(true)}
+              data-testid="mobile-menu-button"
             >
               <Menu className="h-4 w-4" />
             </Button>

+ 30 - 4
tests/e2e/pages/admin/dashboard.page.ts

@@ -27,16 +27,42 @@ export class DashboardPage {
   }
 
   async navigateToUserManagement() {
-    // 使用更具体的定位器来避免重复元素问题
-    const userManagementCard = this.page.locator('text=用户管理').first();
-    await userManagementCard.click();
+    // 检查是否为移动端,需要先打开菜单
+    const isMobile = (this.page.viewportSize()?.width || 0) < 768;
+
+    if (isMobile) {
+      // 移动端需要先点击菜单按钮 - 使用测试ID
+      const menuButton = this.page.getByTestId('mobile-menu-button');
+      await expect(menuButton).toBeVisible({ timeout: 10000 });
+      await menuButton.click({ timeout: 15000 });
+      await this.page.waitForTimeout(1000); // 等待菜单完全展开
+    }
+
+    // 移动端需要点击侧边栏菜单项,而不是快捷操作卡片
+    const userManagementCard = isMobile
+      ? this.page.getByRole('button', { name: '用户管理' }).first()
+      : this.page.locator('text=用户管理').first();
+
+    await expect(userManagementCard).toBeVisible({ timeout: 10000 });
+    await userManagementCard.click({ timeout: 10000 });
     await this.page.waitForLoadState('networkidle');
   }
 
   async navigateToSystemSettings() {
+    // 检查是否为移动端,需要先打开菜单
+    const isMobile = (this.page.viewportSize()?.width || 0) < 768;
+
+    if (isMobile) {
+      // 移动端需要先点击菜单按钮 - 使用测试ID
+      const menuButton = this.page.getByTestId('mobile-menu-button');
+      await expect(menuButton).toBeVisible({ timeout: 10000 });
+      await menuButton.click({ timeout: 15000 });
+      await this.page.waitForTimeout(1000); // 等待菜单完全展开
+    }
+
     // 使用更具体的定位器来避免重复元素问题
     const systemSettingsCard = this.page.locator('text=系统设置').first();
-    await systemSettingsCard.click();
+    await systemSettingsCard.click({ timeout: 10000 });
     await this.page.waitForLoadState('networkidle');
   }