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

95 lines
4.0 KiB
TypeScript

/**
* RoleManagement页面E2E测试
*
* 测试角色管理页面的所有功能和交互
*
* @tags @role-management @e2e @view
*/
import { test, expect } from '@playwright/test';
import { TestLogger } from '../core/test-logger.js';
test.describe('E2E: RoleManagement页面', () => {
let logger: TestLogger;
test.beforeEach(async ({ page }) => {
logger = new TestLogger();
// 先登录
await page.goto('http://localhost:5174/login');
await page.fill('input[placeholder="请输入用户名"]', 'admin');
await page.fill('input[placeholder="请输入密码"]', 'admin123');
await page.click('button:has-text("登录")');
await page.waitForURL('**/dashboard');
// 导航到角色管理页面
await page.click('.el-menu-item:has-text("角色管理")');
await page.waitForURL('**/role-management');
});
test('应该显示角色管理页面 @smoke', async ({ page }) => {
await expect(page.locator('.role-management, .el-table')).toBeVisible();
await expect(page.locator('.el-pagination')).toBeVisible();
});
test('应该显示角色列表 @smoke', async ({ page }) => {
await expect(page.locator('.el-table__row')).toHaveCount.greaterThan(0);
const headers = ['角色名称', '角色编码', '描述', '状态', '操作'];
for (const header of headers) {
await expect(page.locator(`.el-table__header:has-text("${header}")`)).toBeVisible();
}
});
test('应该能够打开新增角色对话框 @critical', async ({ page }) => {
const addBtn = page.locator('button:has-text("新增"), .add-btn').first();
await addBtn.click();
await expect(page.locator('.el-dialog:has-text("新增角色")')).toBeVisible();
});
test('应该能够创建新角色 @critical', async ({ page }) => {
const addBtn = page.locator('button:has-text("新增"), .add-btn').first();
await addBtn.click();
await page.fill('.el-dialog input[placeholder*="角色名称"]', '测试角色');
await page.fill('.el-dialog input[placeholder*="角色编码"]', 'test_role');
const submitBtn = page.locator('.el-dialog button:has-text("确定")').first();
await submitBtn.click();
await expect(page.locator('.el-message--success')).toBeVisible();
});
test('应该能够编辑角色 @critical', async ({ page }) => {
const editBtn = page.locator('.el-table__row .el-button:has-text("编辑"), .el-table__row .edit-btn').first();
if (await editBtn.isVisible()) {
await editBtn.click();
await expect(page.locator('.el-dialog:has-text("编辑角色")')).toBeVisible();
const nameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
await nameInput.clear();
await nameInput.fill('更新角色');
const submitBtn = page.locator('.el-dialog button:has-text("确定")').first();
await submitBtn.click();
await expect(page.locator('.el-message--success')).toBeVisible();
}
});
test('应该能够删除角色 @critical', async ({ page }) => {
const deleteBtn = page.locator('.el-table__row .el-button:has-text("删除"), .el-table__row .delete-btn').first();
if (await deleteBtn.isVisible()) {
await deleteBtn.click();
await expect(page.locator('.el-message-box:has-text("确认删除")')).toBeVisible();
const confirmBtn = page.locator('.el-message-box button:has-text("确定")').first();
await confirmBtn.click();
await expect(page.locator('.el-message--success')).toBeVisible();
}
});
test('应该能够分配权限 @critical', async ({ page }) => {
const permissionBtn = page.locator('.el-table__row .el-button:has-text("权限"), .el-table__row .permission-btn').first();
if (await permissionBtn.isVisible()) {
await permissionBtn.click();
await expect(page.locator('.el-dialog:has-text("分配权限")')).toBeVisible();
await expect(page.locator('.el-tree')).toBeVisible();
const submitBtn = page.locator('.el-dialog button:has-text("确定")').first();
await submitBtn.click();
await expect(page.locator('.el-message--success')).toBeVisible();
}
});
});