mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
test: 补充侧边栏滚动位置持久化的前端测试
- AppSidebar.spec.ts:验证 template ref 绑定、sidebarNavRef 声明、 onBeforeUnmount 保存 scrollTop、onMounted 恢复 - app.spec.ts:验证 sidebarScrollTop 默认值为 0 且可读写
This commit is contained in:
@@ -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}\}/)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user