Files
novalon-website/e2e/landing/demo.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

217 lines
9.5 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 门禁 ③:首屏演示剧本 + 无 JS 降级 + reduced-motion(移植自
* `novavis-authority/scripts/landing-demo-verify.py`)
*
* ## 这道门禁守的是「内容在、但看不见」
*
* 2026-11-04 的 Blocking①(屏 2 白底白字)与 2026-11-07 的 BLOCKING-2(nojs 断言只读
* `textContent` + computed `display`,注入 `opacity:0;visibility:hidden` 后仍 PASS)是同一
* 失效模式。所以无 JS 断言必须是**四层真实可见性**,缺一不可:
*
* ① `checkVisibility({checkOpacity, checkVisibilityCSS})` —— 浏览器自己的口径
* ② 祖先链上 opacity 有效值 > 0.05(旧内核 checkVisibility 对 opacity 的处理不一致)
* ③ 元素矩形有面积(排除被 layout 折叠)
* ④ 文字非空
*
* 另加两条**防恒真**的断言(本仓反复踩过「判据通过态是 0 或空集时,0 本身不是证据」):
* - 反向:仅动画层的步骤徽标在无 JS 时必须**不可见**(`badge_visible === 0`);
* - 金丝雀:徽标选择器必须真的命中元素(`badge_count > 0`),否则上一条恒真。
*
* ## 采样时刻未改
*
* `DUR = {s1:2.6, s2:3.4, s3:3.2, s4:3.8, hold:1.6}`,故 1.4 / 4.4 / 7.6 / 11.6 / 16.4 的
* 采样点落在各自的步内。**时刻不改**,因为改动时刻会让「脚本采样点」与「动画真实时间轴」
* 脱钩,那是判据自伤而不是适配(原脚本注释原文)。
*/
const LANDING_URL = '/novavis';
/** 采样时刻(秒,相对页面 load 完成)。 */
const STEPS = [
{ name: 'step1-create', at: 1.4 },
{ name: 'step2-open', at: 4.4 },
{ name: 'step3-import', at: 7.6 },
{ name: 'step4-ready', at: 11.6 },
{ name: 'loop-restart', at: 16.4 },
] as const;
/** 步号 → 该步应显示的徽标文案(与 index.html 的 `data-badge` 一一对应)。 */
const BADGE_OF_STEP: Record<string, string> = {
'demo-step-1': '新建任务',
'demo-step-2': '打开任务',
'demo-step-3': '导入数据',
'demo-step-4': '就绪',
};
async function heroClass(page: Page): Promise<string> {
return page.evaluate(() => document.getElementById('heroDemo')?.className ?? '');
}
/**
* 当前**真实可见**的徽标文案(三层可见性,与 nojs 判定同口径)。
*/
async function visibleBadges(page: Page): Promise<string[]> {
return page.evaluate(() => {
const els = [...document.querySelectorAll<HTMLElement>('.demo-chrome-badge-item')];
return els
.filter((el) => {
const r = el.getBoundingClientRect();
if (!el.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true })) return false;
if (r.width <= 0 || r.height <= 0) return false;
let op = 1;
let n: Element | null = el;
while (n && n.nodeType === 1) {
const o = parseFloat(getComputedStyle(n).opacity);
if (!Number.isNaN(o)) op *= o;
if (op <= 0.05) return false;
n = n.parentElement;
}
return true;
})
.map((el) => (el.textContent ?? '').trim());
});
}
/**
* 徽标正向断言:每个采样点上当前步必须**恰好显示 1 个**徽标,且文案与该步同义。
*
* 为什么是「恰好 1 个」而不是「>= 1」:同时显示两个说明映射有重叠(正是 2026-11-07 首轮
* 「徽标错位一整步」的伴生症状),那会让观众同时看到两个互斥的进度。
*/
function checkBadgeMatchesStep(
classSamples: Record<string, string>,
badgeSamples: Record<string, string[]>,
): string[] {
const problems: string[] = [];
for (const [name, cls] of Object.entries(classSamples)) {
const step = Object.keys(BADGE_OF_STEP).find((st) => cls.includes(st));
if (step === undefined) continue; // loop-restart 采样点落在复位瞬间,不判
const want = BADGE_OF_STEP[step];
const got = badgeSamples[name] ?? [];
if (got.length !== 1) {
problems.push(`${name}: ${step} 应恰好显示 1 个徽标,实测 ${got.length} 个 ${JSON.stringify(got)}`);
} else if (got[0] !== want) {
problems.push(`${name}: ${step} 应显示「${want}」,实测「${got[0]}」`);
}
}
return problems;
}
test.describe('landing ③ 首屏剧本与降级', () => {
test('剧本四步推进 + 徽标一一对应 + 循环复位', async ({ page }) => {
const pageErrors: string[] = [];
page.on('pageerror', (e) => pageErrors.push(String(e)));
await page.goto(LANDING_URL, { waitUntil: 'load' });
const start = Date.now();
const classSamples: Record<string, string> = {};
const badgeSamples: Record<string, string[]> = {};
for (const step of STEPS) {
const delta = step.at * 1000 - (Date.now() - start);
if (delta > 0) await page.waitForTimeout(delta);
classSamples[step.name] = await heroClass(page);
badgeSamples[step.name] = await visibleBadges(page);
}
expect(pageErrors, `landing 页有 JS 运行时错误:${pageErrors.join(' | ')}`).toEqual([]);
// 循环复位:采样到第 1 步说明时间轴在循环
expect(
classSamples['loop-restart'],
`剧本未循环复位到 demo-step-1:实测 ${classSamples['loop-restart']}`,
).toContain('demo-step-1');
const problems = checkBadgeMatchesStep(classSamples, badgeSamples);
expect(problems, problems.join('\n')).toEqual([]);
});
test('无 JS 降级:内容在且看得见(四层真实可见性)', async ({ browser }) => {
// 独立 context 关掉 JS:用 browser 而不是 page fixture(后者已带 JS)
const context = await browser.newContext({ javaScriptEnabled: false, viewport: { width: 1440, height: 900 } });
const page = await context.newPage();
await page.goto(LANDING_URL, { waitUntil: 'load' });
await page.waitForTimeout(500);
const nojs = await page.evaluate(() => {
const rows = [...document.querySelectorAll<HTMLElement>('.nv-home-row')];
const visibleRows = rows.filter((el) => {
const r = el.getBoundingClientRect();
// ② 祖先链有效 opacity
let op = 1;
let n: Element | null = el;
while (n && n.nodeType === 1) {
const o = parseFloat(getComputedStyle(n).opacity);
if (!Number.isNaN(o)) op *= o;
if (op <= 0.05) return false;
n = n.parentElement;
}
// ① + ③ + ④
return (
el.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) &&
r.width > 0 &&
r.height > 0 &&
(el.textContent ?? '').trim().length > 0
);
}).length;
const badgeItems = [...document.querySelectorAll<HTMLElement>('.demo-chrome-badge-item')];
const visibleBadge = badgeItems.filter((el) => {
const r = el.getBoundingClientRect();
return el.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) && r.width > 0 && r.height > 0;
}).length;
const pager = document.querySelector<HTMLElement>('.nv-home-pager b');
const cols = document.querySelector<HTMLElement>('.nv-home-cols');
return {
taskTotal: pager?.textContent ?? null,
currentRow: document.querySelectorAll('.nv-home-row.is-current').length,
colsVisible: cols ? cols.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) : false,
demoRowsSeen: rows.length,
rowsVisible: visibleRows,
badgeCount: badgeItems.length,
badgeVisible: visibleBadge,
// 状态栏的静态读数:无 JS 时也应直接可见
bodyText: (document.body.textContent ?? '').length,
};
});
// 台账读数是**静态数据**(6 个任务),不是动画指标 —— 它旁边就列着 4 行真实任务,
// 若写成 0 就与内容自相矛盾。故无 JS 时必须等于 6。
expect(nojs.taskTotal, `无 JS 时任务总数应为 6,实测 ${nojs.taskTotal}`).toBe('6');
expect(nojs.currentRow, '无 JS 时当前行(is-current 是静态类,不靠 JS 加)应恰有 1 行').toBe(1);
expect(nojs.colsVisible, '无 JS 时列头不可见(视口锁定后列头只渲染一次,它是纯静态结构)').toBe(true);
expect(nojs.demoRowsSeen, '无 JS 时一行任务都没渲染(判据分母为空)').toBeGreaterThan(0);
expect(
nojs.rowsVisible,
`无 JS 时任务行不可见:${nojs.rowsVisible}/${nojs.demoRowsSeen}(内容在、但被 opacity/visibility 藏起来)`,
).toBe(nojs.demoRowsSeen);
// 反向断言 + 金丝雀:仅动画层的徽标无 JS 时不得可见;选择器必须非空否则上一条恒真
expect(nojs.badgeCount, '徽标选择器零命中(反向断言会恒真)').toBeGreaterThan(0);
expect(nojs.badgeVisible, `仅动画层的徽标在无 JS 时不得可见,实测 ${nojs.badgeVisible} 个`).toBe(0);
await context.close();
});
test('prefers-reduced-motion:直达终态、不排时间轴', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.goto(LANDING_URL, { waitUntil: 'load' });
await page.waitForTimeout(1200);
const hero = await heroClass(page);
expect(hero, `reduced-motion 下应挂 demo-final,实测 className="${hero}"`).toContain('demo-final');
const readings = await page.evaluate(() => ({
taskTotal: document.querySelector<HTMLElement>('.nv-home-pager b')?.textContent ?? null,
currentRow: document.querySelectorAll('.nv-home-row.is-current').length,
}));
expect(readings.taskTotal, 'reduced-motion 下任务总数应为 6').toBe('6');
expect(readings.currentRow, 'reduced-motion 下当前行应恰有 1 行').toBe(1);
});
});