argus/src/web/tests/playwright/dashboard.spec.ts
2025-10-29 16:59:52 +08:00

59 lines
2.0 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('Dashboard 页面测试', () => {
test.beforeEach(async ({ page }) => {
// 打开仪表盘页面
await page.goto('http://web.argus.com/dashboard', { waitUntil: 'networkidle' });
});
test('应能成功加载页面并显示标题', async ({ page }) => {
await expect(page.locator('text=仪表盘')).toBeVisible();
});
test('应显示节点健康状态卡片', async ({ page }) => {
const healthCard = page.locator('text=节点健康状态');
await expect(healthCard).toBeVisible();
// 检查环形图是否渲染
const ring = page.locator('svg'); // RingProgress 是 SVG 渲染的
const ringCount = await ring.count();
expect(ringCount).toBeGreaterThan(0);
});
test('应显示告警统计信息', async ({ page }) => {
const alertCard = page.locator('text=告警统计');
await expect(alertCard).toBeVisible();
// 检查告警类别
const labels = ['总数', '严重', '警告', '信息'];
for (const label of labels) {
await expect(page.locator(`text=${label}`)).toBeVisible();
}
});
test('应正确渲染集群节点表格', async ({ page }) => {
const tableHeaders = ['ID', '名称', '状态', '类型', '版本'];
for (const header of tableHeaders) {
await expect(page.locator(`th:has-text("${header}")`)).toBeVisible();
}
// 至少有一行节点数据
const rows = await page.locator('tbody tr').count();
expect(rows).toBeGreaterThan(0);
});
test('“查看更多”链接应存在并指向 /nodeInfo', async ({ page }) => {
const link = page.locator('a:has-text("查看更多")');
await expect(link).toBeVisible();
const href = await link.getAttribute('href');
expect(href).toContain('/nodeInfo');
});
test('页面应无加载错误提示', async ({ page }) => {
await expect(page.locator('text=加载中...')).toHaveCount(0);
await expect(page.locator('text=数据加载失败')).toHaveCount(0);
});
});