diff --git a/frontend/src/components/layout/__tests__/AppSidebar.spec.ts b/frontend/src/components/layout/__tests__/AppSidebar.spec.ts index 592ce8a3b8..8439c23fcd 100644 --- a/frontend/src/components/layout/__tests__/AppSidebar.spec.ts +++ b/frontend/src/components/layout/__tests__/AppSidebar.spec.ts @@ -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(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}\}/) diff --git a/frontend/src/stores/__tests__/app.spec.ts b/frontend/src/stores/__tests__/app.spec.ts index 7dbe6bc37c..803dad0e90 100644 --- a/frontend/src/stores/__tests__/app.spec.ts +++ b/frontend/src/stores/__tests__/app.spec.ts @@ -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)