Files
novalon-website/e2e/uj-11-home-conversion.spec.ts
zhangxiang ec543ff242 test(e2e): 六个 spec 随双轴 IA 与 home v16 重新锚定,锚点全部取自实测 DOM
一级导航改「行业 × 能力 + 洞察」+ 首页收 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` 才真断言)。
2026-10-17 01:07:53 +08:00

208 lines
10 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect, type Page } from './fixtures';
/**
* UJ-11: 首页转化旅程(设计优化专项)
*
* 覆盖首页关键转化路径,作为封版验收依据:
* UJ-11a: 首屏说服链路 — Hero + 可审计数字账本 → 透明信任层 → 成果槽 → 转化 CTA
* UJ-11b: 信任验证旅程 — 口径标注 + 首批客户共创 → 联系转化
* UJ-11c: 移动端首屏转化旅程 — 390px 下 CTA 首屏可见、无横向滚动
*
* 关联设计优化计划:docs/plans/2026-08-18-vibe-design-optimization-plan.md
* 关联 critique:.impeccable/critique/
*
* ⚠ 2026-10-17 按 home-content-v16 重写(ADR-0008 决策四:首页 10 段收 8 段,对标 Bain 段序)。
* 锚点全部以实测 DOM 为准,探针与读数留存于 `docs/acceptance/2026-10-17-ia-e2e/probe-home*.mjs`。
* 三处断言语义随结构变化,逐条说明(不要把它们改回旧锚点,旧锚点已不存在):
* 1) `hero-primary-cta` / `hero-secondary-link` → 合并为 `hero-cta`(v16 Hero 只留一条主 CTA,
* 次级链接按对标语法取消:两家 Hero 只有一条动作)。
* 2) `trust-section` → `home-ledger` + `home-ledger-signals` + `metrics-basis-note`:
* 原「信任四元组」被拆成**量化项与定性项两列**,因为「成都 / 全流程 / 共创」根本不是数字。
* 3) 「数据来源」→ 「目标口径,非既成结果」:口径角注由 `MetricsBasisNote` 按最弱 basis 出文,
* 本仓当前最弱口径是 target,所以文案是这一条。断言**判据是"有没有口径标注"**,
* 不是某个具体字符串——否则 target 升到 verified 时会误红。
* 4) 原 `narrative-section`(01/02/03 问题→方法→结果)整段删除:v16 把它的位置让给
* 成果槽(ResultsSlot),共创四步「问题梳理 / 小步验证 / 交付物验收 / 能力交接」
* 承担了原来那三幕想说的"过程可控",不再单独占一段。
* ⇒ 这里改为断言成果槽的**可判别空态**,语义更强:既验"有过程叙事",也验"没有假案例"。
*/
test.setTimeout(90000);
// ==================== 辅助函数 ====================
async function closeCookieBanner(page: Page) {
const acceptAllButton = page.locator('button:has-text("接受所有")').first();
if ((await acceptAllButton.count()) > 0 && (await acceptAllButton.isVisible())) {
await acceptAllButton.click();
await page.waitForTimeout(500);
}
}
/**
* 断言页面无横向滚动(scrollWidth <= clientWidth + 1px 容差)
*/
async function expectNoHorizontalOverflow(page: Page) {
const overflow = await page.evaluate(() => {
const doc = document.documentElement;
return { scrollWidth: doc.scrollWidth, clientWidth: doc.clientWidth };
});
expect(overflow.scrollWidth).toBeLessThanOrEqual(overflow.clientWidth + 1);
}
async function gotoHome(page: Page) {
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
await page.waitForTimeout(2500);
await closeCookieBanner(page);
}
// ==================== UJ-11a: 首屏说服链路 ====================
test.describe('UJ-11a: 首屏说服链路(Hero → 账本 → 信任 → 成果)', () => {
test('@journey @critical 首页首屏 Hero、单一 CTA、可审计数字账本渲染正常', async ({ page }) => {
await gotoHome(page);
// === L1 Hero:声明先行 + 单一 CTA(v16 起 min-h 90vh → 70vh,且无粒子场)===
const heroSection = page.locator('[data-testid="hero-section"]').first();
await expect(heroSection).toBeVisible({ timeout: 15000 });
const heroTitle = page.locator('h1').first();
await expect(heroTitle).toBeVisible();
// === 单一主 CTA,且必须落到联系页 ===
const cta = page.locator('[data-testid="hero-cta"]').first();
await expect(cta).toBeVisible();
await expect(cta).toHaveAttribute('href', '/contact');
// === L2 数字账本:量化项与口径角注同时在场 ===
const ledger = page.locator('[data-testid="home-ledger"]').first();
await expect(ledger).toBeVisible({ timeout: 10000 });
expect(await page.locator('[data-testid="ledger-metric"]').count()).toBeGreaterThan(0);
await expectNoHorizontalOverflow(page);
});
test('@journey @critical 首页信任层展示可验证信号与口径标注', async ({ page }) => {
await gotoHome(page);
// 定性信号列(成都 / 全流程 / 共创)—— 它们不是数字,所以与 ledger-metric 分列
const signals = page.locator('[data-testid="home-ledger-signals"]').first();
await signals.scrollIntoViewIfNeeded();
await expect(signals).toBeVisible({ timeout: 10000 });
const signalText = await signals.textContent();
expect(signalText).toContain('成都');
expect(signalText).toContain('全流程');
expect(signalText).toContain('共创');
// 口径标注:零编造前提下每个数字必须带可追溯口径。
// 判据是「这一格存在且非空」,不锁具体措辞(口径升级时文案会变,锁字符串会误红)。
const basisNote = page.locator('[data-testid="metrics-basis-note"]').first();
await expect(basisNote).toBeVisible();
expect(((await basisNote.textContent()) ?? '').trim().length).toBeGreaterThan(0);
});
test('@journey @critical 首页按对标段序呈现 洞察 → 行业 → 能力 三段', async ({ page }) => {
await gotoHome(page);
// v16 段序:Hero(1) 账本(2) 承诺(3) 成果(4) 洞察(5) 行业(6) 能力(7) CTA(8)
// 这三段是原「叙事区」位置上的替代结构,逐个锚 testid 而不是靠文案,
// 因为三段的标题都可被 CMS pageCopy 覆盖。
const anchors = ['home-insights', 'home-industries', 'home-capabilities'];
const positions: number[] = [];
for (const id of anchors) {
const el = page.locator(`[data-testid="${id}"]`).first();
await expect(el).toBeVisible({ timeout: 10000 });
// 段序要用**文档坐标**,不能用 boundingBox().y —— 那是视口相对值,
// scrollIntoViewIfNeeded 之后每段都被滚到同一带区,读数只反映滚动位置不反映先后
// (第一版就是这么错的:y 出现 -0.5 / -151.8 这类值,断言按"自上而下"必然判不出顺序)。
const docY = await el.evaluate((e) => e.getBoundingClientRect().top + window.scrollY);
positions.push(docY);
}
// 段序即信息架构:颠倒说明装配顺序被动过
expect(positions).toEqual([...positions].sort((a, b) => a - b));
});
});
// ==================== UJ-11b: 信任验证旅程 ====================
test.describe('UJ-11b: 信任验证旅程(共创 → 转化)', () => {
test('@journey @critical 首页首批客户共创标签引导至联系转化', async ({ page }) => {
await gotoHome(page);
const placeholder = page.locator('[data-testid="results-slot-placeholder"]').first();
await placeholder.scrollIntoViewIfNeeded();
await expect(placeholder).toBeVisible({ timeout: 10000 });
const cardText = await placeholder.textContent();
expect(cardText).toContain('共创');
const coCreationCta = placeholder.locator('a[href="/contact"]').first();
await expect(coCreationCta).toBeVisible();
await expect(coCreationCta).toContainText('成为首批共创客户');
});
test('@journey @critical 空案例区呈现共创内容块而非裸空态', async ({ page }) => {
await gotoHome(page);
const bodyText = await page.locator('body').textContent();
// 无「暂无案例数据」裸空态
expect(bodyText).not.toContain('暂无案例数据');
// 成果槽处于**可判别的共创态**,而不是"没数据所以什么都不渲染"
await expect(page.locator('[data-testid="results-slot-co-creation"]').first()).toBeVisible();
// 明说不冒充案例(反伪造不变量的用户可见面)
expect(bodyText).toContain('不会写一个出来');
// 过程叙事在场:原「01/02/03 三幕」的语义由共创四步承担
expect(bodyText).toContain('问题梳理');
expect(bodyText).toContain('交付物验收');
// 转化出口仍在
const placeholder = page.locator('[data-testid="results-slot-placeholder"]').first();
await expect(placeholder.locator('a[href="/contact"]').first()).toBeVisible();
});
});
// ==================== UJ-11c: 移动端首屏转化旅程 ====================
test.describe('UJ-11c: 移动端首屏转化旅程', () => {
test('@mobile @journey @critical 移动端 CTA 首屏可见且无横向滚动', async ({ page }) => {
// 模拟移动端视口
await page.setViewportSize({ width: 390, height: 844 });
await gotoHome(page);
// 无横向滚动
await expectNoHorizontalOverflow(page);
// 首屏 Hero 区块可见
const heroSection = page.locator('[data-testid="hero-section"]').first();
await expect(heroSection).toBeVisible({ timeout: 15000 });
// CTA 不只是"存在",必须在 844px 首屏折线内 —— 实测 hero 收 70vh 后 y≈418、h≈51
const cta = page.locator('[data-testid="hero-cta"]').first();
await expect(cta).toBeVisible();
const box = await cta.boundingBox();
expect(box).not.toBeNull();
expect(box!.y).toBeGreaterThanOrEqual(0);
expect(box!.y + box!.height).toBeLessThanOrEqual(844);
});
test('@mobile @journey @critical 移动端信任层与成果区单列堆叠无溢出', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await gotoHome(page);
// dev 服务高负载下区块节点会被替换,直接 scrollIntoViewIfNeeded 会撞上
// 「Element is not attached to the DOM」(chain3 实测 firefox),先等可见再滚动。
for (const id of ['home-ledger', 'home-ledger-signals', 'results-slot-placeholder', 'home-capabilities']) {
const el = page.locator(`[data-testid="${id}"]`).first();
await expect(el).toBeVisible({ timeout: 15000 });
await el.scrollIntoViewIfNeeded();
await expect(el).toBeVisible();
}
const basisNote = page.locator('[data-testid="metrics-basis-note"]').first();
await expect(basisNote).toBeVisible();
// 全程无横向滚动(滚动到页面底部后再测一次,窄视口下的溢出通常在末段才暴露)
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await page.waitForTimeout(400);
await expectNoHorizontalOverflow(page);
});
});