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

163 lines
4.6 KiB
TypeScript

import { Page } from 'playwright';
export class MiniProgramUserPage {
constructor(private page: Page) {}
async navigate() {
await this.page.goto('http://localhost:9527/#/pages/user/index');
await this.page.waitForLoadState('networkidle');
}
async getUsername() {
const username = await this.page.locator('.username').textContent();
return username || '';
}
async getUserAvatar() {
const avatar = await this.page.locator('.user-avatar');
return await avatar.getAttribute('src');
}
async isLoggedIn() {
const loginButton = this.page.locator('.login-button');
return !(await loginButton.isVisible());
}
async login(username: string, password: string) {
await this.page.fill('.login-username input', username);
await this.page.fill('.login-password input', password);
await this.page.click('.login-button');
await this.page.waitForLoadState('networkidle');
}
async logout() {
await this.page.click('.logout-button');
await this.page.waitForLoadState('networkidle');
}
async navigateToProfile() {
await this.page.click('.profile-button');
await this.page.waitForLoadState('networkidle');
}
async navigateToSettings() {
await this.page.click('.settings-button');
await this.page.waitForLoadState('networkidle');
}
async navigateToHistory() {
await this.page.click('.history-button');
await this.page.waitForLoadState('networkidle');
}
async navigateToFavorites() {
await this.page.click('.favorites-button');
await this.page.waitForLoadState('networkidle');
}
async updateProfile(data: { username?: string; email?: string; phone?: string }) {
await this.navigateToProfile();
if (data.username) {
await this.page.fill('.profile-username input', data.username);
}
if (data.email) {
await this.page.fill('.profile-email input', data.email);
}
if (data.phone) {
await this.page.fill('.profile-phone input', data.phone);
}
await this.page.click('.save-button');
await this.page.waitForLoadState('networkidle');
}
async getProfile() {
const profile = {
username: await this.page.locator('.profile-username').textContent() || '',
email: await this.page.locator('.profile-email').textContent() || '',
phone: await this.page.locator('.profile-phone').textContent() || '',
};
return profile;
}
async toggleTheme() {
await this.page.click('.theme-toggle');
await this.page.waitForTimeout(500);
}
async getCurrentTheme() {
const theme = await this.page.locator('.current-theme').textContent();
return theme || '';
}
async getSettings() {
const settings = {
theme: await this.page.locator('.setting-theme').textContent() || '',
language: await this.page.locator('.setting-language').textContent() || '',
notifications: await this.page.locator('.setting-notifications').textContent() || '',
};
return settings;
}
async updateSetting(key: string, value: string) {
await this.navigateToSettings();
await this.page.click(`.setting-${key}`);
await this.page.click(`[data-value="${value}"]`);
await this.page.click('.save-button');
await this.page.waitForLoadState('networkidle');
}
async getHistory() {
const historyItems = await this.page.locator('.history-item').allTextContents();
return historyItems;
}
async clearHistory() {
await this.navigateToHistory();
await this.page.click('.clear-history-button');
await this.page.waitForLoadState('networkidle');
}
async getFavorites() {
const favorites = await this.page.locator('.favorite-item').allTextContents();
return favorites;
}
async removeFavorite(id: string) {
await this.navigateToFavorites();
await this.page.click(`[data-favorite-id="${id}"] .remove-button`);
await this.page.waitForLoadState('networkidle');
}
async tapButton(buttonClass: string) {
await this.page.tap(`.${buttonClass}`);
}
async longPressButton(buttonClass: string) {
const element = this.page.locator(`.${buttonClass}`);
await element.tap();
await this.page.waitForTimeout(500);
}
async swipeUp() {
await this.page.touchscreen.tap(0, 100);
await this.page.touchscreen.tap(0, 0);
}
async swipeDown() {
await this.page.touchscreen.tap(0, 0);
await this.page.touchscreen.tap(0, 100);
}
async getUserInfo() {
const userInfo = await this.page.locator('.user-info').textContent();
return userInfo || '';
}
async getNavigationItems() {
const navItems = await this.page.locator('.nav-item').allTextContents();
return navItems;
}
}