feat(layout): OPEN-02a 内缩白浮条落地(px 令牌 + 195 张基线重采)

导航由全宽贴顶条改为内缩白浮条:top 48 / 高 64,左右对齐 container-x 的 gutter。
值走 px 令牌(--header-inset-top / --header-height),避免根字号 16/17/18px 导致 rem 漂移。

契约变化:新增 data-header-state="top|scrolled" 与浮条测试锚点;外壳仍 top-0,
chrome-persistence 既有的「滚动后 top===0」断言保持不变,另加浮条 rect(48/64)断言;
移动抽屉起点改 calc(inset + height)。

基线:ADR-0012 预测 180 张,实测 195 张(32 页 × 5 + 主题首页 10 + 页头 5 + 元素级 20),
逐项归因后以 --update-snapshots=changed 写入;独立只读复跑 225 passed / 0 failed / EXIT=0(9.0 分钟)。
门禁:type-check / check:grammar 21/21 / check:motion / check:a11y 全绿,lint 0 error / 88 warning,
test:unit 159 套件 / 1883 例,导航三 spec 52 passed / 8 skipped(skip 均既有条件)。

OPEN-02a 关闭;OPEN-02b(滚动收方汉堡)维持不做。
This commit is contained in:
zhangxiang committed 2026-11-28 08:01:16 +08:00
1 parent f41c57d638
commit 353fbde8da
201 files changed
+237 -30

No files matched your search

+87
View File
@@ -202,3 +202,90 @@ test('能力 mega 面板在 1280x720 下不被裁切,或自身可滚', async (
await expect(lastLink).toBeVisible({ timeout: 3000 });
}
});
/**
* 内缩白浮条(ADR-0012 §4 / `OPEN-02a`)。
*
* 为什么断言 `getComputedStyle` 而不只读 `getBoundingClientRect`:
* 本仓根字号随断点变 16/17/18px,若有人把 `--header-inset-top` 换回 `top-12`(3rem)、
* 把高度换回 `h-16`(4rem),类名照样在、type-check 照样过,而实测会变成 48/51/54 与 64/68/72。
* computed style 直接读解析后的 px,与视口/滚动无关。
*
* ⚠ 移动 project(`isMobile: true`)**不做** rect 断言:移动视口模拟下 `position: fixed`
* 的 `getBoundingClientRect().top` 会随视觉视口偏移漂移(本轮实测同一用例连跑得到 0 / 48 / 139
* 三个值),那是模拟层的量法噪声,不是产品缺陷。桌面 project 才断言「距顶 48 + 左右内缩」。
*/
test('页头是内缩浮条:padding-top 48px / 高 64px(px 令牌,不是 rem 漂移值)', async ({ page }, testInfo) => {
const isMobileProject = testInfo.project.name.includes('mobile');
await page.goto('/', { waitUntil: 'domcontentloaded' });
const wrap = page.locator('header > div').first();
const bar = page.getByTestId('header-bar');
await expect(bar).toBeVisible({ timeout: 15000 });
// ① 解析后的 px —— 这条同时钉住「token 被删/被换成 rem 档」两种腐化
await expect
.poll(() => wrap.evaluate((el) => getComputedStyle(el).paddingTop), { timeout: 15000 })
.toBe('48px');
await expect
.poll(() => bar.evaluate((el) => getComputedStyle(el).height), { timeout: 15000 })
.toBe('64px');
// ② 桌面档:距视口顶 48、自身高 64、左右内缩;滚动后不收起、不位移
if (!isMobileProject) {
await page.setViewportSize({ width: 1600, height: 900 });
// ⚠ 必须等入场动画交接(`data-content-ready=1`)后再量:`page-transition.tsx` 的
// `will-change: transform` 会劫持 `fixed` 的包含块,此时滚动 600 ⇒ 浮条 top 读到
// **48−600 = −552**(本用例首版实测就是这个值)。这与 §5.52 是同一个机理,
// 既有两条用例已经在用这个交接标记,这里复用而不是新造锚点。
await expect
.poll(() => page.evaluate(() => document.documentElement.getAttribute('data-content-ready')), { timeout: 15000 })
.toBe('1');
expect(
await page.evaluate(() => {
let n: Element | null = document.querySelector('header');
while (n && n !== document.documentElement) {
if (getComputedStyle(n).transform !== 'none') return getComputedStyle(n).transform;
n = n.parentElement;
}
return null;
}),
'祖先链上仍有 transform,此时量 fixed 元素读到的是动画帧',
).toBeNull();
const readBar = () =>
bar.evaluate((el) => {
const r = el.getBoundingClientRect();
return {
top: Math.round(r.top),
height: Math.round(r.height),
left: Math.round(r.left),
right: Math.round(r.right),
};
});
await expect.poll(async () => (await readBar()).top, { timeout: 15000 }).toBe(48);
const top = await readBar();
expect(top.top, '浮条顶距必须是 48px').toBe(48);
expect(top.height, '浮条高度必须是 64px').toBe(64);
expect(top.left, '1600 视口下浮条必须内缩(左边界 > 0)').toBeGreaterThan(0);
expect(top.right, '1600 视口下浮条必须内缩(右边界 < 视口宽)').toBeLessThan(1600);
await page.evaluate(() => {
document.documentElement.style.scrollBehavior = 'auto';
window.scrollTo(0, 600);
});
await expect.poll(() => page.evaluate(() => Math.round(window.scrollY)), { timeout: 5000 }).toBe(600);
const scrolled = await readBar();
expect(scrolled.top, '滚动后浮条仍应在 48px').toBe(48);
expect(scrolled.height, '滚动后浮条高度不变(02b「收成方汉堡」已判定不做)').toBe(64);
await expect(page.locator('header'), '滚动后应切到 scrolled 状态').toHaveAttribute('data-header-state', 'scrolled');
// 外壳仍贴顶 —— chrome-persistence 既有断言的形态不变
await expect
.poll(() => page.evaluate(() => Math.round(document.querySelector('header')!.getBoundingClientRect().top)), { timeout: 5000 })
.toBe(0);
}
});