279 lines
9.0 KiB
TypeScript
279 lines
9.0 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 }) => {
|
|
// 验证查询词筛选下拉框存在
|
|
const queryFilterLabel = authenticatedPage.getByText("查询词");
|
|
const hasLabel = await queryFilterLabel.isVisible({ timeout: 15000 }).catch(() => false);
|
|
|
|
if (!hasLabel) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 点击查询词下拉框
|
|
const querySelectTrigger = authenticatedPage.locator("#query-filter");
|
|
const hasSelect = await querySelectTrigger.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (!hasSelect) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
await querySelectTrigger.click();
|
|
|
|
// 等待下拉选项出现
|
|
const selectContent = authenticatedPage.locator("[data-radix-popper-content-wrapper], [role='listbox']").first();
|
|
const hasOptions = await selectContent.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (!hasOptions) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 选择"全部查询词"选项(始终存在)
|
|
const allOption = authenticatedPage.getByRole("option", { name: "全部查询词" })
|
|
.or(authenticatedPage.locator("[data-radix-collection-item]").filter({ hasText: "全部查询词" }));
|
|
const hasAllOption = await allOption.first().isVisible({ timeout: 3000 }).catch(() => false);
|
|
|
|
if (hasAllOption) {
|
|
await allOption.first().click();
|
|
}
|
|
});
|
|
|
|
test("按平台筛选引用记录", async ({ authenticatedPage }) => {
|
|
// 验证平台筛选下拉框存在
|
|
const platformFilterLabel = authenticatedPage.getByText("平台");
|
|
const hasLabel = await platformFilterLabel.isVisible({ timeout: 15000 }).catch(() => false);
|
|
|
|
if (!hasLabel) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 点击平台下拉框
|
|
const platformSelectTrigger = authenticatedPage.locator("#platform-filter");
|
|
const hasSelect = await platformSelectTrigger.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (!hasSelect) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
await platformSelectTrigger.click();
|
|
|
|
// 等待下拉选项出现
|
|
const selectContent = authenticatedPage.locator("[data-radix-popper-content-wrapper], [role='listbox']").first();
|
|
const hasOptions = await selectContent.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (!hasOptions) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 选择"全部平台"选项
|
|
const allOption = authenticatedPage.getByRole("option", { name: "全部平台" })
|
|
.or(authenticatedPage.locator("[data-radix-collection-item]").filter({ hasText: "全部平台" }));
|
|
const hasAllOption = await allOption.first().isVisible({ timeout: 3000 }).catch(() => false);
|
|
|
|
if (hasAllOption) {
|
|
await allOption.first().click();
|
|
}
|
|
});
|
|
|
|
test("设置日期范围筛选", async ({ authenticatedPage }) => {
|
|
// 验证日期输入框存在
|
|
const startDateInput = authenticatedPage.locator("#start-date");
|
|
const endDateInput = authenticatedPage.locator("#end-date");
|
|
|
|
const hasStart = await startDateInput.isVisible({ timeout: 10000 }).catch(() => false);
|
|
const hasEnd = await endDateInput.isVisible({ timeout: 3000 }).catch(() => false);
|
|
|
|
if (!hasStart || !hasEnd) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 填入日期
|
|
const today = new Date();
|
|
const sevenDaysAgo = new Date(today);
|
|
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
|
|
|
|
const formatDate = (d: Date) => d.toISOString().split("T")[0];
|
|
|
|
await startDateInput.fill(formatDate(sevenDaysAgo));
|
|
await endDateInput.fill(formatDate(today));
|
|
|
|
// 点击筛选按钮
|
|
const filterBtn = authenticatedPage.getByRole("button", { name: "筛选" });
|
|
await expect(filterBtn).toBeVisible();
|
|
await filterBtn.click();
|
|
|
|
// 验证筛选已触发(页面重新加载数据)
|
|
await authenticatedPage.waitForLoadState("networkidle");
|
|
});
|
|
|
|
test("点击重置按钮清除筛选条件", async ({ authenticatedPage }) => {
|
|
const resetBtn = authenticatedPage.getByRole("button", { name: "重置" });
|
|
const hasReset = await resetBtn.isVisible({ timeout: 10000 }).catch(() => false);
|
|
|
|
if (!hasReset) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
await resetBtn.click();
|
|
|
|
// 验证筛选条件已重置 - 查询词和平台应回到默认值
|
|
await authenticatedPage.waitForLoadState("networkidle");
|
|
});
|
|
});
|
|
|
|
test.describe("引用记录 - 引用详情交互测试", () => {
|
|
test.beforeEach(async ({ authenticatedPage }) => {
|
|
await authenticatedPage.goto("/dashboard/citations");
|
|
await authenticatedPage.waitForLoadState("networkidle");
|
|
});
|
|
|
|
test("引用记录列表显示表格数据", async ({ authenticatedPage }) => {
|
|
// 等待数据加载
|
|
await authenticatedPage.waitForTimeout(2000);
|
|
|
|
const emptyState = authenticatedPage.getByText("暂无引用记录");
|
|
const hasEmpty = await emptyState.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (hasEmpty) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 验证表格存在
|
|
const table = authenticatedPage.locator("table");
|
|
const hasTable = await table.isVisible({ timeout: 10000 }).catch(() => false);
|
|
|
|
if (!hasTable) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 验证表头
|
|
const platformHeader = authenticatedPage.getByText("平台").first();
|
|
const citedHeader = authenticatedPage.getByText("是否引用").first();
|
|
await expect(platformHeader).toBeVisible();
|
|
await expect(citedHeader).toBeVisible();
|
|
});
|
|
|
|
test("点击引用记录行查看详情", async ({ authenticatedPage }) => {
|
|
await authenticatedPage.waitForTimeout(2000);
|
|
|
|
const emptyState = authenticatedPage.getByText("暂无引用记录");
|
|
const hasEmpty = await emptyState.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (hasEmpty) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 查找引用记录表格行
|
|
const tableRows = authenticatedPage.locator("table tbody tr");
|
|
const rowCount = await tableRows.count();
|
|
|
|
if (rowCount === 0) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 点击第一行查看详情
|
|
const firstRow = tableRows.first();
|
|
await firstRow.click();
|
|
|
|
// 验证点击后不报错(可能有详情展开或跳转)
|
|
expect(true).toBeTruthy();
|
|
});
|
|
|
|
test("引用记录显示已引用/未引用状态", async ({ authenticatedPage }) => {
|
|
await authenticatedPage.waitForTimeout(2000);
|
|
|
|
const emptyState = authenticatedPage.getByText("暂无引用记录");
|
|
const hasEmpty = await emptyState.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (hasEmpty) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
const tableRows = authenticatedPage.locator("table tbody tr");
|
|
const rowCount = await tableRows.count();
|
|
|
|
if (rowCount === 0) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 验证已引用或未引用状态标签
|
|
const citedBadge = authenticatedPage.getByText("已引用").first();
|
|
const notCitedBadge = authenticatedPage.getByText("未引用").first();
|
|
const hasCited = await citedBadge.isVisible({ timeout: 5000 }).catch(() => false);
|
|
const hasNotCited = await notCitedBadge.isVisible({ timeout: 3000 }).catch(() => false);
|
|
|
|
expect(hasCited || hasNotCited).toBeTruthy();
|
|
});
|
|
|
|
test("引用记录显示竞争品牌标签", async ({ authenticatedPage }) => {
|
|
await authenticatedPage.waitForTimeout(2000);
|
|
|
|
const emptyState = authenticatedPage.getByText("暂无引用记录");
|
|
const hasEmpty = await emptyState.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
if (hasEmpty) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 查找竞争品牌 Badge
|
|
const competitorBrands = authenticatedPage.locator("table tbody tr").first().locator("span.text-xs");
|
|
const hasBrands = await competitorBrands.isVisible({ timeout: 5000 }).catch(() => false);
|
|
|
|
// 竞争品牌可能为空,仅验证不报错
|
|
expect(true).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
test.describe("引用记录 - 导出功能交互测试", () => {
|
|
test.beforeEach(async ({ authenticatedPage }) => {
|
|
await authenticatedPage.goto("/dashboard/citations");
|
|
await authenticatedPage.waitForLoadState("networkidle");
|
|
});
|
|
|
|
test("点击导出CSV按钮触发下载", async ({ authenticatedPage }) => {
|
|
const exportCsvBtn = authenticatedPage.getByRole("button", { name: /导出 CSV/ });
|
|
const hasBtn = await exportCsvBtn.isVisible({ timeout: 15000 }).catch(() => false);
|
|
|
|
if (!hasBtn) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 验证按钮可点击
|
|
await expect(exportCsvBtn).toBeEnabled();
|
|
});
|
|
|
|
test("点击导出PDF按钮触发下载", async ({ authenticatedPage }) => {
|
|
const exportPdfBtn = authenticatedPage.getByRole("button", { name: /导出 PDF/ });
|
|
const hasBtn = await exportPdfBtn.isVisible({ timeout: 15000 }).catch(() => false);
|
|
|
|
if (!hasBtn) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
// 验证按钮可点击
|
|
await expect(exportPdfBtn).toBeEnabled();
|
|
});
|
|
});
|