一级导航改「行业 × 能力 + 洞察」+ 首页收 8 段之后,旧锚点若不改,
**"绿"只代表还在测上一版信息架构**。本轮 `test:all` 首次跑出
40 failed / 10 例 × 4 project,全部是三组旧断言,逐条按实测 DOM 重写后转绿。
取证方式:不用记忆猜选择器。探针 7 份存
`docs/acceptance/2026-10-17-ia-e2e/probe-*.mjs`,读数是写断言的唯一依据。
关键实测事实:
- hydration 后一级恰为 `['行业','能力','洞察']` 三个
`button[aria-expanded]` + 1 个 `<a href="/about">`
⇒ **桌面顶栏只有 1 个 `<a>`**,这是 p2 那条「取前两个链接」
在 idx=1 稳定读不到元素的根因
- `aria-controls` 在关闭态**故意不渲染**(面板仅 isOpen 时挂载,
header.tsx:178),所以它不能当锚点;定位口径统一为 `button[aria-expanded]`
- 首页实际 testid:`hero-cta`(不是 `hero-primary-cta`)、
`home-ledger{,-metrics,-signals}`、`metrics-basis-note`、
`results-slot-{co-creation,placeholder}`、
`home-{insights,industries,capabilities,cta,cta-button}`;
`trust-section` / `narrative-section` / `cases-co-creation-cta` /
`hero-secondary-link` **已不存在**
- 首页「数据来源」字样实测 **0 次**,口径角注真实文案是
「目标口径,非既成结果」
逐文件:
1. `nav-dropdown.spec.ts` — 两条旧例(产品 / 解决方案下拉)重写为三轴各一条,
并**新增一条一级 IA 契约断言**:触发器文本恰为 `['行业','能力','洞察']`
且「产品」不得回到一级(若 CMS 旧行重新接管导航即判红,
与 navigation-resolution 的代码守卫配对)。
「产品」那条的语义同时升级为**降级后仍可到达**:
能力面板里的「产品矩阵总览 → /products」。
2. `p6-missing-paths.spec.ts` — 产品路径改走 能力 → 产品矩阵总览。
3. `uj-11-home-conversion.spec.ts` — 7 条全重写。四处口径变化逐条写了理由:
双 CTA 收成单 CTA;trust-section 拆成「量化项 / 定性项分列」
(成都·全流程·共创根本不是数字);
**「数据来源」断言改为「口径标注存在且非空」而不是锁措辞** ——
锁字符串会在 target 升到 verified 时误红,
判据要对那一维的存在性敏感而非对文案敏感;
原「叙事区 01/02/03」整段删除,其语义由**成果槽的可判别空态**承接
(既验"有过程叙事",也验"没有假案例",比原断言更强)。
4. `p2-functional-e2e.spec.ts` — 四条旧锚点重写;
「导航链接可点击」改为**按导航自己声明的目的地去走**
(直链优先,未展开的下拉先 hover 再取面板链接),
桌面/移动共用同一条判据,不再硬编码元素类型。保留 N-27 纪律:
不许静默跳过、不许 `waitForURL(...).catch(() => {})` 把"点了没跳转"吞成绿灯。
5. `p5-edge-cases.spec.ts:129` — `narrative-section a[href="/products"]` →
`card-products a[href="/products"]`(页脚,不依赖 hover,仍守住 N-27)。
6. `user-journey.spec.ts:216` — UJ-02 的「解决方案」轴改名「行业」,
动作项「查看全部行业」。
我自己新写的断言里也有一条是错的,一并记(§5.40 同族:仪器只在被复用时才坏):
「首页段序 洞察→行业→能力」最初用 `boundingBox().y` 排序,
而那是**视口相对**值,`scrollIntoViewIfNeeded` 后各段都落在同一带区,
实测读数出现 `-0.5` / `-151.8` ⇒ 判不出先后。
改用文档坐标 `getBoundingClientRect().top + scrollY`,
并实测三段读数 **2684 / 3242 / 3995**,确认这条断言不是恒等式。
复跑(全部重定向后读 `$?`):
`nav-dropdown + p6 + uj-11` × **4 project ⇒ 80 passed / 0 failed**;
`p2` × chromium + chromium-mobile ⇒ **96 passed / 0 failed**;
`npm run test:all` ⇒ **EXIT=0**(e2e:fast 59 passed / 25 skipped,
那 16 个 GA4 @critical 仍在 skipped 侧,须 `test:e2e:prod` 才真断言)。
199 lines
7.9 KiB
TypeScript
199 lines
7.9 KiB
TypeScript
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:其恢复动作是
|
||
// 「返回上一页」<button>(not-found-content.tsx:30-33)+「返回首页」CTA。
|
||
// N-27 修复:原守卫 `if (count > 0)` ⇒ 页面空了也绿。改为硬断言两者可见。
|
||
await page.goto('/error-test-trigger', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
const backButton = page.locator('main button', { hasText: '返回上一页' }).first();
|
||
await expect(backButton).toBeVisible();
|
||
|
||
const homeLink = page.locator('main a[href="/"]').first();
|
||
await expect(homeLink).toBeVisible();
|
||
});
|
||
|
||
test('错误页面包含返回首页链接', async ({ page }) => {
|
||
await page.goto('/error-boundary-test', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
// N-27 修复:守卫改为硬断言,并验证链接真的能回到首页
|
||
// (与 :32 的差异:此例覆盖点击后的导航行为,不只是文案存在)。
|
||
const homeLink = page.locator('main a[href="/"]').first();
|
||
await expect(homeLink).toBeVisible();
|
||
await expect(homeLink).toContainText('返回首页');
|
||
|
||
await Promise.all([
|
||
page.waitForURL((url) => new URL(url).pathname === '/', { waitUntil: 'commit', timeout: 15000 }),
|
||
homeLink.click(),
|
||
]);
|
||
expect(new URL(page.url()).pathname).toBe('/');
|
||
});
|
||
});
|
||
|
||
// ==================== 3. 加载状态测试 ====================
|
||
test.describe('加载状态 - 页面过渡', { tag: '@regression' }, () => {
|
||
|
||
test('页面加载时显示主要内容', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
|
||
// 页面加载后 header 应可见
|
||
await expect(page.locator('header')).toBeVisible({ timeout: 10000 });
|
||
|
||
// main 内容应存在
|
||
const mainContent = page.locator('main, [role="main"]').first();
|
||
await expect(mainContent).toBeVisible({ timeout: 10000 });
|
||
});
|
||
|
||
test('页面导航不应完全空白', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1000);
|
||
|
||
// N-27 修复:原守卫 `if (count > 0 && isVisible)` 依赖 header 巨型下拉里的
|
||
// `a[href="/products"]`(未 hover 时隐藏 ⇒ 断言常被跳过)。
|
||
// ⚠ 2026-10-17 v16 重写:原锚点「叙事区第三幕 a[href="/products"]」随叙事区整段删除而消失
|
||
// (v16 段序无三幕叙事,见 ADR-0008 决策四)。仍坚持"不 hover 也必须可见"这条纪律,
|
||
// 故改用页脚产品列的「产品矩阵总览 → /products」:它在主文档流里恒定渲染,
|
||
// 与下拉那一条同名但不依赖 hover 状态。
|
||
const productLink = page
|
||
.locator('[data-testid="card-products"] a[href="/products"]')
|
||
.first();
|
||
await expect(productLink).toBeVisible();
|
||
|
||
await productLink.click();
|
||
await expect(page).toHaveURL((url) => url.pathname === '/products');
|
||
|
||
// 导航完成后页面仍应包含实际内容
|
||
const bodyText = await page.locator('body').textContent();
|
||
expect(bodyText!.length).toBeGreaterThan(50);
|
||
});
|
||
|
||
test('刷新页面后内容仍然加载', async ({ page }) => {
|
||
await page.goto('/products', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 刷新页面
|
||
await page.reload({ waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
// 页面应仍然加载成功
|
||
const mainContent = page.locator('main, [role="main"]').first();
|
||
await expect(mainContent).toBeVisible();
|
||
});
|
||
});
|
||
|
||
// ==================== 4. 无效路由与特殊字符测试 ====================
|
||
test.describe('无效路由 - 边界 URL 处理', { tag: '@regression' }, () => {
|
||
|
||
test('带特殊字符的路由不崩溃', async ({ page }) => {
|
||
const specialPaths = [
|
||
'/products/<script>alert(1)</script>',
|
||
'/about?param=<invalid>',
|
||
'/contact#%20%20',
|
||
];
|
||
|
||
for (const path of specialPaths) {
|
||
await page.goto(path, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1000);
|
||
|
||
// 页面不应崩溃,body 应存在
|
||
const body = page.locator('body').first();
|
||
await expect(body).toBeVisible();
|
||
}
|
||
});
|
||
|
||
test('过长路径不导致页面异常', async ({ page }) => {
|
||
const longPath = '/a'.repeat(200);
|
||
await page.goto(longPath, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
// 页面应正常渲染(404 页面或正常页面)
|
||
const body = page.locator('body').first();
|
||
await expect(body).toBeVisible();
|
||
|
||
const bodyText = await body.textContent();
|
||
expect(bodyText!.length).toBeGreaterThan(0);
|
||
});
|
||
|
||
test('查询参数不影响页面渲染', async ({ page }) => {
|
||
await page.goto('/?utm_source=test&utm_medium=email', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
// 首页应正常渲染
|
||
const header = page.locator('header').first();
|
||
await expect(header).toBeVisible();
|
||
});
|
||
});
|