mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-31 16:26:30 +00: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}\}/)
|
||||
|
||||
Reference in New Issue
Block a user