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('..'); const textarea = servicesConfig.locator('textarea'); await textarea.fill(''); await servicesConfig.locator('button:has-text("保存")').click(); await adminPage.waitForTimeout(2000); await page.goto('/'); await page.waitForLoadState('networkidle'); const serviceCards = page.locator('#services .card'); const count = await serviceCards.count(); expect(count).toBe(0); }); 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('-5'); await newsConfig.locator('button:has-text("保存")').click(); await adminPage.waitForTimeout(2000); await page.goto('/'); await page.waitForLoadState('networkidle'); const newsCards = page.locator('#news .card'); const count = await newsCards.count(); expect(count).toBeGreaterThanOrEqual(0); }); 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('1000'); 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).toBeLessThanOrEqual(100); }); 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).toBeGreaterThanOrEqual(0); }); 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 selectElement = newsConfig.locator('select'); await selectElement.selectOption('invalid'); await newsConfig.locator('button:has-text("保存")').click(); await adminPage.waitForTimeout(2000); await page.goto('/'); await page.waitForLoadState('networkidle'); const newsCards = page.locator('#news .card'); const count = await newsCards.count(); expect(count).toBeGreaterThanOrEqual(0); }); test('配置项不存在 - 访问不存在的配置', async ({ page, context }) => { const adminPage = await context.newPage(); await adminPage.goto('/admin/settings'); await adminPage.waitForLoadState('networkidle'); const nonExistentConfig = adminPage.locator('text=feature_nonexistent'); expect(nonExistentConfig).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 checkbox = servicesConfig.locator('input[type="checkbox"]').first(); for (let i = 0; i < 5; i++) { await checkbox.setChecked(i % 2 === 0); await servicesConfig.locator('button:has-text("保存")').click(); await adminPage.waitForSelector('text=保存成功', { timeout: 5000 }); await page.goto('/'); await page.waitForLoadState('networkidle'); const isVisible = await page.locator('#services').isVisible(); expect(isVisible).toBe(i % 2 === 0); await adminPage.goto('/admin/settings'); await adminPage.waitForLoadState('networkidle'); } }); 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'); const originalValue = await textarea.inputValue(); await textarea.fill(''); 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(0); await textarea.fill(originalValue); 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).toBeGreaterThan(0); }); });