Keycloak

Форк
0
/
i18n_test.spec.ts 
179 строк · 6.0 Кб
1
import RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
2
import LoginPage from "../support/pages/LoginPage";
3
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
4
import ProviderPage from "../support/pages/admin-ui/manage/providers/ProviderPage";
5
import adminClient from "../support/util/AdminClient";
6
import { keycloakBefore } from "../support/util/keycloak_hooks";
7

8
const loginPage = new LoginPage();
9
const sidebarPage = new SidebarPage();
10

11
const providersPage = new ProviderPage();
12

13
const usernameI18nTest = "user_i18n_test";
14
let usernameI18nId: string;
15

16
let originalMasterRealm: RealmRepresentation;
17

18
describe("i18n tests", () => {
19
  before(() => {
20
    cy.wrap(null).then(async () => {
21
      const realm = (await adminClient.getRealm("master"))!;
22
      originalMasterRealm = realm;
23
      realm.supportedLocales = ["en", "de", "de-CH", "fo"];
24
      realm.internationalizationEnabled = true;
25
      await adminClient.updateRealm("master", realm);
26

27
      const { id: userId } = await adminClient.createUser({
28
        username: usernameI18nTest,
29
        enabled: true,
30
        credentials: [
31
          { type: "password", temporary: false, value: usernameI18nTest },
32
        ],
33
      });
34
      usernameI18nId = userId!;
35

36
      await adminClient.addRealmRoleToUser(usernameI18nId, "admin");
37
    });
38
  });
39

40
  after(async () => {
41
    await adminClient.deleteUser(usernameI18nTest);
42

43
    if (originalMasterRealm) {
44
      await adminClient.updateRealm("master", originalMasterRealm);
45
    }
46
  });
47

48
  afterEach(async () => {
49
    await adminClient.removeAllLocalizationTexts();
50
  });
51

52
  const realmLocalizationEn = "realmSettings en";
53
  const themeLocalizationEn = "Realm settings";
54
  const realmLocalizationDe = "realmSettings de";
55
  const themeLocalizationDe = "Realm-Einstellungen";
56
  const realmLocalizationDeCh = "realmSettings de-CH";
57

58
  it("should use THEME localization for fallback (en) when language without theme localization is requested and no realm localization exists", () => {
59
    updateUserLocale("fo");
60

61
    goToUserFederationPage();
62

63
    sidebarPage.checkRealmSettingsLinkContainsText(themeLocalizationEn);
64
  });
65

66
  it("should use THEME localization for language when language with theme localization is requested and no realm localization exists", () => {
67
    updateUserLocale("de");
68

69
    goToUserFederationPage();
70

71
    sidebarPage.checkRealmSettingsLinkContainsText(themeLocalizationDe);
72
  });
73

74
  it("should use REALM localization for fallback (en) when language without theme localization is requested and realm localization exists for fallback (en)", () => {
75
    addCommonRealmSettingsLocalizationText("en", realmLocalizationEn);
76
    updateUserLocale("fo");
77

78
    goToUserFederationPage();
79

80
    sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationEn);
81
  });
82

83
  it("should use THEME localization for language when language with theme localization is requested and realm localization exists for fallback (en) only", () => {
84
    addCommonRealmSettingsLocalizationText("en", realmLocalizationEn);
85
    updateUserLocale("de");
86

87
    goToUserFederationPage();
88

89
    sidebarPage.checkRealmSettingsLinkContainsText(themeLocalizationDe);
90
  });
91

92
  it("should use REALM localization for language when language is requested and realm localization exists for language", () => {
93
    addCommonRealmSettingsLocalizationText("de", realmLocalizationDe);
94
    updateUserLocale("de");
95

96
    goToUserFederationPage();
97

98
    sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDe);
99
  });
100

101
  // TODO: currently skipped due to https://github.com/keycloak/keycloak/issues/20412
102
  it.skip("should use REALM localization for region when region is requested and realm localization exists for region", () => {
103
    addCommonRealmSettingsLocalizationText("de-CH", realmLocalizationDeCh);
104
    updateUserLocale("de-CH");
105

106
    goToUserFederationPage();
107

108
    sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDeCh);
109
  });
110

111
  it("should use REALM localization for language when language is requested and realm localization exists for fallback (en), language, region", () => {
112
    addCommonRealmSettingsLocalizationText("en", realmLocalizationEn);
113
    addCommonRealmSettingsLocalizationText("de", realmLocalizationDe);
114
    addCommonRealmSettingsLocalizationText("de-CH", realmLocalizationDeCh);
115
    updateUserLocale("de");
116

117
    goToUserFederationPage();
118

119
    sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDe);
120
  });
121

122
  it("should use REALM localization for language when region is requested and realm localization exists for fallback (en), language", () => {
123
    addCommonRealmSettingsLocalizationText("en", realmLocalizationEn);
124
    addCommonRealmSettingsLocalizationText("de", realmLocalizationDe);
125
    updateUserLocale("de-CH");
126

127
    goToUserFederationPage();
128

129
    sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDe);
130
  });
131

132
  it("should apply plurals and interpolation for THEME localization", () => {
133
    updateUserLocale("en");
134

135
    goToUserFederationPage();
136

137
    providersPage.assertCardContainsText("ldap", "Add Ldap providers");
138
  });
139

140
  it("should apply plurals and interpolation for REALM localization", () => {
141
    addLocalization(
142
      "en",
143
      "addProvider_other",
144
      "addProvider_other en: {{provider}}",
145
    );
146
    updateUserLocale("en");
147

148
    goToUserFederationPage();
149

150
    providersPage.assertCardContainsText("ldap", "addProvider_other en: Ldap");
151
  });
152

153
  function goToUserFederationPage() {
154
    loginPage.logIn(usernameI18nTest, usernameI18nTest);
155
    keycloakBefore();
156
    sidebarPage.goToUserFederation();
157
  }
158

159
  function updateUserLocale(locale: string) {
160
    cy.wrap(null).then(() =>
161
      adminClient.updateUser(usernameI18nId, {
162
        attributes: { locale: locale },
163
      }),
164
    );
165
  }
166

167
  function addCommonRealmSettingsLocalizationText(
168
    locale: string,
169
    value: string,
170
  ) {
171
    addLocalization(locale, "realmSettings", value);
172
  }
173

174
  function addLocalization(locale: string, key: string, value: string) {
175
    cy.wrap(null).then(() =>
176
      adminClient.addLocalizationText(locale, key, value),
177
    );
178
  }
179
});
180

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

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

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

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