决策二把「产品」退出一级后,**手机上到 /products 没有任何导航路径**(只剩页脚)。
判据抓到的,不是人肉走查:`mobile-user-journeys.spec.ts` 里那条
「抽屉里没有、底部 TabBar 里也没有 ⇒ 可能已成孤儿」的守卫稳定判红。
实测证据(探针 `docs/acceptance/2026-10-17-ia-e2e/probe-tabbar.mjs` / `probe-drawer.mjs`):
底部 TabBar 的 hrefs 只有 `['/','/solutions','/services','/insights','/contact']`,
而移动抽屉原本只渲染 `config.mainNav` 这一层(header.tsx:222-246)。
桌面端靠 hover mega 面板仍可达 ⇒ 这是**只有移动端会中**的 IA 完成度缺口。
若把那条断言改成"找不到就跳过",/products 会在手机上静默消失。
改动:
- 抽屉为带 `dropdownKey` 的轴渲染其 mega 组(组标题 + 二级链接)。
不做手风琴:抽屉本身 `overflow-y-auto` 可滚,常驻展开少一个交互态、
也少一处 a11y 契约要维护。复测:抽屉 **26 条链接、含 /products 1 条、二级项 21 个**。
- `group.items` 加 `?? []` 守卫 —— CMS 行的形状不受类型约束,
`header.test.tsx` 的夹具里就有无 items 的组,5 例因 `undefined.map` 崩。
这条是单测抓到的:我的 dev-server 探针走的是真实 config,看不出这个边界。
- `mobile-tab-bar.tsx` 的 `<nav>` 补 `role/aria-label="底部标签导航"` 与
`data-testid="mobile-tab-bar"`:原来两个 nav landmark 里只有抽屉有名字,
而用例只能靠"页面上任何 a[href]"去找底部导航 —— 那会命中页脚那条同名链接,
被抽屉遮罩拦住指针事件,15s 重试 6 次全超时(本轮真实症状)。
- `uj-08-service-journey.spec.ts`:helper 从 `a:has-text("服务")` 改为
hover「能力」→ `a[href="/services"]`。旧注释那句
「服务导航项是直接链接,无下拉菜单」在新 IA 下已不成立。
- `user-journey.spec.ts` UJ-03 teardown:删行后补一次 revalidate。
根因链(证据:`news.html` 的 mtime 与 uj03 命中、allure 步骤时序):
01:16:31 创建 → 01:16:33 revalidate ⇒ ISR 在这一刻把**带测试行的 HTML 落盘** →
01:16:35 DELETE ⇒ 库里行没了但没人再刷 ⇒ 之后 UJ-10 断言"筛出恰 1 条"拿 2 条判红,
而 `x-nextjs-cache: HIT`、`s-maxage=3600`。
**只修测试这一层**;产品层缺口(后台发布/删除全都不触发失效)另记 DEC-N5。
本笔也记一次自伤(§5.42,因为它差点把结论带偏):
为清那份冻结产物我 `rm -rf` 了构建输出子树,连带删掉已编译的 `news/page.js` ⇒
服务打 `Cannot find module` ×6、两条旅程因页面 500 而红;
而我当时的"清除验证"是数产物里的 uj03 命中数,得到 **0** ——
读起来像"缓存干净了",实际是 **500 的错误页里当然不含那一行**。
重建后 uj03 又出现 2 次,才暴露库里真有 2 条因中途失败而未清理的残留行。
善后:按 id 删自造的 2 条 news(连带 AuditLog 与 ContentZone.items 引用),
`news` 已发布行回到 seed 的 2 条,再 `npm run build`。
⇒ 三条纪律进 lessons:重置 ISR 只靠重建或 revalidate、不许手删 dist/**;
「命中 0」必须同时断言页面健康(正对照),否则"仪器坏了"与"问题没了"共用同一个 0;
破坏性清理让用例中途失败后要清点它留下了什么半成品数据。
另记 §5.43 / DEC-N6:`e2e/**/*.ts` 不在 tsconfig include 里 ⇒
teardown 补丁中重复的 `const revalidateSecret` 让 type-check 全程 EXIT=0,
只有 `npx playwright test --list` 才报 `already been declared`(整档无法加载)。
台账与文档:`qa-tracker.md` §11.5(25 条 prod 目标红的三类归因、真缺陷、自伤、
新登记 DEC-N5/DEC-N6)、ADR-0008「已知偏差」补第 7、8 条、
`CONTEXT.md` 加「移动端二级目的地必须在抽屉里可达」、
`docs/lessons-learned.md` §5.42–§5.43 + 更新记录 2 行。
复跑(一律重定向后读 `$?`,不用管道):
`header.test.tsx` 18 passed;`UJ-01/02/08/10` × chromium + chromium-mobile **14 passed**;
`npm run test:all` ⇒ **EXIT=0**(141 套件 / 1747 例、integration 23、
check:visual 11/11 + accents 成立、e2e:fast 59 passed / 25 skipped);
`type-check` EXIT=0、`lint` EXIT=0(0 error / 81 warning)、`build` EXIT=0。
未闭合(须单独授权或另行裁定):视觉基线重采(AUTH-VISUAL,只读复跑实测
**109 failed = 104 例像素不符 + 5 例死选择器超时**,后者已在本笔改成反向守卫并经
变异验证:把 founder-quote-section 塞回首页 ⇒ 该条判红、还原 ⇒ 通过);
`--radius-cta: 12px` 负对照依赖基线先入库;
GA4 在本 worktree **无法取证**(worktree 无 `.env.production`,
`NEXT_PUBLIC_*` 在 build 期烘焙 ⇒ 那 16 例即便 `E2E_TARGET=production` 仍是 skipped);
`check:motion` 残留 8 处(基线既有红);DEC-N1 彩色编码第二通道待设计裁定。
475 lines
21 KiB
TypeScript
475 lines
21 KiB
TypeScript
import { test, expect, type Page } from './fixtures';
|
||
|
||
/**
|
||
* 移动端用户旅程 E2E 测试
|
||
*
|
||
* 覆盖范围(UJ-01 ~ UJ-10 移动端变体):
|
||
* - UJ-01 Mobile: 潜在客户从首页到联系表单的完整旅程
|
||
* - UJ-02 Mobile: 行业客户浏览解决方案到产品的旅程
|
||
* - UJ-04 Mobile: 新闻读者浏览旅程(列表 → 详情 → 返回)
|
||
* - UJ-05 Mobile: 案例浏览者筛选旅程(列表 → 筛选 → 详情)
|
||
* - UJ-10 Mobile: 深度搜索者旅程(分类浏览 → 逐篇阅读 → 内容发现)
|
||
*
|
||
* 所有测试使用 iPhone 14 视口(isMobile: true, hasTouch: true),
|
||
* 通过 `chromium-mobile` 项目自动注入。
|
||
*/
|
||
|
||
test.setTimeout(90000);
|
||
|
||
// ==================== 辅助函数 ====================
|
||
|
||
/**
|
||
* 关闭 Cookie 同意横幅(如果存在)
|
||
*/
|
||
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);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 通过移动端汉堡菜单导航到指定页面
|
||
* 移动端导航菜单中所有项均为 `<a>` 链接(无下拉展开),直接点击对应标签跳转。
|
||
*/
|
||
async function navigateViaMobileMenu(page: Page, targetPath: string) {
|
||
// 检查是否在移动端视口(移动端菜单按钮可见)
|
||
const menuButton = page.locator('[data-testid="mobile-menu-button"]').first();
|
||
const isMobileViewport = await menuButton.isVisible().catch(() => false);
|
||
|
||
if (!isMobileViewport) {
|
||
// 桌面端视口 — 直接导航到目标路径
|
||
console.log('Desktop viewport detected, navigating directly to:', targetPath);
|
||
await page.goto(targetPath, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
return;
|
||
}
|
||
|
||
// 移动端:通过汉堡菜单导航
|
||
await menuButton.click();
|
||
await page.waitForTimeout(500);
|
||
|
||
const mobileNav = page.locator('[data-testid="mobile-navigation"]').first();
|
||
await expect(mobileNav).toBeVisible({ timeout: 5000 });
|
||
|
||
// 路径到导航标签的映射
|
||
const pathToLabel: Record<string, string> = {
|
||
'/products': '产品',
|
||
'/solutions': '解决方案',
|
||
'/services': '服务',
|
||
'/cases': '案例',
|
||
'/news': '新闻动态',
|
||
'/about': '关于我们',
|
||
'/contact': '联系我们',
|
||
};
|
||
|
||
const label = pathToLabel[targetPath];
|
||
if (!label) {
|
||
// 未知路径,直接导航
|
||
await page.goto(targetPath, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
return;
|
||
}
|
||
|
||
/**
|
||
* 2026-10-17 双轴 IA 后改为**按 href 定位**,并显式覆盖移动端的两条真实导航机制。
|
||
*
|
||
* 原来写死 `a:has-text("产品")` / `("解决方案")` / `("服务")`:一级导航改成
|
||
* 行业 × 能力 + 洞察后,抽屉里只剩 行业 / 能力 / 洞察 / 关于我们 四项
|
||
* (`header.tsx:223-244` 只渲染 `config.mainNav`),于是这三条映射在抽屉里**永不命中**,
|
||
* UJ-01/UJ-02 稳定判红 —— 而目的地其实仍可达:`/products`、`/solutions`、`/cases`
|
||
* 落在**底部 TabBar**(`mobile-tab-bar.tsx`:首页/产品/方案/案例/联系)上。
|
||
* ⇒ 一张标签映射表把"移动端的可达性"窄化成了"抽屉里的可达性",这是测试口径缺陷。
|
||
*
|
||
* 顺序是:抽屉直链 → 关抽屉 → 底部 TabBar。
|
||
* 中间那步「关抽屉」不是礼节:抽屉是 `fixed inset-0 z-40` 的全屏遮罩,
|
||
* 开着它会拦截 TabBar 与页脚链接的指针事件(本轮实测就是
|
||
* `locator.click` 超时 + 日志里 `<div id="mobile-menu" …> intercepts pointer events`,
|
||
* 15s 内重试 6 次全被遮罩吃掉)。
|
||
* 两处都到不了才判红 —— 那才是「一级导航降级后该路径成了孤儿」这种真事故。
|
||
* 与 e9bd9654「查看全部不再靠中文标签反推路由」是同一条纪律。
|
||
*/
|
||
const drawerLink = mobileNav.locator(`a[href="${targetPath}"]`).first();
|
||
if ((await drawerLink.count()) && (await drawerLink.isVisible().catch(() => false))) {
|
||
await drawerLink.click();
|
||
return;
|
||
}
|
||
|
||
// 抽屉里没有 → 关掉遮罩,走底部 TabBar
|
||
await menuButton.click();
|
||
await expect(mobileNav).toBeHidden({ timeout: 5000 });
|
||
|
||
const tabLink = page
|
||
.locator(`[data-testid="mobile-tab-bar"] a[href="${targetPath}"]`)
|
||
.first();
|
||
await expect(
|
||
tabLink,
|
||
`移动端两条导航机制都到不了 ${targetPath}:抽屉里没有、底部 TabBar 里也没有 ` +
|
||
`⇒ 一级导航降级后该路径可能已成孤儿`,
|
||
).toBeVisible({ timeout: 5000 });
|
||
await tabLink.click();
|
||
}
|
||
|
||
// ==================== UJ-01 Mobile: 潜在客户从首页到联系表单的完整旅程 ====================
|
||
test.describe('UJ-01 Mobile: 潜在客户从首页到联系表单的完整旅程', () => {
|
||
test('@mobile @journey @regression 访客从首页浏览产品并提交联系表单', async ({ page }) => {
|
||
// === Step 1: 访问首页,验证 Hero 区域 ===
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2500);
|
||
await closeCookieBanner(page);
|
||
|
||
// 验证 Hero 区域可见
|
||
const heroTitle = page.locator('h1').first();
|
||
await expect(heroTitle).toBeVisible({ timeout: 15000 });
|
||
const titleText = await heroTitle.textContent();
|
||
expect(titleText).toBeTruthy();
|
||
expect(titleText!.length).toBeGreaterThan(0);
|
||
|
||
// === Step 2: 通过移动端菜单导航到产品页面 ===
|
||
await navigateViaMobileMenu(page, '/products');
|
||
|
||
await page.waitForURL(/\/products/, { timeout: 10000 });
|
||
await expect(page).toHaveURL(/\/products/);
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 验证产品页面有标题
|
||
const productsTitle = page.locator('h1, h2').first();
|
||
await expect(productsTitle).toBeVisible();
|
||
const productsTitleText = await productsTitle.textContent();
|
||
expect(productsTitleText).toContain('产品');
|
||
|
||
// 验证产品卡片存在
|
||
const productLinks = page.locator('a[href*="/products/"]:not([href$="/products"])');
|
||
const linkCount = await productLinks.count();
|
||
expect(linkCount).toBeGreaterThan(0);
|
||
|
||
// === Step 3: 点击产品进入详情页 ===
|
||
const firstProductLink = productLinks.first();
|
||
await firstProductLink.click();
|
||
|
||
await page.waitForURL(/\/products\/.+/, { timeout: 10000 });
|
||
await expect(page).toHaveURL(/\/products\/.+/);
|
||
await page.waitForTimeout(2000);
|
||
|
||
// === Step 4: 验证产品详情页内容 ===
|
||
const detailTitle = page.locator('h1').first();
|
||
await expect(detailTitle).toBeVisible({ timeout: 10000 });
|
||
|
||
// 验证 L4 CTA 区域存在(移动端寻找 CTA 按钮/咨询入口)
|
||
const ctaSection = page.locator('main').first();
|
||
await expect(ctaSection).toBeVisible();
|
||
const ctaSectionText = await ctaSection.textContent();
|
||
const hasCTA = ctaSectionText!.includes('咨询') ||
|
||
ctaSectionText!.includes('联系') ||
|
||
ctaSectionText!.includes('了解更多') ||
|
||
ctaSectionText!.includes('立即') ||
|
||
ctaSectionText!.includes('contact');
|
||
expect(hasCTA).toBeTruthy();
|
||
|
||
// === Step 5: 导航到联系页面 ===
|
||
await page.goto('/contact', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2500);
|
||
|
||
// === Step 6: 填写联系表单 ===
|
||
const nameInput = page.locator('[data-testid="name-input"]').first();
|
||
await expect(nameInput).toBeVisible({ timeout: 5000 });
|
||
|
||
await page.locator('[data-testid="name-input"]').fill('移动端客户');
|
||
await page.locator('[data-testid="phone-input"]').fill('13912345678');
|
||
await page.locator('[data-testid="email-input"]').fill('mobile@example.com');
|
||
await page.locator('[data-testid="subject-input"]').fill('产品咨询 - 移动端');
|
||
await page.locator('[data-testid="message-input"]').fill('您好,我在手机上浏览了贵司产品,希望进一步了解。');
|
||
|
||
// === Step 7: 拦截 API 并提交表单 ===
|
||
let routeHit = false;
|
||
await page.route('/api/contact', async (route) => {
|
||
routeHit = true;
|
||
await route.fulfill({
|
||
status: 200,
|
||
contentType: 'application/json',
|
||
body: JSON.stringify({ success: true, message: '发送成功' }),
|
||
});
|
||
});
|
||
|
||
const submitButton = page.locator('[data-testid="submit-button"]').first();
|
||
await submitButton.scrollIntoViewIfNeeded();
|
||
await page.waitForTimeout(300);
|
||
|
||
// 隐藏可能覆盖底部元素的固定返回顶部按钮
|
||
await page.evaluate(() => {
|
||
const backToTop = document.querySelector('[aria-label="返回顶部"]') as HTMLElement | null;
|
||
if (backToTop) backToTop.style.display = 'none';
|
||
});
|
||
|
||
// 使用原生 DOM click() 触发提交
|
||
await page.evaluate(() => {
|
||
const btn = document.querySelector('[data-testid="submit-button"]') as HTMLButtonElement | null;
|
||
btn?.click();
|
||
});
|
||
|
||
// === Step 8: 验证成功消息 ===
|
||
await page.waitForTimeout(2000);
|
||
|
||
console.log('UJ-01 Mobile route hit:', routeHit);
|
||
|
||
const bodyText = await page.locator('body').textContent();
|
||
const hasSuccessIndicator =
|
||
bodyText!.includes('消息已发送') ||
|
||
bodyText!.includes('感谢') ||
|
||
bodyText!.includes('发送成功') ||
|
||
bodyText!.includes('提交成功');
|
||
expect(hasSuccessIndicator).toBe(true);
|
||
});
|
||
});
|
||
|
||
// ==================== UJ-02 Mobile: 行业客户浏览解决方案到产品的旅程 ====================
|
||
test.describe('UJ-02 Mobile: 行业客户浏览解决方案到产品的旅程', () => {
|
||
test('@mobile @journey @regression 客户从解决方案浏览到产品详情', async ({ page }) => {
|
||
// === Step 1: 访问首页 ===
|
||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
await closeCookieBanner(page);
|
||
|
||
const heroTitle = page.locator('h1').first();
|
||
await expect(heroTitle).toBeVisible({ timeout: 10000 });
|
||
|
||
// === Step 2: 导航到解决方案页面 ===
|
||
await navigateViaMobileMenu(page, '/solutions');
|
||
|
||
await page.waitForURL(/\/solutions/, { timeout: 10000 });
|
||
await expect(page).toHaveURL(/\/solutions/);
|
||
await page.waitForTimeout(2000);
|
||
|
||
const solutionsTitle = page.locator('h1, h2').first();
|
||
await expect(solutionsTitle).toBeVisible();
|
||
|
||
// === Step 3: 点击一个解决方案 ===
|
||
const solutionLinks = page.locator('a[href*="/solutions/"]:not([href$="/solutions"])');
|
||
const solutionLinkCount = await solutionLinks.count();
|
||
expect(solutionLinkCount).toBeGreaterThan(0);
|
||
|
||
const firstSolutionLink = solutionLinks.first();
|
||
await firstSolutionLink.click();
|
||
|
||
await page.waitForURL(/\/solutions\/.+/, { timeout: 10000 });
|
||
await expect(page).toHaveURL(/\/solutions\/.+/);
|
||
await page.waitForTimeout(2000);
|
||
|
||
// === Step 4: 验证解决方案详情页 ===
|
||
const solutionDetailTitle = page.locator('h1').first();
|
||
await expect(solutionDetailTitle).toBeVisible({ timeout: 10000 });
|
||
|
||
// 验证包含核心内容
|
||
const solutionMain = page.locator('main').first();
|
||
await expect(solutionMain).toBeVisible();
|
||
const solutionMainText = await solutionMain.textContent();
|
||
expect(solutionMainText!.length).toBeGreaterThan(200);
|
||
|
||
// === Step 5: 导航到产品页面 ===
|
||
await page.goto('/products', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
|
||
const productsPageTitle = page.locator('h1, h2').first();
|
||
await expect(productsPageTitle).toBeVisible();
|
||
|
||
// === Step 6: 点击产品进入详情页 ===
|
||
const productDetailLinks = page.locator('a[href*="/products/"]:not([href$="/products"])');
|
||
const productDetailLinkCount = await productDetailLinks.count();
|
||
expect(productDetailLinkCount).toBeGreaterThan(0);
|
||
|
||
const firstProductDetailLink = productDetailLinks.first();
|
||
await firstProductDetailLink.click();
|
||
|
||
await page.waitForURL(/\/products\/.+/, { timeout: 10000 });
|
||
await expect(page).toHaveURL(/\/products\/.+/);
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 验证产品详情页
|
||
const productDetailTitle = page.locator('h1').first();
|
||
await expect(productDetailTitle).toBeVisible({ timeout: 10000 });
|
||
|
||
// 验证存在 CTA 内容(移动端寻找 CTA 按钮/咨询入口)
|
||
const productMain = page.locator('main').first();
|
||
await expect(productMain).toBeVisible();
|
||
const productMainText = await productMain.textContent();
|
||
const hasCTA = productMainText!.includes('咨询') ||
|
||
productMainText!.includes('联系') ||
|
||
productMainText!.includes('了解更多') ||
|
||
productMainText!.includes('立即') ||
|
||
productMainText!.includes('contact');
|
||
expect(hasCTA).toBeTruthy();
|
||
});
|
||
});
|
||
|
||
// ==================== UJ-04 Mobile: 新闻读者浏览旅程 ====================
|
||
test.describe('UJ-04 Mobile: 新闻读者浏览旅程(列表 → 详情 → 返回)', () => {
|
||
test('@mobile @journey @regression 读者从新闻列表浏览到详情页并返回', async ({ page }) => {
|
||
// N-27 修复:同桌面版 UJ-04(user-journey.spec.ts)——原 `if (articleCount > 0)`
|
||
// 包住整段旅程,新闻消失时静默通过。种子恰有 2 篇已发布新闻,改为全程硬断言。
|
||
// === Step 1: 访问新闻列表 ===
|
||
await page.goto('/news', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
await closeCookieBanner(page);
|
||
|
||
// 验证新闻列表页加载成功
|
||
const newsTitle = page.locator('h1').first();
|
||
await expect(newsTitle).toBeVisible({ timeout: 10000 });
|
||
|
||
// 验证新闻列表存在文章条目
|
||
const firstArticle = page.locator('a[href*="/news/"]').first();
|
||
await expect(firstArticle).toBeVisible({ timeout: 5000 });
|
||
|
||
// === Step 2: 点击第一篇新闻进入详情页 ===
|
||
await Promise.all([
|
||
page.waitForURL(/\/news\/.+/, { timeout: 15000, waitUntil: 'commit' }),
|
||
firstArticle.click(),
|
||
]);
|
||
await page.waitForTimeout(1000);
|
||
|
||
// === Step 3: 验证新闻详情页 ===
|
||
const detailTitle = page.locator('h1').first();
|
||
await expect(detailTitle).toBeVisible({ timeout: 10000 });
|
||
const detailTitleText = await detailTitle.textContent();
|
||
expect(detailTitleText).toBeTruthy();
|
||
expect(detailTitleText!.length).toBeGreaterThan(0);
|
||
|
||
const detailContent = page.locator('main').first();
|
||
await expect(detailContent).toBeVisible();
|
||
const detailText = await detailContent.textContent();
|
||
expect(detailText!.length).toBeGreaterThan(50);
|
||
|
||
// === Step 4: 通过面包屑返回新闻列表 ===
|
||
// news-detail-content-v3.tsx:68-71 恒渲染 breadcrumb nav 中的「新闻动态」链接
|
||
const breadcrumbNewsLink = page.locator('nav[aria-label="breadcrumb"] a[href="/news"]');
|
||
await expect(breadcrumbNewsLink).toBeVisible();
|
||
await Promise.all([
|
||
page.waitForURL(/\/news\/?$/, { timeout: 15000, waitUntil: 'commit' }),
|
||
breadcrumbNewsLink.click(),
|
||
]);
|
||
|
||
await page.waitForTimeout(1000);
|
||
await expect(page).toHaveURL(/\/news\/?$/);
|
||
});
|
||
});
|
||
|
||
// ==================== UJ-05 Mobile: 案例浏览者筛选旅程 ====================
|
||
test.describe('UJ-05 Mobile: 案例浏览者筛选旅程(列表 → 筛选 → 详情)', () => {
|
||
test('@mobile @journey @regression 客户访问案例页,零案例种子下经共创空态转化到联系页', async ({ page }) => {
|
||
// N-27 修复:同桌面版 UJ-05。种子刻意 0 案例(prisma/seed.ts:628-631),
|
||
// 原 `if (caseLinkCount > 0)` + else 兜底 ⇒ 案例区为空也绿。
|
||
// 现断言当前真实契约:空态卡存在、筛选器缺席,并走完空态转化出口到联系页。
|
||
await page.goto('/cases', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
await closeCookieBanner(page);
|
||
|
||
const casesTitle = page.locator('h1').first();
|
||
await expect(casesTitle).toBeVisible({ timeout: 10000 });
|
||
await expect(casesTitle).toContainText('以成果为目标');
|
||
|
||
// 零案例契约:行业筛选按钮组与案例卡片必须不存在
|
||
await expect(page.getByRole('group', { name: '按行业筛选' })).toHaveCount(0);
|
||
await expect(page.locator('a[href*="/cases/"]')).toHaveCount(0);
|
||
|
||
// 空态转化卡:预约咨询 CTA 恒定渲染(cases-content-v3.tsx:334-336)
|
||
const emptyPrimaryCta = page.locator('[data-testid="cases-empty-primary-cta"]');
|
||
await expect(emptyPrimaryCta).toBeVisible();
|
||
await expect(emptyPrimaryCta).toHaveAttribute('href', '/contact');
|
||
|
||
// === 点击转化出口,验证抵达联系页 ===
|
||
await Promise.all([
|
||
page.waitForURL((url) => new URL(url).pathname === '/contact', { timeout: 15000, waitUntil: 'commit' }),
|
||
emptyPrimaryCta.click(),
|
||
]);
|
||
await expect(page).toHaveURL((url) => url.pathname === '/contact');
|
||
|
||
const contactTitle = page.locator('h1').first();
|
||
await expect(contactTitle).toBeVisible({ timeout: 10000 });
|
||
const contactText = await page.locator('main').first().textContent();
|
||
expect(contactText!.length).toBeGreaterThan(50);
|
||
});
|
||
});
|
||
|
||
// ==================== UJ-10 Mobile: 深度搜索者旅程 ====================
|
||
test.describe('UJ-10 Mobile: 深度搜索者旅程(分类浏览 → 逐篇阅读 → 内容发现)', () => {
|
||
test('@mobile @journey @regression 用户通过分类筛选浏览多篇文章并发现相关内容', async ({ page }) => {
|
||
// N-27 修复:同桌面版 UJ-10(user-journey.spec.ts)——原 Step 2/3/4/5/6 全部被
|
||
// `if (isVisible)`/`if (count > 0)` 包住。分类按钮组与 2 篇种子新闻(各属一类)
|
||
// 均为恒定契约 ⇒ 全程硬断言。
|
||
await page.goto('/news', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(2000);
|
||
await closeCookieBanner(page);
|
||
|
||
const newsTitle = page.locator('h1').first();
|
||
await expect(newsTitle).toBeVisible({ timeout: 10000 });
|
||
|
||
// 验证分类筛选按钮存在且可点(news-content-v3.tsx:159-167 无条件渲染)
|
||
const companyNewsBtn = page.locator('button', { hasText: '公司新闻' }).first();
|
||
const devNewsBtn = page.locator('button', { hasText: '研发动态' }).first();
|
||
await expect(companyNewsBtn).toBeVisible();
|
||
await expect(devNewsBtn).toBeVisible();
|
||
|
||
// === Step 2: 点击"公司新闻"分类筛选 → 恰收窄到 1 篇 ===
|
||
await companyNewsBtn.click();
|
||
await expect(page.locator('a[href*="/news/"]')).toHaveCount(1);
|
||
|
||
// === Step 3: 阅读第一篇新闻文章 ===
|
||
const firstArticle = page.locator('a[href*="/news/"]').first();
|
||
await expect(firstArticle).toContainText('正式成立');
|
||
await Promise.all([
|
||
page.waitForURL(/\/news\/.+/, { timeout: 15000, waitUntil: 'commit' }),
|
||
firstArticle.click(),
|
||
]);
|
||
await page.waitForTimeout(1000);
|
||
|
||
const detailTitle = page.locator('h1').first();
|
||
await expect(detailTitle).toContainText('正式成立');
|
||
|
||
const detailContent = page.locator('main').first();
|
||
await expect(detailContent).toBeVisible();
|
||
const detailText = await detailContent.textContent();
|
||
expect(detailText!.length).toBeGreaterThan(100);
|
||
|
||
// 两篇新闻分属不同分类 ⇒ 同分类相关新闻恒为空,区域必须缺席
|
||
await expect(page.getByRole('heading', { name: '相关新闻' })).toHaveCount(0);
|
||
|
||
// === Step 4: 返回新闻列表,切换分类 ===
|
||
await page.goto('/news', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
const devNewsBtn2 = page.locator('button', { hasText: '研发动态' }).first();
|
||
await expect(devNewsBtn2).toBeVisible();
|
||
await devNewsBtn2.click();
|
||
await expect(page.locator('a[href*="/news/"]')).toHaveCount(1);
|
||
|
||
// === Step 5: 阅读第二篇新闻文章 ===
|
||
const secondArticle = page.locator('a[href*="/news/"]').first();
|
||
await Promise.all([
|
||
page.waitForURL(/\/news\/.+/, { timeout: 15000, waitUntil: 'commit' }),
|
||
secondArticle.click(),
|
||
]);
|
||
await page.waitForTimeout(1000);
|
||
|
||
const secondDetailTitle = page.locator('h1').first();
|
||
await expect(secondDetailTitle).toContainText('数字化转型');
|
||
const secondDetailContent = page.locator('main').first();
|
||
await expect(secondDetailContent).toBeVisible();
|
||
const secondDetailText = await secondDetailContent.textContent();
|
||
expect(secondDetailText!.length).toBeGreaterThan(100);
|
||
|
||
// === Step 6: 返回全部新闻列表 ===
|
||
await page.goto('/news', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||
await page.waitForTimeout(1500);
|
||
|
||
const allBtn = page.locator('button', { hasText: '全部' }).first();
|
||
await expect(allBtn).toBeVisible();
|
||
await allBtn.click();
|
||
|
||
// 全部种子新闻恰好 2 篇
|
||
await expect(page.locator('a[href*="/news/"]')).toHaveCount(2);
|
||
|
||
// 最终验证:搜索发现能力('数字化转型' 恰命中 1 篇)
|
||
const searchInput = page.getByLabel('搜索新闻');
|
||
await expect(searchInput).toBeVisible();
|
||
await searchInput.fill('数字化转型');
|
||
await expect(page.locator('a[href*="/news/"]')).toHaveCount(1);
|
||
});
|
||
}); |