Fix Monolith and Cobalt Stripe closing-block squeeze; guard Monolith flow notes
When only the closing block moved to page 2, the page-1 deficit was shared across every gap, including the closing block's own gaps, which cannot help page 1. Page 1 then came out a few points short and the totals spilled over with the closing block. Monolith and Cobalt Stripe now squeeze only the page-1 gaps in that case, as Marble and Highlighter already do. Monolith's flow notes block could start in the last few points of a page and be cut into zero-height lines. It now holds 70 pt of room under its label first, as Marble does. Adds tests for both cases (they failed before the fix) and notes in the template specs. Fingerprint goldens and thumbnails are unchanged.
This commit is contained in:
@@ -286,6 +286,41 @@ describe("long text", () => {
|
||||
expect(r.pdf.pages.map((p, i) => textsOf(r, i)).join(" ")).toContain("Note 18");
|
||||
});
|
||||
|
||||
it("when only the closing block moves to page 2 the page-1 gaps are squeezed enough to keep the items and totals on page 1", async () => {
|
||||
// Row counts where the overflow before the closing block is within the gaps that help page 1 (A4 / Letter).
|
||||
const cases: Array<["A4" | "LETTER", number]> = [["A4", 4], ["A4", 5], ["LETTER", 4]];
|
||||
for (const [size, n] of cases) {
|
||||
const r = await renderFixture({ name: "s", items: n, logo: "none" }, prefsFor(size, { templateId: "monolith" }));
|
||||
const where = (id: string) => {
|
||||
const pages: number[] = [];
|
||||
r.result.core.layout.forEach((pg, i) => walk(pg.nodes, (x) => x.id === id && pages.push(i)));
|
||||
return pages;
|
||||
};
|
||||
const rowPages = new Set<number>();
|
||||
r.result.core.layout.forEach((pg, i) => walk(pg.nodes, (x) => x.id?.startsWith(TABLE_ROW_PREFIX) && rowPages.add(i)));
|
||||
expect([...rowPages], `${size} n=${n} rows`).toEqual([0]);
|
||||
expect(where(TOTALS_ID), `${size} n=${n} totals`).toEqual([0]);
|
||||
expect(where(CLOSING_ID), `${size} n=${n} closing`).toEqual([1]);
|
||||
expect(r.result.pages).toBe(2);
|
||||
}
|
||||
});
|
||||
|
||||
it("flow notes never start with less than a line of room: the block starts on the next page instead of collapsing into zero-height lines", async () => {
|
||||
const base = FIXTURES.find((f) => f.name === "long-notes")!;
|
||||
// Row counts where the notes' label used to land in the last few points of a page (A4 / Letter).
|
||||
const cases: Array<["A4" | "LETTER", number]> = [["A4", 3], ["A4", 14], ["LETTER", 13]];
|
||||
for (const [size, n] of cases) {
|
||||
const r = await renderFixture({ ...base, items: n, logo: "none" }, prefsFor(size, { templateId: "monolith" }));
|
||||
expect(r.result.issues.filter((i) => i.severity === "error"), `${size} n=${n}`).toEqual([]);
|
||||
const frame = frameForPrefs(r.prefs);
|
||||
const label = nodes(r.result.core.layout).find((x) => x.type === "text" && x.lines?.some((l) => /^notes/i.test(l.text)))!;
|
||||
let page = -1;
|
||||
r.result.core.layout.forEach((pg, i) => walk(pg.nodes, (x) => x === label && (page = i)));
|
||||
expect(label.box.y + 70, `${size} n=${n} label room`).toBeLessThanOrEqual(frame.page.height - frame.pad.bottom);
|
||||
expect(page).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("an over-long vendor name wraps right-aligned in its column and never reaches the title", async () => {
|
||||
const r = await renderFixture({ ...FIXTURES.find((f) => f.name === "id-tokens")!, logo: "none" }, prefsFor("A4", { templateId: "monolith" }));
|
||||
const brand = textLines(byId(r, BRAND_ID));
|
||||
|
||||
Reference in New Issue
Block a user