argus/src/web/tests/playwright/alerts.spec.ts
2025-10-30 10:19:39 +08:00

79 lines
3.0 KiB
TypeScript

import {test, expect} from "@playwright/test";
import { BASE_URL } from './helpers/utils'
test.describe("Alerts 页面功能测试", () => {
test.beforeEach(async ({page}) => {
await page.goto(`${BASE_URL}/alerts`); // 根据你实际路由调整
});
test("页面加载并显示告警统计", async ({page}) => {
await expect(page.locator("text=告警详情")).toBeVisible();
await expect(page.locator("text=总数")).toBeVisible();
await expect(page.locator("text=严重")).toBeVisible();
await expect(page.locator("text=警告")).toBeVisible();
await expect(page.locator("text=信息")).toBeVisible();
});
test("筛选功能验证", async ({page}) => {
const severitySelect = page.getByLabel("严重性");
const stateSelect = page.getByLabel("状态");
const nodeSelect = page.getByLabel("节点");
await severitySelect.selectOption("critical");
await expect(severitySelect).toHaveValue("critical");
await stateSelect.selectOption("active");
await expect(stateSelect).toHaveValue("active");
await nodeSelect.selectOption("all");
await expect(nodeSelect).toHaveValue("all");
});
test("排序功能", async ({page}) => {
const severityHeader = page.locator("th:has-text('严重性') button");
await severityHeader.click(); // 切换升序
await severityHeader.click(); // 切换降序
const instanceHeader = page.locator("th:has-text('节点') button");
await instanceHeader.click();
await instanceHeader.click();
});
test("分页功能", async ({page}) => {
const nextButton = page.locator("button:has-text('下一页')");
const prevButton = page.locator("button:has-text('上一页')");
if (await nextButton.isEnabled()) {
await nextButton.click();
await expect(prevButton).toBeEnabled();
}
});
test("展开更多信息行", async ({page}) => {
const infoIcons = page.locator("table tbody tr td [title='显示/隐藏更多信息']");
if (await infoIcons.count() > 0) {
await infoIcons.first().click();
// 展开的详情行应出现
const details = page.locator("table tbody tr >> text=alertname");
const detailCount = await details.count();
expect(detailCount).toBeGreaterThan(0);
}
});
test("自动刷新开关与刷新按钮", async ({page}) => {
const switchBtn = page.getByRole("switch", {name: "自动刷新"});
const refreshBtn = page.getByTitle("刷新");
await expect(switchBtn).toBeVisible();
await expect(refreshBtn).toBeVisible();
// 手动点击刷新按钮
await refreshBtn.click();
// 自动刷新开关切换
const isChecked = await switchBtn.isChecked();
await switchBtn.click();
await expect(switchBtn).toHaveJSProperty("checked", !isChecked);
});
});