import { test, expect } from '../../fixtures/admin.fixture'; import { generateTestContent } from '../../data/admin-test-data'; test.describe('成功案例管理E2E测试', () => { test('应该能够创建案例', async ({ page, adminContentPage }) => { const caseData = generateTestContent('case'); await adminContentPage.goto(); await adminContentPage.createContent(caseData); await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); await adminContentPage.goto(); await adminContentPage.searchContent(caseData.title); const caseCount = await adminContentPage.contentList.count(); expect(caseCount).toBeGreaterThan(0); }); test('应该能够编辑案例', async ({ page, adminContentPage }) => { await adminContentPage.goto(); await adminContentPage.searchContent('测试案例'); const initialCount = await adminContentPage.contentList.count(); if (initialCount === 0) { test.skip(true, '没有找到可编辑的案例'); } await adminContentPage.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 }); }); test('应该能够删除案例', async ({ page, adminContentPage }) => { const caseData = generateTestContent('case'); await adminContentPage.goto(); await adminContentPage.createContent(caseData); await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); await adminContentPage.goto(); await adminContentPage.searchContent(caseData.title); const initialCount = await adminContentPage.contentList.count(); if (initialCount === 0) { test.skip(true, '没有找到可删除的案例'); } await adminContentPage.deleteContent(0); await expect(adminContentPage.contentList).toHaveCount(initialCount - 1, { timeout: 5000 }); }); test('应该能够设置案例封面图', async ({ page, adminContentPage }) => { await adminContentPage.goto(); await adminContentPage.createButton.click(); await page.locator('select[name="type"]').selectOption('case'); await page.locator('input[name="title"]').fill('封面图测试案例-' + Date.now()); await page.locator('input[name="slug"]').fill('cover-test-case-' + Date.now()); const fileInput = page.locator('input[type="file"]'); if (await fileInput.count() > 0) { await fileInput.setInputFiles({ name: 'test-cover.jpg', mimeType: 'image/jpeg', buffer: Buffer.from('test image content') }); } await page.getByRole('button', { name: /保存/i }).click(); await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); }); test('应该能够筛选案例类型', async ({ page, adminContentPage }) => { await adminContentPage.goto(); const typeFilter = page.locator('select').first(); await typeFilter.selectOption('case'); await page.waitForTimeout(1000); const items = await adminContentPage.contentList.all(); for (const item of items) { const typeBadge = await item.locator('span').first().textContent(); expect(typeBadge).toContain('案例'); } }); });