Files
novalon-website/e2e/landing/layout.spec.ts
T
zhangxiang 99eaa8c66a feat(landing): 睿视 landing 由本仓统一管理——源码子目录化 + 四道门禁移植 + 契约路由
承接 ADR-0014 §4「第二等产品镜像起必须子目录化 + rewrites 前缀映射并回溯睿视」。
上一轮(2026-12-02)只搬了字节,源码落在 public/ 根命名空间;本轮把源码、门禁、
发布职责一并收进本仓,authority 侧退役对应产物。

源码与 URL 契约:
- public/novavis/{index.html,css,js,assets,images/logos} 一棵树自成一体
- index.html 引用保持站点级绝对路径(/css /js /assets /images/logos)不变。
  因为同一份字节要服务两个落点:官网镜像 novalon.cn/novavis/,以及独立子域
  novavis.p.novalon.cn/(页面在根路径)。改绝对路径会把子域首页变成 /novavis/
- 故用 4 条 prefix rewrite 把根命名空间映射进子目录,而非改写 HTML

四道门禁(从 authority 的四个 python 脚本移植为 Playwright,已并入 test:all):
- e2e/landing/{layout,motion,demo,a11y}.spec.ts + 独立 config(单引擎单 project 串行)
- layout:几何与焦点 / motion:js-grow 渐进生长与 reduced-motion 直达终态
- demo:首屏剧本四步 + 徽标一一对应 + 无 JS 降级四层真实可见性
- a11y:结构与全量对比度(同色无条件阻断)+ axe critical/serious=0
- 实测 13 passed / EXIT=0(1.4m)

补一个映射期暴露的真缺陷:landing 的 main.js 固定 POST /api/v1/contact 且只认
code===200,而本仓只有 /api/contact(formData + 必填 subject),镜像侧转化路径
一直 404。新增 src/app/api/v1/contact/route.ts 按 authority 契约响应(JSON +
{code:200}),而非改前端去适配本仓——改前端等于把适配成本转嫁给子域,且会让
两个落点的成功判据不一致。9 个单测覆盖校验、限流、上游失败不透传 5xx。

文档与配置同步:CLAUDE.md → AGENTS.md(单文档真源)、docs/landing.md、
docs/deployment.md §八、ADR-0014、qa-tracker §32、README 与 quality-gates 脚本表、
Jenkinsfile 落地「♿ 可访问性门禁」阶段的 landing 四道门禁、eslint 忽略
.next-dev-live 构建产物目录(未忽略时 eslint . 会扫出 21195 errors)。

门禁:tsc 0 / eslint 0 / jest app/api/v1 9/9 / test:landing 13 passed。
2026-12-03 22:56:17 +08:00

241 lines
11 KiB
TypeScript
Raw 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 '@playwright/test';
/**
* Landing 门禁 ①:布局几何与焦点管理(移植自 `novavis-authority/scripts/verify-landing-layout.py`)
*
* ## 判据来源与迁移口径
*
* 迁移前的脚本是 python + playwright,只在 authority 仓手动跑、从不在任何门禁链里
* (本仓反复记录过那个失效模式:**门禁不在链里就等于没有**)。2026-12-03 landing 迁入本仓,
* 四道门禁一并移植为 Playwright spec,由 `npm run test:landing` 承载并进 `test:all`。
*
* **判据一个不放宽**,逐条对应原脚本:
*
* | 原检查项 | 本文件 |
* |---|---|
* | 1 tabs:各视口下 `.showcase-tabs` 每个 tab 中心不被 `#showcasePause` 覆盖,且无横向溢出 | `showcase tab 行与暂停按钮几何` |
* | 2a focus:焦点进入卡片后轮播让位 | `焦点进入卡片后轮播让位` |
* | 2b focus:持焦 tab 不被摘掉 tabindex | 同上 |
* | 2c focus:失焦后轮播恢复(证明 2a 不是「轮播整体坏了」的假通过) | 同上 |
* | 3 roving:方向键后整组只留一只可 Tab 到达,且该只即 active、焦点跟随 | `键盘 roving tabindex 单点不变量` |
* | 4 cta:nav 转化入口与信息链接有可视分层 | `nav 转化入口与信息链接分层` |
*
* ## 两个必须知道的操作前提(原脚本注释里踩过)
*
* 1. **悬停会冻结轮播**(既有设计)。focus 项全程把鼠标移到 (0,0),否则测的是 hover 冻结
* 而不是 focusin 暂停。
* 2. **视口是被测对象**:每条用例自己 `setViewportSize`,不依赖 project 的 viewport。
*/
const LANDING_URL = '/novavis';
/** 与迁移前一致的五个视口(桌面 / 笔记本 / 平板竖屏 / 手机 480 / 手机 375)。 */
const VIEWPORTS = [
{ name: '桌面 1440', width: 1440, height: 900 },
{ name: '笔记本 1024', width: 1024, height: 768 },
{ name: '平板竖屏 768', width: 768, height: 1024 },
{ name: '手机 480', width: 480, height: 900 },
{ name: '手机 375', width: 375, height: 812 },
] as const;
/** 轮播周期 5500ms + 余量:等待窗口内若未暂停,active tab 必定已切换。 */
const CYCLE_MS = 5500;
const WAIT_MS = CYCLE_MS + 2000;
/**
* tab 行的几何读数(与迁移前 `TAB_INFO` 逐字同义)。
*
* 注意这里必须是**真函数**而不是字符串:Playwright 的 JS 版 `page.evaluate(string)` 把入参
* 当「表达式」求值,`"() => {...}"` 求值结果是一个函数对象、序列化成 undefined
* (python 版把字符串当函数体,所以原脚本能用字符串;两个绑定语义不同)。
*/
function readTabInfo() {
const pause = document.querySelector<HTMLElement>('#showcasePause');
const pr = pause && getComputedStyle(pause).display !== 'none' ? pause.getBoundingClientRect() : null;
const covers = (r: DOMRect): boolean => {
if (!pr) return false;
const cx = r.left + r.width / 2;
const cy = r.top + r.height / 2;
return pr.left <= cx && cx <= pr.right && pr.top <= cy && cy <= pr.bottom;
};
return [...document.querySelectorAll<HTMLElement>('.showcase-tab')].map((t) => {
const r = t.getBoundingClientRect();
const cx = r.left + r.width / 2;
const cy = r.top + r.height / 2;
return {
id: t.id,
covered: covers(r),
centerInViewport: cx >= 0 && cy >= 0 && cx <= window.innerWidth && cy <= window.innerHeight,
};
});
}
interface TabInfo {
id: string;
covered: boolean;
centerInViewport: boolean;
}
async function gotoLanding(page: Page): Promise<void> {
await page.goto(LANDING_URL, { waitUntil: 'load' });
// CSS 与 main.js 都是同源静态资源,等 1.2s 让 scroll-spy / 轮播完成首轮初始化
// (迁移前脚本同样 sleep 1.2s,理由相同:过早采样会读到轮播尚未挂上的中间态)。
await page.waitForTimeout(1200);
}
async function activeTabId(page: Page): Promise<string | null> {
return page.evaluate(() => document.querySelector<HTMLElement>('.showcase-tab.active')?.id ?? null);
}
async function focusedTabState(page: Page): Promise<{ id: string; tabindex: string | null } | null> {
return page.evaluate(() => {
const el = document.activeElement;
if (!el || !el.classList || !el.classList.contains('showcase-tab')) return null;
return { id: (el as HTMLElement).id, tabindex: el.getAttribute('tabindex') };
});
}
test.describe('landing ① 布局几何与焦点', () => {
test.beforeEach(async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
await gotoLanding(page);
});
test('showcase tab 行与暂停按钮几何(五视口)', async ({ page }) => {
const failures: string[] = [];
for (const vp of VIEWPORTS) {
await page.setViewportSize({ width: vp.width, height: vp.height });
await page.evaluate(() => window.scrollTo(0, 0));
await page.mouse.move(0, 0);
await page.locator('.showcase-tabs').scrollIntoViewIfNeeded();
await page.waitForTimeout(300);
const tabs = (await page.evaluate(readTabInfo)) as TabInfo[];
expect(tabs.length, `${vp.name}: .showcase-tab 一个都没选中(判据的分母为空)`).toBeGreaterThan(0);
const covered = tabs.filter((t) => t.covered).map((t) => t.id);
const offscreen = tabs.filter((t) => !t.centerInViewport).map((t) => t.id);
const overflow = await page.evaluate(
() => document.documentElement.scrollWidth - document.documentElement.clientWidth,
);
if (covered.length > 0) failures.push(`${vp.name}: tab 被 #showcasePause 覆盖 ${covered.join(',')}`);
if (offscreen.length > 0) failures.push(`${vp.name}: tab 中心不在视口内 ${offscreen.join(',')}`);
if (overflow > 1) failures.push(`${vp.name}: 页面横向溢出 ${overflow}px`);
}
expect(failures, failures.join('\n')).toEqual([]);
});
test('焦点进入卡片后轮播让位、持焦不被摘 tabindex、失焦后恢复', async ({ page }) => {
await page.mouse.move(0, 0);
await page.locator('.showcase-tabs').scrollIntoViewIfNeeded();
await page.waitForTimeout(600);
await page.mouse.move(0, 0);
const before = await activeTabId(page);
expect(before, 'showcase 轮播没有 active tab(用例前提不成立)').not.toBeNull();
await page.evaluate(() => {
const t = document.querySelector<HTMLElement>('.showcase-tab.active');
t?.focus();
});
const state = await focusedTabState(page);
expect(state, '未能把焦点放进 tablist(用例前提不成立)').not.toBeNull();
// 2a:持焦期间轮播必须让位
await page.waitForTimeout(WAIT_MS);
const after = await activeTabId(page);
expect(after, `焦点在卡片内时轮播未让位:active ${before} → ${after}`).toBe(before);
// 2b:持焦 tab 不得被摘成 tabindex="-1"(摘掉即被移出 tab 序列,键盘焦点无处可回)
const held = await focusedTabState(page);
if (held) {
expect(held.tabindex, `持焦 tab ${held.id} 的 tabindex 被摘成 -1`).not.toBe('-1');
}
// 2c:失焦后必须恢复轮播 —— 否则上一条「不变」可能只是轮播整体失效的假通过
await page.evaluate(() => (document.activeElement as HTMLElement | null)?.blur());
await page.evaluate(() => window.scrollTo(0, 0));
await page.mouse.move(0, 0);
await page.locator('#nav').scrollIntoViewIfNeeded();
await page.locator('.showcase-tabs').scrollIntoViewIfNeeded();
await expect
.poll(async () => await activeTabId(page), {
timeout: WAIT_MS + 1000,
message: `失焦后轮播未恢复:active 恒为 ${before}(前一条「持焦不变」可能是轮播整体失效的假通过)`,
})
.not.toBe(before);
});
test('键盘 roving tabindex 单点不变量', async ({ page }) => {
await page.mouse.move(0, 0);
await page.locator('.showcase-tabs').scrollIntoViewIfNeeded();
await page.waitForTimeout(400);
await page.evaluate(() => {
const t = document.querySelector<HTMLElement>('.showcase-tab.active');
t?.focus();
});
expect(await focusedTabState(page), '未能把焦点放进 tablist(roving 不变量前提不成立)').not.toBeNull();
await page.keyboard.press('ArrowRight');
await page.waitForTimeout(300);
const state = await page.evaluate(() => {
const tabs = [...document.querySelectorAll<HTMLElement>('.showcase-tab')];
const isTab = (el: Element | null): el is HTMLElement =>
!!el && el.classList.contains('showcase-tab');
return {
zero: tabs.filter((t) => t.getAttribute('tabindex') === '0').map((t) => t.id),
active: tabs.filter((t) => t.classList.contains('active')).map((t) => t.id),
focused: isTab(document.activeElement) ? document.activeElement.id : null,
};
});
// 单点不变量:整组只能有一只 tab 可被 Tab 键到达
expect(
state.zero.length,
`方向键切换后整组有 ${state.zero.length} 只 tab 可被 Tab 键到达(${state.zero.join(',')}),违反 roving tabindex 单点(旧 tab 仍留在序列里)`,
).toBe(1);
expect(state.active.length, '方向键切换后无 active tab').toBeGreaterThan(0);
expect(state.zero[0], `可被 Tab 键到达的 tab(${state.zero[0]})不是 active tab(${state.active[0]})`).toBe(
state.active[0],
);
expect(state.focused, `方向键切换后焦点未跟随 active tab(持焦 ${state.focused})`).toBe(state.active[0]);
});
test('nav 转化入口与信息链接分层', async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
await page.evaluate(() => window.scrollTo(0, 0));
const styles = await page.evaluate(() => {
const links = [...document.querySelectorAll<HTMLElement>('.nav-links a')];
const info = links.find((a) => a.getAttribute('href') === '#features');
const cta = links.find((a) => a.getAttribute('href') === '#contact');
const pick = (el: HTMLElement | undefined) => {
if (!el) return null;
const s = getComputedStyle(el);
return {
cls: el.className,
border: `${s.borderTopWidth} ${s.borderTopStyle} ${s.borderTopColor}`,
bg: s.backgroundColor,
color: s.color,
};
};
return { info: pick(info), cta: pick(cta) };
});
expect(styles.info, 'nav 信息链接(#features)不存在').not.toBeNull();
expect(styles.cta, 'nav 转化入口(#contact)不存在').not.toBeNull();
expect(
styles.cta,
'nav 转化入口与信息链接样式完全相同(无分层)',
).not.toEqual(styles.info);
});
});