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
This commit is contained in:
@@ -0,0 +1,106 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test.describe('前后台配置并发修改测试', () => {
|
||||||
|
test('多个管理员同时修改同一配置', async ({ page, context }) => {
|
||||||
|
const adminPage1 = await context.newPage();
|
||||||
|
const adminPage2 = await context.newPage();
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
adminPage1.goto('/admin/settings'),
|
||||||
|
adminPage2.goto('/admin/settings')
|
||||||
|
]);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
adminPage1.waitForLoadState('networkidle'),
|
||||||
|
adminPage2.waitForLoadState('networkidle')
|
||||||
|
]);
|
||||||
|
|
||||||
|
const servicesConfig1 = adminPage1.locator('text=feature_services').locator('..').locator('..');
|
||||||
|
const servicesConfig2 = adminPage2.locator('text=feature_services').locator('..').locator('..');
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
servicesConfig1.locator('input[type="checkbox"]').first().check(),
|
||||||
|
servicesConfig2.locator('input[type="checkbox"]').first().uncheck()
|
||||||
|
]);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
servicesConfig1.locator('button:has-text("保存")').click(),
|
||||||
|
servicesConfig2.locator('button:has-text("保存")').click()
|
||||||
|
]);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
adminPage1.waitForSelector('text=保存成功', { timeout: 10000 }),
|
||||||
|
adminPage2.waitForSelector('text=保存成功', { timeout: 10000 })
|
||||||
|
]);
|
||||||
|
|
||||||
|
await page.goto('/');
|
||||||
|
await page.waitForLoadState('networkidle');
|
||||||
|
|
||||||
|
const checkbox = servicesConfig1.locator('input[type="checkbox"]').first();
|
||||||
|
const isChecked = await checkbox.isChecked();
|
||||||
|
expect(isChecked).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
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"]');
|
||||||
|
|
||||||
|
for (let i = 1; i <= 3; i++) {
|
||||||
|
await displayCountInput.fill(String(i));
|
||||||
|
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(i);
|
||||||
|
|
||||||
|
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 productsConfig = adminPage.locator('text=feature_products').locator('..').locator('..');
|
||||||
|
const newsConfig = adminPage.locator('text=feature_news').locator('..').locator('..');
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
servicesConfig.locator('input[type="checkbox"]').first().check(),
|
||||||
|
productsConfig.locator('input[type="checkbox"]').first().uncheck(),
|
||||||
|
newsConfig.locator('input[type="checkbox"]').first().check()
|
||||||
|
]);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
servicesConfig.locator('button:has-text("保存")').click(),
|
||||||
|
productsConfig.locator('button:has-text("保存")').click(),
|
||||||
|
newsConfig.locator('button:has-text("保存")').click()
|
||||||
|
]);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
servicesConfig.waitForSelector('text=保存成功', { timeout: 10000 }),
|
||||||
|
productsConfig.waitForSelector('text=保存成功', { timeout: 10000 }),
|
||||||
|
newsConfig.waitForSelector('text=保存成功', { timeout: 10000 })
|
||||||
|
]);
|
||||||
|
|
||||||
|
await page.goto('/');
|
||||||
|
await page.waitForLoadState('networkidle');
|
||||||
|
|
||||||
|
await expect(page.locator('#services')).toBeVisible();
|
||||||
|
await expect(page.locator('#products')).not.toBeVisible();
|
||||||
|
await expect(page.locator('#news')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user