fix: keep reading bookmarks bound to route

This commit is contained in:
kuyua9
2026-05-12 18:10:42 +08:00
parent 6517eeb1a2
commit e2c9e0f06d
3 changed files with 93 additions and 22 deletions
@@ -3,6 +3,7 @@ import { describe, it } from 'node:test'
import {
createReadingBookmark,
createReadingBookmarkSnapshot,
getReadingBookmarkKey,
readReadingBookmark,
writeReadingBookmark
@@ -62,6 +63,44 @@ describe('reading bookmarks', () => {
)
})
it('keeps delayed saves bound to the path captured before navigation', () => {
const storage = createStorage()
let currentPath = '/easy-vibe/zh-cn/page-a/'
const scheduledPath = currentPath
currentPath = '/easy-vibe/zh-cn/page-b/'
writeReadingBookmark(
storage,
createReadingBookmarkSnapshot({
path: scheduledPath,
getTitle: () => '页面 A',
getSection: () => '小节 A',
getScrollY: () => 240,
getProgress: () => 32,
now: () => 777
})
)
assert.equal(
readReadingBookmark(storage, currentPath, 1000),
null
)
assert.deepEqual(
readReadingBookmark(storage, scheduledPath, 1000),
{
version: 1,
path: scheduledPath,
title: '页面 A',
section: '小节 A',
scrollY: 240,
progress: 32,
updatedAt: 777
}
)
})
it('normalizes invalid numeric values', () => {
assert.deepEqual(
createReadingBookmark({