You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ghost/e2e/tests/admin/analytics/post-analytics/overview.test.ts

80 lines
4.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 导入Playwright测试核心工具test用于定义测试用例expect用于用于断言验证结果
// 从项目helpers目录导入导入playwright工具包封装含项目自定义的测试配置或工具函数
import { test, expect } from '../../../../helpers/playwright';
// 导入所需的页面对象类(对应管理后台的不同页面/组件)
import {
AnalyticsOverviewPage, // 分析概览页面(入口页面)
PostAnalyticsPage, // 文章分析主页面Overview视图
PostAnalyticsGrowthPage, // 文章分析的Growth详情页面
PostAnalyticsWebTrafficPage // 文章分析的Web Traffic详情页面
} from '../../../../helpers/pages/admin';
/**
* 文件说明:
* 这个测试文件包含文章级别 Analytics 的 Overview 视图相关的 e2e 测试。
* 场景主要验证在“空数据”情况下,各个卡片/选项卡的可见性和提示文本。
*/
// 定义测试套件Ghost管理后台 - 文章分析 - Overview概览视图的测试
// 所有相关测试用例都归类在此套件下,便于管理和理解测试范围
test.describe('Ghost Admin - Post Analytics - Overview', () => {
// 前置操作:每个测试用例执行前都会运行的代码(初始化测试环境)
test.beforeEach(async ({ page }) => {
// 1. 实例化分析概览页面对象(进入分析模块的入口页面)
const analyticsOverviewPage = new AnalyticsOverviewPage(page);
// 2. 导航到分析概览页面(内部实现页面跳转和加载验证)
await analyticsOverviewPage.goto();
// 3. 在概览页面中点击“最新文章”的analytics按钮进入该文章的分析面板
// (模拟用户从概览页查看单篇文章详情分析的操作流程)
await analyticsOverviewPage.latestPost.analyticsButton.click();
});
// 测试用例1验证概览页面存在三个主要选项卡确保页面结构完整性
test('empty page with all tabs', async ({ page }) => {
// 实例化文章分析主页面对象当前处于Overview视图
const postAnalyticsPage = new PostAnalyticsPage(page);
// 断言三个视图切换按钮Overview/Web traffic/Growth都应可见
// 验证页面基本结构完整,用户可正常切换不同分析视图
await expect(postAnalyticsPage.overviewButton).toBeVisible();
await expect(postAnalyticsPage.webTrafficButton).toBeVisible();
await expect(postAnalyticsPage.growthButton).toBeVisible();
});
// 测试用例2验证从Overview的Web performance区块点击"View more"的跳转和空数据提示
test('empty page - overview - web performance - view more', async ({ page }) => {
// 实例化文章分析主页面对象
const postAnalyticsPage = new PostAnalyticsPage(page);
// 点击Web performance区块的“View more”按钮预期跳转到Web traffic详情页
await postAnalyticsPage.webPerformanceSection.viewMoreButton.click();
// 实例化Web traffic详情页面对象跳转后的目标页面
const postAnalyticsWebTrafficPage = new PostAnalyticsWebTrafficPage(page);
// 断言空数据场景下Web traffic页面应显示指定提示文本验证空状态展示正确
await expect(postAnalyticsWebTrafficPage.body).toContainText('No visitors in the last 30 days');
});
// 测试用例3验证Overview视图中Growth区块的空数据展示成员数相关
test('empty page - overview - growth', async ({ page }) => {
// 实例化文章分析主页面对象
const postAnalyticsPage = new PostAnalyticsPage(page);
// 断言1Growth区块应包含“Free members”标签验证成员类型标签正确
await expect(postAnalyticsPage.growthSection.card).toContainText('Free members');
// 断言2Growth区块应显示成员数量为0验证空数据时数量展示正确
await expect(postAnalyticsPage.growthSection.card).toContainText('0');
});
// 测试用例4验证从Overview的Growth区块点击"View more"的跳转和空数据提示
test('empty page - overview - growth - view more', async ({ page }) => {
// 实例化文章分析主页面对象
const postAnalyticsPage = new PostAnalyticsPage(page);
// 点击Growth区块的“View more”按钮预期跳转到Growth详情页
await postAnalyticsPage.growthSection.viewMoreButton.click();
// 实例化Growth详情页面对象跳转后的目标页面
const postAnalyticsGrowthPage = new PostAnalyticsGrowthPage(page);
// 断言空数据场景下Top sources卡片应显示指定提示文本验证空状态展示正确
await expect(postAnalyticsGrowthPage.topSourcesCard).toContainText('No sources data available');
});
});