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";
8
const loginPage = new LoginPage();
9
const sidebarPage = new SidebarPage();
11
const providersPage = new ProviderPage();
13
const usernameI18nTest = "user_i18n_test";
14
let usernameI18nId: string;
16
let originalMasterRealm: RealmRepresentation;
18
describe("i18n tests", () => {
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);
27
const { id: userId } = await adminClient.createUser({
28
username: usernameI18nTest,
31
{ type: "password", temporary: false, value: usernameI18nTest },
34
usernameI18nId = userId!;
36
await adminClient.addRealmRoleToUser(usernameI18nId, "admin");
41
await adminClient.deleteUser(usernameI18nTest);
43
if (originalMasterRealm) {
44
await adminClient.updateRealm("master", originalMasterRealm);
48
afterEach(async () => {
49
await adminClient.removeAllLocalizationTexts();
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";
58
it("should use THEME localization for fallback (en) when language without theme localization is requested and no realm localization exists", () => {
59
updateUserLocale("fo");
61
goToUserFederationPage();
63
sidebarPage.checkRealmSettingsLinkContainsText(themeLocalizationEn);
66
it("should use THEME localization for language when language with theme localization is requested and no realm localization exists", () => {
67
updateUserLocale("de");
69
goToUserFederationPage();
71
sidebarPage.checkRealmSettingsLinkContainsText(themeLocalizationDe);
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");
78
goToUserFederationPage();
80
sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationEn);
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");
87
goToUserFederationPage();
89
sidebarPage.checkRealmSettingsLinkContainsText(themeLocalizationDe);
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");
96
goToUserFederationPage();
98
sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDe);
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");
106
goToUserFederationPage();
108
sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDeCh);
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");
117
goToUserFederationPage();
119
sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDe);
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");
127
goToUserFederationPage();
129
sidebarPage.checkRealmSettingsLinkContainsText(realmLocalizationDe);
132
it("should apply plurals and interpolation for THEME localization", () => {
133
updateUserLocale("en");
135
goToUserFederationPage();
137
providersPage.assertCardContainsText("ldap", "Add Ldap providers");
140
it("should apply plurals and interpolation for REALM localization", () => {
144
"addProvider_other en: {{provider}}",
146
updateUserLocale("en");
148
goToUserFederationPage();
150
providersPage.assertCardContainsText("ldap", "addProvider_other en: Ldap");
153
function goToUserFederationPage() {
154
loginPage.logIn(usernameI18nTest, usernameI18nTest);
156
sidebarPage.goToUserFederation();
159
function updateUserLocale(locale: string) {
160
cy.wrap(null).then(() =>
161
adminClient.updateUser(usernameI18nId, {
162
attributes: { locale: locale },
167
function addCommonRealmSettingsLocalizationText(
171
addLocalization(locale, "realmSettings", value);
174
function addLocalization(locale: string, key: string, value: string) {
175
cy.wrap(null).then(() =>
176
adminClient.addLocalizationText(locale, key, value),