import { test, expect } from '@playwright/test'; test.describe('前后台配置持久化测试', () => { test.beforeEach(async ({ page }) => { await page.goto('/admin/login'); await page.fill('input[type="email"]', 'admin@novalon.cn'); await page.fill('input[type="password"]', 'admin123456'); await page.click('button[type="submit"]'); await page.waitForURL('/admin'); }); test('配置保存后重启服务仍然有效', async ({ page, context }) => { const adminPage = await context.newPage(); await adminPage.goto('/admin/settings'); await adminPage.waitForLoadState('networkidle'); const servicesConfig = adminPage.locator('text=feature_services').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 adminPage.reload(); await adminPage.waitForLoadState('networkidle'); const checkbox = servicesConfig.locator('input[type="checkbox"]').first(); await expect(checkbox).toBeChecked(); }); test('配置修改后立即生效到前台', async ({ page, context }) => { const adminPage = await context.newPage(); await adminPage.goto('/admin/settings'); await adminPage.waitForLoadState('networkidle'); const newsConfig = adminPage.locator('text=feature_news').locator('..').locator('..'); const displayCountInput = newsConfig.locator('input[type="number"]'); await displayCountInput.fill('3'); 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(3); }); test('配置删除后前台不再显示', async ({ page, context }) => { const adminPage = await context.newPage(); await adminPage.goto('/admin/settings'); await adminPage.waitForLoadState('networkidle'); const productsConfig = adminPage.locator('text=feature_products').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(); }); test('配置值修改后前台实时更新', async ({ page, context }) => { const adminPage = await context.newPage(); await adminPage.goto('/admin/settings'); await adminPage.waitForLoadState('networkidle'); const servicesConfig = adminPage.locator('text=feature_services').locator('..').locator('..'); const textarea = servicesConfig.locator('textarea'); await textarea.fill('erp'); 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(1); await textarea.fill('erp\ncrm'); await servicesConfig.locator('button:has-text("保存")').click(); await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); await page.reload(); await page.waitForLoadState('networkidle'); const newCount = await serviceCards.count(); expect(newCount).toBe(2); }); });