Explorar el Código

🔥 chore(e2e): 重构端到端测试结构

- 删除auth相关页面文件: login.page.ts和register.page.ts
- 删除auth相关测试用例: login.spec.ts、logout.spec.ts和register.spec.ts
- 删除用户个人资料测试: profile.spec.ts
- 重命名用户CRUD测试文件路径: users/user-crud.spec.ts → admin/user-crud.spec.ts
yourname hace 2 meses
padre
commit
5b8d8e1846

+ 0 - 44
tests/e2e/pages/auth/login.page.ts

@@ -1,44 +0,0 @@
-import { Page, Locator, expect } from '@playwright/test';
-
-export class LoginPage {
-  readonly page: Page;
-  readonly usernameInput: Locator;
-  readonly passwordInput: Locator;
-  readonly loginButton: Locator;
-  readonly registerLink: Locator;
-  readonly errorMessage: Locator;
-
-  constructor(page: Page) {
-    this.page = page;
-    this.usernameInput = page.getByPlaceholder('请输入用户名');
-    this.passwordInput = page.getByPlaceholder('请输入密码');
-    this.loginButton = page.getByRole('button', { name: '登录' });
-    this.registerLink = page.getByRole('link', { name: '立即注册' });
-    this.errorMessage = page.locator('[data-sonner-toast]');
-  }
-
-  async goto() {
-    await this.page.goto('/admin/login');
-    await this.page.waitForLoadState('networkidle');
-  }
-
-  async login(username: string, password: string) {
-    await this.usernameInput.fill(username);
-    await this.passwordInput.fill(password);
-    await this.loginButton.click();
-  }
-
-  async expectLoginSuccess() {
-    // 登录成功后应该重定向到管理后台首页或用户管理页面
-    await expect(this.page).not.toHaveURL('/login');
-    await expect(this.page.locator('text=登录成功')).toBeVisible();
-  }
-
-  async expectLoginError() {
-    await expect(this.errorMessage).toBeVisible();
-  }
-
-  async navigateToRegister() {
-    await this.registerLink.click();
-  }
-}

+ 0 - 46
tests/e2e/pages/auth/register.page.ts

@@ -1,46 +0,0 @@
-import { Page, Locator, expect } from '@playwright/test';
-
-export class RegisterPage {
-  readonly page: Page;
-  readonly usernameInput: Locator;
-  readonly passwordInput: Locator;
-  readonly confirmPasswordInput: Locator;
-  readonly registerButton: Locator;
-  readonly loginLink: Locator;
-  readonly errorMessage: Locator;
-
-  constructor(page: Page) {
-    this.page = page;
-    this.usernameInput = page.getByPlaceholder('请输入用户名');
-    this.passwordInput = page.getByPlaceholder('请输入密码');
-    this.confirmPasswordInput = page.getByPlaceholder('请再次输入密码');
-    this.registerButton = page.getByRole('button', { name: '注册账号' });
-    this.loginLink = page.getByRole('link', { name: '立即登录' });
-    this.errorMessage = page.locator('[data-sonner-toast]');
-  }
-
-  async goto() {
-    await this.page.goto('/register');
-    await this.page.waitForLoadState('networkidle');
-  }
-
-  async register(username: string, password: string, confirmPassword?: string) {
-    await this.usernameInput.fill(username);
-    await this.passwordInput.fill(password);
-    await this.confirmPasswordInput.fill(confirmPassword || password);
-    await this.registerButton.click();
-  }
-
-  async expectRegistrationSuccess() {
-    await expect(this.page).toHaveURL('/');
-    await expect(this.page.locator('text=注册成功')).toBeVisible();
-  }
-
-  async expectRegistrationError() {
-    await expect(this.errorMessage).toBeVisible();
-  }
-
-  async navigateToLogin() {
-    await this.loginLink.click();
-  }
-}

+ 0 - 0
tests/e2e/specs/users/user-crud.spec.ts → tests/e2e/specs/admin/user-crud.spec.ts


+ 0 - 49
tests/e2e/specs/auth/login.spec.ts

@@ -1,49 +0,0 @@
-import { test, expect } from '../../utils/test-setup';
-import testUsers from '../../fixtures/test-users.json' with { type: 'json' };
-
-test.describe('用户认证流程', () => {
-  test.beforeEach(async ({ page }) => {
-    await page.goto('/login');
-    await page.waitForLoadState('networkidle');
-  });
-
-  test('成功登录', async ({ loginPage, dashboardPage }) => {
-    await loginPage.login(testUsers.admin.username, testUsers.admin.password);
-    await dashboardPage.expectToBeVisible();
-  });
-
-  test('登录失败 - 错误密码', async ({ loginPage }) => {
-    await loginPage.login(testUsers.admin.username, 'wrongpassword');
-    await loginPage.expectLoginError();
-  });
-
-  test('登录失败 - 不存在的用户', async ({ loginPage }) => {
-    await loginPage.login('nonexistent', testUsers.admin.password);
-    await loginPage.expectLoginError();
-  });
-
-  test('导航到注册页面', async ({ loginPage, page }) => {
-    await loginPage.navigateToRegister();
-    await expect(page).toHaveURL('/register');
-  });
-
-  test('表单验证 - 空用户名', async ({ loginPage }) => {
-    await loginPage.login('', testUsers.admin.password);
-    await expect(loginPage.usernameInput).toHaveClass(/border-destructive/);
-  });
-
-  test('表单验证 - 空密码', async ({ loginPage }) => {
-    await loginPage.login(testUsers.admin.username, '');
-    await expect(loginPage.passwordInput).toHaveClass(/border-destructive/);
-  });
-
-  test('记住登录状态', async ({ loginPage, dashboardPage, context }) => {
-    await loginPage.login(testUsers.admin.username, testUsers.admin.password);
-    await dashboardPage.expectToBeVisible();
-
-    // 重新打开浏览器验证登录状态保持
-    const newPage = await context.newPage();
-    await newPage.goto('/');
-    await expect(newPage).toHaveURL('/');
-  });
-});

+ 0 - 37
tests/e2e/specs/auth/logout.spec.ts

@@ -1,37 +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 }) => {
-    // 点击用户菜单(需要根据实际UI调整选择器)
-    const userMenu = page.locator('[data-testid="user-menu"]');
-    await userMenu.click();
-
-    // 点击登出按钮
-    const logoutButton = page.getByRole('button', { name: '登出' });
-    await logoutButton.click();
-
-    // 验证重定向到登录页面
-    await expect(page).toHaveURL('/login');
-    await expect(page.getByText('欢迎回来')).toBeVisible();
-  });
-
-  test('登出后无法访问受保护页面', async ({ page }) => {
-    // 先登出
-    const userMenu = page.locator('[data-testid="user-menu"]');
-    await userMenu.click();
-    const logoutButton = page.getByRole('button', { name: '登出' });
-    await logoutButton.click();
-
-    // 尝试访问受保护页面
-    await page.goto('/dashboard');
-
-    // 应该被重定向到登录页面
-    await expect(page).toHaveURL(/\/login/);
-  });
-});

+ 0 - 45
tests/e2e/specs/auth/register.spec.ts

@@ -1,45 +0,0 @@
-import { test, expect } from '../../utils/test-setup';
-
-test.describe('用户注册流程', () => {
-  test.beforeEach(async ({ registerPage }) => {
-    await registerPage.goto();
-  });
-
-  test('成功注册新用户', async ({ registerPage, dashboardPage }) => {
-    const testUsername = `testuser_${Date.now()}`;
-    const testPassword = 'Test123!@#';
-
-    await registerPage.register(testUsername, testPassword);
-    await dashboardPage.expectToBeVisible();
-  });
-
-  test('注册失败 - 用户名已存在', async ({ registerPage }) => {
-    await registerPage.register('admin', 'Test123!@#');
-    await registerPage.expectRegistrationError();
-  });
-
-  test('注册失败 - 密码不一致', async ({ registerPage }) => {
-    await registerPage.register('newuser', 'password123', 'differentpassword');
-    await expect(registerPage.confirmPasswordInput).toHaveClass(/border-destructive/);
-  });
-
-  test('表单验证 - 用户名太短', async ({ registerPage }) => {
-    await registerPage.register('ab', 'Test123!@#');
-    await expect(registerPage.usernameInput).toHaveClass(/border-destructive/);
-  });
-
-  test('表单验证 - 密码太短', async ({ registerPage }) => {
-    await registerPage.register('newuser', 'short');
-    await expect(registerPage.passwordInput).toHaveClass(/border-destructive/);
-  });
-
-  test('表单验证 - 无效用户名格式', async ({ registerPage }) => {
-    await registerPage.register('invalid user!', 'Test123!@#');
-    await expect(registerPage.usernameInput).toHaveClass(/border-destructive/);
-  });
-
-  test('导航到登录页面', async ({ registerPage, page }) => {
-    await registerPage.navigateToLogin();
-    await expect(page).toHaveURL('/login');
-  });
-});

+ 0 - 135
tests/e2e/specs/users/profile.spec.ts

@@ -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();
-  });
-});