Files
novalon-manage-system/novalon-manage-web/e2e/journeys/config-workflow.spec.ts
T
张翔 7e54d7fb46 refactor(审计日志): 优化审计日志架构和 E2E 测试质量
架构改进:
- 引入审计日志服务层,实现业务逻辑与数据访问分离
- 添加 Spring Data 审计注解,自动填充创建人、创建时间等字段
- 修复切面范围,避免 Repository 和 Dao 层重复记录

代码优化:
- 移除构造函数中的冗余 info 日志,降低生产环境日志量
- 恢复 SQL 文件格式,提高可读性
- 优化 E2E 测试等待策略,移除硬编码等待时间,提高测试稳定性

影响范围:
- 后端:审计日志模块(Service、Repository、Aspect、Entity)
- 前端:E2E 测试文件(4 个 workflow 测试)
- 数据库:审计日志表结构
2026-04-08 19:49:55 +08:00

141 lines
5.1 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { SystemConfigPage } from '../pages/SystemConfigPage';
test.describe('系统配置工作流', () => {
let configPage: SystemConfigPage;
const timestamp = Date.now();
const configKey = `test_config_${timestamp}`;
const configName = `测试配置_${timestamp}`;
const configValue = `测试值_${timestamp}`;
test.beforeEach(async ({ page }) => {
configPage = new SystemConfigPage(page);
});
test('查看系统配置列表', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('验证表格显示', async () => {
await expect(configPage.table).toBeVisible({ timeout: 10000 });
});
await test.step('验证数据加载', async () => {
const rowCount = await configPage.getTableRowCount();
console.log(`系统配置列表包含 ${rowCount} 条记录`);
expect(rowCount).toBeGreaterThanOrEqual(0);
});
});
test('新增系统配置', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('点击新增配置按钮', async () => {
await configPage.addButton.click();
await configPage.dialog.waitFor({ state: 'visible', timeout: 5000 });
});
await test.step('填写配置表单', async () => {
await configPage.configNameInput.fill(configName);
await configPage.configKeyInput.fill(configKey);
await configPage.configValueInput.fill(configValue);
});
await test.step('提交表单', async () => {
await configPage.saveButton.click();
await page.waitForLoadState('networkidle');
});
await test.step('验证创建成功', async () => {
await expect(configPage.dialog).not.toBeVisible({ timeout: 5000 });
console.log(`配置 ${configName} 创建完成`);
});
});
test('编辑系统配置', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('等待数据加载', async () => {
await expect(configPage.table).toBeVisible({ timeout: 10000 });
});
await test.step('点击编辑按钮', async () => {
const rows = await configPage.getTableRowCount();
if (rows > 0) {
const firstRow = configPage.table.locator('tr').first();
const editBtn = firstRow.getByRole('button', { name: '编辑' });
if (await editBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
await editBtn.click();
await configPage.dialog.waitFor({ state: 'visible', timeout: 5000 });
await test.step('修改配置值', async () => {
const newValue = `更新值_${timestamp}`;
await configPage.configValueInput.clear();
await configPage.configValueInput.fill(newValue);
});
await test.step('提交表单', async () => {
await configPage.saveButton.click();
await page.waitForLoadState('networkidle');
});
await test.step('验证更新成功', async () => {
await expect(configPage.dialog).not.toBeVisible({ timeout: 5000 });
console.log(`配置已更新`);
});
} else {
console.log('未找到编辑按钮,跳过编辑测试');
}
} else {
console.log('当前没有配置记录,跳过编辑测试');
}
});
});
test('删除系统配置', async ({ page }) => {
await test.step('导航到系统配置页面', async () => {
await configPage.goto();
});
await test.step('等待数据加载', async () => {
await expect(configPage.table).toBeVisible({ timeout: 10000 });
});
await test.step('点击删除按钮', async () => {
const rows = await configPage.getTableRowCount();
if (rows > 0) {
const firstRow = configPage.table.locator('tr').first();
const deleteBtn = firstRow.getByRole('button', { name: '删除' });
if (await deleteBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
await deleteBtn.click();
const confirmBtn = page.locator('.el-message-box');
await confirmBtn.waitFor({ state: 'visible', timeout: 3000 });
await test.step('确认删除', async () => {
const confirmBtn = page.locator('.el-message-box').getByRole('button', { name: '确定' });
if (await confirmBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
await confirmBtn.click();
await page.waitForLoadState('networkidle');
}
});
await test.step('验证删除成功', async () => {
const messageBox = page.locator('.el-message-box');
await expect(messageBox).not.toBeVisible({ timeout: 5000 });
console.log(`配置已删除`);
});
} else {
console.log('未找到删除按钮,跳过删除测试');
}
} else {
console.log('当前没有配置记录,跳过删除测试');
}
});
});
});