36160cb0e4
新增文件: - e2e/journeys/admin-content-journey.spec.ts - 管理员内容发布完整旅程 测试场景: - 管理员发布新闻并验证用户可见性 - 管理员发布产品并验证前端展示 - 管理员编辑已发布的内容 - 管理员删除内容并验证前端不可见 特性: - 使用 @journey @admin 标签 - 完整的用户旅程测试,覆盖端到端业务流程 - 使用 test.step 组织测试步骤,提升可读性 - 自动清理测试数据,避免污染环境 - 使用认证固件,简化登录流程 - 修复ESLint错误:未使用参数添加下划线前缀
124 lines
4.3 KiB
TypeScript
124 lines
4.3 KiB
TypeScript
import { test, expect } from '../fixtures/auth';
|
|
import { AdminContentPage, FrontendNewsPage, FrontendProductPage } from '../pages';
|
|
import { testFixtures } from '../fixtures/test-data';
|
|
|
|
test.describe('管理员内容发布完整旅程 @journey @admin', () => {
|
|
let contentPage: AdminContentPage;
|
|
let newsPage: FrontendNewsPage;
|
|
let productPage: FrontendProductPage;
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
contentPage = new AdminContentPage(page);
|
|
newsPage = new FrontendNewsPage(page);
|
|
productPage = new FrontendProductPage(page);
|
|
});
|
|
|
|
test('管理员发布新闻并验证用户可见性', async ({ page: _page, authenticatedPage: _authenticatedPage }) => {
|
|
const testNews = testFixtures.testContent.news;
|
|
let contentId: string | null = null;
|
|
|
|
await test.step('步骤1: 管理员创建新闻内容', async () => {
|
|
contentId = await contentPage.createContent(testNews);
|
|
expect(contentId).not.toBeNull();
|
|
});
|
|
|
|
await test.step('步骤2: 验证后台列表显示', async () => {
|
|
await contentPage.expectContentInList(testNews.title);
|
|
});
|
|
|
|
await test.step('步骤3: 验证前端用户可见', async () => {
|
|
await newsPage.goto();
|
|
await newsPage.expectNewsVisible(testNews.title);
|
|
});
|
|
|
|
await test.step('步骤4: 用户点击查看详情', async () => {
|
|
await newsPage.clickNews(testNews.title);
|
|
await newsPage.expectNewsDetailVisible(testNews.excerpt || '');
|
|
});
|
|
|
|
await test.step('步骤5: 清理测试数据', async () => {
|
|
if (contentId) {
|
|
await contentPage.deleteContent(contentId);
|
|
}
|
|
});
|
|
});
|
|
|
|
test('管理员发布产品并验证前端展示', async ({ page: _page, authenticatedPage: _authenticatedPage }) => {
|
|
const testProduct = testFixtures.testContent.product;
|
|
let contentId: string | null = null;
|
|
|
|
await test.step('步骤1: 管理员创建产品内容', async () => {
|
|
contentId = await contentPage.createContent(testProduct);
|
|
expect(contentId).not.toBeNull();
|
|
});
|
|
|
|
await test.step('步骤2: 验证后台列表显示', async () => {
|
|
await contentPage.expectContentInList(testProduct.title);
|
|
});
|
|
|
|
await test.step('步骤3: 验证前端用户可见', async () => {
|
|
await productPage.goto();
|
|
await productPage.expectProductVisible(testProduct.title);
|
|
});
|
|
|
|
await test.step('步骤4: 清理测试数据', async () => {
|
|
if (contentId) {
|
|
await contentPage.deleteContent(contentId);
|
|
}
|
|
});
|
|
});
|
|
|
|
test('管理员编辑已发布的内容', async ({ page, authenticatedPage: _authenticatedPage }) => {
|
|
const testNews = testFixtures.testContent.news;
|
|
let contentId: string | null = null;
|
|
|
|
await test.step('步骤1: 创建初始内容', async () => {
|
|
contentId = await contentPage.createContent(testNews);
|
|
expect(contentId).not.toBeNull();
|
|
});
|
|
|
|
await test.step('步骤2: 编辑内容', async () => {
|
|
await page.goto(`/admin/content/${contentId}`);
|
|
await page.fill('input[placeholder="请输入标题"]', `${testNews.title}-已编辑`);
|
|
await page.click('button:has-text("保存")');
|
|
await page.waitForURL(/\/admin\/content$/);
|
|
});
|
|
|
|
await test.step('步骤3: 验证编辑成功', async () => {
|
|
await contentPage.expectContentInList(`${testNews.title}-已编辑`);
|
|
});
|
|
|
|
await test.step('步骤4: 清理测试数据', async () => {
|
|
if (contentId) {
|
|
await contentPage.deleteContent(contentId);
|
|
}
|
|
});
|
|
});
|
|
|
|
test('管理员删除内容并验证前端不可见', async ({ page: _page, authenticatedPage: _authenticatedPage }) => {
|
|
const testNews = testFixtures.testContent.news;
|
|
let contentId: string | null = null;
|
|
|
|
await test.step('步骤1: 创建测试内容', async () => {
|
|
contentId = await contentPage.createContent(testNews);
|
|
expect(contentId).not.toBeNull();
|
|
});
|
|
|
|
await test.step('步骤2: 验证前端可见', async () => {
|
|
await newsPage.goto();
|
|
await newsPage.expectNewsVisible(testNews.title);
|
|
});
|
|
|
|
await test.step('步骤3: 删除内容', async () => {
|
|
if (contentId) {
|
|
await contentPage.deleteContent(contentId);
|
|
}
|
|
});
|
|
|
|
await test.step('步骤4: 验证前端不可见', async () => {
|
|
await newsPage.goto();
|
|
await newsPage.expectNewsNotVisible(testNews.title);
|
|
});
|
|
});
|
|
});
|