110 lines
4.1 KiB
TypeScript
110 lines
4.1 KiB
TypeScript
import { test, expect } from "../fixtures";
|
|
|
|
test.describe("竞品分析 - 页面渲染测试", () => {
|
|
test.beforeEach(async ({ authenticatedPage }) => {
|
|
await authenticatedPage.goto("/dashboard/competitors");
|
|
await authenticatedPage.waitForLoadState("networkidle");
|
|
});
|
|
|
|
test("竞品分析页面标题正确显示", async ({ authenticatedPage }) => {
|
|
await expect(
|
|
authenticatedPage.getByRole("heading", { name: "竞品分析", level: 2 })
|
|
).toBeVisible({ timeout: 15000 });
|
|
});
|
|
|
|
test("竞品分析页面副标题正确显示", async ({ authenticatedPage }) => {
|
|
await expect(
|
|
authenticatedPage.getByText("分析竞品表现,发现差距与机会")
|
|
).toBeVisible({ timeout: 15000 });
|
|
});
|
|
|
|
test("竞品分析页面显示添加竞品按钮", async ({ authenticatedPage }) => {
|
|
await expect(
|
|
authenticatedPage.getByRole("button", { name: /添加竞品/ })
|
|
).toBeVisible({ timeout: 15000 });
|
|
});
|
|
});
|
|
|
|
test.describe("竞品分析 - 添加竞品对话框测试", () => {
|
|
test.beforeEach(async ({ authenticatedPage }) => {
|
|
await authenticatedPage.goto("/dashboard/competitors");
|
|
await authenticatedPage.waitForLoadState("networkidle");
|
|
});
|
|
|
|
test("点击添加竞品打开对话框", async ({ authenticatedPage }) => {
|
|
const addBtn = authenticatedPage.getByRole("button", { name: /添加竞品/ });
|
|
await expect(addBtn).toBeVisible({ timeout: 15000 });
|
|
await addBtn.click();
|
|
|
|
const dialog = authenticatedPage.getByRole("dialog");
|
|
await expect(dialog).toBeVisible({ timeout: 10000 });
|
|
});
|
|
|
|
test("添加竞品对话框包含推荐选择和手动输入Tab", async ({ authenticatedPage }) => {
|
|
const addBtn = authenticatedPage.getByRole("button", { name: /添加竞品/ });
|
|
await expect(addBtn).toBeVisible({ timeout: 15000 });
|
|
await addBtn.click();
|
|
|
|
const dialog = authenticatedPage.getByRole("dialog");
|
|
await expect(dialog).toBeVisible({ timeout: 10000 });
|
|
|
|
const recommendTab = dialog.getByRole("tab", { name: "从推荐选择" });
|
|
const manualTab = dialog.getByRole("tab", { name: "手动输入" });
|
|
await expect(recommendTab).toBeVisible();
|
|
await expect(manualTab).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test.describe("竞品分析 - 竞品列表与空状态测试", () => {
|
|
test.beforeEach(async ({ authenticatedPage }) => {
|
|
await authenticatedPage.goto("/dashboard/competitors");
|
|
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 analysisCard = authenticatedPage.getByText("竞品分析");
|
|
const hasCard = await analysisCard.isVisible({ timeout: 10000 }).catch(() => false);
|
|
if (!hasCard) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
const competitorSelect = authenticatedPage.getByText("选择竞品");
|
|
const analysisTypeSelect = authenticatedPage.getByText("分析类型");
|
|
const hasCompetitorSelect = await competitorSelect.isVisible({ timeout: 5000 }).catch(() => false);
|
|
const hasAnalysisTypeSelect = await analysisTypeSelect.isVisible({ timeout: 3000 }).catch(() => false);
|
|
|
|
if (!hasCompetitorSelect && !hasAnalysisTypeSelect) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
expect(hasCompetitorSelect || hasAnalysisTypeSelect).toBeTruthy();
|
|
});
|
|
|
|
test("竞品分析页面显示雷达图或空状态", async ({ authenticatedPage }) => {
|
|
const radarChart = authenticatedPage.locator(".recharts-radar");
|
|
const emptyRadar = authenticatedPage.getByText("暂无对比数据");
|
|
|
|
const hasChart = await radarChart.isVisible({ timeout: 10000 }).catch(() => false);
|
|
const hasEmpty = await emptyRadar.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (!hasChart && !hasEmpty) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
expect(hasChart || hasEmpty).toBeTruthy();
|
|
});
|
|
});
|