From 05b67a57666f54729d8ccfe12e4034140d35b52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 12 Mar 2026 22:03:16 +0800 Subject: [PATCH] feat: add product management E2E tests --- .../tests/admin/product-management.spec.ts | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 e2e/src/tests/admin/product-management.spec.ts diff --git a/e2e/src/tests/admin/product-management.spec.ts b/e2e/src/tests/admin/product-management.spec.ts new file mode 100644 index 0000000..c264bdd --- /dev/null +++ b/e2e/src/tests/admin/product-management.spec.ts @@ -0,0 +1,117 @@ +import { test, expect } from '../../fixtures/base.fixture'; +import { AdminLoginPage, AdminContentPage } from '../../pages/AdminPage'; +import { adminTestData, generateTestContent } from '../../data/admin-test-data'; + +test.describe('产品服务管理E2E测试', () => { + let loginPage: AdminLoginPage; + let contentPage: AdminContentPage; + + test.beforeEach(async ({ page }) => { + loginPage = new AdminLoginPage(page); + contentPage = new AdminContentPage(page); + + await loginPage.goto(); + await loginPage.login(adminTestData.users.admin.email, adminTestData.users.admin.password); + + await expect(async () => { + await page.waitForURL(/\/admin/, { timeout: 10000 }); + }).toPass({ timeout: 15000 }); + }); + + test('应该能够创建产品', async ({ page }) => { + const productData = generateTestContent('product'); + + await contentPage.goto(); + await contentPage.createContent(productData); + + await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); + + await contentPage.goto(); + await contentPage.searchContent(productData.title); + + const productCount = await contentPage.contentList.count(); + expect(productCount).toBeGreaterThan(0); + }); + + test('应该能够编辑产品', async ({ page }) => { + await contentPage.goto(); + await contentPage.searchContent('测试产品'); + + const initialCount = await contentPage.contentList.count(); + if (initialCount === 0) { + test.skip(true, '没有找到可编辑的产品'); + } + + await contentPage.editContent(0); + + const updatedTitle = '更新后的产品标题-' + Date.now(); + await page.locator('input[name="title"]').fill(updatedTitle); + await page.getByRole('button', { name: /保存/i }).click(); + + await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); + + await contentPage.goto(); + await contentPage.searchContent(updatedTitle); + + const foundCount = await contentPage.contentList.count(); + expect(foundCount).toBeGreaterThan(0); + }); + + test('应该能够删除产品', async ({ page }) => { + const productData = generateTestContent('product'); + + await contentPage.goto(); + await contentPage.createContent(productData); + await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); + + await contentPage.goto(); + await contentPage.searchContent(productData.title); + + const initialCount = await contentPage.contentList.count(); + if (initialCount === 0) { + test.skip(true, '没有找到可删除的产品'); + } + + await contentPage.deleteContent(0); + + await expect(contentPage.contentList).toHaveCount(initialCount - 1, { timeout: 5000 }); + }); + + test('应该能够筛选产品类型', async ({ page }) => { + await contentPage.goto(); + + const typeFilter = page.locator('select').first(); + await typeFilter.selectOption('product'); + await page.waitForTimeout(1000); + + const items = await contentPage.contentList.all(); + for (const item of items) { + const typeBadge = await item.locator('span').first().textContent(); + expect(typeBadge).toContain('产品'); + } + }); + + test('应该能够按状态筛选产品', async ({ page }) => { + await contentPage.goto(); + + const statusFilter = page.locator('select').nth(1); + await statusFilter.selectOption('published'); + await page.waitForTimeout(1000); + + const items = await contentPage.contentList.all(); + for (const item of items) { + const statusBadge = await item.locator('span').nth(1).textContent(); + expect(statusBadge).toContain('已发布'); + } + }); + + test('应该能够搜索产品', async ({ page }) => { + await contentPage.goto(); + + await contentPage.searchContent('产品'); + await page.waitForTimeout(1000); + + const itemCount = await contentPage.contentList.count(); + expect(itemCount).toBeGreaterThanOrEqual(0); + }); +});