feat: 完善系统配置审计通知功能并优化异常处理

- 新增异常处理体系(BaseException及其子类)
- 优化密码、邮箱、用户名等基础类型
- 添加字典管理、登录日志、操作日志的E2E测试
- 完善API集成测试和安全测试
- 添加性能测试配置和脚本
- 优化OpenAPI配置和全局异常处理器
This commit is contained in:
张翔
2026-03-24 14:05:35 +08:00
parent be5d5ede90
commit e4721053bd
47 changed files with 3006 additions and 816 deletions
+109 -261
View File
@@ -1,325 +1,173 @@
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
import { DashboardPage } from './pages/DashboardPage';
import { SystemConfigPage } from './pages/SystemConfigPage';
import { DictionaryManagementPage } from './pages/DictionaryManagementPage';
test.describe('系统配置 E2E 测试', () => {
test.describe('系统配置E2E测试', () => {
let loginPage: LoginPage;
let dashboardPage: DashboardPage;
let systemConfigPage: SystemConfigPage;
let dictionaryManagementPage: DictionaryManagementPage;
let configPage: SystemConfigPage;
test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
dashboardPage = new DashboardPage(page);
systemConfigPage = new SystemConfigPage(page);
dictionaryManagementPage = new DictionaryManagementPage(page);
configPage = new SystemConfigPage(page);
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
test('CONFIG-001: 管理员查看系统配置列表', async ({ page }) => {
await test.step('管理员登录', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
test.afterEach(async ({ page }) => {
await loginPage.logout();
});
test('系统配置页面导航', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await page.goto('/sys/config');
await page.waitForLoadState('networkidle');
await configPage.goto();
await expect(page).toHaveURL(/.*config/);
});
await test.step('验证系统配置页面加载', async () => {
await expect(systemConfigPage.table).toBeVisible();
const rowCount = await systemConfigPage.getTableRowCount();
expect(rowCount).toBeGreaterThan(0);
});
await test.step('验证配置表格包含必要列', async () => {
await expect(systemConfigPage.table).toContainText('参数名称');
await expect(systemConfigPage.table).toContainText('参数键名');
await expect(systemConfigPage.table).toContainText('参数值');
await expect(systemConfigPage.table).toContainText('类型');
await test.step('验证页面元素可见', async () => {
await expect(configPage.table).toBeVisible();
await expect(configPage.addButton).toBeVisible();
await expect(configPage.searchInput).toBeVisible();
});
});
test('CONFIG-002: 管理员新增系统配置', async ({ page }) => {
await test.step('管理员登录并导航到系统配置', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await systemConfigPage.goto();
test('创建系统配置', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('新系统配置', async () => {
const testConfigName = `测试配置_${Date.now()}`;
const testConfigKey = `test.config.${Date.now()}`;
const testConfigValue = 'test_value_123';
await test.step('创建新系统配置', async () => {
const configName = `测试配置_${Date.now()}`;
const configKey = `test.config.${Date.now()}`;
const configValue = `test_value_${Date.now()}`;
await systemConfigPage.addConfig(testConfigName, testConfigKey, testConfigValue);
await page.waitForTimeout(1000);
await configPage.addConfig(configName, configKey, configValue);
await expect(systemConfigPage.table).toBeVisible();
await configPage.verifyTableContains(configName);
});
});
test('CONFIG-003: 管理员修改系统配置', async ({ page }) => {
await test.step('管理员登录并导航到系统配置', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await systemConfigPage.goto();
test('编辑系统配置', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('修改系统配置', async () => {
const rows = await systemConfigPage.table.locator('.el-table__row').count();
if (rows > 0) {
const firstRow = systemConfigPage.table.locator('.el-table__row').first();
const configKey = await firstRow.locator('td').nth(1).textContent();
if (configKey && configKey.includes('test.config')) {
const newValue = `updated_value_${Date.now()}`;
await systemConfigPage.editConfig(configKey, newValue);
await page.waitForTimeout(1000);
await expect(systemConfigPage.table).toBeVisible();
}
}
await test.step('编辑现有系统配置', async () => {
const configKey = 'system.site.name';
const newValue = `Novalon管理系统_${Date.now()}`;
await configPage.editConfig(configKey, newValue);
await configPage.verifyTableContains(newValue);
});
});
test('CONFIG-004: 管理员删除系统配置', async ({ page }) => {
await test.step('管理员登录并导航到系统配置', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await systemConfigPage.goto();
test('删除系统配置', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('删除系统配置', async () => {
const rows = await systemConfigPage.table.locator('.el-table__row').count();
if (rows > 0) {
const testRow = systemConfigPage.table.locator('tr').filter({ hasText: 'test.config' }).first();
const testRowCount = await testRow.count();
if (testRowCount > 0) {
const configKey = await testRow.locator('td').nth(1).textContent();
if (configKey) {
await systemConfigPage.deleteConfig(configKey);
await page.waitForTimeout(1000);
await expect(systemConfigPage.table).toBeVisible();
}
}
}
const configName = `测试配置_${Date.now()}`;
const configKey = `test.config.${Date.now()}`;
const configValue = `test_value_${Date.now()}`;
await configPage.addConfig(configName, configKey, configValue);
await configPage.verifyTableContains(configName);
await configPage.deleteConfig(configKey);
await configPage.verifyTableNotContains(configName);
});
});
test('CONFIG-005: 管理员搜索系统配置', async ({ page }) => {
await test.step('管理员登录并导航到系统配置', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await systemConfigPage.goto();
test('搜索系统配置', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('搜索系统配置', async () => {
await systemConfigPage.searchConfig('用户');
await page.waitForTimeout(1000);
const configName = '系统名称';
await configPage.searchConfig(configName);
await configPage.verifyTableContains(configName);
});
await test.step('清除搜索条件', async () => {
await systemConfigPage.clearSearch();
const rowCount = await systemConfigPage.getTableRowCount();
await test.step('清除搜索', async () => {
await configPage.clearSearch();
const rowCount = await configPage.getTableRowCount();
expect(rowCount).toBeGreaterThan(0);
});
});
test('CONFIG-006: 验证系统配置权限控制', async ({ page }) => {
await test.step('普通用户登录', async () => {
await loginPage.goto();
await loginPage.login('user', 'user123');
await expect(page).toHaveURL(/.*dashboard/);
test('系统配置分页功能', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('尝试访问系统配置页面', async () => {
await page.goto('/sysconfig');
await page.waitForLoadState('networkidle');
const currentURL = page.url();
if (currentURL.includes('/sys/config')) {
await expect(systemConfigPage.table).toBeVisible();
} else {
await expect(page).toHaveURL(/.*dashboard/);
}
await test.step('验证表格数据加载', async () => {
const rowCount = await configPage.getTableRowCount();
expect(rowCount).toBeGreaterThan(0);
});
});
test('CONFIG-007: 验证配置修改生效', async ({ page }) => {
await test.step('管理员登录并导航到系统配置', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await systemConfigPage.goto();
test('系统配置响应式布局', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('修改配置并验证生效', async () => {
const rows = await systemConfigPage.table.locator('.el-table__row').count();
await test.step('验证桌面端布局', async () => {
await page.setViewportSize({ width: 1280, height: 720 });
await expect(configPage.table).toBeVisible();
await expect(configPage.addButton).toBeVisible();
});
await test.step('验证平板端布局', async () => {
await page.setViewportSize({ width: 768, height: 1024 });
await expect(configPage.table).toBeVisible();
await expect(configPage.addButton).toBeVisible();
});
await test.step('验证移动端布局', async () => {
await page.setViewportSize({ width: 375, height: 667 });
await expect(configPage.table).toBeVisible();
});
});
test('系统配置权限验证', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('验证添加按钮可见性', async () => {
await expect(configPage.addButton).toBeVisible();
});
await test.step('验证编辑和删除按钮可见性', async () => {
const rows = await configPage.table.locator('.el-table__row').count();
if (rows > 0) {
const firstRow = systemConfigPage.table.locator('.el-table__row').first();
const configKey = await firstRow.locator('td').nth(1).textContent();
if (configKey) {
const newValue = `test_value_${Date.now()}`;
await systemConfigPage.editConfig(configKey, newValue);
await page.waitForTimeout(1000);
await expect(systemConfigPage.table).toBeVisible();
}
await expect(configPage.table).toBeVisible();
}
});
});
test('CONFIG-008: 管理员查看字典管理列表', async ({ page }) => {
await test.step('管理员登录', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
test('系统配置数据验证', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('导航到字典管理页面', async () => {
await page.goto('/dict');
await page.waitForLoadState('networkidle');
});
await test.step('验证字典管理页面加载', async () => {
await expect(dictionaryManagementPage.table).toBeVisible();
const rowCount = await dictionaryManagementPage.getTableRowCount();
expect(rowCount).toBeGreaterThan(0);
});
await test.step('验证字典表格包含必要列', async () => {
await expect(dictionaryManagementPage.table).toContainText('字典名称');
await expect(dictionaryManagementPage.table).toContainText('字典类型');
await expect(dictionaryManagementPage.table).toContainText('状态');
await expect(dictionaryManagementPage.table).toContainText('备注');
});
});
test('CONFIG-009: 管理员新增字典类型', async ({ page }) => {
await test.step('管理员登录并导航到字典管理', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dictionaryManagementPage.goto();
});
await test.step('新增字典类型', async () => {
const testDictName = `测试字典_${Date.now()}`;
const testDictType = `test_dict_${Date.now()}`;
await test.step('验证配置键名唯一性', async () => {
const configName = `测试配置_${Date.now()}`;
const configKey = `test.config.${Date.now()}`;
const configValue = `test_value_${Date.now()}`;
await dictionaryManagementPage.addDictionary(testDictName, testDictType);
await page.waitForTimeout(1000);
await expect(dictionaryManagementPage.table).toBeVisible();
});
});
test('CONFIG-010: 管理员搜索字典类型', async ({ page }) => {
await test.step('管理员登录并导航到字典管理', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dictionaryManagementPage.goto();
await configPage.addConfig(configName, configKey, configValue);
await configPage.verifyTableContains(configName);
});
await test.step('搜索字典类型', async () => {
await dictionaryManagementPage.searchDictionary('用户');
await page.waitForTimeout(1000);
});
await test.step('清除搜索条件', async () => {
await dictionaryManagementPage.clearSearch();
const rowCount = await dictionaryManagementPage.getTableRowCount();
expect(rowCount).toBeGreaterThan(0);
});
});
test('CONFIG-011: 验证字典管理权限控制', async ({ page }) => {
await test.step('普通用户登录', async () => {
await loginPage.goto();
await loginPage.login('user', 'user123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('尝试访问字典管理页面', async () => {
await page.goto('/system/dict');
await page.waitForLoadState('networkidle');
const currentURL = page.url();
if (currentURL.includes('/system/dict')) {
await expect(dictionaryManagementPage.table).toBeVisible();
} else {
await expect(page).toHaveURL(/.*dashboard/);
}
});
});
test('CONFIG-012: 验证配置数据完整性', async ({ page }) => {
await test.step('管理员登录并导航到系统配置', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await systemConfigPage.goto();
});
await test.step('验证配置数据完整性', async () => {
const rows = await systemConfigPage.table.locator('.el-table__row').count();
await test.step('验证配置值格式正确', async () => {
const rows = await configPage.table.locator('.el-table__row').count();
expect(rows).toBeGreaterThan(0);
const firstRow = systemConfigPage.table.locator('.el-table__row').first();
await expect(firstRow).toBeVisible();
});
});
test('CONFIG-013: 验证字典数据完整性', async ({ page }) => {
await test.step('管理员登录并导航到字典管理', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dictionaryManagementPage.goto();
});
await test.step('验证字典数据完整性', async () => {
const rows = await dictionaryManagementPage.table.locator('.el-table__row').count();
expect(rows).toBeGreaterThan(0);
const firstRow = dictionaryManagementPage.table.locator('.el-table__row').first();
await expect(firstRow).toBeVisible();
});
});
test('CONFIG-014: 验证配置操作按钮可见性', async ({ page }) => {
await test.step('管理员登录并导航到系统配置', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await systemConfigPage.goto();
});
await test.step('验证新增按钮可见', async () => {
await expect(systemConfigPage.addButton).toBeVisible();
});
await test.step('验证搜索框可见', async () => {
await expect(systemConfigPage.searchInput).toBeVisible();
});
});
test('CONFIG-015: 验证字典操作按钮可见性', async ({ page }) => {
await test.step('管理员登录并导航到字典管理', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dictionaryManagementPage.goto();
});
await test.step('验证新增按钮可见', async () => {
await expect(dictionaryManagementPage.addButton).toBeVisible();
});
await test.step('验证搜索框可见', async () => {
await expect(dictionaryManagementPage.searchInput).toBeVisible();
});
});
});
});