Files
everything-is-suitable/everything-is-suitable-test/e2e/role-mock.spec.ts
T
张翔 08ea5fbe98 feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
2026-03-28 14:37:29 +08:00

75 lines
3.2 KiB
TypeScript

import { test, expect } from './test-fixtures';
test.describe('角色管理 - 完全Mock模式', () => {
test.beforeEach(async ({ page, mockManager }) => {
mockManager.enableMock();
mockManager.configureMock({
mode: 'full',
delay: 100
});
mockManager.presetTestData({
roles: [
{ id: 1, name: '超级管理员', roleKey: 'super_admin', description: '拥有所有权限', status: 'ENABLED', sortOrder: 1, remark: '系统默认角色', menuIds: [1, 2, 3], createdAt: '2024-01-01T10:00:00.000Z', updatedAt: '2024-01-01T10:00:00.000Z' },
{ id: 2, name: '管理员', roleKey: 'admin', description: '拥有大部分权限', status: 'ENABLED', sortOrder: 2, remark: '系统管理员', menuIds: [1, 2], createdAt: '2024-01-02T10:00:00.000Z', updatedAt: '2024-01-02T10:00:00.000Z' },
{ id: 3, name: '普通用户', roleKey: 'user', description: '拥有基本权限', status: 'ENABLED', sortOrder: 3, remark: '普通用户角色', menuIds: [1], createdAt: '2024-01-03T10:00:00.000Z', updatedAt: '2024-01-03T10:00:00.000Z' }
]
});
await page.goto('/');
await page.fill('input[placeholder="请输入用户名"]', 'admin');
await page.fill('input[placeholder="请输入密码"]', 'admin123');
await page.click('button[type="submit"]');
await page.waitForURL(/.*dashboard/, { timeout: 10000 });
});
test.afterEach(async ({ mockManager }) => {
mockManager.clearPresets();
mockManager.disableMock();
});
test('应该显示角色列表', async ({ page }) => {
await page.goto('/roles');
await page.waitForLoadState('networkidle');
await expect(page.locator('.ant-table')).toBeVisible();
await expect(page.locator('text=超级管理员')).toBeVisible();
await expect(page.locator('text=管理员')).toBeVisible();
await expect(page.locator('text=普通用户')).toBeVisible();
});
test('应该能够创建新角色', async ({ page }) => {
await page.goto('/roles');
await page.waitForLoadState('networkidle');
await page.click('button:has-text("新增角色")');
await page.fill('input[placeholder="请输入角色名称"]', '测试角色');
await page.fill('input[placeholder="请输入角色标识"]', 'test_role');
await page.fill('textarea[placeholder="请输入角色描述"]', '这是一个测试角色');
await page.click('button:has-text("确定")');
await expect(page.locator('text=创建成功')).toBeVisible();
});
test('应该能够编辑角色', async ({ page }) => {
await page.goto('/roles');
await page.waitForLoadState('networkidle');
await page.click('button:has-text("编辑"):first');
await page.fill('input[placeholder="请输入角色名称"]', '更新后的角色名称');
await page.click('button:has-text("确定")');
await expect(page.locator('text=更新成功')).toBeVisible();
});
test('应该能够删除角色', async ({ page }) => {
await page.goto('/roles');
await page.waitForLoadState('networkidle');
page.on('dialog', dialog => dialog.accept());
await page.click('button:has-text("删除"):first');
await expect(page.locator('text=删除成功')).toBeVisible();
});
});