fix: 修复长文档分页与滚动同步
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getNearestPageNumber } from "../src/preview-page";
|
||||
|
||||
const pages = [
|
||||
{ top: 0, bottom: 100 },
|
||||
{ top: 124, bottom: 224 },
|
||||
{ top: 248, bottom: 348 }
|
||||
];
|
||||
|
||||
describe("getNearestPageNumber", () => {
|
||||
it("返回视口中心所在的页面", () => {
|
||||
expect(getNearestPageNumber(180, pages)).toBe(2);
|
||||
});
|
||||
|
||||
it("在页间空隙中返回距离最近的页面", () => {
|
||||
expect(getNearestPageNumber(110, pages)).toBe(1);
|
||||
expect(getNearestPageNumber(116, pages)).toBe(2);
|
||||
});
|
||||
|
||||
it("没有页面或中心坐标无效时返回 0", () => {
|
||||
expect(getNearestPageNumber(20, [])).toBe(0);
|
||||
expect(getNearestPageNumber(Number.NaN, pages)).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user