Files
张翔 08ea5fbe98 feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
2026-03-28 14:37:29 +08:00

124 lines
3.7 KiB
TypeScript

import { test, expect } from './test-fixtures';
import { LoginPage } from './pages/login-page';
test.describe('用户管理', () => {
let loginPage: LoginPage;
test.beforeEach(async ({ page, mockManager }) => {
loginPage = new LoginPage(page);
mockManager.presetTestData({
menus: [
{
id: 1,
name: '仪表盘',
code: 'dashboard',
path: '/dashboard',
icon: 'DashboardOutlined',
sortOrder: 1,
status: 'active',
parentId: 0,
component: 'views/Dashboard.vue',
createBy: 'system',
updateBy: 'system',
createdAt: '2024-01-01T00:00:00.000Z',
updatedAt: '2024-01-01T00:00:00.000Z',
children: []
},
{
id: 2,
name: '用户管理',
code: 'user',
path: '/users',
icon: 'UserOutlined',
sortOrder: 2,
status: 'active',
parentId: 0,
component: 'views/UserManagement.vue',
createBy: 'system',
updateBy: 'system',
createdAt: '2024-01-01T00:00:00.000Z',
updatedAt: '2024-01-01T00:00:00.000Z',
children: []
}
],
users: [
{
id: 1,
username: 'admin',
email: 'admin@example.com',
phone: '13800138000',
status: 'active',
createBy: 'system',
updateBy: 'admin',
createdAt: '2024-01-01T00:00:00.000Z',
updatedAt: '2024-01-01T00:00:00.000Z'
},
{
id: 2,
username: 'testuser',
email: 'test@example.com',
phone: '13800138001',
status: 'active',
createBy: 'admin',
updateBy: 'admin',
createdAt: '2024-01-01T00:00:00.000Z',
updatedAt: '2024-01-01T00:00:00.000Z'
}
]
});
page.on('console', msg => {
console.log('浏览器控制台:', msg.text());
});
page.on('request', request => {
console.log('页面请求:', request.method(), request.url());
});
page.on('response', async response => {
const url = response.url();
if (url.includes('/sys/')) {
console.log('API响应:', response.status(), url);
try {
const body = await response.text();
console.log('响应体:', body.substring(0, 200));
} catch (e) {
console.log('响应体读取失败');
}
}
});
await page.goto('/login');
await loginPage.loginAndWaitForDashboard('admin', 'admin123');
});
test('应该能够通过侧边栏导航到用户管理页面', async ({ page }) => {
const userManagementMenuItem = page.locator('text=用户管理');
await userManagementMenuItem.waitFor({ state: 'visible', timeout: 10000 });
await userManagementMenuItem.click();
await page.waitForURL(/.*users/, { timeout: 10000 });
expect(page.url()).toContain('/users');
});
test('应该显示用户管理页面标题', async ({ page }) => {
const userManagementMenuItem = page.locator('text=用户管理');
await userManagementMenuItem.waitFor({ state: 'visible', timeout: 10000 });
await userManagementMenuItem.click();
await page.waitForURL(/.*users/, { timeout: 10000 });
await page.waitForTimeout(2000);
const userListTitle = page.locator('text=用户列表');
await expect(userListTitle).toBeVisible({ timeout: 5000 });
const searchButton = page.locator('button:has-text("搜索")');
await expect(searchButton).toBeVisible({ timeout: 5000 });
const addUserButton = page.locator('button:has-text("新增用户")');
await expect(addUserButton).toBeVisible({ timeout: 5000 });
});
});