Skip to content

Commit

Permalink
fix(pdf-service): styling fixes after move to pdfkit (#1530)
Browse files Browse the repository at this point in the history
* fix(pdf-service): change checklist title from Anhang to Ihre nächsten Schritte

* fix(pdf-service): align indentation on BerH checklist page

* fix(pdf-service): fix indentations before headings in BerH attachment pdf

* test(pdf-service): adapt checklist tests
  • Loading branch information
rbrtrfl authored Dec 9, 2024
1 parent 99f08a1 commit 3bd06cf
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ describe("createChecklistPage", () => {
1,
"Merkblatt: Antrag auf Bewilligung von Beratungshilfe von Luca Mustermensch",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(2, "Anhang");
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
2,
"Ihre nächsten Schritte",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
3,
"So schicken Sie den Antrag ins Amtsgericht",
Expand All @@ -42,7 +45,10 @@ describe("createChecklistPage", () => {
1,
"Merkblatt: Antrag auf Bewilligung von Beratungshilfe von Luca Mustermensch",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(2, "Anhang");
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
2,
"Ihre nächsten Schritte",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
3,
"So stellen Sie den Antrag online",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,64 @@ import { abgabeContext } from "~/domains/shared/formular/abgabe/context";
import { createChecklistSteps } from "../createChecklistSteps";

describe("createChecklistSteps", () => {
const mockDocumentStruct = mockPdfKitDocumentStructure();
const mockPDFDocument = mockPdfKitDocument(mockDocumentStruct);
mockPDFDocument.x = 0;
mockPDFDocument.y = 0;

it("should create checklist steps for 'ausdrucken' abgabeArt", () => {
const mockDocumentStruct = mockPdfKitDocumentStructure();
const mockPDFDocument = mockPdfKitDocument(mockDocumentStruct);
const userData: BeratungshilfeFormularContext = {
abgabeArt: abgabeContext.abgabeArt.Enum.ausdrucken,
};
createChecklistSteps(mockPDFDocument, mockDocumentStruct, userData);

expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
1,
"1. Antrag ausdrucken",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
3,
expect(mockPDFDocument.text).toHaveBeenCalledWith("1. Antrag ausdrucken");
expect(mockPDFDocument.text).toHaveBeenCalledWith(
"2. Antrag unterschreiben",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
5,
expect(mockPDFDocument.text).toHaveBeenCalledWith(
"3. Benötigte Dokumente kopieren",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
7,
"4. Antrag abgeben",
);
expect(mockPDFDocument.text).toHaveBeenCalledWith("4. Antrag abgeben");
expect(mockPDFDocument.list).toHaveBeenCalledWith(
[
"Unterlagen zu Ihrem rechtlichen Problem",
"Kopie Ihres aktuellen Mietvertrags",
],
expect.any(Number),
expect.any(Number),
expect.any(Object),
);
});

it("should create checklist steps for 'online' abgabeArt", () => {
const mockDocumentStruct = mockPdfKitDocumentStructure();
const mockPDFDocument = mockPdfKitDocument(mockDocumentStruct);
const onlineUserData: BeratungshilfeFormularContext = {
abgabeArt: abgabeContext.abgabeArt.Enum.online,
};

createChecklistSteps(mockPDFDocument, mockDocumentStruct, onlineUserData);

expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
1,
expect(mockPDFDocument.text).toHaveBeenCalledWith(
"1. Antrag prüfen und speichern",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
3,
expect(mockPDFDocument.text).toHaveBeenCalledWith(
"2. Benötigte Dokumente scannen",
);
expect(mockPDFDocument.text).toHaveBeenNthCalledWith(
5,
expect(mockPDFDocument.text).toHaveBeenCalledWith(
"3. Antrag über das Portal Mein Justizpostfach versenden",
);
expect(mockPDFDocument.list).toHaveBeenCalledWith(
[
"Unterlagen zu Ihrem rechtlichen Problem",
"Kopie Ihres aktuellen Mietvertrags",
],
expect.any(Number),
expect.any(Number),
expect.any(Object),
);
});

it("should include relevant documents based on user data conditions", () => {
const mockDocumentStruct = mockPdfKitDocumentStructure();
const mockPDFDocument = mockPdfKitDocument(mockDocumentStruct);
const customUserData: BeratungshilfeFormularContext = {
abgabeArt: abgabeContext.abgabeArt.Enum.ausdrucken,
staatlicheLeistungen: "buergergeld",
Expand All @@ -94,6 +86,8 @@ describe("createChecklistSteps", () => {
"Kontoauszüge der letzten 3 Monate",
"Kopie des letzten Jahreskontoauszugs für Ihre Lebensversicherung",
]),
expect.any(Number),
expect.any(Number),
expect.any(Object),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createChecklistPage = (
);
const checklistPageStruct = doc.struct("Sect");

createHeading(doc, checklistPageStruct, "Anhang", "H1");
createHeading(doc, checklistPageStruct, "Ihre nächsten Schritte", "H1");

createHeading(
doc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ export const createChecklistSteps = (
typeof step.value === "string"
? step.value
: step.value(Boolean(conditions.courtName)),
{
indent: pdfStyles.sectionIndented.paddingLeft,
},
doc.x + pdfStyles.sectionIndented.paddingLeft,
doc.y,
)
// workaround, because pdfkit only supports indentation for the first line of a paragraph
.text("", doc.x - pdfStyles.sectionIndented.paddingLeft, doc.y)
.moveDown(1);
}),
);
Expand All @@ -145,8 +146,15 @@ export const createChecklistSteps = (
.font(pdfStyles.page.font)
.list(
relevantDocuments.map((doc) => doc),
{ paragraphGap: 8, indent: pdfStyles.list.paddingLeft },
);
doc.x + pdfStyles.sectionIndented.paddingLeft,
doc.y,
{
paragraphGap: 8,
// the value of bulletIdent does not seem to have any effect
bulletIndent: pdfStyles.list.paddingLeft,
},
)
.text("", doc.x - pdfStyles.sectionIndented.paddingLeft, doc.y);
}),
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/services/pdf/attachment/createAttachmentEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,29 @@ export function createAttachmentEntries(
attachment: AttachmentEntries | undefined,
) {
if (attachment) {
attachment.forEach((entry) => {
attachment.forEach((entry, index) => {
documentStruct.add(
doc.struct(entry.level?.toUpperCase() ?? "P", {}, () => {
doc
// only move down if the current entry is a heading
// and the previous entry is not a heading
// and the current entry is not the first entry
.moveDown(
entry.level && !attachment[index - 1]?.level && index !== 0
? 1
: 0,
)
.fontSize(
entry.level
? pdfStyles[entry.level].fontSize
: pdfStyles.page.fontSize,
)
.font(pdfStyles.bold.font)
.text(entry.title)
.moveDown(entry.level ? 0.5 : 0);
.moveDown(entry.level ? 1 : 0);
}),
);

if (entry.text) {
documentStruct.add(
doc.struct("P", {}, () => {
Expand Down
2 changes: 1 addition & 1 deletion app/services/pdf/pdfStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export const pdfStyles = {
font: fontMap.bold,
},
list: {
paddingLeft: 23,
paddingLeft: 10,
},
};

0 comments on commit 3bd06cf

Please sign in to comment.