geo/frontend/e2e/tests/dashboard-pages-smoke.spec.ts

56 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, expect } from "../fixtures";
const pages = [
{ path: "/dashboard/agents", heading: "Agent监控", allowError: true },
{ path: "/dashboard/lifecycle", heading: "GEO项目管理", fallback: "功能开发中" },
{ path: "/dashboard/roi", heading: "效果归因与ROI报告" },
{ path: "/dashboard/reports", heading: "报告导出" },
{ path: "/dashboard/settings", heading: "设置" },
{ path: "/dashboard/publishing", heading: "分发执行", fallback: "功能开发中" },
{ path: "/dashboard/suggestions", heading: "优化建议" },
{ path: "/dashboard/queries", heading: "查询词管理" },
{ path: "/dashboard/usage", heading: "用量统计" },
{ path: "/dashboard/ai-engines", heading: "AI引擎分析" },
{ path: "/dashboard/clients", heading: "组织管理" },
{ path: "/dashboard/detection", heading: "检测任务" },
{ path: "/dashboard/health-score", heading: "健康评分" },
{ path: "/dashboard/content/editor", heading: "内容编辑器" },
{ path: "/dashboard/admin", heading: "管理后台" },
];
test.describe("Dashboard 页面烟雾测试", () => {
for (const { path, heading, fallback, allowError } of pages) {
test(`${path} 加载并显示标题「${heading}`, async ({ authenticatedPage }) => {
await authenticatedPage.goto(path);
await authenticatedPage.waitForLoadState("networkidle");
// 检查是否有页面错误(如 React ErrorBoundary
const errorBoundary = authenticatedPage.getByText("页面出现了错误");
if (await errorBoundary.isVisible({ timeout: 3000 }).catch(() => false)) {
if (allowError) {
// 某些页面可能有已知 bug标记为 skip 而非失败
test.skip(true, `页面 ${path} 存在运行时错误ErrorBoundary`);
return;
}
// 不允许错误的页面,断言失败
expect(errorBoundary.isVisible()).toBeFalsy();
return;
}
if (fallback) {
// 有 fallback 的页面,标题或 fallback 至少一个可见
const headingLocator = authenticatedPage.getByText(heading).first();
const fallbackLocator = authenticatedPage.getByText(fallback).first();
const isHeadingVisible = await headingLocator.isVisible({ timeout: 5000 }).catch(() => false);
if (isHeadingVisible) {
return; // 标题可见,测试通过
}
await expect(fallbackLocator).toBeVisible({ timeout: 10000 });
} else {
// 没有 fallback 的页面,标题必须可见
await expect(authenticatedPage.getByText(heading).first()).toBeVisible({ timeout: 15000 });
}
});
}
});