Files
novalon-manage-system/novalon-manage-web/e2e/journeys/notice-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

139 lines
5.0 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { NotificationPage } from '../pages/NotificationPage';
test.describe('通知管理工作流', () => {
let noticePage: NotificationPage;
const timestamp = Date.now();
const noticeTitle = `测试通知_${timestamp}`;
const noticeContent = `这是测试通知内容_${timestamp}`;
test.beforeEach(async ({ page }) => {
noticePage = new NotificationPage(page);
});
test('查看通知列表', async ({ page }) => {
await test.step('导航到通知管理页面', async () => {
await noticePage.goto();
});
await test.step('验证表格显示', async () => {
await expect(noticePage.table).toBeVisible({ timeout: 10000 });
});
await test.step('验证数据加载', async () => {
const rowCount = await noticePage.getTableRowCount();
console.log(`通知列表包含 ${rowCount} 条记录`);
expect(rowCount).toBeGreaterThanOrEqual(0);
});
});
test('新增通知', async ({ page }) => {
await test.step('导航到通知管理页面', async () => {
await noticePage.goto();
});
await test.step('点击新增通知按钮', async () => {
await noticePage.addButton.click();
await noticePage.dialog.waitFor({ state: 'visible', timeout: 5000 });
});
await test.step('填写通知表单', async () => {
await noticePage.titleInput.fill(noticeTitle);
await noticePage.contentInput.fill(noticeContent);
});
await test.step('提交表单', async () => {
await noticePage.saveButton.click();
await page.waitForLoadState('networkidle');
});
await test.step('验证创建成功', async () => {
await expect(noticePage.dialog).not.toBeVisible({ timeout: 5000 });
console.log(`通知 ${noticeTitle} 创建完成`);
});
});
test('编辑通知', async ({ page }) => {
await test.step('导航到通知管理页面', async () => {
await noticePage.goto();
});
await test.step('等待数据加载', async () => {
await expect(noticePage.table).toBeVisible({ timeout: 10000 });
});
await test.step('点击编辑按钮', async () => {
const rows = await noticePage.getTableRowCount();
if (rows > 0) {
const firstRow = noticePage.table.locator('tr').first();
const editBtn = firstRow.getByRole('button', { name: '编辑' });
if (await editBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
await editBtn.click();
await noticePage.dialog.waitFor({ state: 'visible', timeout: 5000 });
await test.step('修改通知内容', async () => {
const newContent = `更新通知内容_${timestamp}`;
await noticePage.contentInput.clear();
await noticePage.contentInput.fill(newContent);
});
await test.step('提交表单', async () => {
await noticePage.saveButton.click();
await page.waitForLoadState('networkidle');
});
await test.step('验证更新成功', async () => {
await expect(noticePage.dialog).not.toBeVisible({ timeout: 5000 });
console.log(`通知已更新`);
});
} else {
console.log('未找到编辑按钮,跳过编辑测试');
}
} else {
console.log('当前没有通知记录,跳过编辑测试');
}
});
});
test('删除通知', async ({ page }) => {
await test.step('导航到通知管理页面', async () => {
await noticePage.goto();
});
await test.step('等待数据加载', async () => {
await expect(noticePage.table).toBeVisible({ timeout: 10000 });
});
await test.step('点击删除按钮', async () => {
const rows = await noticePage.getTableRowCount();
if (rows > 0) {
const firstRow = noticePage.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('当前没有通知记录,跳过删除测试');
}
});
});
});