Skip to content

Commit

Permalink
refactor: use pdf page buffer for snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Oct 23, 2023
1 parent 637a102 commit a2f8e7c
Show file tree
Hide file tree
Showing 11 changed files with 16,322 additions and 89 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@
"svg"
],
"volta": {
"node": "20.8.0"
"node": "20.8.1"
}
}
2,367 changes: 2,361 additions & 6 deletions src/pdf/swissqrbill.test.snap

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions src/pdf/swissqrbill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ describe("qr-bill", async () => {
const qrBill = new SwissQRBill(minimalRequired);

qrBill.attachTo(pdf);
pdf.end();

await expect(pdf.snapshot).resolves.toMatchSnapshot();
await pdf.writeFile();

expect(pdf.snapshots).toMatchSnapshot();
});

it("should render the qr bill in a a4 document with insufficient space on a new page", async () => {
Expand All @@ -30,9 +31,10 @@ describe("qr-bill", async () => {
});

qrBill.attachTo(pdf);
pdf.end();

await expect(pdf.snapshot).resolves.toMatchSnapshot();
await pdf.writeFile();

expect(pdf.snapshots).toMatchSnapshot();
});

it("should render the qr bill in a a4 document with multiple pages and enough space on the last page", async () => {
Expand All @@ -41,9 +43,10 @@ describe("qr-bill", async () => {

pdf.addPage();
qrBill.attachTo(pdf);
pdf.end();

await expect(pdf.snapshot).resolves.toMatchSnapshot();
await pdf.writeFile();

expect(pdf.snapshots).toMatchSnapshot();
});

it("should render the qr bill in a a4 document with multiple pages and insufficient space on a new page", async () => {
Expand All @@ -58,9 +61,9 @@ describe("qr-bill", async () => {
});

qrBill.attachTo(pdf);
pdf.end();
await pdf.writeFile();

await expect(pdf.snapshot).resolves.toMatchSnapshot();
expect(pdf.snapshots).toMatchSnapshot();
});

it("should render multiple qr bills on the same page if enough space is left and the positions are fixed", async () => {
Expand All @@ -72,19 +75,21 @@ describe("qr-bill", async () => {
qrBill1.attachTo(pdf, 0, 0);
qrBill2.attachTo(pdf, 0, mm2pt(105));
qrBill3.attachTo(pdf, 0, mm2pt(210));
pdf.end();

await expect(pdf.snapshot).resolves.toMatchSnapshot();
await pdf.writeFile();

expect(pdf.snapshots).toMatchSnapshot();
});

it("should render the qr bills freely on a page", async () => {
const pdf = new TestDocument("qr-bill/freely-placed.pdf", { layout: "landscape", size: "A4" });
const qrBill = new SwissQRBill(minimalRequired);

qrBill.attachTo(pdf, mm2pt(43.5), mm2pt(52.5));
pdf.end();

await expect(pdf.snapshot).resolves.toMatchSnapshot();
await pdf.writeFile();

expect(pdf.snapshots).toMatchSnapshot();
});

});
Loading

0 comments on commit a2f8e7c

Please sign in to comment.