fix: 修复长文档分页与滚动同步

This commit is contained in:
SkyJourney
2026-07-26 08:43:56 +08:00
parent 1d93f31f85
commit d62552384f
15 changed files with 449 additions and 61 deletions
+51
View File
@@ -0,0 +1,51 @@
import { describe, expect, it } from "vitest";
import {
getScrollProgress,
getSyncedScrollTop
} from "../src/scroll-sync";
describe("编辑与预览滚动同步", () => {
it("按可滚动范围计算阅读进度", () => {
expect(
getScrollProgress({
scrollTop: 600,
scrollHeight: 1600,
clientHeight: 400
})
).toBe(0.5);
});
it("把源区域进度映射到目标区域", () => {
expect(
getSyncedScrollTop(
{
scrollTop: 600,
scrollHeight: 1600,
clientHeight: 400
},
{
scrollTop: 0,
scrollHeight: 5000,
clientHeight: 1000
}
)
).toBe(2000);
});
it("处理无滚动范围和越界位置", () => {
expect(
getScrollProgress({
scrollTop: 100,
scrollHeight: 500,
clientHeight: 500
})
).toBe(0);
expect(
getScrollProgress({
scrollTop: 1800,
scrollHeight: 1600,
clientHeight: 400
})
).toBe(1);
});
});