68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
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();
|
|
}
|
|
}
|