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

110 lines
3.9 KiB
TypeScript

import { test, expect } from "../fixtures";
test.describe("引用记录 - 页面渲染测试", () => {
test.beforeEach(async ({ authenticatedPage }) => {
await authenticatedPage.goto("/dashboard/citations");
await authenticatedPage.waitForLoadState("networkidle");
});
test("引用记录页面标题正确显示", async ({ authenticatedPage }) => {
await expect(
authenticatedPage.getByRole("heading", { name: "引用记录", exact: true })
).toBeVisible({ timeout: 15000 });
});
test("引用记录页面副标题正确显示", async ({ authenticatedPage }) => {
await expect(
authenticatedPage.getByText("查看各平台的引用检测结果")
).toBeVisible({ timeout: 15000 });
});
test("引用记录页面显示导出按钮", async ({ authenticatedPage }) => {
await expect(
authenticatedPage.getByRole("button", { name: /导出 CSV/ })
).toBeVisible({ timeout: 15000 });
await expect(
authenticatedPage.getByRole("button", { name: /导出 PDF/ })
).toBeVisible();
});
test("引用记录页面显示筛选条件", async ({ authenticatedPage }) => {
await expect(
authenticatedPage.getByRole("button", { name: "筛选" })
).toBeVisible({ timeout: 15000 });
await expect(
authenticatedPage.getByRole("button", { name: "重置" })
).toBeVisible();
});
});
test.describe("引用记录 - 统计卡片测试", () => {
test.beforeEach(async ({ authenticatedPage }) => {
await authenticatedPage.goto("/dashboard/citations");
await authenticatedPage.waitForLoadState("networkidle");
});
test("引用记录页面显示统计卡片", async ({ authenticatedPage }) => {
const citationRate = authenticatedPage.getByText("引用率");
const avgPosition = authenticatedPage.getByText("平均位置");
const totalCitations = authenticatedPage.getByText("总引用数");
const hasRate = await citationRate.isVisible({ timeout: 10000 }).catch(() => false);
const hasPosition = await avgPosition.isVisible({ timeout: 3000 }).catch(() => false);
const hasTotal = await totalCitations.isVisible({ timeout: 3000 }).catch(() => false);
if (!hasRate && !hasPosition && !hasTotal) {
test.skip();
return;
}
expect(hasRate || hasPosition || hasTotal).toBeTruthy();
});
});
test.describe("引用记录 - 空状态与图表测试", () => {
test.beforeEach(async ({ authenticatedPage }) => {
await authenticatedPage.goto("/dashboard/citations");
await authenticatedPage.waitForLoadState("networkidle");
});
test("无引用记录时显示空状态", async ({ authenticatedPage }) => {
const emptyState = authenticatedPage.getByText("暂无引用记录");
const hasEmpty = await emptyState.isVisible({ timeout: 10000 }).catch(() => false);
if (!hasEmpty) {
test.skip();
return;
}
await expect(emptyState).toBeVisible();
});
test("引用记录页面显示平台分布图表", async ({ authenticatedPage }) => {
const chartContainer = authenticatedPage.locator(".recharts-pie");
const emptyChart = authenticatedPage.getByText("暂无平台分布数据");
const hasChart = await chartContainer.isVisible({ timeout: 10000 }).catch(() => false);
const hasEmpty = await emptyChart.isVisible({ timeout: 3000 }).catch(() => false);
if (!hasChart && !hasEmpty) {
test.skip();
return;
}
expect(hasChart || hasEmpty).toBeTruthy();
});
test("引用记录页面显示趋势图表", async ({ authenticatedPage }) => {
const chartContainer = authenticatedPage.locator(".recharts-line");
const emptyChart = authenticatedPage.getByText("暂无趋势数据");
const hasChart = await chartContainer.isVisible({ timeout: 10000 }).catch(() => false);
const hasEmpty = await emptyChart.isVisible({ timeout: 3000 }).catch(() => false);
if (!hasChart && !hasEmpty) {
test.skip();
return;
}
expect(hasChart || hasEmpty).toBeTruthy();
});
});