|
|
@@ -1,135 +0,0 @@
|
|
|
-import { test, expect } from '../../utils/test-setup';
|
|
|
-import testUsers from '../../fixtures/test-users.json' with { type: 'json' };
|
|
|
-
|
|
|
-test.describe('用户个人资料管理', () => {
|
|
|
- test.beforeEach(async ({ loginPage }) => {
|
|
|
- await loginPage.goto();
|
|
|
- await loginPage.login(testUsers.admin.username, testUsers.admin.password);
|
|
|
- });
|
|
|
-
|
|
|
- test('查看个人资料页面', async ({ page }) => {
|
|
|
- // 导航到个人资料页面(需要根据实际路由调整)
|
|
|
- await page.goto('/profile');
|
|
|
- await page.waitForLoadState('networkidle');
|
|
|
-
|
|
|
- // 验证页面标题和基本信息
|
|
|
- await expect(page.getByRole('heading', { name: '个人资料' })).toBeVisible();
|
|
|
- await expect(page.getByText(testUsers.admin.username)).toBeVisible();
|
|
|
- });
|
|
|
-
|
|
|
- test('更新个人资料信息', async ({ page }) => {
|
|
|
- await page.goto('/profile');
|
|
|
- await page.waitForLoadState('networkidle');
|
|
|
-
|
|
|
- // 点击编辑按钮
|
|
|
- const editButton = page.getByRole('button', { name: '编辑资料' });
|
|
|
- await editButton.click();
|
|
|
-
|
|
|
- // 更新昵称
|
|
|
- const nicknameInput = page.getByLabel('昵称');
|
|
|
- const newNickname = `测试昵称_${Date.now()}`;
|
|
|
- await nicknameInput.fill(newNickname);
|
|
|
-
|
|
|
- // 保存更改
|
|
|
- const saveButton = page.getByRole('button', { name: '保存' });
|
|
|
- await saveButton.click();
|
|
|
-
|
|
|
- // 验证更新成功
|
|
|
- await expect(page.locator('text=资料更新成功')).toBeVisible();
|
|
|
- await expect(page.getByText(newNickname)).toBeVisible();
|
|
|
- });
|
|
|
-
|
|
|
- test('修改密码', async ({ page }) => {
|
|
|
- await page.goto('/profile');
|
|
|
- await page.waitForLoadState('networkidle');
|
|
|
-
|
|
|
- // 导航到修改密码页面
|
|
|
- const changePasswordTab = page.getByRole('tab', { name: '修改密码' });
|
|
|
- await changePasswordTab.click();
|
|
|
-
|
|
|
- // 填写密码表单
|
|
|
- const currentPasswordInput = page.getByLabel('当前密码');
|
|
|
- const newPasswordInput = page.getByLabel('新密码');
|
|
|
- const confirmPasswordInput = page.getByLabel('确认新密码');
|
|
|
-
|
|
|
- await currentPasswordInput.fill(testUsers.admin.password);
|
|
|
- await newPasswordInput.fill('NewPassword123!');
|
|
|
- await confirmPasswordInput.fill('NewPassword123!');
|
|
|
-
|
|
|
- // 提交修改
|
|
|
- const submitButton = page.getByRole('button', { name: '修改密码' });
|
|
|
- await submitButton.click();
|
|
|
-
|
|
|
- // 验证密码修改成功
|
|
|
- await expect(page.locator('text=密码修改成功')).toBeVisible();
|
|
|
-
|
|
|
- // 使用新密码重新登录验证
|
|
|
- const logoutButton = page.getByRole('button', { name: '登出' });
|
|
|
- await logoutButton.click();
|
|
|
-
|
|
|
- await page.goto('/login');
|
|
|
- await page.getByPlaceholder('请输入用户名').fill(testUsers.admin.username);
|
|
|
- await page.getByPlaceholder('请输入密码').fill('NewPassword123!');
|
|
|
- await page.getByRole('button', { name: '登录' }).click();
|
|
|
-
|
|
|
- // 验证登录成功
|
|
|
- await expect(page).toHaveURL('/');
|
|
|
- });
|
|
|
-
|
|
|
- test('密码修改验证 - 当前密码错误', async ({ page }) => {
|
|
|
- await page.goto('/profile');
|
|
|
- await page.waitForLoadState('networkidle');
|
|
|
-
|
|
|
- const changePasswordTab = page.getByRole('tab', { name: '修改密码' });
|
|
|
- await changePasswordTab.click();
|
|
|
-
|
|
|
- const currentPasswordInput = page.getByLabel('当前密码');
|
|
|
- const newPasswordInput = page.getByLabel('新密码');
|
|
|
- const confirmPasswordInput = page.getByLabel('确认新密码');
|
|
|
-
|
|
|
- await currentPasswordInput.fill('wrongpassword');
|
|
|
- await newPasswordInput.fill('NewPassword123!');
|
|
|
- await confirmPasswordInput.fill('NewPassword123!');
|
|
|
-
|
|
|
- const submitButton = page.getByRole('button', { name: '修改密码' });
|
|
|
- await submitButton.click();
|
|
|
-
|
|
|
- // 验证错误提示
|
|
|
- await expect(page.locator('text=当前密码错误')).toBeVisible();
|
|
|
- });
|
|
|
-
|
|
|
- test('密码修改验证 - 新密码不一致', async ({ page }) => {
|
|
|
- await page.goto('/profile');
|
|
|
- await page.waitForLoadState('networkidle');
|
|
|
-
|
|
|
- const changePasswordTab = page.getByRole('tab', { name: '修改密码' });
|
|
|
- await changePasswordTab.click();
|
|
|
-
|
|
|
- const currentPasswordInput = page.getByLabel('当前密码');
|
|
|
- const newPasswordInput = page.getByLabel('新密码');
|
|
|
- const confirmPasswordInput = page.getByLabel('确认新密码');
|
|
|
-
|
|
|
- await currentPasswordInput.fill(testUsers.admin.password);
|
|
|
- await newPasswordInput.fill('NewPassword123!');
|
|
|
- await confirmPasswordInput.fill('DifferentPassword123!');
|
|
|
-
|
|
|
- const submitButton = page.getByRole('button', { name: '修改密码' });
|
|
|
- await submitButton.click();
|
|
|
-
|
|
|
- // 验证错误提示
|
|
|
- await expect(page.locator('text=两次密码输入不一致')).toBeVisible();
|
|
|
- });
|
|
|
-
|
|
|
- test('查看登录历史', async ({ page }) => {
|
|
|
- await page.goto('/profile');
|
|
|
- await page.waitForLoadState('networkidle');
|
|
|
-
|
|
|
- // 导航到安全设置页面
|
|
|
- const securityTab = page.getByRole('tab', { name: '安全设置' });
|
|
|
- await securityTab.click();
|
|
|
-
|
|
|
- // 验证登录历史记录可见
|
|
|
- await expect(page.getByText('登录历史')).toBeVisible();
|
|
|
- await expect(page.getByText('最近登录')).toBeVisible();
|
|
|
- });
|
|
|
-});
|