Repository: SAP/luigi (js)
Issue: add 'setCurrentLocale' to wc client uxManager
... and dispatch corresponding event in container and compoundContainer
Pull request description: Adds setCurrentLocale to WC client
**Description**

Changes proposed in this pull request:

- adds setCurrentLocale to WC client

**Related issue(s)**

Resolves #4219 


Patch:
diff --git a/container/src/services/webcomponents.service.ts b/container/src/services/webcomponents.service.ts
index 34f26b4f..2a235c70 100644
--- a/container/src/services/webcomponents.service.ts
+++ b/container/src/services/webcomponents.service.ts
@@ -314,6 +314,11 @@ export class WebComponentService {
           setDocumentTitle: (title) => {
             this.dispatchLuigiEvent(Events.SET_DOCUMENT_TITLE_REQUEST, title);
           },
+          setCurrentLocale: (locale: string) => {
+            if (locale) {
+              this.dispatchLuigiEvent(Events.SET_CURRENT_LOCALE_REQUEST, { currentLocale: locale });
+            }
+          },
           removeBackdrop: () => {
             this.dispatchLuigiEvent(Events.REMOVE_BACKDROP_REQUEST, {});
           },


Test patch:
diff --git a/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js b/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js
index d429dd4b..1d3a163f 100644
--- a/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js
+++ b/container/cypress/e2e/test-app/compound/wc-compound-container.cy.js
@@ -57,6 +57,18 @@ describe('Compound Container Tests', () => {
         });
     });
 
+    it('LuigiClient API - setCurrentLocale', () => {
+      cy.on('window:alert', stub);
+
+      cy.get(containerSelector)
+        .shadow()
+        .contains('setCurrentLocale')
+        .click()
+        .then(() => {
+          expect(stub.getCall(0)).to.be.calledWith('LuigiClient.uxManager().setCurrentLocale()=de');
+        });
+    });
+
     it('LuigiClient API - getDirtyStatus', () => {
       cy.on('window:alert', stub);
 
diff --git a/container/cypress/e2e/test-app/wc/wc-container.cy.js b/container/cypress/e2e/test-app/wc/wc-container.cy.js
index 0f79b872..63dc7baf 100644
--- a/container/cypress/e2e/test-app/wc/wc-container.cy.js
+++ b/container/cypress/e2e/test-app/wc/wc-container.cy.js
@@ -35,6 +35,18 @@ describe('Web Container Test', () => {
         });
     });
 
+    it('setCurrentLocale', () => {
+      cy.on('window:alert', stub);
+
+      cy.get(containerSelector)
+        .shadow()
+        .contains('setCurrentLocale')
+        .click()
+        .then(() => {
+          expect(stub.getCall(0)).to.be.calledWith('LuigiClient.uxManager().setCurrentLocale()=de');
+        });
+    });
+
     it('getCoreSearchParams', () => {
       cy.on('window:alert', stub);
 
diff --git a/container/test-app/compound/compoundClientAPI.html b/container/test-app/compound/compoundClientAPI.html
index 081b1d6c..4540b760 100644
--- a/container/test-app/compound/compoundClientAPI.html
+++ b/container/test-app/compound/compoundClientAPI.html
@@ -255,6 +255,15 @@
       compoundContainer.addEventListener(MFEventID.SET_ANCHOR_LINK_REQUEST, (event) => {
         console.log('anchor', event.detail);
       });
+      compoundContainer.addEventListener(
+        MFEventID.SET_CURRENT_LOCALE_REQUEST,
+        (event) => {
+          console.log('locale', event.detail);
+          alert(
+            'LuigiClient.uxManager().setCurrentLocale()=' + event.detail.currentLocale,
+          );
+        },
+      );
       compoundContainer.addEventListener(
         MFEventID.OPEN_USER_SETTINGS_REQUEST,
         (event) => {
diff --git a/container/test-app/compound/helloWorldWC.js b/container/test-app/compound/helloWorldWC.js
index 92a5f773..0f6f7eef 100644
--- a/container/test-app/compound/helloWorldWC.js
+++ b/container/test-app/compound/helloWorldWC.js
@@ -19,6 +19,9 @@ export default class extends HTMLElement {
     const current_locale = document.createElement('template');
     current_locale.innerHTML = '<button id="current_locale">getCurrentLocale</button>';
 
+    const setLocaleBtn = document.createElement('template');
+    setLocaleBtn.innerHTML = '<button id="setCurrentLocale">setCurrentLocale</button>';
+
     const templateBtn2 = document.createElement('template');
     templateBtn2.innerHTML = '<button id="publishEvent">Publish event</button>';
 
@@ -144,6 +147,7 @@ export default class extends HTMLElement {
     this._shadowRoot.appendChild(setViewGroupDataBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(confirmationModalBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(current_locale.content.cloneNode(true));
+    this._shadowRoot.appendChild(setLocaleBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(closeAlertResponseDiv.cloneNode(true));
     this._shadowRoot.appendChild(confirmationModalResponseDiv.cloneNode(true));
 
@@ -159,6 +163,13 @@ export default class extends HTMLElement {
       }
     });
 
+    this.$setLocaleBtn = this._shadowRoot.querySelector('#setCurrentLocale');
+    this.$setLocaleBtn.addEventListener('click', () => {
+      if (this.LuigiClient) {
+        this.LuigiClient.uxManager().setCurrentLocale('de');
+      }
+    });
+
     this.$paragraph = this._shadowRoot.querySelector('p');
 
     this.$button = this._shadowRoot.querySelector('#aButton');
diff --git a/container/test-app/wc/clientAPI.html b/container/test-app/wc/clientAPI.html
index ef36f115..6623e28e 100644
--- a/container/test-app/wc/clientAPI.html
+++ b/container/test-app/wc/clientAPI.html
@@ -189,6 +189,12 @@
         luigiContainer.addEventListener(MFEventID.SET_ANCHOR_LINK_REQUEST, (event) => {
           console.log('anchor', event.detail);
         });
+        luigiContainer.addEventListener(MFEventID.SET_CURRENT_LOCALE_REQUEST, (event) => {
+          console.log('locale', event.detail);
+          alert(
+            'LuigiClient.uxManager().setCurrentLocale()=' + event.detail.currentLocale,
+          );
+        });
         luigiContainer.addEventListener(MFEventID.OPEN_USER_SETTINGS_REQUEST, (event) => {
           console.log('Open User Settings Request received', event.detail);
           alert('LuigiClient.uxManager().openUserSettings()');
diff --git a/container/test-app/wc/helloWorldWC.js b/container/test-app/wc/helloWorldWC.js
index 882dbda6..5f7609fd 100644
--- a/container/test-app/wc/helloWorldWC.js
+++ b/container/test-app/wc/helloWorldWC.js
@@ -28,6 +28,9 @@ export default class extends HTMLElement {
     const setAnchorBtn = document.createElement('template');
     setAnchorBtn.innerHTML = '<button id="setAnchor">setAnchor</button>';
 
+    const setLocaleBtn = document.createElement('template');
+    setLocaleBtn.innerHTML = '<button id="setCurrentLocale">setCurrentLocale</button>';
+
     const getCoreSearchParamsBtn = document.createElement('template');
     getCoreSearchParamsBtn.innerHTML = '<button id="coreSearchParams">getCoreSearchParams</button>';
 
@@ -122,6 +125,7 @@ export default class extends HTMLElement {
     this._shadowRoot.appendChild(addNodeParamsBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(getNodeParamsBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(setAnchorBtn.content.cloneNode(true));
+    this._shadowRoot.appendChild(setLocaleBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(getCoreSearchParamsBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(getPathParamsBtn.content.cloneNode(true));
     this._shadowRoot.appendChild(getClientPermissionsBtn.content.cloneNode(true));
@@ -227,6 +231,13 @@ export default class extends HTMLElement {
       }
     });
 
+    this.$setLocaleBtn = this._shadowRoot.querySelector('#setCurrentLocale');
+    this.$setLocaleBtn.addEventListener('click', () => {
+      if (this.LuigiClient) {
+        this.LuigiClient.uxManager().setCurrentLocale('de');
+      }
+    });
+
     this.$coreSearchParamsBtn = this._shadowRoot.querySelector('#coreSearchParams');
     this.$coreSearchParamsBtn.addEventListener('click', () => {
       if (this.LuigiClient) {
diff --git a/container/test/services/webcomponents.service.spec.ts b/container/test/services/webcomponents.service.spec.ts
index 04e47bb6..53694f34 100644
--- a/container/test/services/webcomponents.service.spec.ts
+++ b/container/test/services/webcomponents.service.spec.ts
@@ -754,6 +754,21 @@ describe('createClientAPI', () => {
       expect(result).toEqual(false);
     });
 
+    it('test uxManager setCurrentLocale', () => {
+      const locale = 'en';
+
+      // mock and spy on functions
+      service.containerService.dispatch = jest.fn();
+      const dispatchEventSpy = jest.spyOn(service, 'dispatchLuigiEvent');
+
+      // act
+      const clientAPI = service.createClientAPI(undefined, 'nodeId', 'wc_id', 'component');
+      clientAPI.uxManager().setCurrentLocale(locale);
+
+      // assert
+      expect(dispatchEventSpy).toHaveBeenCalledWith(Events.SET_CURRENT_LOCALE_REQUEST, { currentLocale: locale });
+    });
+
     it('test uxManager removeBackdrop', () => {
       // mock and spy on functions
       service.containerService.dispatch = jest.fn();