test: 补充侧边栏滚动位置持久化的前端测试

- AppSidebar.spec.ts:验证 template ref 绑定、sidebarNavRef 声明、
  onBeforeUnmount 保存 scrollTop、onMounted 恢复
- app.spec.ts:验证 sidebarScrollTop 默认值为 0 且可读写
This commit is contained in:
li
2026-07-07 21:11:40 +08:00
parent c7e44a83ad
commit a86c534cb0
2 changed files with 34 additions and 0 deletions
@@ -19,6 +19,29 @@ describe('AppSidebar custom SVG styles', () => {
})
})
describe('AppSidebar scroll position persistence', () => {
it('binds a template ref to the sidebar nav element', () => {
expect(componentSource).toContain('ref="sidebarNavRef"')
expect(componentSource).toContain('sidebar-nav')
})
it('declares sidebarNavRef in script setup', () => {
expect(componentSource).toContain("const sidebarNavRef = ref<HTMLElement | null>(null)")
})
it('saves scroll position on beforeUnmount', () => {
expect(componentSource).toContain('onBeforeUnmount')
expect(componentSource).toContain('appStore.sidebarScrollTop')
expect(componentSource).toContain('sidebarNavRef.value.scrollTop')
})
it('restores scroll position on mount', () => {
expect(componentSource).toContain('onMounted')
expect(componentSource).toContain('appStore.sidebarScrollTop')
expect(componentSource).toContain('nextTick')
})
})
describe('AppSidebar header styles', () => {
it('does not clip the version badge dropdown', () => {
const sidebarHeaderBlockMatch = styleSource.match(/\.sidebar-header\s*\{[\s\S]*?\n {2}\}/)
+11
View File
@@ -147,6 +147,17 @@ describe('useAppStore', () => {
expect(store.sidebarCollapsed).toBe(false)
})
it('sidebarScrollTop 默认为 0 且可读写', () => {
const store = useAppStore()
expect(store.sidebarScrollTop).toBe(0)
store.sidebarScrollTop = 256
expect(store.sidebarScrollTop).toBe(256)
store.sidebarScrollTop = 0
expect(store.sidebarScrollTop).toBe(0)
})
it('toggleMobileSidebar 切换移动端状态', () => {
const store = useAppStore()
expect(store.mobileOpen).toBe(false)