geo/frontend/e2e/tests/analytics.spec.ts

61 lines
3.1 KiB
TypeScript

import { test, expect } from "../fixtures";
test.describe("数据监测中心页面", () => {
test.beforeEach(async ({ authenticatedPage }) => {
await authenticatedPage.goto("/dashboard/analytics");
await authenticatedPage.waitForLoadState("networkidle");
});
test("数据监测中心页面标题正确显示", async ({ authenticatedPage }) => {
await expect(authenticatedPage.getByRole("heading", { name: "数据监测中心" })).toBeVisible({ timeout: 10000 });
});
test("数据监测中心页面副标题正确显示", async ({ authenticatedPage }) => {
await expect(authenticatedPage.getByText("全渠道内容表现追踪")).toBeVisible({ timeout: 10000 });
});
test("数据监测中心页面显示时间范围选择", async ({ authenticatedPage }) => {
const range7 = authenticatedPage.getByRole("button", { name: "最近7天" });
const range30 = authenticatedPage.getByRole("button", { name: "最近30天" });
const range90 = authenticatedPage.getByRole("button", { name: "最近90天" });
const has7 = await range7.isVisible({ timeout: 10000 }).catch(() => false);
const has30 = await range30.isVisible({ timeout: 3000 }).catch(() => false);
const has90 = await range90.isVisible({ timeout: 3000 }).catch(() => false);
expect(has7 || has30 || has90).toBeTruthy();
});
test("数据监测中心页面显示统计指标", async ({ authenticatedPage }) => {
const metricTotal = authenticatedPage.getByText("总发布").first();
const metricExposure = authenticatedPage.getByText("总曝光").first();
const metricInteraction = authenticatedPage.getByText("总互动").first();
const metricAI = authenticatedPage.getByText("AI引用数").first();
const hasTotal = await metricTotal.isVisible({ timeout: 5000 }).catch(() => false);
const hasExposure = await metricExposure.isVisible({ timeout: 3000 }).catch(() => false);
const hasInteraction = await metricInteraction.isVisible({ timeout: 3000 }).catch(() => false);
const hasAI = await metricAI.isVisible({ timeout: 3000 }).catch(() => false);
if (!hasTotal && !hasExposure && !hasInteraction && !hasAI) {
test.skip();
return;
}
expect(hasTotal || hasExposure || hasInteraction || hasAI).toBeTruthy();
});
test("数据监测中心页面显示平台分布图表或空状态", async ({ authenticatedPage }) => {
const emptyState = authenticatedPage.getByText("暂无平台分布数据");
const chart = authenticatedPage.locator(".recharts-composed-chart, .recharts-wrapper, canvas");
await expect(emptyState.or(chart)).toBeVisible({ timeout: 10000 });
});
test("数据监测中心页面显示AI洞察或空状态", async ({ authenticatedPage }) => {
const adoptBtn = authenticatedPage.getByRole("button", { name: "采纳建议" });
const emptyState = authenticatedPage.getByText("暂无AI洞察");
if (await adoptBtn.isVisible({ timeout: 5000 }).catch(() => false)) {
await expect(adoptBtn).toBeVisible();
} else if (await emptyState.isVisible({ timeout: 5000 }).catch(() => false)) {
await expect(emptyState).toBeVisible();
} else {
test.skip();
}
});
});