退役(零视觉影响:NEXT_PUBLIC_HERO_SCENE 从未在任何 .env* 设置): - 删 hero-scene.tsx(694行)/caption/单测/文案真源/CC0 机柜/海报帧 - R26 删除、R22 登记归零、e2e heroSceneMask 移除(无命中的假安全网) - R22 自证改可注入(夹具不再依赖生产条目) 落库(flag NEXT_PUBLIC_HERO_FIELD 样期默认关 ⇒ 基线零影响): - hero-field.tsx 三拍:噪声→增长→判断;bloom 半分辨率;DPR≤1.5 - 降级统一看结论帧(reduced-motion 定格 T_HOLD=40500 非 0) - 文案真源含承诺词正则守卫(禁帮助/赋能/提升/%/倍) - 海报帧 capture 脚本与资产同批入库(1920x864/26.9KB,可复现) - eslint 忽略 demo/**/vendor/**(vendored three 不可被 lint-staged --fix 改写) 守卫重建:R26 指向 hero-field(43260ms/3 拍合规);R22 登记 HeroField 条目 验证:tsc 0 / eslint 0 error / jest 162 套件 1906 例 / check:grammar 26+26 / check:a11y 0 违规 / 默认构建首页 DOM 冒烟 E 案不变
442 lines
24 KiB
TypeScript
442 lines
24 KiB
TypeScript
import { test, expect, Page } from './fixtures';
|
||
|
||
test.describe.configure({ mode: 'parallel' });
|
||
|
||
// dev 指示器 <nextjs-portal> 的剥离已上移到 e2e/fixtures.ts 的 context 夹具,全站所有 project 共用。
|
||
|
||
// 基线口径固定为「用户已表达 Cookie 偏好」。同意条由 2s 定时器后才渲染,慢引擎(firefox / webkit)
|
||
// 会在截图前把它画进首屏底部,快引擎(chromium)则赶不上 —— 这是与引擎速度相关的竞态,
|
||
// 且这两个 project 为规避 newContext 兼容噪声而使用空 storageState(见 5a4d310),拿不到预置偏好。
|
||
// 时间戳取常量而非 Date.now(),避免基线随采集日漂移。
|
||
test.beforeEach(async ({ page }) => {
|
||
await page.addInitScript(() => {
|
||
localStorage.setItem(
|
||
'novalon-cookie-preferences',
|
||
JSON.stringify({
|
||
necessary: true,
|
||
analytics: false,
|
||
marketing: false,
|
||
functionality: true,
|
||
timestamp: 1784284000000,
|
||
}),
|
||
);
|
||
});
|
||
});
|
||
|
||
const VISUAL_TEST_PAGES = [
|
||
{ path: '/', name: 'home', label: '首页' },
|
||
{ path: '/about', name: 'about', label: '关于我们' },
|
||
{ path: '/contact', name: 'contact', label: '联系我们' },
|
||
{ path: '/products', name: 'products', label: '产品中心' },
|
||
{ path: '/products/erp', name: 'product-erp', label: '产品详情-ERP' },
|
||
// 与 /products/erp 是不同路由:此前只在 Lighthouse URL 表里,视觉表缺它 ⇒ 同型覆盖缺口(验收 §8 限制⑦)
|
||
{ path: '/products/erp-upgrade', name: 'product-erp-upgrade', label: '产品 ERP 升级页' },
|
||
// 2026-11-03 补:这条路由此前遗留 hero 的 2 个调用点之一,但视觉表里从来没有它 ——
|
||
// 磁盘上那 5 张 `product-erp-upgrade-v3-*` 基线成了**孤儿**(有文件、无用例)。
|
||
// 退役遗留 hero 时顺手接上,否则改完这个页面没有任何视觉守卫。
|
||
{ path: '/products/erp-upgrade-v3', name: 'product-erp-upgrade-v3', label: '产品 ERP 升级页 v3' },
|
||
{ path: '/about/brand', name: 'about-brand', label: '品牌资产页' },
|
||
{ path: '/solutions', name: 'solutions', label: '解决方案列表' },
|
||
{ path: '/solutions/manufacturing', name: 'solution-manufacturing', label: '解决方案详情-制造' },
|
||
{ path: '/services', name: 'services', label: '服务列表' },
|
||
{ path: '/services/software', name: 'service-software', label: '服务详情-软件开发' },
|
||
{ path: '/news', name: 'news', label: '新闻列表' },
|
||
{ path: '/news/company-founded', name: 'news-detail', label: '新闻详情' },
|
||
{ path: '/team', name: 'team', label: '团队介绍' },
|
||
{ path: '/methodology', name: 'methodology', label: '方法论' },
|
||
// ── 2026-11-25 收尾轮:把 18 条有基线却从未被用例消费的路由接回来 ──
|
||
// 背景:`4c007c4b`(AUTH-1 重采)往磁盘写了 95 张全页基线,但 VISUAL_TEST_PAGES
|
||
// 里从来没有这 18 条 —— 于是它们既占着 139MB 版本库,又不产生任何守卫(ADR-0009
|
||
// 「追加发现 1」只登记了 container-wide,没登记这批孤儿)。探针实测:这 18 条路由
|
||
// 全部 200 可达,而 95 张参照**全部过期**(例:/privacy 参照高 2402px、实际 2444px,
|
||
// 那 42px 正是本轮 container-x 修复带来的)。接回 = 让这 18 条重新受视觉守卫。
|
||
// ⚠ slug 修正:基线文件名里的 `news-digital-transformation` 是**拼错的**
|
||
// (真实 slug 是 digital-transformation-solution,拼错那条 404)。
|
||
{ path: '/privacy', name: 'privacy', label: '隐私政策' },
|
||
{ path: '/terms', name: 'terms', label: '服务条款' },
|
||
{ path: '/insights', name: 'insights', label: '洞察枢纽' },
|
||
{ path: '/cases', name: 'cases', label: '客户案例' },
|
||
{ path: '/products/bi', name: 'product-bi', label: '产品详情-BI' },
|
||
{ path: '/products/cms', name: 'product-cms', label: '产品详情-CMS' },
|
||
{ path: '/products/crm', name: 'product-crm', label: '产品详情-CRM' },
|
||
{ path: '/products/oa', name: 'product-oa', label: '产品详情-OA' },
|
||
{ path: '/products/sds', name: 'product-sds', label: '产品详情-SDS' },
|
||
{ path: '/services/consulting', name: 'service-consulting', label: '服务详情-战略咨询' },
|
||
{ path: '/services/data', name: 'service-data', label: '服务详情-数据服务' },
|
||
{ path: '/services/solutions', name: 'service-solutions', label: '服务详情-解决方案' },
|
||
{ path: '/solutions/education', name: 'solution-education', label: '解决方案详情-教育' },
|
||
{ path: '/solutions/finance', name: 'solution-finance', label: '解决方案详情-金融' },
|
||
{ path: '/solutions/healthcare', name: 'solution-healthcare', label: '解决方案详情-医疗' },
|
||
{ path: '/solutions/logistics', name: 'solution-logistics', label: '解决方案详情-物流' },
|
||
{ path: '/solutions/retail', name: 'solution-retail', label: '解决方案详情-零售' },
|
||
{ path: '/news/digital-transformation-solution', name: 'news-digital-transformation', label: '新闻详情-数字化转型' },
|
||
// 404 页:用一条确定不存在的路径进去。此前磁盘上有 5 张 `not-found-*` 基线却无用例
|
||
// (同 18.2 那批孤儿),这里是它唯一可能的消费方。不写 `/_not-found` —— 该路径本身
|
||
// 由 Next 作为 404 契约返回,走普通不存在路径更贴近用户真实到达方式。
|
||
{ path: '/visual-regression-404-probe', name: 'not-found', label: '404 页面' },
|
||
];
|
||
|
||
async function waitForPageStable(page: Page) {
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 触发全页 ScrollReveal / StaggerReveal:逐屏滚到底再回顶,让所有 below-the-fold
|
||
// 模块的 whileInView 动画进入最终态,避免全页截图时内容停在 opacity:0 初始态。
|
||
// 不能直接 `scrollTo(scrollHeight)` 一跳到底:IntersectionObserver 只会回调当前视口
|
||
// 内的目标,中间各屏被跳过 ⇒ 截图出来是空白段(2026-10-20 移除路由级 AnimatePresence
|
||
// 后首屏不再替子树屏蔽 initial,这条路径才真正被走到)。
|
||
// dwell 由 120ms 提到 260ms 并排掉两帧:120ms 在 4 worker 抢 CPU 时不足以让
|
||
// IO 回调 + framer 提交动画,中间某屏会被跳过(lessons §5.51)。
|
||
await page.evaluate(async () => {
|
||
const nextFrame = () =>
|
||
new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
||
const step = Math.max(400, Math.floor(window.innerHeight * 0.8));
|
||
for (let y = 0; y <= document.body.scrollHeight; y += step) {
|
||
window.scrollTo({ top: y, behavior: 'instant' });
|
||
await new Promise((resolve) => setTimeout(resolve, 260));
|
||
await nextFrame();
|
||
}
|
||
window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' });
|
||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||
window.scrollTo({ top: 0, behavior: 'instant' });
|
||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||
});
|
||
|
||
await page.evaluate(() => {
|
||
document.querySelectorAll('img').forEach(img => {
|
||
if (!img.complete) {
|
||
img.loading = 'eager';
|
||
}
|
||
});
|
||
});
|
||
await page.waitForTimeout(1000);
|
||
await page.evaluate(() => document.fonts?.ready);
|
||
await page.waitForTimeout(500);
|
||
|
||
await assertCmsStateOk(page);
|
||
await waitForRevealsSettled(page);
|
||
}
|
||
|
||
/**
|
||
* 等 whileInView 真正提交:framer 把未开始的动画写成 inline `opacity: 0`,
|
||
* 完成后改写成 1。两者只差这一笔,所以按 inline style 判定即可。
|
||
* 排除 display:none 与零高度元素(折叠菜单、屏外测距节点),避免把「本来就不可见」判成未提交。
|
||
* 表达式以字符串传入:它在浏览器上下文求值,闭包里的 Node 侧变量带不过去。
|
||
*/
|
||
const PENDING_REVEALS_EXPR =
|
||
"Array.from(document.querySelectorAll('main *')).filter((el) => el.style.opacity === '0' && getComputedStyle(el).display !== 'none' && el.getBoundingClientRect().height > 0)";
|
||
|
||
async function waitForRevealsSettled(page: Page) {
|
||
try {
|
||
await page.waitForFunction(`${PENDING_REVEALS_EXPR}.length === 0`, undefined, {
|
||
timeout: 8000,
|
||
polling: 100,
|
||
});
|
||
} catch {
|
||
const total: number = await page.evaluate(`${PENDING_REVEALS_EXPR}.length`);
|
||
const pending: string[] = await page.evaluate(
|
||
`${PENDING_REVEALS_EXPR}.slice(0, 5).map((el) => el.tagName.toLowerCase() + '.' + String(el.className).split(' ').slice(0, 2).join('.'))`,
|
||
);
|
||
throw new Error(
|
||
`${total} 个元素仍停在 inline opacity:0(whileInView 未提交):${pending.join(' , ')}`,
|
||
);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 首页把 CMS 读数状态写在 `data-cms-state` 上。退化时页面照常 200、只是整套落到常量版式,
|
||
* 像素比对只会给出一团无从归因的差异 —— 在这里先按名字判一次。
|
||
* 首页**必须有**这个标记:标记消失(改坏 prop / 改回旧组件)时不能静默放行,
|
||
* 否则这条守卫会退化成永不生效的死判据。其它页面不标,跳过。
|
||
*/
|
||
async function assertCmsStateOk(page: Page) {
|
||
const isHome = new URL(page.url()).pathname === '/';
|
||
if (!isHome) return;
|
||
|
||
const marker = page.locator('main [data-cms-state]').first();
|
||
if ((await marker.count()) === 0) {
|
||
throw new Error('首页缺少 data-cms-state 标记:CMS 退化守卫已失效(见 lessons §5.51)');
|
||
}
|
||
const state = await marker.getAttribute('data-cms-state');
|
||
if (state !== 'ok') {
|
||
throw new Error(
|
||
`CMS 数据退化:data-cms-state=${state};页面已回落到常量版式,像素比对无意义(lessons §5.51)`,
|
||
);
|
||
}
|
||
}
|
||
|
||
test.describe('L1: 全页面视觉回归测试', () => {
|
||
test.setTimeout(60000);
|
||
|
||
for (const { path, name, label } of VISUAL_TEST_PAGES) {
|
||
test(`${label} (${path}) - 全页截图对比`, async ({ page }) => {
|
||
await page.goto(path, { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
await expect(page).toHaveScreenshot(`${name}-fullpage.png`, {
|
||
fullPage: true,
|
||
animations: 'disabled',
|
||
caret: 'hide',
|
||
});
|
||
});
|
||
}
|
||
});
|
||
|
||
test.describe('L2: 组件视觉状态测试', () => {
|
||
test.setTimeout(45000);
|
||
|
||
test('按钮组件 - 默认/悬停/聚焦状态', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
// N-15(c) 诊断结论:**装配缺陷,不是产品缺陷**。
|
||
// 旧选择器 `button, a[role="button"]` 的 .first() 取的是 DOM 序第一个 <button>,即桌面导航的
|
||
// 「产品」下拉触发器;它的祖先 <nav class="hidden md:flex …" data-testid="desktop-navigation">
|
||
// (src/components/layout/header.tsx:124)在 md(768px) 以下 display:none ⇒ 按设计不可见。
|
||
// 实测(同一 fixture:reducedMotion=reduce + 已同意 Cookie + 剥离 nextjs-portal,390x844 iPhone14):
|
||
// 匹配总数 4、其中可见 1;.first().isVisible() = false;
|
||
// 前 3 个匹配(产品/解决方案下拉 + header.tsx:169 那个 `hidden md:flex` 容器里的主题切换按钮)
|
||
// 的祖先链里各有一个 display:none 容器。
|
||
// 390px 下页面真正提供的按钮是 src/components/layout/header.tsx:184-196 的
|
||
// data-testid="mobile-menu-button"(aria-label="打开菜单"、style minWidth/minHeight 44px),
|
||
// 实测盒 44x44 @ (338,10) ⇒ 触控目标达标,导航入口存在 ⇒ 产品侧无缺陷。
|
||
// 修法:用 Playwright 的 :visible 伪类过滤,让每个 project 拍到「该视口下第一个真实可见的按钮」。
|
||
// 桌面/平板档目标元素不变(那里 .first() 本来就是可见节点,过滤不改变选择结果):
|
||
// 实测 1280px 下新选择器盒 = 81x43.98,与现存基线 button-default-visual-chromium-desktop.png 的 81x44 一致。
|
||
const primaryBtn = page.locator('button:visible, a[role="button"]:visible').first();
|
||
await expect(primaryBtn).toBeVisible();
|
||
await expect(primaryBtn).toHaveScreenshot('button-default.png');
|
||
|
||
await primaryBtn.hover();
|
||
await page.waitForTimeout(300);
|
||
await expect(primaryBtn).toHaveScreenshot('button-hover.png');
|
||
|
||
await primaryBtn.focus();
|
||
await page.waitForTimeout(200);
|
||
await expect(primaryBtn).toHaveScreenshot('button-focus.png');
|
||
});
|
||
|
||
test('导航菜单 - 桌面端视觉', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
const header = page.locator('header').first();
|
||
await expect(header).toBeVisible();
|
||
await expect(header).toHaveScreenshot('header-navigation.png');
|
||
});
|
||
|
||
test('页脚区域 - 视觉一致性', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
const footer = page.locator('footer').first();
|
||
await expect(footer).toBeVisible();
|
||
// 2026-12-02 抖动修复(§28.4.1)——两轮尝试的结论都记在这里:
|
||
// ① 落点钉死(照卡片用例先例把 footer 顶边滚到「头部下沿 + 8px」)**不够**:
|
||
// Playwright 元素截图内部还会再滚动,外部 scrollTo 被覆盖,落点不可控;
|
||
// ② 真正的抖动源是两个 **fixed 元素**:粘性头部(内缩浮条,ADR-0012)会随机压入
|
||
// 元素盒,回到顶部按钮(back-to-top,framer fade 显隐)按滚动阈值淡入——
|
||
// 两者在截图里的位置/有无都不确定。旧基线本身就采自「头部压入页脚」的抖动形态
|
||
// (diff 实证:基线上部有双份导航条),之前「绿」只是自动滚动多数时候恰好复现了它。
|
||
// 修法 = Playwright 标准方案:**mask 掉两个 fixed 元素**,截图与滚动彻底解耦;
|
||
// 700ms 先让 fade(≤300ms)与入场动画(硬上限 ≤700ms,CONTEXT.md)到终态。
|
||
// 基线随本修正重采(footer-section ×5,逐张读图追认,见台账 §29.7)。
|
||
const header = page.locator('header').first();
|
||
const backToTop = page.getByRole('button', { name: '返回顶部' });
|
||
await page.waitForTimeout(700);
|
||
await expect(footer).toHaveScreenshot('footer-section.png', {
|
||
mask: [header, backToTop],
|
||
});
|
||
});
|
||
|
||
test('卡片组件 - 视觉样式', async ({ page }) => {
|
||
await page.goto('/products', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
// N-15(b) 修正:旧选择器 [class*="card"] 在 /products 上匹配 **0 个元素**(实测 1280/834/390 三档
|
||
// 视口 count 均为 0)——本页卡片由 BentoItem 渲染,class 只有 Tailwind 的形状/颜色描述
|
||
// (`h-full md:col-span-2 lg:col-span-2 …`),不含 "card" 子串 ⇒ 用例在截图之前就死在
|
||
// `element(s) not found` 上,5/5 project 恒红,且 product-card.png 从未存在。
|
||
// 真实 DOM 的语义锚点:src/components/sections/bento-grid.tsx:48 输出 data-testid,
|
||
// 值由 src/app/(marketing)/products/products-content-v3.tsx:105 的
|
||
// `bento-product-card-${product.id}` 传入 ⇒ 实测 7 个匹配,首个为 bento-product-card-erp,
|
||
// 三档视口均 isVisible()=true(1280px 盒 594.5x791.8)。
|
||
const card = page.locator('[data-testid^="bento-product-card-"]').first();
|
||
await expect(card).toBeVisible();
|
||
// 钉住断言对象确实是 Bento 卡片单元(role="listitem" 的容器),防止选择器再次漂回空匹配
|
||
await expect(card).toHaveAttribute('role', 'listitem');
|
||
await expect(card).toHaveAttribute('data-bento-size', /.+/);
|
||
// 2026-12-01:hub 首屏加入构图原语后页面变高,Playwright 的**自动滚动落点**随之改变,
|
||
// 固定头部压在卡片上的像素位置就跟着挪 —— 元素截图不再稳定(webkit 捕获高 1636→1638,
|
||
// chromium 831 像素差)。这类「截什么取决于前面有多高」的捕获不叫守卫,叫脆。
|
||
// 修法是把落点钉死:卡片顶边滚到「固定头部下沿 + 8px」,与页面总高解耦。
|
||
//
|
||
// 2026-12-01 二次修正:原来取的是 `header.height + 8`,但头部是**内缩浮条**
|
||
// (top 48 / 高 64,见 ADR-0012),它的下沿在 112 而不是 72 —— 卡片顶边因此被压在
|
||
// 半透明模糊条底下,截图会拍到条子后面**透出来的页面内容**。本轮 products 页改了内容,
|
||
// 这层透出的像素就变了(831 px / 0.01),红在「截到了背景」而不是「卡片变了」。
|
||
// 改取 `rect.bottom + 8`,卡片整体落在浮条下方,截图与页面背景彻底解耦。
|
||
await card.evaluate((el) => {
|
||
const header = document.querySelector('header');
|
||
const rect = header?.getBoundingClientRect();
|
||
const offset = (rect ? rect.bottom : 0) + 8;
|
||
const top = el.getBoundingClientRect().top + window.scrollY - offset;
|
||
window.scrollTo(0, Math.max(0, Math.round(top)));
|
||
});
|
||
await page.waitForTimeout(250);
|
||
// OPEN-02b(ADR-0015):页头随滚动在「浮条 ⇄ 方汉堡」两态间切换,而卡片 791px 高
|
||
// 装不进 800 视口 ⇒ toHaveScreenshot 自带的 scroll-into-view 会再滚一次,
|
||
// 半透明浮条/汉堡的像素就可能落进卡片盒(2026-12-02 实测 3926px 差,diff 图上
|
||
// 叠着行业/能力触发器与 logo 字样)。与 footer-section 用例同一先例:mask 掉
|
||
// fixed 页头,截图与页头状态彻底解耦。卡片本体像素不受 mask 影响。
|
||
await expect(card).toHaveScreenshot('product-card.png', {
|
||
mask: [page.locator('header')],
|
||
});
|
||
});
|
||
|
||
/**
|
||
* 创始团队观点区(FounderQuote)**反向守卫** —— 2026-10-17 由截图用例改写。
|
||
*
|
||
* 原用例对 `[data-testid="founder-quote-section"]` 做区域截图。该区块已按 ADR-0008 决策一
|
||
* **整块删除**(它是全站唯一 `bg-brand-section #8B1530` 满幅面:实测两家近单色对标里
|
||
* 饱和红用作"面"的次数为 **0** —— Porsche 的红出现 4 次全是按钮,
|
||
* Bain 的 #CC0000 出现 65 次无一次是面或阴影;两家也都没有 CEO 引言带,那是 Accenture 的语法),
|
||
* 于是选择器**永不可能命中** ⇒ 5 个 project 各挂一次 `scrollIntoViewIfNeeded` 超时
|
||
* (本轮只读复跑实测:109 failed = 104 例像素不符 + 5 例超时,超时正是这一条 ×5)。
|
||
*
|
||
* 修法不是给它补一张新基线 —— 那等于为一个"按裁定不该存在的东西"重建参照。
|
||
* 改成断言它**确实不在**,并顺带钉住"全站无满幅饱和红面"这条实测语法判据:
|
||
* 若将来有人把深红区块加回首页,这里会红。
|
||
*/
|
||
test('首页不再有创始团队观点区,也没有满幅饱和红面(反向守卫)', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
// 区块本体不得复活
|
||
await expect(page.locator('[data-testid="founder-quote-section"]')).toHaveCount(0);
|
||
// 承载它的满幅饱和红面也不得出现(全站唯一一处已随该区块退役)
|
||
await expect(page.locator('.bg-brand-section')).toHaveCount(0);
|
||
});
|
||
|
||
test('表单输入框 - 默认/聚焦状态', async ({ page }) => {
|
||
await page.goto('/contact', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
// N-15(b) 修正:/contact 上 DOM 序第一个 input[type="text"] 是**反垃圾蜜罐**,它按设计隐藏
|
||
// (src/app/(marketing)/contact/contact-content-v3.tsx:431-439:
|
||
// style={{ display: 'none' }} + tabIndex={-1} + autoComplete="off" + aria-hidden="true"
|
||
// + aria-label="honeypot" + name="website")。
|
||
// 旧选择器 `input[type="text"], input[type="email"]` 的 .first() 恰好命中它
|
||
// (实测 name="website"、isVisible()=false,5/5 project 恒红,报 Expected: visible / Received: hidden)
|
||
// ⇒ 断言对象是一个故意不可见的安全控件,失败是测试错而不是页面坏。
|
||
// 蜜罐覆盖**不删**:改为在此单独、显式地断言它的存在与隐藏属性(这才是它真正的契约)。
|
||
const honeypot = page.locator('form input[name="website"]');
|
||
await expect(honeypot).toHaveCount(1);
|
||
await expect(honeypot).toHaveAttribute('type', 'text');
|
||
await expect(honeypot).toHaveAttribute('tabindex', '-1');
|
||
await expect(honeypot).toHaveAttribute('autocomplete', 'off');
|
||
await expect(honeypot).toHaveAttribute('aria-hidden', 'true');
|
||
await expect(honeypot).toHaveAttribute('aria-label', 'honeypot');
|
||
await expect(honeypot).toBeHidden();
|
||
|
||
// 可见字段:限定在表单内并用 Playwright 的 :visible 过滤掉蜜罐。
|
||
// 实测(1280/834/390 三档一致):form input 共 5 个、可见 4 个,
|
||
// 第一个可见者 = <input id="name" name="name" data-testid="name-input">(真实姓名框,
|
||
// 由 src/components/ui/input.tsx:29 的 {...props} 透传 testid),蜜罐被自然排除。
|
||
const input = page.locator('form input:visible').first();
|
||
// 回归护栏:选中的必须是带 name 的真实字段,永不再漂回蜜罐
|
||
await expect(input).toHaveAttribute('name', /^(name|email|phone|subject)$/);
|
||
await expect(input).not.toHaveAttribute('aria-hidden', 'true');
|
||
await expect(input).toBeVisible();
|
||
await expect(input).toHaveScreenshot('input-default.png');
|
||
|
||
await input.click();
|
||
await page.waitForTimeout(200);
|
||
await expect(input).toHaveScreenshot('input-focused.png');
|
||
});
|
||
});
|
||
|
||
test.describe('L2: 主题切换视觉测试', () => {
|
||
test.setTimeout(45000);
|
||
|
||
// 主题由「系统偏好」驱动(默认跟随系统,见 src/lib/theme.ts),因此用 Playwright 的
|
||
// colorScheme 上下文选项模拟 OS 偏好,而不是事后 setAttribute:
|
||
// 挂载后的 ThemeToggle 会把 html[data-theme] 重置为解析结果,事后改属性存在竞态
|
||
// (hydration 晚于 setAttribute 时会被覆盖,深色快照拍成浅色)。
|
||
test.describe('系统偏好浅色', () => {
|
||
test.use({ colorScheme: 'light' });
|
||
|
||
test('浅色主题 - 首页视觉', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
|
||
|
||
await expect(page.locator('main').first()).toHaveScreenshot('theme-light-main.png');
|
||
});
|
||
});
|
||
|
||
test.describe('系统偏好深色', () => {
|
||
test.use({ colorScheme: 'dark' });
|
||
|
||
test('深色主题 - 首页视觉', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
|
||
|
||
await expect(page.locator('main').first()).toHaveScreenshot('theme-dark-main.png');
|
||
});
|
||
});
|
||
});
|
||
|
||
test.describe('L3: 排版与色彩验证', () => {
|
||
test.setTimeout(30000);
|
||
|
||
test('首页 H1 标题字体样式', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
const h1 = page.locator('h1').first();
|
||
await expect(h1).toBeVisible();
|
||
const styles = await h1.evaluate(el => {
|
||
const computed = window.getComputedStyle(el);
|
||
return {
|
||
fontSize: computed.fontSize,
|
||
fontWeight: computed.fontWeight,
|
||
fontFamily: computed.fontFamily,
|
||
color: computed.color,
|
||
lineHeight: computed.lineHeight,
|
||
};
|
||
});
|
||
|
||
const size = parseFloat(styles.fontSize);
|
||
expect(isNaN(size)).toBe(false);
|
||
expect(size).toBeGreaterThanOrEqual(16);
|
||
expect(styles.color).toBeTruthy();
|
||
expect(styles.fontFamily).toBeTruthy();
|
||
expect(styles.fontWeight).toBeTruthy();
|
||
expect(styles.lineHeight).toBeTruthy();
|
||
});
|
||
|
||
test('品牌主色调验证', async ({ page }) => {
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||
await waitForPageStable(page);
|
||
|
||
const primaryColor = await page.evaluate(() => {
|
||
const style = getComputedStyle(document.documentElement);
|
||
return {
|
||
brand: style.getPropertyValue('--color-brand')?.trim(),
|
||
ink: style.getPropertyValue('--color-ink')?.trim(),
|
||
bg: style.getPropertyValue('--color-bg-primary')?.trim(),
|
||
text: style.getPropertyValue('--color-text-primary')?.trim(),
|
||
};
|
||
});
|
||
|
||
// 逐个令牌断言,不用 `a || b` —— 任一令牌缺失即门失效
|
||
for (const [token, value] of Object.entries(primaryColor)) {
|
||
expect(value, `--color-${token} 未解析出值`).toBeTruthy();
|
||
}
|
||
});
|
||
});
|