/** * 顶部导航栏与胶囊避让度量工具单测 */ import { describe, it, expect } from './harness.mjs' import { getNavMetrics } from '../common/utils/navbar.js' describe('顶部导航栏 · 规范度量与胶囊避让', () => { it('无 uni 环境或默认兜底时返回安全度量', () => { const m = getNavMetrics() expect(typeof m.statusBarHeight).toBe('number') expect(typeof m.navBarHeight).toBe('number') expect(typeof m.capsulePadding).toBe('number') expect(typeof m.totalHeight).toBe('number') expect(m.statusBarHeight >= 0).toBe(true) expect(m.navBarHeight >= 38).toBe(true) expect(m.totalHeight).toBe(m.statusBarHeight + m.navBarHeight) }) it('模拟微信小程序环境精确计算胶囊避让与导航栏高度', () => { const originalUni = globalThis.uni try { globalThis.uni = { getSystemInfoSync: () => ({ statusBarHeight: 44, windowWidth: 390 }), getMenuButtonBoundingClientRect: () => ({ left: 280, right: 380, top: 48, bottom: 80, width: 100, height: 32, }), } const m = getNavMetrics() expect(m.statusBarHeight).toBe(44) // capsulePadding = (390 - 280) + 8 = 118 expect(m.capsulePadding).toBe(118) // navBarHeight = (48 - 44) * 2 + 32 = 40 expect(m.navBarHeight).toBe(40) expect(m.totalHeight).toBe(84) } finally { globalThis.uni = originalUni } }) })