Skip to content

Commit

Permalink
Add tests for assessment page & PDF download
Browse files Browse the repository at this point in the history
  • Loading branch information
monachilada committed Jun 14, 2024
1 parent 0ee0566 commit 6e12614
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { PDFDocument, PDFForm, PDFTextField } from "pdf-lib";

const FIELD_NAME_POLICY_TITLE: string = "Titel des Regelungsvorhabens";
const FIELD_NAME_PRE_CHECK_POSITIVE_1: string = "Vorprüfung positiv - 1";
const FIELD_NAME_PRE_CHECK_POSITIVE_2: string = "Vorprüfung positiv - 2";
const FIELD_NAME_PRE_CHECK_POSITIVE_3: string = "Vorprüfung positiv - 3";
const FIELD_NAME_PRE_CHECK_POSITIVE_4: string = "Vorprüfung positiv - 4";
const FIELD_NAME_PRE_CHECK_POSITIVE_5: string = "Vorprüfung positiv - 5";
const FIELD_NAME_PRE_CHECK_NEGATIVE: string = "Vorprüfung negativ";
const FIELD_NAME_PRE_CHECK_NEGATIVE_ASSESMENT: string =
export const FIELD_NAME_POLICY_TITLE: string = "Titel des Regelungsvorhabens";
export const FIELD_NAME_PRE_CHECK_POSITIVE_1: string = "Vorprüfung positiv - 1";
export const FIELD_NAME_PRE_CHECK_POSITIVE_2: string = "Vorprüfung positiv - 2";
export const FIELD_NAME_PRE_CHECK_POSITIVE_3: string = "Vorprüfung positiv - 3";
export const FIELD_NAME_PRE_CHECK_POSITIVE_4: string = "Vorprüfung positiv - 4";
export const FIELD_NAME_PRE_CHECK_POSITIVE_5: string = "Vorprüfung positiv - 5";
export const FIELD_NAME_PRE_CHECK_NEGATIVE: string = "Vorprüfung negativ";
export const FIELD_NAME_PRE_CHECK_NEGATIVE_ASSESMENT: string =
"Vorprüfung negativ - Erläuterung";

interface PreCheckAnswer {
Expand Down
159 changes: 159 additions & 0 deletions packages/dito/tests/e2e/preCheck.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { expect, test } from "@playwright/test";
import * as fs from "node:fs";
import * as path from "node:path";
import { PDFDocument } from "pdf-lib";
import { preCheck } from "resources/content";
import {
PATH_ASSESSMENT,
PATH_DOCUMENTATION,
PATH_PRECHECK,
PATH_RESULT,
} from "resources/staticRoutes";
import {
FIELD_NAME_POLICY_TITLE,
FIELD_NAME_PRE_CHECK_NEGATIVE,
FIELD_NAME_PRE_CHECK_POSITIVE_1,
FIELD_NAME_PRE_CHECK_POSITIVE_2,
FIELD_NAME_PRE_CHECK_POSITIVE_3,
FIELD_NAME_PRE_CHECK_POSITIVE_4,
FIELD_NAME_PRE_CHECK_POSITIVE_5,
} from "routes/vorpruefung_.ergebnis.einschaetzung.$fileName[.pdf]";

const { questions } = preCheck;

Expand Down Expand Up @@ -305,6 +318,152 @@ test.describe("test result page", () => {
await expect(page.getByRole("main")).not.toContainText("IT-System");
});

test("assessment page is available", async ({ page }) => {
await page.goto(PATH_PRECHECK);
await page.getByRole("link", { name: "Digitalbezug einschätzen" }).click();
for (let i = 0; i < 5; i++) {
await page.getByLabel("Ja").click();
await page.getByRole("button", { name: "Übernehmen" }).click();
}
await page
.getByRole("link", { name: "Einschätzung als PDF bekommen" })
.click();
await expect(page).toHaveURL(PATH_ASSESSMENT);
});

test("accepts user input on assessment page", async ({ page }) => {
await page.goto(PATH_PRECHECK);
await page.getByRole("link", { name: "Digitalbezug einschätzen" }).click();
for (let i = 0; i < 5; i++) {
await page.getByLabel("Ja").click();
await page.getByRole("button", { name: "Übernehmen" }).click();
}
await page
.getByRole("link", { name: "Einschätzung als PDF bekommen" })
.click();
await page.getByLabel("Arbeitstitel des Vorhabens").fill("Policy #123");
await expect(page.getByLabel("Arbeitstitel des Vorhabens")).toHaveValue(
"Policy #123",
);
await page.getByRole("button", { name: "Als PDF herunterladen" }).click();
});

test("generates and downloads PDF with user input", async ({ page }) => {
await page.goto(PATH_PRECHECK);
await page.getByRole("link", { name: "Digitalbezug einschätzen" }).click();
for (let i = 0; i < 5; i++) {
await page.getByLabel("Ja").click();
await page.getByRole("button", { name: "Übernehmen" }).click();
}
await page
.getByRole("link", { name: "Einschätzung als PDF bekommen" })
.click();
await page.getByLabel("Arbeitstitel des Vorhabens").fill("Policy #123");
const downloadPromise = page.waitForEvent("download");
await page.getByRole("button", { name: "Als PDF herunterladen" }).click();
const download = await downloadPromise;
expect(download.url()).toContain(
PATH_ASSESSMENT +
"/digitalcheck-vorpruefung.pdf?title=Policy+%23123&it-system=yes&verpflichtungen-fuer-beteiligte=yes&datenaustausch=yes&kommunikation=yes&automatisierung=yes&download",
);
const filePath = path.resolve(await download.path());
const fileData = fs.readFileSync(filePath);
const pdfDoc = await PDFDocument.load(fileData);
const form = pdfDoc.getForm();

const titleField = form.getTextField(FIELD_NAME_POLICY_TITLE).getText();
expect(titleField).toBe("Policy #123");

const positive_1 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_1)
.isChecked();
expect(positive_1).toBe(true);

const positive_2 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_2)
.isChecked();
expect(positive_2).toBe(true);

const positive_3 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_3)
.isChecked();
expect(positive_3).toBe(true);

const positive_4 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_4)
.isChecked();
expect(positive_4).toBe(true);

const positive_5 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_5)
.isChecked();
expect(positive_5).toBe(true);

const negative = form
.getCheckBox(FIELD_NAME_PRE_CHECK_NEGATIVE)
.isChecked();
expect(negative).toBe(false);
});

test("generates correct PDF in negative case", async ({ page }) => {
await page.goto(PATH_PRECHECK);
await page.getByRole("link", { name: "Digitalbezug einschätzen" }).click();
for (let i = 0; i < 5; i++) {
await page.getByLabel("Nein").click();
await page.getByRole("button", { name: "Übernehmen" }).click();
}
await page
.getByRole("link", { name: "Einschätzung als PDF bekommen" })
.click();
await page.getByLabel("Arbeitstitel des Vorhabens").fill("Policy #987");
const downloadPromise = page.waitForEvent("download");
await page.getByRole("button", { name: "Als PDF herunterladen" }).click();
const download = await downloadPromise;
expect(download.url()).toContain(
PATH_ASSESSMENT +
"/digitalcheck-vorpruefung.pdf?title=Policy+%23987&it-system=no&verpflichtungen-fuer-beteiligte=no&datenaustausch=no&kommunikation=no&automatisierung=no&download",
);
const filePath = path.resolve(await download.path());
const fileData = fs.readFileSync(filePath);
const pdfDoc = await PDFDocument.load(fileData);
const form = pdfDoc.getForm();

const titleField = form.getTextField(FIELD_NAME_POLICY_TITLE).getText();
expect(titleField).toBe("Policy #987");

const positive_1 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_1)
.isChecked();
expect(positive_1).toBe(false);

const positive_2 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_2)
.isChecked();
expect(positive_2).toBe(false);

const positive_3 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_3)
.isChecked();
expect(positive_3).toBe(false);

const positive_4 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_4)
.isChecked();
expect(positive_4).toBe(false);

const positive_5 = form
.getCheckBox(FIELD_NAME_PRE_CHECK_POSITIVE_5)
.isChecked();
expect(positive_5).toBe(false);

const negative = form
.getCheckBox(FIELD_NAME_PRE_CHECK_NEGATIVE)
.isChecked();
expect(negative).toBe(true);
});
// test("generates PDF with user input", async ({ page }) => {
// test("generates correct PDF in negative case", async ({ page }) => {

test("result page links to documentation", async ({ page }) => {
await page.goto(PATH_PRECHECK);
await page.getByRole("link", { name: "Digitalbezug einschätzen" }).click();
Expand Down

0 comments on commit 6e12614

Please sign in to comment.