feat: implement core UAT test scenarios
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
import { Page, Locator } from '@playwright/test';
|
||||||
|
import { UserManagementPage as BaseUserManagementPage } from '../../../novalon-manage-web/e2e/pages/UserManagementPage';
|
||||||
|
|
||||||
|
export class UserManagementPage extends BaseUserManagementPage {
|
||||||
|
readonly logoutButton: Locator;
|
||||||
|
|
||||||
|
constructor(page: Page) {
|
||||||
|
super(page);
|
||||||
|
this.logoutButton = page.getByRole('button', { name: '退出登录' }).or(page.locator('.logout-button'));
|
||||||
|
}
|
||||||
|
|
||||||
|
async navigateTo() {
|
||||||
|
await this.goto();
|
||||||
|
}
|
||||||
|
|
||||||
|
async logout() {
|
||||||
|
await this.logoutButton.click();
|
||||||
|
await this.page.waitForURL(/.*login/);
|
||||||
|
}
|
||||||
|
|
||||||
|
async approveUser(username: string) {
|
||||||
|
await this.search(username);
|
||||||
|
await this.page.waitForTimeout(500);
|
||||||
|
|
||||||
|
const row = this.table.locator(`tbody tr:has-text("${username}")`);
|
||||||
|
const approveButton = row.getByRole('button', { name: '审批' }).or(row.locator('.approve-button'));
|
||||||
|
|
||||||
|
if (await approveButton.count() > 0) {
|
||||||
|
await approveButton.click();
|
||||||
|
await this.page.waitForTimeout(500);
|
||||||
|
await this.page.getByRole('button', { name: '确定' }).click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async createUser(userData: {
|
||||||
|
username: string;
|
||||||
|
nickname?: string;
|
||||||
|
email: string;
|
||||||
|
phone?: string;
|
||||||
|
department?: string;
|
||||||
|
manager?: string;
|
||||||
|
password: string;
|
||||||
|
confirmPassword?: string;
|
||||||
|
}) {
|
||||||
|
await this.clickCreateUser();
|
||||||
|
await this.fillUserForm(userData);
|
||||||
|
await this.submitForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateUser(userId: number, userData: {
|
||||||
|
nickname?: string;
|
||||||
|
email?: string;
|
||||||
|
phone?: string;
|
||||||
|
department?: string;
|
||||||
|
}) {
|
||||||
|
await this.editUser(userId);
|
||||||
|
|
||||||
|
if (userData.nickname) {
|
||||||
|
await this.page.locator('.el-dialog').locator('input').nth(1).fill(userData.nickname);
|
||||||
|
}
|
||||||
|
if (userData.email) {
|
||||||
|
await this.page.locator('.el-dialog').locator('input').nth(3).fill(userData.email);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.submitForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { LoginPage } from '../../../novalon-manage-web/e2e/pages/LoginPage';
|
||||||
|
import { UserManagementPage } from '../../pages/UserManagementPage';
|
||||||
|
import { UATHelper } from '../../utils/uat-helper';
|
||||||
|
import { DataLoader } from '../../utils/data-loader';
|
||||||
|
|
||||||
|
test.describe('UAT - 多角色协作场景', () => {
|
||||||
|
let loginPage: LoginPage;
|
||||||
|
let userManagementPage: UserManagementPage;
|
||||||
|
let helper: UATHelper;
|
||||||
|
|
||||||
|
test('跨部门协作流程', async ({ page, context }) => {
|
||||||
|
const adminUser = DataLoader.getUserByRole('admin');
|
||||||
|
const managerUser = DataLoader.getUserByRole('manager');
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(adminUser.username, adminUser.password);
|
||||||
|
|
||||||
|
await userManagementPage.navigateTo();
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
await userManagementPage.clickCreateUser();
|
||||||
|
|
||||||
|
const timestamp = Date.now();
|
||||||
|
const userData = {
|
||||||
|
username: `collab_user_${timestamp}`,
|
||||||
|
nickname: `协作用户${timestamp}`,
|
||||||
|
email: `collab_${timestamp}@example.com`,
|
||||||
|
department: '技术部',
|
||||||
|
manager: managerUser.username,
|
||||||
|
password: 'Collab123!@#',
|
||||||
|
confirmPassword: 'Collab123!@#',
|
||||||
|
};
|
||||||
|
|
||||||
|
await userManagementPage.fillUserForm(userData);
|
||||||
|
await userManagementPage.submitForm();
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('创建成功');
|
||||||
|
|
||||||
|
await userManagementPage.logout();
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(managerUser.username, managerUser.password);
|
||||||
|
|
||||||
|
await userManagementPage.navigateTo();
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
await expect(userManagementPage.table).toContainText(userData.username);
|
||||||
|
await expect(userManagementPage.table).toContainText(userData.department);
|
||||||
|
|
||||||
|
await userManagementPage.approveUser(userData.username);
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('审批成功');
|
||||||
|
|
||||||
|
await userManagementPage.logout();
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(userData.username, userData.password);
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(/.*dashboard/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('数据一致性验证', async ({ page, context }) => {
|
||||||
|
const adminUser = DataLoader.getUserByRole('admin');
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(adminUser.username, adminUser.password);
|
||||||
|
|
||||||
|
await userManagementPage.navigateTo();
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
const initialCount = await userManagementPage.getUserCount();
|
||||||
|
|
||||||
|
await userManagementPage.clickCreateUser();
|
||||||
|
|
||||||
|
const timestamp = Date.now();
|
||||||
|
const userData = {
|
||||||
|
username: `consistency_user_${timestamp}`,
|
||||||
|
nickname: `一致性用户${timestamp}`,
|
||||||
|
email: `consistency_${timestamp}@example.com`,
|
||||||
|
password: 'Consistency123!@#',
|
||||||
|
confirmPassword: 'Consistency123!@#',
|
||||||
|
};
|
||||||
|
|
||||||
|
await userManagementPage.fillUserForm(userData);
|
||||||
|
await userManagementPage.submitForm();
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('创建成功');
|
||||||
|
await helper.waitForPageLoad();
|
||||||
|
|
||||||
|
const finalCount = await userManagementPage.getUserCount();
|
||||||
|
|
||||||
|
expect(finalCount).toBe(initialCount + 1);
|
||||||
|
|
||||||
|
await page.reload();
|
||||||
|
await helper.waitForPageLoad();
|
||||||
|
|
||||||
|
const reloadedCount = await userManagementPage.getUserCount();
|
||||||
|
|
||||||
|
expect(reloadedCount).toBe(finalCount);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { LoginPage } from '../../../novalon-manage-web/e2e/pages/LoginPage';
|
||||||
|
import { UserManagementPage } from '../../pages/UserManagementPage';
|
||||||
|
import { RoleManagementPage } from '../../../novalon-manage-web/e2e/pages/RoleManagementPage';
|
||||||
|
import { UATHelper } from '../../utils/uat-helper';
|
||||||
|
import { DataLoader } from '../../utils/data-loader';
|
||||||
|
|
||||||
|
test.describe('UAT - 角色管理场景', () => {
|
||||||
|
let loginPage: LoginPage;
|
||||||
|
let userManagementPage: UserManagementPage;
|
||||||
|
let roleManagementPage: RoleManagementPage;
|
||||||
|
let helper: UATHelper;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
loginPage = new LoginPage(page);
|
||||||
|
userManagementPage = new UserManagementPage(page);
|
||||||
|
roleManagementPage = new RoleManagementPage(page);
|
||||||
|
helper = new UATHelper(page);
|
||||||
|
|
||||||
|
const adminUser = DataLoader.getUserByRole('admin');
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(adminUser.username, adminUser.password);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('角色分配与权限验证', async ({ page }) => {
|
||||||
|
await roleManagementPage.goto();
|
||||||
|
await helper.waitForElement('[data-testid="role-table"]');
|
||||||
|
|
||||||
|
await roleManagementPage.clickCreateRole();
|
||||||
|
|
||||||
|
const timestamp = Date.now();
|
||||||
|
const roleData = {
|
||||||
|
roleName: `测试角色_${timestamp}`,
|
||||||
|
roleKey: `ROLE_${timestamp}`,
|
||||||
|
description: '这是一个测试角色',
|
||||||
|
permissions: ['user:read', 'user:write']
|
||||||
|
};
|
||||||
|
|
||||||
|
await roleManagementPage.fillRoleForm(roleData);
|
||||||
|
await roleManagementPage.submitForm();
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('创建成功');
|
||||||
|
await helper.waitForPageLoad();
|
||||||
|
|
||||||
|
await expect(roleManagementPage.table).toContainText(roleData.roleName);
|
||||||
|
|
||||||
|
await userManagementPage.navigateTo();
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
await userManagementPage.editUser(1);
|
||||||
|
await page.selectOption('select[name="role"]', roleData.roleName);
|
||||||
|
await userManagementPage.submitForm();
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('更新成功');
|
||||||
|
|
||||||
|
await userManagementPage.logout();
|
||||||
|
|
||||||
|
const testUser = DataLoader.getUserByRole('user');
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(testUser.username, testUser.password);
|
||||||
|
|
||||||
|
await page.goto('/user-management');
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
await expect(page.locator('[data-testid="create-user-button"]')).not.toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { LoginPage } from '../../../novalon-manage-web/e2e/pages/LoginPage';
|
||||||
|
import { UserManagementPage } from '../../pages/UserManagementPage';
|
||||||
|
import { UATHelper } from '../../utils/uat-helper';
|
||||||
|
import { DataLoader } from '../../utils/data-loader';
|
||||||
|
|
||||||
|
test.describe('UAT - 用户生命周期场景', () => {
|
||||||
|
let loginPage: LoginPage;
|
||||||
|
let userManagementPage: UserManagementPage;
|
||||||
|
let helper: UATHelper;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
loginPage = new LoginPage(page);
|
||||||
|
userManagementPage = new UserManagementPage(page);
|
||||||
|
helper = new UATHelper(page);
|
||||||
|
|
||||||
|
const adminUser = DataLoader.getUserByRole('admin');
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(adminUser.username, adminUser.password);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('新用户注册与激活', async ({ page }) => {
|
||||||
|
await userManagementPage.navigateTo();
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
await userManagementPage.clickCreateUser();
|
||||||
|
|
||||||
|
const timestamp = Date.now();
|
||||||
|
const userData = {
|
||||||
|
username: `newuser_${timestamp}`,
|
||||||
|
nickname: `新用户${timestamp}`,
|
||||||
|
email: `newuser_${timestamp}@example.com`,
|
||||||
|
phone: '13800138000',
|
||||||
|
password: 'Test123!@#',
|
||||||
|
confirmPassword: 'Test123!@#',
|
||||||
|
};
|
||||||
|
|
||||||
|
await userManagementPage.fillUserForm(userData);
|
||||||
|
await userManagementPage.submitForm();
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('创建成功');
|
||||||
|
await helper.waitForPageLoad();
|
||||||
|
|
||||||
|
await expect(userManagementPage.table).toContainText(userData.username);
|
||||||
|
|
||||||
|
await userManagementPage.logout();
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(userData.username, userData.password);
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(/.*dashboard/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('用户信息变更', async ({ page }) => {
|
||||||
|
const testUser = DataLoader.getUserByRole('user');
|
||||||
|
|
||||||
|
await userManagementPage.navigateTo();
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
await userManagementPage.editUser(1);
|
||||||
|
|
||||||
|
await page.fill('input[name="email"]', 'updated@example.com');
|
||||||
|
await page.fill('input[name="nickname"]', '更新后的昵称');
|
||||||
|
|
||||||
|
await userManagementPage.submitForm();
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('更新成功');
|
||||||
|
await helper.waitForPageLoad();
|
||||||
|
|
||||||
|
await expect(userManagementPage.table).toContainText('updated@example.com');
|
||||||
|
await expect(userManagementPage.table).toContainText('更新后的昵称');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('用户角色演进', async ({ page }) => {
|
||||||
|
const testUser = DataLoader.getUserByRole('user');
|
||||||
|
|
||||||
|
await userManagementPage.navigateTo();
|
||||||
|
await helper.waitForElement('[data-testid="user-table"]');
|
||||||
|
|
||||||
|
await userManagementPage.editUser(1);
|
||||||
|
|
||||||
|
await page.selectOption('select[name="role"]', 'manager');
|
||||||
|
|
||||||
|
await userManagementPage.submitForm();
|
||||||
|
|
||||||
|
await helper.verifySuccessMessage('更新成功');
|
||||||
|
await helper.waitForPageLoad();
|
||||||
|
|
||||||
|
await userManagementPage.logout();
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(testUser.username, testUser.password);
|
||||||
|
|
||||||
|
await page.goto('/role-management');
|
||||||
|
await helper.waitForElement('[data-testid="role-table"]');
|
||||||
|
|
||||||
|
await expect(page.locator('[data-testid="role-table"]')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user