geo/frontend/e2e/tests/dashboard-health.spec.ts

212 lines
9.7 KiB
TypeScript

import { test, expect } from "../fixtures";
import { DashboardPage } from "../pages/dashboard.page";
async function hasProjects(page: import("@playwright/test").Page): Promise<boolean> {
const dashboardPage = new DashboardPage(page);
await dashboardPage.waitForDashboardLoad();
const emptyMsg = page.getByText("开始优化您的AI可见性");
const errorTitle = page.getByText("数据加载失败");
const isEmpty = await emptyMsg.isVisible().catch(() => false);
const isError = await errorTitle.isVisible().catch(() => false);
return !isEmpty && !isError;
}
test.describe("健康状态Dashboard - 页面渲染测试", () => {
test("Dashboard页面标题正确显示为品牌健康中心", async ({ authenticatedPage }) => {
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.pageTitle).toBeVisible();
await expect(dashboardPage.pageTitle).toHaveText("品牌健康中心");
});
test("页面副标题正确显示", async ({ authenticatedPage }) => {
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForDashboardLoad();
if (!(await hasProjects(authenticatedPage))) {
const emptySubtitle = authenticatedPage.getByText("GEO和SEO是AI营销时代的共生体");
await expect(emptySubtitle).toBeVisible();
return;
}
const projectSubtitle = authenticatedPage.getByText(/—/);
await expect(projectSubtitle).toBeVisible();
});
});
test.describe("健康状态Dashboard - 空状态测试", () => {
test("空状态时显示引导文案和创建项目按钮", async ({ authenticatedPage }) => {
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForDashboardLoad();
const emptyMsg = authenticatedPage.getByText("开始优化您的AI可见性");
const hasEmpty = await emptyMsg.isVisible().catch(() => false);
if (!hasEmpty) { test.skip(); return; }
await expect(emptyMsg).toBeVisible();
const createBtn = authenticatedPage.getByRole("button", { name: /创建项目/ });
await expect(createBtn.first()).toBeVisible();
});
});
test.describe("健康状态Dashboard - KPI卡片测试", () => {
test("4个MetricCard全部显示", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForHealthCards();
await expect(dashboardPage.activeProjectCard).toBeVisible();
await expect(dashboardPage.contentOutputCard).toBeVisible();
await expect(dashboardPage.aiCitationCard).toBeVisible();
await expect(dashboardPage.completedProjectCard).toBeVisible();
});
test("活跃项目数卡片显示数值", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForHealthCards();
await expect(dashboardPage.activeProjectCard).toBeVisible();
});
test("内容产出统计卡片显示数值", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForHealthCards();
await expect(dashboardPage.contentOutputCard).toBeVisible();
});
test("AI引用率卡片显示百分比", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForHealthCards();
await expect(dashboardPage.aiCitationCard).toBeVisible();
});
test("已完成项目卡片显示数值", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForHealthCards();
await expect(dashboardPage.completedProjectCard).toBeVisible();
});
});
test.describe("健康状态Dashboard - 生命周期进度测试", () => {
test("生命周期进度区域标题正确显示", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.lifecycleProgress).toBeVisible();
});
test("生命周期进度显示当前阶段Badge", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.lifecycleProgress).toBeVisible();
const stageBadge = authenticatedPage.getByText(/当前阶段:/);
await expect(stageBadge).toBeVisible();
});
test("生命周期进度条显示5个阶段", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.lifecycleProgress).toBeVisible();
const stageLabels = authenticatedPage.getByText(/诊断分析|策略制定|内容生产|分发执行|监测优化/);
const count = await stageLabels.count();
expect(count).toBeGreaterThanOrEqual(5);
});
});
test.describe("健康状态Dashboard - 推荐下一步测试", () => {
test("推荐下一步区域标题正确显示", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.recommendedNextStep).toBeVisible();
});
test("推荐下一步包含执行按钮", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.recommendedNextStep).toBeVisible();
const executeBtn = authenticatedPage.getByRole("button", { name: /执行/ });
await expect(executeBtn.first()).toBeVisible();
});
test("推荐下一步包含管理Agent和项目详情按钮", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.recommendedNextStep).toBeVisible();
const agentBtn = authenticatedPage.getByRole("button", { name: /管理Agent/ });
const detailBtn = authenticatedPage.getByRole("button", { name: /项目详情/ });
await expect(agentBtn).toBeVisible();
await expect(detailBtn).toBeVisible();
});
test("点击执行按钮跳转", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.recommendedNextStep).toBeVisible();
const executeBtn = authenticatedPage.getByRole("button", { name: /执行/ }).first();
if (await executeBtn.isVisible()) {
await executeBtn.click();
}
});
});
test.describe("健康状态Dashboard - Agent活动测试", () => {
test("Agent活动卡片显示功能开发中", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.agentActivity).toBeVisible();
await expect(authenticatedPage.getByText("功能开发中")).toBeVisible();
});
});
test.describe("健康状态Dashboard - 骨架屏测试", () => {
test("加载时显示骨架屏", async ({ authenticatedPage }) => {
// authenticatedPage already loaded
});
});
test.describe("健康状态Dashboard - 颜色传达状态测试", () => {
test("页面元素正确渲染", async ({ authenticatedPage }) => {
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForDashboardLoad();
await expect(dashboardPage.pageTitle).toBeVisible();
});
test("MetricCard包含趋势标签", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForHealthCards();
const trendLabels = authenticatedPage.getByText(/全部内容|平均引用率|共.*个项目|活跃.*个/);
const count = await trendLabels.count();
expect(count).toBeGreaterThan(0);
});
test("生命周期进度使用颜色区分阶段状态", async ({ authenticatedPage }) => {
if (!(await hasProjects(authenticatedPage))) { test.skip(); return; }
const dashboardPage = new DashboardPage(authenticatedPage);
await expect(dashboardPage.lifecycleProgress).toBeVisible();
});
});
test.describe("健康状态Dashboard - 响应式设计测试", () => {
test("移动端视口下页面正常显示", async ({ authenticatedPage }) => {
await authenticatedPage.setViewportSize({ width: 375, height: 667 });
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForDashboardLoad();
await expect(dashboardPage.pageTitle).toBeVisible();
});
test("桌面端视口下KPI卡片可见", async ({ authenticatedPage }) => {
await authenticatedPage.setViewportSize({ width: 1280, height: 720 });
const dashboardPage = new DashboardPage(authenticatedPage);
await dashboardPage.waitForDashboardLoad();
await expect(dashboardPage.pageTitle).toBeVisible();
if (await hasProjects(authenticatedPage)) {
await expect(dashboardPage.activeProjectCard).toBeVisible();
await expect(dashboardPage.contentOutputCard).toBeVisible();
await expect(dashboardPage.aiCitationCard).toBeVisible();
await expect(dashboardPage.completedProjectCard).toBeVisible();
}
});
});