Browse Source

✅ test(dashboard): 优化仪表盘页面测试用例

- 移除未使用的waitFor导入,精简测试依赖
- 修改快捷操作卡片验证方式,从匹配文本改为直接验证标题存在
- 添加快捷操作区域存在性验证

♻️ refactor(dashboard): 清理未使用组件导入

- 移除Dashboard.tsx中未使用的Badge组件导入
yourname 2 months ago
parent
commit
4cd6e636fb

+ 10 - 4
src/client/__integration_tests__/admin/dashboard.test.tsx

@@ -1,5 +1,5 @@
 import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { render, screen, waitFor } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
 import userEvent from '@testing-library/user-event';
 import { DashboardPage } from '@/client/admin/pages/Dashboard';
 
@@ -162,8 +162,14 @@ describe('DashboardPage 集成测试', () => {
     expect(screen.getByText('执行数据备份操作')).toBeInTheDocument();
     expect(screen.getByText('查看系统日志')).toBeInTheDocument();
 
-    // 验证所有快捷操作卡片都存在
-    const quickActionCards = screen.getAllByText(/用户管理|系统设置|数据备份|日志查看/);
-    expect(quickActionCards.length).toBe(4); // 4个快捷操作卡片
+    // 验证快捷操作区域存在
+    const quickActionSection = screen.getByText('快捷操作');
+    expect(quickActionSection).toBeInTheDocument();
+
+    // 验证快捷操作卡片标题存在
+    expect(screen.getByText('用户管理')).toBeInTheDocument();
+    expect(screen.getByText('系统设置')).toBeInTheDocument();
+    expect(screen.getByText('数据备份')).toBeInTheDocument();
+    expect(screen.getByText('日志查看')).toBeInTheDocument();
   });
 });

+ 0 - 1
src/client/admin/pages/Dashboard.tsx

@@ -2,7 +2,6 @@ import React from 'react';
 import { useNavigate } from 'react-router';
 import { Users, Bell, Eye, TrendingUp, TrendingDown, Activity } from 'lucide-react';
 import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/client/components/ui/card';
-import { Badge } from '@/client/components/ui/badge';
 import { Progress } from '@/client/components/ui/progress';
 
 // 仪表盘页面