7e54d7fb46
架构改进: - 引入审计日志服务层,实现业务逻辑与数据访问分离 - 添加 Spring Data 审计注解,自动填充创建人、创建时间等字段 - 修复切面范围,避免 Repository 和 Dao 层重复记录 代码优化: - 移除构造函数中的冗余 info 日志,降低生产环境日志量 - 恢复 SQL 文件格式,提高可读性 - 优化 E2E 测试等待策略,移除硬编码等待时间,提高测试稳定性 影响范围: - 后端:审计日志模块(Service、Repository、Aspect、Entity) - 前端:E2E 测试文件(4 个 workflow 测试) - 数据库:审计日志表结构
97 lines
3.5 KiB
TypeScript
97 lines
3.5 KiB
TypeScript
import { Page, Locator, expect } from '@playwright/test';
|
|
|
|
export class DictionaryManagementPage {
|
|
readonly page: Page;
|
|
readonly table: 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');
|
|
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() {
|
|
try {
|
|
console.log('导航到字典管理页面...');
|
|
await this.page.goto('/dict');
|
|
|
|
await this.page.waitForLoadState('networkidle');
|
|
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
|
await expect(this.page).toHaveURL(/.*dict/);
|
|
|
|
console.log('字典管理页面加载完成');
|
|
} catch (error) {
|
|
await this.page.screenshot({ path: `test-results/dict-management-error-${Date.now()}.png` });
|
|
console.error('导航到字典管理页面失败:', error);
|
|
throw new Error(`导航到字典管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
}
|
|
}
|
|
|
|
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 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 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);
|
|
|
|
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
|
await confirmBtn.click();
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|