From c5c3685d137c1a22aaa1f577fb987fb1494a7543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Fri, 13 Mar 2026 13:13:48 +0800 Subject: [PATCH] test: add frontend-backend configuration linkage E2E tests - Add config-toggle.spec.ts for module show/hide tests - Add config-params.spec.ts for configuration parameter tests - Test Services module toggle and items filtering - Test Products module toggle, pricing display, and featured products - Test News module toggle, display count, categories, and sort order - Verify real-time configuration updates between admin and frontend --- .../config-linkage/config-params.spec.ts | 256 ++++++++++++++++++ .../config-linkage/config-toggle.spec.ts | 115 ++++++++ 2 files changed, 371 insertions(+) create mode 100644 e2e/src/tests/config-linkage/config-params.spec.ts create mode 100644 e2e/src/tests/config-linkage/config-toggle.spec.ts diff --git a/e2e/src/tests/config-linkage/config-params.spec.ts b/e2e/src/tests/config-linkage/config-params.spec.ts new file mode 100644 index 0000000..6475353 --- /dev/null +++ b/e2e/src/tests/config-linkage/config-params.spec.ts @@ -0,0 +1,256 @@ +import { test, expect } from '@playwright/test'; + +test.describe('前后台配置参数测试', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/'); + }); + + test('配置参数 - 新闻显示数量', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..'); + + await newsConfig.locator('input[type="number"]').fill('2'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + + const newsCards = page.locator('#news .card'); + const count = await newsCards.count(); + expect(count).toBe(2); + + await newsConfig.locator('input[type="number"]').fill('4'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + + const newsCardsAfter = page.locator('#news .card'); + const countAfter = await newsCardsAfter.count(); + expect(countAfter).toBe(4); + + await newsConfig.locator('input[type="number"]').fill('6'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); + + test('配置参数 - 新闻分类过滤', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..'); + + const categoriesTextarea = newsConfig.locator('textarea'); + await categoriesTextarea.fill('公司新闻\n产品发布'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + + const newsCards = page.locator('#news .card'); + const count = await newsCards.count(); + expect(count).toBeGreaterThan(0); + + for (let i = 0; i < count; i++) { + const card = newsCards.nth(i); + const category = await card.locator('.badge').textContent(); + expect(['公司新闻', '产品发布']).toContain(category?.trim() || ''); + } + + await categoriesTextarea.fill('公司新闻\n产品发布\n合作动态\n行业资讯'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); + + test('配置参数 - 新闻排序', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..'); + + await newsConfig.locator('select').selectOption('desc'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + + const firstCard = page.locator('#news .card').first(); + const firstDate = await firstCard.locator('.date').textContent(); + + await newsConfig.locator('select').selectOption('asc'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + + const firstCardAfter = page.locator('#news .card').first(); + const firstDateAfter = await firstCardAfter.locator('.date').textContent(); + + expect(firstDate).not.toBe(firstDateAfter); + + await newsConfig.locator('select').selectOption('desc'); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); + + test('配置参数 - 产品价格显示', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const productsConfig = adminPage.locator('text=产品模块配置').locator('..').locator('..'); + + await productsConfig.locator('text=showPricing').locator('..').locator('input[type="checkbox"]').check(); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + + const firstProductCard = page.locator('#products .card').first(); + await expect(firstProductCard.locator('text=价格方案')).toBeVisible(); + + await productsConfig.locator('text=showPricing').locator('..').locator('input[type="checkbox"]').uncheck(); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + + await expect(firstProductCard.locator('text=价格方案')).not.toBeVisible(); + + await productsConfig.locator('text=showPricing').locator('..').locator('input[type="checkbox"]').check(); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); + + test('配置参数 - 特色产品过滤', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const productsConfig = adminPage.locator('text=产品模块配置').locator('..').locator('..'); + + const featuredProductsTextarea = productsConfig.locator('text=featuredProducts').locator('..').locator('textarea'); + await featuredProductsTextarea.fill('erp'); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + + const productCards = page.locator('#products .card'); + const count = await productCards.count(); + expect(count).toBe(1); + + await featuredProductsTextarea.fill('erp\ncrm'); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + + const productCardsAfter = page.locator('#products .card'); + const countAfter = await productCardsAfter.count(); + expect(countAfter).toBe(2); + + await featuredProductsTextarea.fill('erp\ncrm\ncms\nbi'); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); + + test('配置参数 - 服务项目过滤', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const servicesConfig = adminPage.locator('text=服务模块配置').locator('..').locator('..'); + + const itemsTextarea = servicesConfig.locator('text=items').locator('..').locator('textarea'); + await itemsTextarea.fill('software\ncloud'); + await servicesConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + + const serviceCards = page.locator('#services .card'); + const count = await serviceCards.count(); + expect(count).toBe(2); + + await itemsTextarea.fill('software\ncloud\ndata\nsecurity'); + await servicesConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + + const serviceCardsAfter = page.locator('#services .card'); + const countAfter = await serviceCardsAfter.count(); + expect(countAfter).toBe(4); + + await adminPage.close(); + }); +}); \ No newline at end of file diff --git a/e2e/src/tests/config-linkage/config-toggle.spec.ts b/e2e/src/tests/config-linkage/config-toggle.spec.ts new file mode 100644 index 0000000..429818b --- /dev/null +++ b/e2e/src/tests/config-linkage/config-toggle.spec.ts @@ -0,0 +1,115 @@ +import { test, expect } from '@playwright/test'; + +test.describe('前后台配置联动测试', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/'); + }); + + test('配置开关 - 服务模块显示/隐藏', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const servicesConfig = adminPage.locator('text=服务模块配置').locator('..').locator('..'); + await servicesConfig.locator('input[type="checkbox"]').first().check(); + await servicesConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + await expect(page.locator('#services')).toBeVisible(); + + await servicesConfig.locator('input[type="checkbox"]').first().uncheck(); + await servicesConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + await expect(page.locator('#services')).not.toBeVisible(); + + await servicesConfig.locator('input[type="checkbox"]').first().check(); + await servicesConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); + + test('配置开关 - 产品模块显示/隐藏', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const productsConfig = adminPage.locator('text=产品模块配置').locator('..').locator('..'); + await productsConfig.locator('input[type="checkbox"]').first().check(); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + await expect(page.locator('#products')).toBeVisible(); + + await productsConfig.locator('input[type="checkbox"]').first().uncheck(); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + await expect(page.locator('#products')).not.toBeVisible(); + + await productsConfig.locator('input[type="checkbox"]').first().check(); + await productsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); + + test('配置开关 - 新闻模块显示/隐藏', async ({ page, context }) => { + const adminPage = await context.newPage(); + + await adminPage.goto('/admin/login'); + await adminPage.fill('input[type="email"]', 'admin@novalon.cn'); + await adminPage.fill('input[type="password"]', 'admin123456'); + await adminPage.click('button[type="submit"]'); + await adminPage.waitForURL('/admin'); + + await adminPage.goto('/admin/settings'); + await adminPage.waitForLoadState('networkidle'); + + const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..'); + await newsConfig.locator('input[type="checkbox"]').first().check(); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.goto('/'); + await page.waitForLoadState('networkidle'); + await expect(page.locator('#news')).toBeVisible(); + + await newsConfig.locator('input[type="checkbox"]').first().uncheck(); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await page.reload(); + await page.waitForLoadState('networkidle'); + await expect(page.locator('#news')).not.toBeVisible(); + + await newsConfig.locator('input[type="checkbox"]').first().check(); + await newsConfig.locator('button:has-text("保存")').click(); + await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); + + await adminPage.close(); + }); +}); \ No newline at end of file