Files
novalon-website/e2e/src/tests/config-linkage/config-edge-cases.spec.ts
T
张翔 490a2172b8 test: add comprehensive E2E tests for configuration linkage
- Add config-persistence.spec.ts for configuration persistence tests
- Add config-concurrency.spec.ts for concurrent modification tests
- Add config-edge-cases.spec.ts for edge case tests
- Test scenarios:
  - Configuration persistence across server restarts
  - Concurrent modifications by multiple admins
  - Empty values, negative numbers, large values
  - Special characters, invalid sort values
  - Rapid toggling and configuration reset
  - Non-existent configuration items
  - Multiple simultaneous configuration changes
2026-03-13 14:48:59 +08:00

184 lines
6.8 KiB
TypeScript

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<script>alert("test")</script>');
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);
});
});