Keycloak
107 строк · 3.4 Кб
1import type { UserProfileConfig } from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata";
2import { expect, test } from "@playwright/test";
3import {
4createRandomUserWithPassword,
5deleteUser,
6enableLocalization,
7importUserProfile,
8inRealm,
9} from "../admin-client";
10import { login } from "../login";
11import userProfileConfig from "./user-profile.json" assert { type: "json" };
12import { randomUUID } from "crypto";
13
14const realm = "user-profile";
15
16test.describe("Personal info page", () => {
17let user: string;
18test("sets basic information", async ({ page }) => {
19user = await createRandomUserWithPassword("user-" + randomUUID(), "pwd");
20
21await login(page, user, "pwd");
22
23await page.getByTestId("email").fill(`${user}@somewhere.com`);
24await page.getByTestId("firstName").fill("Erik");
25await page.getByTestId("lastName").fill("de Wit");
26await page.getByTestId("save").click();
27
28const alerts = page.getByTestId("alerts");
29await expect(alerts).toHaveText("Your account has been updated.");
30});
31});
32
33test.describe("Personal info with userprofile enabled", async () => {
34let user: string;
35test.beforeAll(async () => {
36await importUserProfile(userProfileConfig as UserProfileConfig, realm);
37user = await inRealm(realm, () =>
38createRandomUserWithPassword("user-" + randomUUID(), "jdoe", {
39email: "jdoe@keycloak.org",
40firstName: "John",
41lastName: "Doe",
42realmRoles: [],
43clientRoles: {
44account: ["manage-account"],
45},
46}),
47);
48});
49
50test.afterAll(async () => await inRealm(realm, () => deleteUser(user)));
51
52test("render user profile fields", async ({ page }) => {
53await login(page, user, "jdoe", realm);
54
55await expect(page.locator("#select")).toBeVisible();
56await expect(page.getByTestId("help-label-select")).toBeVisible();
57expect(page.getByText("Alternative email")).toBeDefined();
58});
59
60test("save user profile", async ({ page }) => {
61await login(page, user, "jdoe", realm);
62
63await page.locator("#select").click();
64await page.getByRole("option", { name: "two" }).click();
65await page.getByTestId("email2").fill("non-valid");
66await page.getByTestId("save").click();
67await expect(page.getByTestId("alerts")).toHaveText(
68"Could not update account due to validation errors",
69);
70
71await expect(page.locator("#email2-helper")).toHaveText(
72"Invalid email address.",
73);
74
75await page.getByTestId("email2").clear();
76await page.getByTestId("email2").fill("valid@email.com");
77await page.getByTestId("save").click();
78
79await page.reload();
80await page.locator("delete-account").isVisible();
81await expect(page.getByTestId("email2")).toHaveValue("valid@email.com");
82});
83});
84
85// skip currently the locale is not part of the response
86test.describe.skip("Realm localization", async () => {
87test.beforeAll(() => enableLocalization());
88
89test("change locale", async ({ page }) => {
90const user = await createRandomUserWithPassword(
91"user-" + randomUUID(),
92"pwd",
93);
94
95await login(page, user, "pwd");
96await page
97.locator("div")
98.filter({ hasText: /^Deutsch$/ })
99.nth(2)
100.click();
101await page.getByRole("option", { name: "English" }).click();
102await page.getByTestId("save").click();
103await page.reload();
104
105expect(page.locator("div").filter({ hasText: /^English$/ })).toBeDefined();
106});
107});
108