Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
chore: add e2e test for remembering form state
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurin-W committed Dec 19, 2022
1 parent df93db8 commit 32980f3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const DEFAULT_CLIENT_LOGO_URI = "https://app.example/logo";
export const DEFAULT_CLIENT_TOS_URI = "https://app.example/tos";
export const DEFAULT_CLIENT_POLICY_URI = "https://app.example/policy";
export const DEFAULT_CLIENT_EMAIL = "[email protected]";
export const DEFAULT_MAX_AGE = 3600;

export const VALID_CLIENT_IDENTIFIER_DOCUMENT = JSON.stringify({
"@context": ["https://www.w3.org/ns/solid/oidc-context.jsonld"],
Expand Down
69 changes: 66 additions & 3 deletions e2e/generatorForm.playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
DEFAULT_CLIENT_POLICY_URI,
DEFAULT_CLIENT_TOS_URI,
DEFAULT_CLIENT_EMAIL,
DEFAULT_MAX_AGE,
} from "./constants";

async function openAccordion(page: Page, selector: string) {
Expand Down Expand Up @@ -79,6 +80,21 @@ async function fillUserFacingFieldsWithDefaults(page: Page) {
await page.locator('input[name="contacts.0"]').fill(DEFAULT_CLIENT_EMAIL);
}

async function expectUserFacingFieldsDefaults(page: Page) {
await expect(page.locator('input[name="logoUri"]')).toHaveValue(
DEFAULT_CLIENT_LOGO_URI
);
await expect(page.locator('input[name="policyUri"]')).toHaveValue(
DEFAULT_CLIENT_POLICY_URI
);
await expect(page.locator('input[name="tosUri"]')).toHaveValue(
DEFAULT_CLIENT_TOS_URI
);
await expect(page.locator('input[name="contacts.0"]')).toHaveValue(
DEFAULT_CLIENT_EMAIL
);
}

async function fillTechnicalFields(page: Page) {
await openAccordion(page, ".AdvancedFieldsAccordion");

Expand All @@ -90,12 +106,22 @@ async function fillTechnicalFields(page: Page) {

// Set default max age.
await page.locator('input[name="defaultMaxAge"]').click();
await page.locator('input[name="defaultMaxAge"]').fill("3600");
await page
.locator('input[name="defaultMaxAge"]')
.fill(DEFAULT_MAX_AGE.toString());

// Request a time of authentication claim.
await page.locator("text=Request a time of authentication claim").click();
}

async function expectTechnicalFieldsDefaults(page: Page) {
await expect(page.locator("input[name='applicationType']")).toHaveValue(
"native"
);
await expect(page.locator('input[name="defaultMaxAge"]')).toHaveValue("3600");
await expect(page.locator("input[name='requireAuthTime']")).toBeChecked();
}

test.describe("Generator page functionality", () => {
it("has title Client Identifier Helper", async ({ page }) => {
await page.goto("/generator");
Expand Down Expand Up @@ -168,7 +194,7 @@ test.describe("Generator page functionality", () => {

const clientIdentifierDocument = await clickAndGenerateDocument(page);
expect(clientIdentifierDocument.application_type).toBe("native");
expect(clientIdentifierDocument.default_max_age).toBe(3600);
expect(clientIdentifierDocument.default_max_age).toBe(DEFAULT_MAX_AGE);
expect(clientIdentifierDocument.require_auth_time).toBe(true);
});

Expand All @@ -190,7 +216,7 @@ test.describe("Generator page functionality", () => {
expect(clientIdentifierDocument?.contacts[0]).toBe(DEFAULT_CLIENT_EMAIL);

expect(clientIdentifierDocument.application_type).toBe("native");
expect(clientIdentifierDocument.default_max_age).toBe(3600);
expect(clientIdentifierDocument.default_max_age).toBe(DEFAULT_MAX_AGE);
expect(clientIdentifierDocument.require_auth_time).toBe(true);
});

Expand Down Expand Up @@ -228,4 +254,41 @@ test.describe("Generator page functionality", () => {

await expect(page.locator("[name=generatedJson]")).not.toBeVisible();
});

it("Remembers states and values", async ({ page }) => {
await page.goto("/generator");
await fillEssentialFieldsWithDefaults(page);
await fillUserFacingFieldsWithDefaults(page);
await fillTechnicalFields(page);

// Cause field error state for empty clientId.
await page.locator("[name=clientId]").fill("");

// Switch page and go back.
await page.goto("/validator");
await page.goto("/generator");

// Expect values to have remained the same.
await expect(page.locator("[name=clientId]")).toHaveValue("");
await expect(page.locator("[name=clientName]")).toHaveValue(
DEFAULT_CLIENT_NAME
);
await expect(page.locator("[name=clientUri]")).toHaveValue(
DEFAULT_CLIENT_HOMEPAGE
);
await expect(page.locator(`[name="redirectUris.0"]`)).toHaveValue(
`${DEFAULT_CLIENT_REDIRECT_URI}1`
);
await expectUserFacingFieldsDefaults(page);
await expectTechnicalFieldsDefaults(page);

// Expect clientId error state to have remained.
expect(
await page.locator(`.MuiFormHelperText-root.Mui-error`).count()
).toBe(1);
const errorDescriptions = page.locator(`.MuiFormHelperText-root.Mui-error`);
await expect(errorDescriptions).toHaveText(
/The given URI field is not present./
);
});
});

0 comments on commit 32980f3

Please sign in to comment.