Skip to content

Commit

Permalink
Merge branch 'main' into e2e-test-restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
aaschlote authored Nov 22, 2024
2 parents 1478141 + c476af9 commit 109eacf
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("addPlannedFlightDetails", () => {

expect(getTotalCompensationClaim).toHaveBeenCalled();
expect(mockDoc.text).toHaveBeenCalledWith(
`Streitwert: ${mockCompensation}€`,
`Streitwert: ${mockCompensation} €`,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export const addPlannedFlightDetails = (
doc
.fontSize(12)
.font(FONTS_BUNDESSANS_BOLD)
.text(`Streitwert: ${compensationByDistance}€`);
.text(`Streitwert: ${compensationByDistance} €`);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type PDFDocument from "pdfkit";
import { PDF_HEIGHT_SEIZE } from "~/services/pdf/createPdfKitDocument";

const MAX_VERTICAL_SPACE = PDF_HEIGHT_SEIZE - 90;
export const MAX_VERTICAL_SPACE = PDF_HEIGHT_SEIZE - 50;

export const addNewPageInCaseMissingVerticalSpace = (
doc: typeof PDFDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("addCompensationAmount", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addCompensationAmount(mockDoc, mockStruct, userDataMock, 0);
addCompensationAmount(mockDoc, mockStruct, userDataMock);

expect(addOtherDetailsItinerary).toBeCalledTimes(1);
});
Expand All @@ -50,7 +50,7 @@ describe("addCompensationAmount", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addCompensationAmount(mockDoc, mockStruct, userDataMock, 0);
addCompensationAmount(mockDoc, mockStruct, userDataMock);

expect(addDistanceInfo).toBeCalledTimes(1);
});
Expand All @@ -59,7 +59,7 @@ describe("addCompensationAmount", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addCompensationAmount(mockDoc, mockStruct, userDataMock, 0);
addCompensationAmount(mockDoc, mockStruct, userDataMock);

expect(mockDoc.text).toHaveBeenCalledWith(
DEMANDED_COMPENSATION_PAYMENT_TEXT,
Expand All @@ -75,7 +75,7 @@ describe("addCompensationAmount", () => {
isWeiterePersonen: YesNoAnswer.Enum.yes,
};

addCompensationAmount(mockDoc, mockStruct, userDataWeiterePersonenMock, 0);
addCompensationAmount(mockDoc, mockStruct, userDataWeiterePersonenMock);

expect(mockDoc.text).toHaveBeenCalledWith(
OTHER_PASSENGERS_DEMANDED_COMPENSATION_PAYMENT_TEXT,
Expand All @@ -86,7 +86,7 @@ describe("addCompensationAmount", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addCompensationAmount(mockDoc, mockStruct, userDataMock, 0);
addCompensationAmount(mockDoc, mockStruct, userDataMock);

expect(addNewPageInCaseMissingVerticalSpace).toBeCalledTimes(1);
});
Expand All @@ -95,7 +95,7 @@ describe("addCompensationAmount", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addCompensationAmount(mockDoc, mockStruct, userDataMock, 0);
addCompensationAmount(mockDoc, mockStruct, userDataMock);

expect(addMultiplePersonsInfo).toBeCalledTimes(1);
});
Expand All @@ -104,7 +104,7 @@ describe("addCompensationAmount", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addCompensationAmount(mockDoc, mockStruct, userDataMock, 0);
addCompensationAmount(mockDoc, mockStruct, userDataMock);

expect(addWitnessesInfo).toBeCalledTimes(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ describe("addDistanceInfo", () => {
isWeiterePersonen: YesNoAnswer.Enum.no,
};

addDistanceInfo(mockDoc, userDataWeiterePersonenMock, 0);
addDistanceInfo(mockDoc, userDataWeiterePersonenMock);

expect(mockDoc.text).toHaveBeenCalledWith(
`Die Distanz zwischen ${startAirportMock} und ${endAirportMock} beträgt nach Großkreismethode ca. ${distanceValueMock} km. ${ARTICLE_AIR_PASSENGER_REGULATION_TEXT} ${compensationValueMock} €.`,
PDF_MARGIN_HORIZONTAL,
undefined,
);
});

Expand All @@ -81,20 +80,19 @@ describe("addDistanceInfo", () => {
isWeiterePersonen: YesNoAnswer.Enum.yes,
};

addDistanceInfo(mockDoc, userDataWeiterePersonenMock, 0);
addDistanceInfo(mockDoc, userDataWeiterePersonenMock);

expect(mockDoc.text).toHaveBeenCalledWith(
`Die Distanz zwischen ${startAirportMock} und ${endAirportMock} beträgt nach Großkreismethode ca. ${distanceValueMock} km. ${ARTICLE_AIR_PASSENGER_REGULATION_TEXT} ${compensationValueMock} € pro Person, insgesamt aus eigenem und abgetretenem Recht damit eine Gesamtsumme von ${compensationValueMock} €.`,
PDF_MARGIN_HORIZONTAL,
undefined,
);
});

it("should call addNewPageInCaseMissingVerticalSpace", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addDistanceInfo(mockDoc, userDataMock, 0);
addDistanceInfo(mockDoc, userDataMock);

expect(addNewPageInCaseMissingVerticalSpace).toBeCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ describe("addOtherDetailsItinerary", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addOtherDetailsItinerary(mockDoc, 0, userDataMock.zusaetzlicheAngaben);
addOtherDetailsItinerary(mockDoc, userDataMock.zusaetzlicheAngaben);

expect(mockDoc.text).toHaveBeenCalledWith(
OTHER_DETAILS_ITINERARY,
expect.anything(),
expect.anything(),
);

expect(mockDoc.text).toHaveBeenCalledWith(userDataMock.zusaetzlicheAngaben);
Expand All @@ -28,12 +27,11 @@ describe("addOtherDetailsItinerary", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addOtherDetailsItinerary(mockDoc, 0);
addOtherDetailsItinerary(mockDoc);

expect(mockDoc.text).not.toHaveBeenCalledWith(
OTHER_DETAILS_ITINERARY,
expect.anything(),
expect.anything(),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ export const addCompensationAmount = (
doc: typeof PDFDocument,
documentStruct: PDFKit.PDFStructureElement,
userData: FluggastrechtContext,
compensationStartYPosition: number,
) => {
const compensationSect = doc.struct("Sect");
compensationSect.add(
doc.struct("P", {}, () => {
doc.font(FONTS_BUNDESSANS_REGULAR).fontSize(10);

addOtherDetailsItinerary(
doc,
compensationStartYPosition,
userData.zusaetzlicheAngaben,
);
addOtherDetailsItinerary(doc, userData.zusaetzlicheAngaben);

addDistanceInfo(doc, userData, compensationStartYPosition);
addDistanceInfo(doc, userData);

addNewPageInCaseMissingVerticalSpace(doc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { calculateDistanceBetweenAirportsInKilometers } from "~/domains/fluggast
import { getAirportNameByIataCode } from "~/domains/fluggastrechte/services/airports/getAirportNameByIataCode";
import { getCompensationPayment } from "~/domains/fluggastrechte/services/airports/getCompensationPayment";
import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations";
import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument";
import { getStartYPosition } from "./getStartYPosition";
import {
PDF_MARGIN_HORIZONTAL,
PDF_WIDTH_SEIZE,
} from "~/services/pdf/createPdfKitDocument";
import { addNewPageInCaseMissingVerticalSpace } from "../../addNewPageInCaseMissingVerticalSpace";

export const ARTICLE_AIR_PASSENGER_REGULATION_TEXT =
Expand Down Expand Up @@ -40,34 +42,19 @@ const getDistanceText = (userData: FluggastrechtContext): string => {
return `${distanceText} pro Person, insgesamt aus eigenem und abgetretenem Recht damit eine Gesamtsumme von ${compensationTotalAmountValue} €.`;
};

const getYPositionDistanceText = (
doc: typeof PDFDocument,
compensationStartYPosition: number,
zusaetzlicheAngaben?: string,
): number => {
// in case exist the zusaetzlicheAngaben should start to print from the last y position of the document, otherwise from the value compensationStartYPosition
return typeof zusaetzlicheAngaben !== "undefined" &&
zusaetzlicheAngaben.length > 0
? doc.y
: getStartYPosition(compensationStartYPosition, doc.y);
};

export const addDistanceInfo = (
doc: typeof PDFDocument,
userData: FluggastrechtContext,
compensationStartYPosition: number,
) => {
addNewPageInCaseMissingVerticalSpace(doc);
const distanceText = getDistanceText(userData);

const distanceTextHeight = doc.heightOfString(distanceText, {
width: PDF_WIDTH_SEIZE,
});

addNewPageInCaseMissingVerticalSpace(doc, distanceTextHeight);

doc
.text(
getDistanceText(userData),
PDF_MARGIN_HORIZONTAL,
getYPositionDistanceText(
doc,
compensationStartYPosition,
userData.zusaetzlicheAngaben,
),
)
.text(distanceText, PDF_MARGIN_HORIZONTAL)
.moveDown(MARGIN_BETWEEN_SECTIONS);
};
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
import type PDFDocument from "pdfkit";
import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations";
import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument";
import { getStartYPosition } from "./getStartYPosition";
import {
PDF_MARGIN_HORIZONTAL,
PDF_WIDTH_SEIZE,
} from "~/services/pdf/createPdfKitDocument";
import { addNewPageInCaseMissingVerticalSpace } from "../../addNewPageInCaseMissingVerticalSpace";

export const OTHER_DETAILS_ITINERARY = "Weitere Angaben zum Reiseverlauf:";

export const addOtherDetailsItinerary = (
doc: typeof PDFDocument,
compensationStartYPosition: number,
zusaetzlicheAngaben?: string,
) => {
if (
typeof zusaetzlicheAngaben !== "undefined" &&
zusaetzlicheAngaben.length > 0
) {
const otherDetailsItineraryHeight = doc.heightOfString(
OTHER_DETAILS_ITINERARY,
{
width: PDF_WIDTH_SEIZE,
},
);

const zusaetzlicheAngabenHeight = doc.heightOfString(zusaetzlicheAngaben, {
width: doc.widthOfString(zusaetzlicheAngaben),
width: PDF_WIDTH_SEIZE,
});
addNewPageInCaseMissingVerticalSpace(doc, zusaetzlicheAngabenHeight);

addNewPageInCaseMissingVerticalSpace(
doc,
zusaetzlicheAngabenHeight + otherDetailsItineraryHeight,
);

doc
.text(
OTHER_DETAILS_ITINERARY,
PDF_MARGIN_HORIZONTAL,
getStartYPosition(compensationStartYPosition, doc.y), // start to print this text from this line
)
.text(OTHER_DETAILS_ITINERARY, PDF_MARGIN_HORIZONTAL)
.text(zusaetzlicheAngaben)
.moveDown(MARGIN_BETWEEN_SECTIONS);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,5 @@ export const createFactsOfCases = (
addNewPageInCaseMissingVerticalSpace(doc, COLUMN_HEIGHT * 4 + MARGIN_BOTTOM);
const startTableY = doc.y;
addTable(doc, documentStruct, startTableY, userData);
// Set tableEndYPosition based on the existence of `andereErsatzverbindungBeschreibung`
const tableEndYPosition = startTableY + COLUMN_HEIGHT * 4 + MARGIN_BOTTOM;
doc.moveDown(MARGIN_BETWEEN_SECTIONS);
const startCompensationYPosition =
typeof userData.andereErsatzverbindungBeschreibung !== "undefined" &&
userData.andereErsatzverbindungBeschreibung.length >= 0
? doc.y
: tableEndYPosition;

addCompensationAmount(
doc,
documentStruct,
userData,
startCompensationYPosition,
);
addCompensationAmount(doc, documentStruct, userData);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument";
import { YesNoAnswer } from "~/services/validation/YesNoAnswer";
import {
addDetailedReason,
ATTACHMENT_CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT,
ATTACHMENT_CONFIRM_BOOKING_TEXT,
CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT,
CONFIRM_BOOKING_TEXT,
Expand Down Expand Up @@ -58,7 +59,7 @@ describe("addDetailedReason", () => {
);

expect(mockDoc.text).toHaveBeenCalledWith(
ATTACHMENT_CONFIRM_BOOKING_TEXT,
ATTACHMENT_CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT,
PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ describe("addMultiplePersonsText", () => {
addMultiplePersonsText(mockDoc, userDataWeiterePersonenMock);

expect(mockDoc.text).toHaveBeenCalledWith(
"1. Die klagende Partei Test Test",
"1. ",
expect.anything(),
undefined,
expect.anything(),
);

expect(mockDoc.text).toHaveBeenCalledWith("Die klagende Partei Test Test");
});

it("should have the text for persons names given weiter personen", () => {
Expand All @@ -164,6 +168,7 @@ describe("addMultiplePersonsText", () => {
strasseHausnummer: "strasseHausnummer",
ort: "ort",
plz: "plz",
telefonnummer: "telefonnummer",
},
{
vorname: "vorname2",
Expand All @@ -173,18 +178,35 @@ describe("addMultiplePersonsText", () => {
plz: "plz",
buchungsnummer: "123456",
},
{
vorname: "vorname3",
nachname: "nachname3",
strasseHausnummer: "strasseHausnummer",
ort: "ort",
plz: "plz",
},
],
isWeiterePersonen: YesNoAnswer.Values.yes,
};

addMultiplePersonsText(mockDoc, userDataWeiterePersonenMock);

expect(mockDoc.text).toHaveBeenCalledWith("2. ", expect.anything());

expect(mockDoc.text).toHaveBeenCalledWith(
"Vorname nachname, strasseHausnummer, plz ort, Telefonnummer telefonnummer",
);

expect(mockDoc.text).toHaveBeenCalledWith("3. ", expect.anything());

expect(mockDoc.text).toHaveBeenCalledWith(
"2. Vorname nachname, strasseHausnummer, plz ort",
"Vorname2 nachname2, strasseHausnummer, plz ort, abweichende Buchungsnummer: 123456",
);

expect(mockDoc.text).toHaveBeenCalledWith("4. ", expect.anything());

expect(mockDoc.text).toHaveBeenCalledWith(
"3. Vorname2 nachname2, strasseHausnummer, plz ort, abweichende Buchungsnummer: 123456",
"Vorname3 nachname3, strasseHausnummer, plz ort",
);
});
});
Loading

0 comments on commit 109eacf

Please sign in to comment.