Skip to content

Commit

Permalink
✅ Add tests for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Jun 7, 2024
1 parent 21177ae commit 0f9ecf4
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
Binary file added tests/files/test-pdf.foldable.border.pdf
Binary file not shown.
Binary file added tests/files/test-pdf.foldable.mini-cover.pdf
Binary file not shown.
Binary file added tests/files/test-pdf.foldable.mini-fit.pdf
Binary file not shown.
Binary file added tests/files/test-pdf.foldable.mini-stretch.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const testPdf = {
outputPathVerticalOnly: "./files/test-pdf.foldable.vertical.pdf",
outputPathHorizontalOnly: "./files/test-pdf.foldable.horizontal.pdf",
outputPathNoRows: "./files/test-pdf.foldable.no-rows.pdf",
outputPathMiniFit: "./files/test-pdf.foldable.mini-fit.pdf",
outputPathMiniCover: "./files/test-pdf.foldable.mini-cover.pdf",
outputPathMiniStretch: "./files/test-pdf.foldable.mini-stretch.pdf",
outputPathBorder: "./files/test-pdf.foldable.border.pdf",
outputFilename: "test-pdf.foldable.pdf"
}

Expand Down
107 changes: 107 additions & 0 deletions tests/specs/generate-pdf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,110 @@ test("PDF generation: no rows", async ({page, testPdf}, testInfo) => {
// cleanup
await download.delete();
});

test("PDF generation: target size mini fit", async ({page, testPdf}, testInfo) => {
await page.locator("#targetSizePresets").selectOption("mini");
await page.locator("#targetAspectRatio").selectOption("fit");

// generate PDF
await page.locator("#generate").click();

// verify the PDF is generated
await expect(await page.locator("#download-button").getAttribute("href")).toContain("blob:");
await expect(await page.locator("#output iframe").getAttribute("src")).toContain("blob:");

// download PDF
const downloadPromise = page.waitForEvent('download');
await expect(await page.locator("#download-button").getAttribute("download")).toBe(testPdf.outputFilename);
await page.locator("#download-button").click();
const download = await downloadPromise;

// verify the PDF is downloaded
expect(download.url()).toContain("blob:");
expect(download.suggestedFilename()).toMatch(/.pdf$/i);
await checkPdf(download, testPdf.outputPathMiniFit, testInfo);

// cleanup
await download.delete();
});

test("PDF generation: target size mini cover", async ({page, testPdf}, testInfo) => {
await page.locator("#targetSizePresets").selectOption("mini");
await page.locator("#targetAspectRatio").selectOption("cover");

// generate PDF
await page.locator("#generate").click();

// verify the PDF is generated
await expect(await page.locator("#download-button").getAttribute("href")).toContain("blob:");
await expect(await page.locator("#output iframe").getAttribute("src")).toContain("blob:");

// download PDF
const downloadPromise = page.waitForEvent('download');
await expect(await page.locator("#download-button").getAttribute("download")).toBe(testPdf.outputFilename);
await page.locator("#download-button").click();
const download = await downloadPromise;

// verify the PDF is downloaded
expect(download.url()).toContain("blob:");
expect(download.suggestedFilename()).toMatch(/.pdf$/i);
await checkPdf(download, testPdf.outputPathMiniCover, testInfo);

// cleanup
await download.delete();
});

test("PDF generation: target size mini stretch", async ({page, testPdf}, testInfo) => {
await page.locator("#targetSizePresets").selectOption("mini");
await page.locator("#targetAspectRatio").selectOption("stretch");

// generate PDF
await page.locator("#generate").click();

// verify the PDF is generated
await expect(await page.locator("#download-button").getAttribute("href")).toContain("blob:");
await expect(await page.locator("#output iframe").getAttribute("src")).toContain("blob:");

// download PDF
const downloadPromise = page.waitForEvent('download');
await expect(await page.locator("#download-button").getAttribute("download")).toBe(testPdf.outputFilename);
await page.locator("#download-button").click();
const download = await downloadPromise;

// verify the PDF is downloaded
expect(download.url()).toContain("blob:");
expect(download.suggestedFilename()).toMatch(/.pdf$/i);
await checkPdf(download, testPdf.outputPathMiniStretch, testInfo);

// cleanup
await download.delete();
});

test("PDF generation: border", async ({page, testPdf}, testInfo) => {
await page.locator("#innerBorderWidth").fill("1");
await page.locator("#outerBorderWidth").fill("2");
await page.locator("#roundCorners").fill("3");
await page.locator("#backgroundColorFront").fill("#000000");
await page.locator("#backgroundColorBack").fill("#000000");

// generate PDF
await page.locator("#generate").click();

// verify the PDF is generated
await expect(await page.locator("#download-button").getAttribute("href")).toContain("blob:");
await expect(await page.locator("#output iframe").getAttribute("src")).toContain("blob:");

// download PDF
const downloadPromise = page.waitForEvent('download');
await expect(await page.locator("#download-button").getAttribute("download")).toBe(testPdf.outputFilename);
await page.locator("#download-button").click();
const download = await downloadPromise;

// verify the PDF is downloaded
expect(download.url()).toContain("blob:");
expect(download.suggestedFilename()).toMatch(/.pdf$/i);
await checkPdf(download, testPdf.outputPathBorder, testInfo);

// cleanup
await download.delete();
});

0 comments on commit 0f9ecf4

Please sign in to comment.