test(webui): 横竖屏判据跟上新契约(横屏=侧边导航、列表固定 320)

`rotate-verify.mjs` 10/10。途中判据自己错了两次,都记在这里:

1. `content` 选择器取 `.narrow-shell > *:not(.narrow-nav)` —— 横屏改用侧边导航后,
   第一个子元素变成了 60px 侧栏 ⇒ 把侧栏当内容区来判断排布,报出一条假失败。
   改成同时排除 `.bg-chrome-900`。
2. 原先只断言"排布换了",没断言"导航在哪边" ⇒ 用户后续追问的侧边栏
   根本没被判据覆盖。现在补:横屏侧栏必须 60px 且在左侧、底部导航必须不存在;
   竖屏反过来(底部导航存在、无侧栏)。
This commit is contained in:
2026-09-14 11:36:50 +08:00
parent a456d2127e
commit 2b6eb97bc9
3 changed files with 181 additions and 28 deletions

View File

@ -19,7 +19,11 @@ const record = (n, ok, note) => {
const snap = () =>
page.evaluate(() => {
const de = document.documentElement;
const content = document.querySelector('.narrow-shell > *:not(.narrow-nav)');
// 排除底部导航**与侧边栏**:紧凑横屏下第一个子元素是 60px 侧栏(不是内容区),
// 不排除就会把侧栏当成内容区来判断排布(判据自己的错,实测踩到)
const content = document.querySelector(
'.narrow-shell > *:not(.narrow-nav):not(.bg-chrome-900)'
);
const nav = document.querySelector('.narrow-nav')?.getBoundingClientRect();
return {
vw: innerWidth,
@ -28,7 +32,15 @@ const snap = () =>
overflowX: de.scrollWidth - de.clientWidth,
contentCls: content ? content.className.toString().slice(0, 40) : '',
navVisible: nav ? nav.bottom <= innerHeight + 1 && nav.top > 0 : false,
navInset: nav ? Math.round(nav.left) : null
navInset: nav ? Math.round(nav.left) : null,
hasBottomNav: !!document.querySelector('.narrow-nav'),
sideRail: (() => {
const r = document.querySelector('.narrow-shell > .bg-chrome-900');
if (!r) return null;
const b = r.getBoundingClientRect();
return { w: Math.round(b.width), h: Math.round(b.height), x: Math.round(b.x) };
})(),
listPaneW: Math.round((document.querySelector('.comm-pane')?.getBoundingClientRect().width) ?? 0)
};
});
@ -37,6 +49,7 @@ try {
await page.waitForTimeout(1500);
const p1 = await snap();
record('竖屏覆盖式排布NarrowStack', /relative overflow-hidden/.test(p1.contentCls), p1.contentCls);
record('竖屏:导航在**底部**(不是侧边)', p1.hasBottomNav === true && p1.sideRail === null, `底部=${p1.hasBottomNav} 侧栏=${!!p1.sideRail}`);
record('竖屏:--app-height 跟随视口', p1.appHeight === `${p1.vh}px`, `${p1.appHeight} vs ${p1.vh}`);
await page.setViewportSize({ width: 844, height: 390 });
@ -45,7 +58,17 @@ try {
record('横屏:真的换了排布(并排,而不是原样)', /flex-1 min-h-0 flex$/.test(l.contentCls), l.contentCls);
record('横屏:--app-height 重算(旋屏后不是旧值)', l.appHeight === '390px', l.appHeight);
record('横屏:无横向溢出', l.overflowX <= 0, `溢出 ${l.overflowX}px`);
record('横屏:底部导航仍完整可见且浮着', l.navVisible && l.navInset >= 6, `left=${l.navInset}`);
// 用户后续追问:「导航栏在窄屏横屏情况下不也应当是在侧边吗?」⇒ 横屏用侧边栏
record(
'横屏:导航在**侧边**60px 图标栏),底部导航不存在',
!!l.sideRail && l.sideRail.w === 60 && l.sideRail.x <= 12 && l.hasBottomNav === false,
`侧栏=${l.sideRail?.w}px x=${l.sideRail?.x} 底部导航=${l.hasBottomNav}`
);
record(
'横屏:列表栏固定 320lg:断点在 844 宽下不生效,否则会吃掉整宽)',
l.listPaneW === 320,
`列表宽=${l.listPaneW}`
);
await page.setViewportSize({ width: 390, height: 844 });
await page.waitForTimeout(1300);