import { test, expect } from './fixtures'; /** * P5: 边缘情况与缺失路径 E2E 测试 * * 覆盖范围: * 1. 404 未找到页面 * 2. 全局错误边界 * 3. 页面加载状态 * 4. 无效路由与特殊字符 */ test.setTimeout(60000); // ==================== 1. 404 页面测试 ==================== test.describe('404 页面 - 未找到页面', { tag: '@regression' }, () => { test('访问不存在的页面显示 404', async ({ page }) => { await page.goto('/this-page-does-not-exist', { waitUntil: 'domcontentloaded', timeout: 30000 }); await page.waitForTimeout(1500); // URL 应保持为请求的路径或重定向到 404 处理 expect(page.url()).toContain('this-page-does-not-exist'); // 检查 404 页面关键元素 const heading = page.locator('h1').first(); await expect(heading).toBeVisible(); const headingText = await heading.textContent(); expect(headingText).toMatch(/404|页面未找到/); }); test('404 页面包含返回首页按钮', async ({ page }) => { await page.goto('/non-existent-page', { waitUntil: 'domcontentloaded', timeout: 30000 }); await page.waitForTimeout(1500); const homeButton = page.locator('a[href="/"]').first(); await expect(homeButton).toBeVisible(); expect(await homeButton.textContent()).toContain('返回首页'); }); test('404 页面推荐链接可点击', async ({ page }) => { await page.goto('/missing-page', { waitUntil: 'domcontentloaded', timeout: 30000 }); await page.waitForTimeout(1500); // N-27 修复:四个推荐链接在 src/app/not-found-content.tsx:41-81 中恒定渲染, // 原 `if (count > 0 && isVisible)` 守卫会让本例在链接缺失时静默通过。 // 改为主内容区内作用域的轮询断言——任何一条缺失/隐藏即失败。 const recommendedLinks = [ { text: '产品', expectedPath: '/products' }, { text: '解决方案', expectedPath: '/solutions' }, { text: '关于我们', expectedPath: '/about' }, { text: '联系我们', expectedPath: '/contact' }, ]; for (const { text, expectedPath } of recommendedLinks) { const link = page.locator(`main a:has-text("${text}")`).first(); await expect(link, `404 页缺少推荐链接「${text}」`).toBeVisible(); await expect(link).toHaveAttribute('href', expectedPath); } }); test('404 页面标题设置正确', async ({ page }) => { await page.goto('/not-found-test', { waitUntil: 'domcontentloaded', timeout: 30000 }); await page.waitForTimeout(1500); const title = await page.title(); expect(title).toContain('页面未找到'); }); }); // ==================== 2. 错误边界测试 ==================== test.describe('错误边界 - 应用级错误处理', { tag: '@regression' }, () => { test('错误页面包含重试按钮', async ({ page }) => { // 未知路径渲染 src/app/not-found-content.tsx:其恢复动作是 // 「返回上一页」