bug处理

This commit is contained in:
truewhile
2026-09-15 09:58:47 +08:00
parent 1dbc3f8fe7
commit c911a57467
2 changed files with 73 additions and 1 deletions
+38 -1
View File
@@ -1,4 +1,4 @@
import { shouldRememberScroll } from './useScrollMemory.ts'
import { shouldPersistScrollSample, shouldRememberScroll } from './useScrollMemory.ts'
function check(name: string, condition: boolean) {
if (!condition) throw new Error(`useScrollMemory: ${name}`)
@@ -11,4 +11,41 @@ check('media detail remembers scroll', shouldRememberScroll('/media/media-1'))
check('settings does not remember scroll', !shouldRememberScroll('/settings'))
check('player does not remember scroll', !shouldRememberScroll('/play/media-1'))
check(
'route transition collapse is ignored',
!shouldPersistScrollSample({
current: 0,
lastSaved: 1800,
height: 400,
lastHeight: 4200,
}),
)
check(
'intentional scroll to top is persisted',
shouldPersistScrollSample({
current: 0,
lastSaved: 1800,
height: 4200,
lastHeight: 4200,
}),
)
check(
'normal downward scroll is persisted',
shouldPersistScrollSample({
current: 1900,
lastSaved: 1800,
height: 4200,
lastHeight: 4200,
}),
)
check(
'content growth still allows persist',
shouldPersistScrollSample({
current: 1800,
lastSaved: 1800,
height: 5200,
lastHeight: 4200,
}),
)
console.log('useScrollMemory.test.ts ok')