Files

25 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { spreadPages, pageIndexToView, turnView, viewCount, viewToPageIndex } from "../src/lib/cbzPages";
describe("cbzPages", () => {
it("page mode: one page per view", () => {
expect(viewCount(5, "page")).toBe(5);
expect(viewToPageIndex(2, "page")).toBe(2);
expect(pageIndexToView(2, "page")).toBe(2);
});
it("spread mode: pairs [0,1] [2,3] [4]", () => {
expect(viewCount(5, "spread")).toBe(3);
expect(pageIndexToView(3, "spread")).toBe(1);
expect(viewToPageIndex(1, "spread")).toBe(2);
expect(spreadPages(2, 5, false)).toEqual([2, 3]);
expect(spreadPages(4, 5, false)).toEqual([4]); // 落单页
expect(spreadPages(2, 5, true)).toEqual([3, 2]); // RTL 右页为先
});
it("turnView clamps and RTL flips direction", () => {
expect(turnView(0, 1, false, 3)).toBe(1);
expect(turnView(2, 1, false, 3)).toBe(2); // 右边界钳制
expect(turnView(0, -1, false, 3)).toBe(0); // 左边界钳制
expect(turnView(1, 1, true, 3)).toBe(0); // RTL:d=+1 变后退
});
});