From a86c534cb08037b691a09bbac0f61f53534f891a Mon Sep 17 00:00:00 2001 From: li Date: Tue, 7 Jul 2026 21:11:40 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A1=A5=E5=85=85=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=A0=8F=E6=BB=9A=E5=8A=A8=E4=BD=8D=E7=BD=AE=E6=8C=81=E4=B9=85?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E5=89=8D=E7=AB=AF=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AppSidebar.spec.ts:验证 template ref 绑定、sidebarNavRef 声明、 onBeforeUnmount 保存 scrollTop、onMounted 恢复 - app.spec.ts:验证 sidebarScrollTop 默认值为 0 且可读写 --- .../layout/__tests__/AppSidebar.spec.ts | 23 +++++++++++++++++++ frontend/src/stores/__tests__/app.spec.ts | 11 +++++++++ 2 files changed, 34 insertions(+) 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)