import { test, expect } from '@playwright/test'; import { testFixtures } from '../fixtures/test-data'; test.describe('用户认证旅程 @journey @auth', () => { test('管理员成功登录流程', async ({ page }) => { await test.step('步骤1: 访问登录页面', async () => { await page.goto('/admin/login'); await expect(page).toHaveURL(/\/admin\/login/); }); await test.step('步骤2: 填写登录信息', async () => { await page.fill('#email', testFixtures.adminUser.email); await page.fill('#password', testFixtures.adminUser.password); }); await test.step('步骤3: 提交登录表单', async () => { await page.click('button[type="submit"]'); await page.waitForURL(/\/admin(?!\/login)/); }); await test.step('步骤4: 验证登录成功', async () => { await expect(page).toHaveURL(/\/admin(?!\/login)/); }); }); test('管理员登录失败处理', async ({ page }) => { await test.step('步骤1: 访问登录页面', async () => { await page.goto('/admin/login'); }); await test.step('步骤2: 填写错误信息', async () => { await page.fill('#email', 'wrong@example.com'); await page.fill('#password', 'wrongpassword'); }); await test.step('步骤3: 提交登录表单', async () => { await page.click('button[type="submit"]'); }); await test.step('步骤4: 验证错误提示', async () => { await expect(page.locator('[role="alert"], .error-message')).toBeVisible({ timeout: 5000 }); }); }); test('管理员登出流程', async ({ page }) => { await test.step('步骤1: 登录系统', async () => { await page.goto('/admin/login'); await page.fill('#email', testFixtures.adminUser.email); await page.fill('#password', testFixtures.adminUser.password); await page.click('button[type="submit"]'); await page.waitForURL(/\/admin(?!\/login)/); }); await test.step('步骤2: 点击登出按钮', async () => { const logoutButton = page.locator('button:has-text("退出"), a:has-text("退出"), button:has-text("登出")'); if (await logoutButton.count() > 0) { await logoutButton.click(); } }); await test.step('步骤3: 验证登出成功', async () => { await page.waitForURL(/\/admin\/login|\/$/); }); }); test('未登录用户访问管理页面重定向', async ({ page }) => { await test.step('步骤1: 直接访问管理页面', async () => { await page.goto('/admin/content'); }); await test.step('步骤2: 验证重定向到登录页', async () => { await expect(page).toHaveURL(/\/admin\/login/); }); }); });