Keycloak

Форк
0
/
personal-info.spec.ts 
107 строк · 3.4 Кб
1
import type { UserProfileConfig } from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata";
2
import { expect, test } from "@playwright/test";
3
import {
4
  createRandomUserWithPassword,
5
  deleteUser,
6
  enableLocalization,
7
  importUserProfile,
8
  inRealm,
9
} from "../admin-client";
10
import { login } from "../login";
11
import userProfileConfig from "./user-profile.json" assert { type: "json" };
12
import { randomUUID } from "crypto";
13

14
const realm = "user-profile";
15

16
test.describe("Personal info page", () => {
17
  let user: string;
18
  test("sets basic information", async ({ page }) => {
19
    user = await createRandomUserWithPassword("user-" + randomUUID(), "pwd");
20

21
    await login(page, user, "pwd");
22

23
    await page.getByTestId("email").fill(`${user}@somewhere.com`);
24
    await page.getByTestId("firstName").fill("Erik");
25
    await page.getByTestId("lastName").fill("de Wit");
26
    await page.getByTestId("save").click();
27

28
    const alerts = page.getByTestId("alerts");
29
    await expect(alerts).toHaveText("Your account has been updated.");
30
  });
31
});
32

33
test.describe("Personal info with userprofile enabled", async () => {
34
  let user: string;
35
  test.beforeAll(async () => {
36
    await importUserProfile(userProfileConfig as UserProfileConfig, realm);
37
    user = await inRealm(realm, () =>
38
      createRandomUserWithPassword("user-" + randomUUID(), "jdoe", {
39
        email: "jdoe@keycloak.org",
40
        firstName: "John",
41
        lastName: "Doe",
42
        realmRoles: [],
43
        clientRoles: {
44
          account: ["manage-account"],
45
        },
46
      }),
47
    );
48
  });
49

50
  test.afterAll(async () => await inRealm(realm, () => deleteUser(user)));
51

52
  test("render user profile fields", async ({ page }) => {
53
    await login(page, user, "jdoe", realm);
54

55
    await expect(page.locator("#select")).toBeVisible();
56
    await expect(page.getByTestId("help-label-select")).toBeVisible();
57
    expect(page.getByText("Alternative email")).toBeDefined();
58
  });
59

60
  test("save user profile", async ({ page }) => {
61
    await login(page, user, "jdoe", realm);
62

63
    await page.locator("#select").click();
64
    await page.getByRole("option", { name: "two" }).click();
65
    await page.getByTestId("email2").fill("non-valid");
66
    await page.getByTestId("save").click();
67
    await expect(page.getByTestId("alerts")).toHaveText(
68
      "Could not update account due to validation errors",
69
    );
70

71
    await expect(page.locator("#email2-helper")).toHaveText(
72
      "Invalid email address.",
73
    );
74

75
    await page.getByTestId("email2").clear();
76
    await page.getByTestId("email2").fill("valid@email.com");
77
    await page.getByTestId("save").click();
78

79
    await page.reload();
80
    await page.locator("delete-account").isVisible();
81
    await expect(page.getByTestId("email2")).toHaveValue("valid@email.com");
82
  });
83
});
84

85
// skip currently the locale is not part of the response
86
test.describe.skip("Realm localization", async () => {
87
  test.beforeAll(() => enableLocalization());
88

89
  test("change locale", async ({ page }) => {
90
    const user = await createRandomUserWithPassword(
91
      "user-" + randomUUID(),
92
      "pwd",
93
    );
94

95
    await login(page, user, "pwd");
96
    await page
97
      .locator("div")
98
      .filter({ hasText: /^Deutsch$/ })
99
      .nth(2)
100
      .click();
101
    await page.getByRole("option", { name: "English" }).click();
102
    await page.getByTestId("save").click();
103
    await page.reload();
104

105
    expect(page.locator("div").filter({ hasText: /^English$/ })).toBeDefined();
106
  });
107
});
108

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.