08ea5fbe98
添加用户管理视图、API和状态管理文件
151 lines
4.7 KiB
TypeScript
151 lines
4.7 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { MiniProgramUserPage } from '../pages/UserPage';
|
|
|
|
test.describe('小程序用户测试', () => {
|
|
let userPage: MiniProgramUserPage;
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
userPage = new MiniProgramUserPage(page);
|
|
await userPage.navigate();
|
|
});
|
|
|
|
test('应该显示用户名', async () => {
|
|
const username = await userPage.getUsername();
|
|
expect(username).toBeTruthy();
|
|
});
|
|
|
|
test('应该显示用户头像', async () => {
|
|
const avatar = await userPage.getUserAvatar();
|
|
expect(avatar).toBeTruthy();
|
|
});
|
|
|
|
test('应该检查登录状态', async () => {
|
|
const isLoggedIn = await userPage.isLoggedIn();
|
|
expect(typeof isLoggedIn).toBe('boolean');
|
|
});
|
|
|
|
test('应该允许登录', async () => {
|
|
await userPage.navigate();
|
|
const isLoggedInBefore = await userPage.isLoggedIn();
|
|
|
|
if (!isLoggedInBefore) {
|
|
await userPage.login('test-user', 'test-password');
|
|
const isLoggedInAfter = await userPage.isLoggedIn();
|
|
expect(isLoggedInAfter).toBe(true);
|
|
}
|
|
});
|
|
|
|
test('应该允许登出', async () => {
|
|
await userPage.logout();
|
|
const isLoggedIn = await userPage.isLoggedIn();
|
|
expect(isLoggedIn).toBe(false);
|
|
});
|
|
|
|
test('应该能够导航到个人资料', async () => {
|
|
await userPage.login('test-user', 'test-password');
|
|
await userPage.navigateToProfile();
|
|
const profile = await userPage.getProfile();
|
|
expect(profile.username).toBe('test-user');
|
|
});
|
|
|
|
test('应该能够导航到设置', async () => {
|
|
await userPage.navigateToSettings();
|
|
const settings = await userPage.getSettings();
|
|
expect(settings.theme).toBeTruthy();
|
|
});
|
|
|
|
test('应该能够导航到历史记录', async () => {
|
|
await userPage.navigateToHistory();
|
|
const history = await userPage.getHistory();
|
|
expect(Array.isArray(history)).toBe(true);
|
|
});
|
|
|
|
test('应该能够导航到收藏', async () => {
|
|
await userPage.navigateToFavorites();
|
|
const favorites = await userPage.getFavorites();
|
|
expect(Array.isArray(favorites)).toBe(true);
|
|
});
|
|
|
|
test('应该允许更新个人资料', async () => {
|
|
await userPage.updateProfile({
|
|
username: 'updated-user',
|
|
email: 'updated@example.com',
|
|
phone: '1234567890',
|
|
});
|
|
const profile = await userPage.getProfile();
|
|
expect(profile.username).toBe('updated-user');
|
|
});
|
|
|
|
test('应该允许切换主题', async () => {
|
|
const themeBefore = await userPage.getCurrentTheme();
|
|
await userPage.toggleTheme();
|
|
const themeAfter = await userPage.getCurrentTheme();
|
|
expect(themeBefore).not.toBe(themeAfter);
|
|
});
|
|
|
|
test('应该允许更新设置', async () => {
|
|
await userPage.updateSetting('theme', 'dark');
|
|
const settings = await userPage.getSettings();
|
|
expect(settings.theme).toContain('dark');
|
|
});
|
|
|
|
test('应该允许清除历史记录', async () => {
|
|
await userPage.clearHistory();
|
|
const history = await userPage.getHistory();
|
|
expect(history.length).toBe(0);
|
|
});
|
|
|
|
test('应该允许移除收藏', async () => {
|
|
await userPage.navigateToFavorites();
|
|
const favoritesBefore = await userPage.getFavorites();
|
|
|
|
if (favoritesBefore.length > 0) {
|
|
const firstFavoriteId = '1';
|
|
await userPage.removeFavorite(firstFavoriteId);
|
|
const favoritesAfter = await userPage.getFavorites();
|
|
expect(favoritesAfter.length).toBe(favoritesBefore.length - 1);
|
|
}
|
|
});
|
|
|
|
test('应该允许点击按钮', async () => {
|
|
await userPage.navigate();
|
|
await userPage.tapButton('profile-button');
|
|
const profile = await userPage.getProfile();
|
|
expect(profile.username).toBeTruthy();
|
|
});
|
|
|
|
test('应该允许长按按钮', async ({ page }) => {
|
|
await userPage.navigate();
|
|
await userPage.longPressButton('settings-button');
|
|
await page.waitForTimeout(1000);
|
|
const settings = await userPage.getSettings();
|
|
expect(settings.theme).toBeTruthy();
|
|
});
|
|
|
|
test('应该允许上滑', async ({ page }) => {
|
|
await userPage.navigate();
|
|
await userPage.swipeUp();
|
|
await page.waitForTimeout(500);
|
|
const username = await userPage.getUsername();
|
|
expect(username).toBeTruthy();
|
|
});
|
|
|
|
test('应该允许下滑', async ({ page }) => {
|
|
await userPage.navigate();
|
|
await userPage.swipeDown();
|
|
await page.waitForTimeout(500);
|
|
const username = await userPage.getUsername();
|
|
expect(username).toBeTruthy();
|
|
});
|
|
|
|
test('应该显示用户信息', async () => {
|
|
const userInfo = await userPage.getUserInfo();
|
|
expect(userInfo).toBeTruthy();
|
|
});
|
|
|
|
test('应该显示导航项', async () => {
|
|
const navItems = await userPage.getNavigationItems();
|
|
expect(Array.isArray(navItems)).toBe(true);
|
|
});
|
|
});
|