forked from mem9-ai/mem9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-dialog-pagination.test.ts
More file actions
45 lines (37 loc) · 1.44 KB
/
ui-dialog-pagination.test.ts
File metadata and controls
45 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { describe, expect, it } from "vitest";
import { paginatePixelFarmDialogText } from "./ui-dialog-pagination";
function normalize(value: string): string {
return value.replace(/\s+/g, " ").trim();
}
describe("paginatePixelFarmDialogText", () => {
it("keeps short text on one page", () => {
const pages = paginatePixelFarmDialogText({
text: "Short memory line.",
maxLines: 4,
measureLineCount: (value) => Math.ceil(value.length / 20),
});
expect(pages).toEqual(["Short memory line."]);
});
it("splits long text into multiple pages without dropping content", () => {
const text =
"First sentence is long enough to wrap. Second sentence keeps going. Third sentence closes the thought.";
const pages = paginatePixelFarmDialogText({
text,
maxLines: 3,
measureLineCount: (value) => Math.ceil(value.length / 18),
});
expect(pages.length).toBeGreaterThan(1);
expect(normalize(pages.join(" "))).toBe(normalize(text));
});
it("falls back to word groups when a sentence is too long for one page", () => {
const pages = paginatePixelFarmDialogText({
text: "alpha beta gamma delta epsilon zeta eta theta iota kappa",
maxLines: 2,
measureLineCount: (value) => Math.ceil(value.length / 12),
});
expect(pages.length).toBeGreaterThan(1);
expect(normalize(pages.join(" "))).toBe(
"alpha beta gamma delta epsilon zeta eta theta iota kappa",
);
});
});