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

125 lines
4.4 KiB
TypeScript

/**
* UniApp User页面E2E测试
*
* 测试用户页面的所有功能和交互
*
* @tags @user @uniapp @e2e @page
*/
import { test, expect } from '@playwright/test';
import { TestLogger } from '../../core/test-logger.js';
test.describe('E2E: UniApp User页面', () => {
let logger: TestLogger;
test.beforeEach(async ({ page }) => {
logger = new TestLogger();
await page.goto('http://localhost:8081/pages/user/index');
await page.waitForLoadState('networkidle');
});
test('应该显示用户页面内容 @smoke', async ({ page }) => {
await expect(page.locator('.user-container, .user-page')).toBeVisible();
});
test('应该显示用户信息 @smoke', async ({ page }) => {
await expect(page.locator('.user-info, .user-profile')).toBeVisible();
await expect(page.locator('.avatar, .user-avatar')).toBeVisible();
});
test('应该显示用户名 @regression', async ({ page }) => {
await expect(page.locator('.username, .user-name')).toBeVisible();
});
test('应该能够编辑用户信息 @critical', async ({ page }) => {
const editBtn = page.locator('.edit-btn, button:has-text("编辑")').first();
if (await editBtn.isVisible()) {
await editBtn.click();
await expect(page.locator('.edit-form, .user-form')).toBeVisible();
// 修改昵称
const nicknameInput = page.locator('input[placeholder*="昵称"], .nickname-input').first();
if (await nicknameInput.isVisible()) {
await nicknameInput.clear();
await nicknameInput.fill('新昵称');
// 保存
const saveBtn = page.locator('.save-btn, button:has-text("保存")').first();
await saveBtn.click();
// 验证保存成功
await expect(page.locator('.toast, .uni-toast')).toContainText('保存成功').catch(() => {
logger.info('保存提示可能以其他形式显示');
});
}
}
});
test('应该能够修改头像 @regression', async ({ page }) => {
const avatar = page.locator('.avatar, .user-avatar').first();
await avatar.click();
// 验证弹出选择框
await expect(page.locator('.action-sheet, .popup')).toBeVisible().catch(() => {
logger.info('头像修改可能直接打开文件选择');
});
});
test('应该显示设置列表 @regression', async ({ page }) => {
await expect(page.locator('.settings-list, .menu-list')).toBeVisible();
// 验证常见设置项
const settings = ['账号安全', '隐私设置', '关于我们', '退出登录'];
for (const setting of settings) {
await expect(page.locator(`.menu-item:has-text("${setting}"), .setting-item:has-text("${setting}")`)).toBeVisible().catch(() => {
logger.info(`设置项 "${setting}" 可能不存在`);
});
}
});
test('应该能够退出登录 @critical', async ({ page }) => {
const logoutBtn = page.locator('.logout-btn, button:has-text("退出")').first();
if (await logoutBtn.isVisible()) {
await logoutBtn.click();
// 验证确认对话框
await expect(page.locator('.confirm-dialog, .modal')).toBeVisible().catch(() => {
// 可能没有确认对话框
});
// 确认退出
const confirmBtn = page.locator('.confirm-btn, button:has-text("确定")').first();
if (await confirmBtn.isVisible()) {
await confirmBtn.click();
}
// 验证跳转到登录页或首页
await page.waitForURL('**/login/**').catch(() => {
logger.info('可能跳转到其他页面');
});
}
});
test('应该能够查看我的收藏 @regression', async ({ page }) => {
const favoritesBtn = page.locator('.menu-item:has-text("收藏"), .favorites-btn').first();
if (await favoritesBtn.isVisible()) {
await favoritesBtn.click();
await expect(page.locator('.favorites-list, .collection-list')).toBeVisible();
}
});
test('应该能够查看浏览历史 @regression', async ({ page }) => {
const historyBtn = page.locator('.menu-item:has-text("历史"), .history-btn').first();
if (await historyBtn.isVisible()) {
await historyBtn.click();
await expect(page.locator('.history-list')).toBeVisible();
}
});
test('应该在不同视口下正常显示 @responsive', async ({ page }) => {
await page.setViewportSize({ width: 375, height: 667 });
await page.goto('http://localhost:8081/pages/user/index');
await expect(page.locator('.user-container')).toBeVisible();
});
});