feat: extend operation log service and repository with pagination support

This commit is contained in:
张翔
2026-03-18 22:34:43 +08:00
parent 157aee2ffc
commit 8a0cd64829
81 changed files with 8842 additions and 509 deletions
+90 -43
View File
@@ -1,79 +1,126 @@
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
import { DashboardPage } from './pages/DashboardPage';
import { RoleManagementPage } from './pages/RoleManagementPage';
test.describe('角色管理 E2E 测试', () => {
let loginPage: LoginPage;
let dashboardPage: DashboardPage;
let roleManagementPage: RoleManagementPage;
test.beforeEach(async ({ page }) => {
await page.goto('/login');
await page.fill('input[placeholder*="用户名"]', 'admin');
await page.fill('input[type="password"]', 'admin123');
await page.click('button:has-text("登录")');
await page.waitForURL('**/dashboard');
loginPage = new LoginPage(page);
dashboardPage = new DashboardPage(page);
roleManagementPage = new RoleManagementPage(page);
await loginPage.goto();
await loginPage.login('admin', 'password');
});
test('创建角色完整流程', async ({ page }) => {
await page.click('text=角色管理');
await page.waitForURL('**/roles');
await dashboardPage.navigateToRoleManagement();
await page.click('text=创建角色');
await roleManagementPage.clickCreateRole();
const timestamp = Date.now();
const roleName = `测试角色_${timestamp}`;
const roleKey = `test_role_${timestamp}`;
const roleData = {
roleName: `测试角色_${timestamp}`,
roleKey: `test_role_${timestamp}`,
roleSort: '1',
status: '1',
remark: `测试角色备注_${timestamp}`,
};
await page.fill('input[name="roleName"]', roleName);
await page.fill('input[name="roleKey"]', roleKey);
await page.fill('input[name="roleSort"]', '1');
await roleManagementPage.fillRoleForm(roleData);
await roleManagementPage.submitForm();
await page.click('input[type="checkbox"][value="user:view"]');
await page.click('input[type="checkbox"][value="user:create"]');
await page.click('button[type="submit"]');
await expect(page.locator('.success-message')).toBeVisible();
await expect(page.locator('table')).toContainText(roleName);
await expect(roleManagementPage.successMessage).toBeVisible();
await expect(roleManagementPage.table).toContainText(roleData.roleName);
});
test('编辑角色流程', async ({ page }) => {
await page.click('text=角色管理');
await page.waitForURL('**/roles');
await dashboardPage.navigateToRoleManagement();
await page.click('table tbody tr:first-child .edit-button');
await roleManagementPage.editRole(1);
await page.fill('input[name="roleName"]', '更新后的角色名称');
await page.click('button[type="submit"]');
await roleManagementPage.submitForm();
await expect(page.locator('.success-message')).toBeVisible();
await expect(page.locator('table')).toContainText('更新后的角色名称');
await expect(roleManagementPage.successMessage).toBeVisible();
await expect(roleManagementPage.table).toContainText('更新后的角色名称');
});
test('分配权限流程', async ({ page }) => {
await page.click('text=角色管理');
await page.waitForURL('**/roles');
await dashboardPage.navigateToRoleManagement();
await page.click('table tbody tr:first-child .permission-button');
await roleManagementPage.openPermissionDialog(1);
await page.click('input[type="checkbox"][value="user:edit"]');
await page.click('input[type="checkbox"][value="user:delete"]');
await roleManagementPage.selectPermission('user:view');
await roleManagementPage.selectPermission('user:create');
await roleManagementPage.selectPermission('user:edit');
await roleManagementPage.selectPermission('user:delete');
await page.click('.permission-dialog .save-button');
await roleManagementPage.savePermissions();
await expect(page.locator('.success-message')).toBeVisible();
await expect(roleManagementPage.successMessage).toBeVisible();
});
test('删除角色流程', async ({ page }) => {
await page.click('text=角色管理');
await page.waitForURL('**/roles');
await dashboardPage.navigateToRoleManagement();
const firstRow = page.locator('table tbody tr:first-child');
const roleName = await firstRow.locator('td:first-child').textContent();
const roleName = await roleManagementPage.getRoleName(1);
await firstRow.locator('.delete-button').click();
await roleManagementPage.deleteRole(1);
await roleManagementPage.confirmDelete();
await expect(roleManagementPage.successMessage).toBeVisible();
await roleManagementPage.reload();
await expect(roleManagementPage.table).not.toContainText(roleName);
});
test('角色状态切换', async ({ page }) => {
await dashboardPage.navigateToRoleManagement();
await page.click('table tbody tr:first-child .status-toggle');
await expect(roleManagementPage.successMessage).toBeVisible();
});
test('搜索角色功能', async ({ page }) => {
await dashboardPage.navigateToRoleManagement();
await page.fill('input[name="keyword"]', 'admin');
await page.click('button[type="search"]');
await expect(roleManagementPage.table).toContainText('admin');
});
test('批量删除角色', async ({ page }) => {
await dashboardPage.navigateToRoleManagement();
await page.check('table tbody tr:nth-child(1) input[type="checkbox"]');
await page.check('table tbody tr:nth-child(2) input[type="checkbox"]');
await page.click('button:has-text("批量删除")');
await page.click('.confirm-dialog .confirm-button');
await expect(page.locator('.success-message')).toBeVisible();
await page.reload();
await expect(page.locator('table')).not.toContainText(roleName);
await expect(roleManagementPage.successMessage).toBeVisible();
});
});
test('复制角色', async ({ page }) => {
await dashboardPage.navigateToRoleManagement();
await page.click('table tbody tr:first-child .copy-button');
const timestamp = Date.now();
await page.fill('input[name="roleName"]', `复制角色_${timestamp}`);
await page.fill('input[name="roleKey"]', `copy_role_${timestamp}`);
await roleManagementPage.submitForm();
await expect(roleManagementPage.successMessage).toBeVisible();
await expect(roleManagementPage.table).toContainText(`复制角色_${timestamp}`);
});
});