feat: extend operation log service and repository with pagination support
This commit is contained in:
@@ -1,82 +1,118 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { LoginPage } from './pages/LoginPage';
|
||||
import { DashboardPage } from './pages/DashboardPage';
|
||||
import { UserManagementPage } from './pages/UserManagementPage';
|
||||
import { generateTestUser } from './fixtures/test-data';
|
||||
|
||||
test.describe('用户管理 E2E 测试', () => {
|
||||
let loginPage: LoginPage;
|
||||
let dashboardPage: DashboardPage;
|
||||
let userManagementPage: UserManagementPage;
|
||||
|
||||
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);
|
||||
userManagementPage = new UserManagementPage(page);
|
||||
|
||||
await loginPage.goto();
|
||||
await loginPage.login('admin', 'password');
|
||||
});
|
||||
|
||||
test('创建用户完整流程', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
await page.click('text=创建用户');
|
||||
await userManagementPage.clickCreateUser();
|
||||
|
||||
const timestamp = Date.now();
|
||||
const username = `testuser_${timestamp}`;
|
||||
const userData = {
|
||||
username: `testuser_${timestamp}`,
|
||||
email: `test_${timestamp}@example.com`,
|
||||
phone: '13800138000',
|
||||
password: 'Test123!@#',
|
||||
confirmPassword: 'Test123!@#',
|
||||
};
|
||||
|
||||
await page.fill('input[name="username"]', username);
|
||||
await page.fill('input[name="email"]', `test_${timestamp}@example.com`);
|
||||
await page.fill('input[name="phone"]', '13800138000');
|
||||
await page.fill('input[name="password"]', 'Test123!@#');
|
||||
await page.fill('input[name="confirmPassword"]', 'Test123!@#');
|
||||
await userManagementPage.fillUserForm(userData);
|
||||
await userManagementPage.submitForm();
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
await expect(page.locator('table')).toContainText(username);
|
||||
await expect(userManagementPage.successMessage).toBeVisible();
|
||||
await expect(userManagementPage.table).toContainText(userData.username);
|
||||
});
|
||||
|
||||
test('编辑用户流程', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
await page.click('table tbody tr:first-child .edit-button');
|
||||
await userManagementPage.editUser(1);
|
||||
|
||||
await page.fill('input[name="email"]', 'updated@example.com');
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
await userManagementPage.submitForm();
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
await expect(page.locator('table')).toContainText('updated@example.com');
|
||||
await expect(userManagementPage.successMessage).toBeVisible();
|
||||
await expect(userManagementPage.table).toContainText('updated@example.com');
|
||||
});
|
||||
|
||||
test('删除用户流程', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
const firstRow = page.locator('table tbody tr:first-child');
|
||||
const username = await firstRow.locator('td:first-child').textContent();
|
||||
const username = await userManagementPage.getUserName(1);
|
||||
|
||||
await firstRow.locator('.delete-button').click();
|
||||
await userManagementPage.deleteUser(1);
|
||||
await userManagementPage.confirmDelete();
|
||||
|
||||
await page.click('.confirm-dialog .confirm-button');
|
||||
await expect(userManagementPage.successMessage).toBeVisible();
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
|
||||
await page.reload();
|
||||
await expect(page.locator('table')).not.toContainText(username);
|
||||
await userManagementPage.reload();
|
||||
await expect(userManagementPage.table).not.toContainText(username);
|
||||
});
|
||||
|
||||
test('搜索用户功能', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
await page.fill('input[name="keyword"]', 'admin');
|
||||
await page.click('button[type="search"]');
|
||||
await userManagementPage.search('admin');
|
||||
|
||||
await expect(page.locator('table')).toContainText('admin');
|
||||
await expect(userManagementPage.table).toContainText('admin');
|
||||
});
|
||||
|
||||
test('分页功能', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
await page.click('.pagination .next-page');
|
||||
const currentPage = await userManagementPage.getCurrentPage();
|
||||
expect(currentPage).toBe('1');
|
||||
|
||||
await expect(page.locator('.pagination .current-page')).toContainText('2');
|
||||
await userManagementPage.nextPage();
|
||||
|
||||
const newPage = await userManagementPage.getCurrentPage();
|
||||
expect(newPage).toBe('2');
|
||||
});
|
||||
});
|
||||
|
||||
test('批量删除用户', async ({ page }) => {
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
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(userManagementPage.successMessage).toBeVisible();
|
||||
});
|
||||
|
||||
test('用户状态切换', async ({ page }) => {
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
await page.click('table tbody tr:first-child .status-toggle');
|
||||
|
||||
await expect(userManagementPage.successMessage).toBeVisible();
|
||||
});
|
||||
|
||||
test('导出用户数据', async ({ page }) => {
|
||||
await dashboardPage.navigateToUserManagement();
|
||||
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
await page.click('button:has-text("导出")');
|
||||
const download = await downloadPromise;
|
||||
|
||||
expect(download.suggestedFilename()).toMatch(/users.*\.xlsx/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user