Skip to content

Commit 6c0134c

Browse files
committed
chore: add e2e test for remembering form state
1 parent df93db8 commit 6c0134c

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

e2e/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const DEFAULT_CLIENT_LOGO_URI = "https://app.example/logo";
2727
export const DEFAULT_CLIENT_TOS_URI = "https://app.example/tos";
2828
export const DEFAULT_CLIENT_POLICY_URI = "https://app.example/policy";
2929
export const DEFAULT_CLIENT_EMAIL = "[email protected]";
30+
export const DEFAULT_MAX_AGE = 3600;
3031

3132
export const VALID_CLIENT_IDENTIFIER_DOCUMENT = JSON.stringify({
3233
"@context": ["https://www.w3.org/ns/solid/oidc-context.jsonld"],

e2e/generatorForm.playwright.ts

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
DEFAULT_CLIENT_POLICY_URI,
3535
DEFAULT_CLIENT_TOS_URI,
3636
DEFAULT_CLIENT_EMAIL,
37+
DEFAULT_MAX_AGE,
3738
} from "./constants";
3839

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

83+
async function expectUserFacingFieldsDefaults(page: Page) {
84+
await expect(page.locator('input[name="logoUri"]')).toHaveValue(
85+
DEFAULT_CLIENT_LOGO_URI
86+
);
87+
await expect(page.locator('input[name="policyUri"]')).toHaveValue(
88+
DEFAULT_CLIENT_POLICY_URI
89+
);
90+
await expect(page.locator('input[name="tosUri"]')).toHaveValue(
91+
DEFAULT_CLIENT_TOS_URI
92+
);
93+
await expect(page.locator('input[name="contacts.0"]')).toHaveValue(
94+
DEFAULT_CLIENT_EMAIL
95+
);
96+
}
97+
8298
async function fillTechnicalFields(page: Page) {
8399
await openAccordion(page, ".AdvancedFieldsAccordion");
84100

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

91107
// Set default max age.
92108
await page.locator('input[name="defaultMaxAge"]').click();
93-
await page.locator('input[name="defaultMaxAge"]').fill("3600");
109+
await page
110+
.locator('input[name="defaultMaxAge"]')
111+
.fill(DEFAULT_MAX_AGE.toString());
94112

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

117+
async function expectTechnicalFieldsDefaults(page: Page) {
118+
await expect(page.locator("input[name='applicationType']")).toHaveValue(
119+
"native"
120+
);
121+
await expect(page.locator('input[name="defaultMaxAge"]')).toHaveValue("3600");
122+
await expect(page.locator("input[name='requireAuthTime']")).toBeChecked();
123+
}
124+
99125
test.describe("Generator page functionality", () => {
100126
it("has title Client Identifier Helper", async ({ page }) => {
101127
await page.goto("/generator");
@@ -168,7 +194,7 @@ test.describe("Generator page functionality", () => {
168194

169195
const clientIdentifierDocument = await clickAndGenerateDocument(page);
170196
expect(clientIdentifierDocument.application_type).toBe("native");
171-
expect(clientIdentifierDocument.default_max_age).toBe(3600);
197+
expect(clientIdentifierDocument.default_max_age).toBe(DEFAULT_MAX_AGE);
172198
expect(clientIdentifierDocument.require_auth_time).toBe(true);
173199
});
174200

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

192218
expect(clientIdentifierDocument.application_type).toBe("native");
193-
expect(clientIdentifierDocument.default_max_age).toBe(3600);
219+
expect(clientIdentifierDocument.default_max_age).toBe(DEFAULT_MAX_AGE);
194220
expect(clientIdentifierDocument.require_auth_time).toBe(true);
195221
});
196222

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

229255
await expect(page.locator("[name=generatedJson]")).not.toBeVisible();
230256
});
257+
258+
it("Remembers states and values", async ({ page }) => {
259+
await page.goto("/generator");
260+
await fillEssentialFieldsWithDefaults(page);
261+
await fillUserFacingFieldsWithDefaults(page);
262+
await fillTechnicalFields(page);
263+
264+
// Cause field error state for empty clientId.
265+
await page.locator("[name=clientId]").fill("");
266+
267+
// Switch page and go back.
268+
await page.locator(".openValidatorPage").click();
269+
await page.locator(".openGeneratorPage").click();
270+
271+
// Expect values to have remained the same.
272+
await expect(page.locator("[name=clientId]")).toHaveValue("");
273+
await expect(page.locator("[name=clientName]")).toHaveValue(
274+
DEFAULT_CLIENT_NAME
275+
);
276+
await expect(page.locator("[name=clientUri]")).toHaveValue(
277+
DEFAULT_CLIENT_HOMEPAGE
278+
);
279+
await expect(page.locator(`[name="redirectUris.0"]`)).toHaveValue(
280+
`${DEFAULT_CLIENT_REDIRECT_URI}1`
281+
);
282+
await expectUserFacingFieldsDefaults(page);
283+
await expectTechnicalFieldsDefaults(page);
284+
285+
// Expect clientId error state to have remained.
286+
expect(
287+
await page.locator(`.MuiFormHelperText-root.Mui-error`).count()
288+
).toBe(1);
289+
const errorDescriptions = page.locator(`.MuiFormHelperText-root.Mui-error`);
290+
await expect(errorDescriptions).toHaveText(
291+
/The given URI field is not present./
292+
);
293+
});
231294
});

0 commit comments

Comments
 (0)