Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify pdf field filling incl auto-size #1327

Merged
merged 22 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7ae72ca
feat(pdf-service): fill gesetzlicher vetreter in pkh form
rbrtrfl Oct 18, 2024
2187dc3
feat(pdf-service pkh): move concatenateGesetzlicherVertreterString in…
rbrtrfl Oct 18, 2024
13181dd
feat(pdf-service): move maritalDescriptionMapping to shared folder
rbrtrfl Oct 18, 2024
0c81366
feat(pdf-service pkh): fill A - Angaben zu Ihrer Person
rbrtrfl Oct 18, 2024
5c9d5a0
feat(pdf-service): rename generic ts type
rbrtrfl Oct 18, 2024
abb78c3
test(pdf-service): add unit tests for filling section A in the pkh pdf
rbrtrfl Oct 18, 2024
0981910
test(pdf-service): remove hasGesetzlicheVertretung from mock userData
rbrtrfl Oct 18, 2024
4997065
merge main
rbrtrfl Oct 21, 2024
388ac93
Merge branch 'main' of github.com:digitalservicebund/a2j-rechtsantrag…
rbrtrfl Nov 1, 2024
003cf99
feat(pdf generator): add maximum character width and line breaks to f…
rbrtrfl Nov 4, 2024
e3083b2
Merge branch 'main' of github.com:digitalservicebund/a2j-rechtsantrag…
rbrtrfl Nov 4, 2024
f30a5de
feat(pdf generator): add maxCharacters fallback, fix conditions, set …
rbrtrfl Nov 4, 2024
4cc0240
Merge remote-tracking branch 'origin/main' into fill-pdf-field-or-mov…
rbrtrfl Nov 18, 2024
99a7852
Merge remote-tracking branch 'origin/main' into fill-pdf-field-or-mov…
rbrtrfl Dec 17, 2024
96c4e35
feat(pdf-service): add newly generated pdf parameters and types
rbrtrfl Dec 17, 2024
2492953
Merge branch 'main' into fill-pdf-field-or-move-to-attachment
chohner Jan 6, 2025
5ea5be5
refactor(pdf.generator): simplify fieldLimits()
chohner Jan 6, 2025
8702d4b
refactor(fillPdfFieldOrMoveToAttachment): re-use existing type
chohner Jan 6, 2025
b7c8e7a
refactor: rename to fillPdfField
chohner Jan 6, 2025
a4b208e
Merge branch 'main' into fill-pdf-field-or-move-to-attachment
chohner Jan 6, 2025
b4ca163
refactor(tests): test fillPdfField instead of each field
chohner Jan 6, 2025
5527be2
Merge branch 'main' into fill-pdf-field-or-move-to-attachment
chohner Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 40 additions & 66 deletions app/domains/prozesskostenhilfe/services/pdf/pdfForm/A_person.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import type { ProzesskostenhilfeFormularContext } from "~/domains/prozesskostenhilfe/formular";
import { maritalDescriptionMapping } from "~/domains/shared/services/pdf/maritalDescriptionMapping";
import {
type AttachmentEntries,
SEE_IN_ATTACHMENT_DESCRIPTION,
SEE_IN_ATTACHMENT_DESCRIPTION_SHORT,
} from "~/services/pdf/attachment";
import { type AttachmentEntries } from "~/services/pdf/attachment";
import { fillPdfField } from "~/services/pdf/fillPdfField";
import type { PkhPdfFillFunction } from "..";

export const GESETZLICHERVERTRETER_FIELD_MAX_CHARS = 80;
export const NAME_VORNAME_FIELD_MAX_CHARS = 35;
export const ANSCHRIFT_FIELD_MAX_CHARS = 50;
export const FAMILIENSTAND_FIELD_MAX_CHARS = 10;
export const BERUF_FIELD_MAX_CHARS = 25;

export const concatenateGesetzlicherVertreterString = ({
gesetzlicheVertretungDaten,
}: ProzesskostenhilfeFormularContext): string => {
Expand Down Expand Up @@ -45,67 +36,50 @@ export const fillPerson: PkhPdfFillFunction = ({ userData, pdfValues }) => {
const gesetzlicherVertreterString =
concatenateGesetzlicherVertreterString(userData);

if (nameVornameString.length > NAME_VORNAME_FIELD_MAX_CHARS) {
attachment.push({
title: "Name, Vorname, ggf. Geburtsname",
text: nameVornameString,
});
pdfValues.nameVornameggfGeburtsname.value = SEE_IN_ATTACHMENT_DESCRIPTION;
} else {
pdfValues.nameVornameggfGeburtsname.value = nameVornameString;
}

if (userData.beruf && userData.beruf.length > BERUF_FIELD_MAX_CHARS) {
attachment.push({
title: "Beruf, Erwerbstätigkeit",
text: userData.beruf,
});
pdfValues.berufErwerbstaetigkeit.value = SEE_IN_ATTACHMENT_DESCRIPTION;
} else {
pdfValues.berufErwerbstaetigkeit.value = userData.beruf;
}
fillPdfField({
fieldname: "nameVornameggfGeburtsname",
value: nameVornameString,
attachmentTitle: "Name, Vorname, ggf. Geburtsname",
pdfValues,
attachment,
});

fillPdfField({
fieldname: "berufErwerbstaetigkeit",
value: userData?.beruf,
attachmentTitle: "Beruf, Erwerbstätigkeit",
pdfValues,
attachment,
});

pdfValues.geburtsdatum.value = userData?.geburtsdatum;

const maritalDescription =
maritalDescriptionMapping[userData.partnerschaft ?? ""];
if (maritalDescription.length > FAMILIENSTAND_FIELD_MAX_CHARS) {
attachment.push({
title: "Familienstand",
text: maritalDescription,
});
pdfValues.text3.value = SEE_IN_ATTACHMENT_DESCRIPTION_SHORT;
} else {
pdfValues.text3.value = maritalDescription;
}

if (anschriftString.length > ANSCHRIFT_FIELD_MAX_CHARS) {
attachment.push({
title: "Anschrift (Straße, Hausnummer, Postleitzahl Wohnort)",
text: anschriftString,
});
pdfValues.anschriftStrasseHausnummerPostleitzahlWohnort.value =
SEE_IN_ATTACHMENT_DESCRIPTION;
} else {
pdfValues.anschriftStrasseHausnummerPostleitzahlWohnort.value =
anschriftString;
}
fillPdfField({
fieldname: "text3",
value: maritalDescriptionMapping[userData.partnerschaft ?? ""],
attachmentTitle: "Familienstand",
pdfValues,
attachment,
});

fillPdfField({
fieldname: "anschriftStrasseHausnummerPostleitzahlWohnort",
value: anschriftString,
attachmentTitle: "Anschrift (Straße, Hausnummer, Postleitzahl Wohnort)",
pdfValues,
attachment,
});

pdfValues.text2.value = userData?.telefonnummer;

if (
gesetzlicherVertreterString.length > GESETZLICHERVERTRETER_FIELD_MAX_CHARS
) {
attachment.push({
title: "Gesetzlicher Vertreter",
text: gesetzlicherVertreterString,
});
pdfValues.sofernvorhandenGesetzlicherVertreterNameVornameAnschriftTelefon.value =
SEE_IN_ATTACHMENT_DESCRIPTION;
} else {
pdfValues.sofernvorhandenGesetzlicherVertreterNameVornameAnschriftTelefon.value =
gesetzlicherVertreterString;
}
fillPdfField({
fieldname:
"sofernvorhandenGesetzlicherVertreterNameVornameAnschriftTelefon",
value: gesetzlicherVertreterString,
attachmentTitle: "Gesetzlicher Vertreter",
pdfValues,
attachment,
});

if (attachment.length > 0) {
attachment.unshift({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@ import {
type ProzesskostenhilfePDF,
} from "data/pdf/prozesskostenhilfe/prozesskostenhilfe.generated";
import type { ProzesskostenhilfeFormularContext } from "~/domains/prozesskostenhilfe/formular";
import { maritalDescriptionMapping } from "~/domains/shared/services/pdf/maritalDescriptionMapping";
import {
SEE_IN_ATTACHMENT_DESCRIPTION,
SEE_IN_ATTACHMENT_DESCRIPTION_SHORT,
} from "~/services/pdf/attachment";
import {
ANSCHRIFT_FIELD_MAX_CHARS,
BERUF_FIELD_MAX_CHARS,
concatenateAnschriftString,
concatenateGesetzlicherVertreterString,
concatenateNameVornameString,
fillPerson,
GESETZLICHERVERTRETER_FIELD_MAX_CHARS,
NAME_VORNAME_FIELD_MAX_CHARS,
} from "../A_person";

let pdfParams: ProzesskostenhilfePDF;
Expand Down Expand Up @@ -57,141 +48,58 @@ describe("A_person", () => {
expect(attachment).toHaveLength(0);
});

it("should fill the Name, Vorname, ggf. Geburtsname section with a new page hint if the string is too long", () => {
const userDataWithLongString = {
...userData,
nachname: "a".repeat(
NAME_VORNAME_FIELD_MAX_CHARS - userData.nachname!.length + 2, // one more char than NAME_VORNAME_FIELD_MAX_CHARS
),
} as ProzesskostenhilfeFormularContext;

it("should fill the Beruf, Erwerbstätigkeit section", () => {
const { pdfValues, attachment } = fillPerson({
userData: userDataWithLongString,
userData,
pdfValues: pdfParams,
});

expect(pdfValues.nameVornameggfGeburtsname.value).toBe(
SEE_IN_ATTACHMENT_DESCRIPTION,
);
expect(attachment?.at(1)?.title).toBe("Name, Vorname, ggf. Geburtsname");
expect(attachment?.at(1)?.text).toBe(
concatenateNameVornameString(userDataWithLongString),
);
});
});

it("should fill the Beruf, Erwerbstätigkeit section", () => {
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
});

expect(pdfValues.berufErwerbstaetigkeit.value).toBe(userData.beruf);
expect(attachment).toHaveLength(0);
});

it("should fill the Beruf, Erwerbstätigkeit section with a new page hint if the string is too long", () => {
const userDataWithLongString = {
...userData,
beruf: "a".repeat(
BERUF_FIELD_MAX_CHARS + 1, // one more char than BERUF_FIELD_MAX_CHARS
),
} as ProzesskostenhilfeFormularContext;

const { pdfValues, attachment } = fillPerson({
userData: userDataWithLongString,
pdfValues: pdfParams,
});

expect(pdfValues.berufErwerbstaetigkeit.value).toBe(
SEE_IN_ATTACHMENT_DESCRIPTION,
);
expect(attachment?.at(1)?.title).toBe("Beruf, Erwerbstätigkeit");
expect(attachment?.at(1)?.text).toBe(userDataWithLongString.beruf);
});

it("should fill the Geburtsdatum section", () => {
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
});

expect(pdfValues.geburtsdatum.value).toBe(userData.geburtsdatum);
expect(attachment).toHaveLength(0);
});

it("should fill the Familienstand section", () => {
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
expect(pdfValues.berufErwerbstaetigkeit.value).toBe(userData.beruf);
expect(attachment).toHaveLength(0);
});

expect(pdfValues.text3.value).toBe("ledig");
expect(attachment).toHaveLength(0);
});

it("should fill the Familienstand section with a new page hint if the string is too long", () => {
const userDataWithLongString = {
...userData,
partnerschaft: "yes",
} as ProzesskostenhilfeFormularContext;
it("should fill the Geburtsdatum section", () => {
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
});

const { pdfValues, attachment } = fillPerson({
userData: userDataWithLongString,
pdfValues: pdfParams,
expect(pdfValues.geburtsdatum.value).toBe(userData.geburtsdatum);
expect(attachment).toHaveLength(0);
});

expect(pdfValues.text3.value).toBe(SEE_IN_ATTACHMENT_DESCRIPTION_SHORT);
expect(attachment?.at(1)?.title).toBe("Familienstand");
expect(attachment?.at(1)?.text).toBe(maritalDescriptionMapping.yes);
});
it("should fill the Familienstand section", () => {
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
});

it("should fill the Anschrift section", () => {
const anschriftString = concatenateAnschriftString(userData);
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
expect(pdfValues.text3.value).toBe("ledig");
expect(attachment).toHaveLength(0);
});

expect(pdfValues.anschriftStrasseHausnummerPostleitzahlWohnort.value).toBe(
anschriftString,
);
expect(attachment).toHaveLength(0);
});
it("should fill the Anschrift section", () => {
const anschriftString = concatenateAnschriftString(userData);
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
});

it("shold fill the Anschift section with a new page hint if the string is too long", () => {
const userDataWithLongString = {
...userData,
ort: "a".repeat(
ANSCHRIFT_FIELD_MAX_CHARS - userData.ort!.length + 2, // one more char than ANSCHRIFT_FIELD_MAX_CHARS
),
} as ProzesskostenhilfeFormularContext;
const anschriftStringLong = concatenateAnschriftString(
userDataWithLongString,
);

const { pdfValues, attachment } = fillPerson({
userData: userDataWithLongString,
pdfValues: pdfParams,
expect(
pdfValues.anschriftStrasseHausnummerPostleitzahlWohnort.value,
).toBe(anschriftString);
expect(attachment).toHaveLength(0);
});

expect(pdfValues.anschriftStrasseHausnummerPostleitzahlWohnort.value).toBe(
SEE_IN_ATTACHMENT_DESCRIPTION,
);
expect(attachment?.at(1)?.title).toBe(
"Anschrift (Straße, Hausnummer, Postleitzahl Wohnort)",
);
expect(attachment?.at(1)?.text).toBe(anschriftStringLong);
});
it("should fill the Telefonnummer section", () => {
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
});

it("should fill the Telefonnummer section", () => {
const { pdfValues, attachment } = fillPerson({
userData,
pdfValues: pdfParams,
expect(pdfValues.text2.value).toBe(userData.telefonnummer);
expect(attachment).toHaveLength(0);
});

expect(pdfValues.text2.value).toBe(userData.telefonnummer);
expect(attachment).toHaveLength(0);
});

describe("gesetzlicher Vertreter", () => {
Expand All @@ -210,33 +118,5 @@ describe("A_person", () => {
).toBe(gesetzlicherVertreterString);
expect(attachment).toHaveLength(0);
});

it("should fill the gesetzlicher Vertreter section with a new page hint if the string is too long", () => {
const userDataWithLongString = {
gesetzlicheVertretungDaten: {
...userData.gesetzlicheVertretungDaten,
nachname: "a".repeat(
GESETZLICHERVERTRETER_FIELD_MAX_CHARS -
gesetzlicherVertreterString.length +
2, // one more char than GESETZLICHERVERTRETER_FIELD_MAX_CHARS
),
},
} as ProzesskostenhilfeFormularContext;
const gesetzlicherVertreterStringLong =
concatenateGesetzlicherVertreterString(userDataWithLongString);

const { pdfValues, attachment } = fillPerson({
userData: userDataWithLongString,
pdfValues: pdfParams,
});

expect(
pdfValues
.sofernvorhandenGesetzlicherVertreterNameVornameAnschriftTelefon
.value,
).toBe(SEE_IN_ATTACHMENT_DESCRIPTION);
expect(attachment?.at(1)?.title).toBe("Gesetzlicher Vertreter");
expect(attachment?.at(1)?.text).toBe(gesetzlicherVertreterStringLong);
});
});
});
Loading
Loading