Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container: set svelte component context variable on ctx update #4051

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ describe('Compound Container Tests', () => {
expect(stub.getCall(0)).to.be.calledWith(
'compoundWC.ctx={"label":"Dashboard","title":"Some input","instant":true,"newContextData":"some data"}'
);
//Test if context property on luigi compound container is also updated
cy.get('#cc-ctx')
.invoke('html')
.then((innerHtml) => {
expect(innerHtml).to.include('{"newContextData":"some data"}');
});
});
});
});
Expand All @@ -170,7 +176,7 @@ describe('Compound Container Tests', () => {
const alertMessages = [
'UPDATE_TOP_NAVIGATION_REQUEST event received',
'some goBackValue',
'LuigiClient.linkManager().pathExists()=true\nthis.LuigiClient.linkManager().hasBack()=false',
'LuigiClient.linkManager().pathExists()=true\nthis.LuigiClient.linkManager().hasBack()=false'
];

cy.get(containerSelector)
Expand All @@ -192,7 +198,7 @@ describe('Compound Container Tests', () => {
.get('#showAlert')
.click()
.then(() => {
expect(stub.getCall(0)).to.be.calledWith("uxManager().showAlert() test");
expect(stub.getCall(0)).to.be.calledWith('uxManager().showAlert() test');
});
});

Expand Down Expand Up @@ -246,7 +252,7 @@ describe('Compound Container Tests', () => {
});
it('openAsDrawer webcomponent container', () => {
cy.on('window:alert', stub);

cy.get(containerSelector)
.shadow()
.get('#openAsDrawerBtn')
Expand All @@ -257,7 +263,7 @@ describe('Compound Container Tests', () => {
});
it('openAsSplitview webcomponent container', () => {
cy.on('window:alert', stub);

cy.get(containerSelector)
.shadow()
.get('#openAsSplitviewBtn')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ describe('Iframe Container Test', () => {
'have.been.calledWith',
'Custom message received: {"id":"my.contextMessage","_metaData":{},"data":{"myContext":"some context data"}}'
);

//Test if context property on luigi container is also updated
cy.get('#container-ctx')
.invoke('html')
.then((innerHtml) => {
expect(innerHtml).to.include('{"myContext":"some context data"}');
});
});
});
});
Expand Down
1 change: 1 addition & 0 deletions container/src/LuigiCompoundContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
thisComponent.updateContext = (contextObj: object, internal?: object) => {
const rootElement = thisComponent.getNoShadow() ? thisComponent : mainComponent;
rootElement._luigi_mfe_webcomponent.context = contextObj;
context = contextObj;

const compoundChildrenQueryElement = rootElement._luigi_mfe_webcomponent;
if (compoundChildrenQueryElement) {
Expand Down
1 change: 1 addition & 0 deletions container/src/LuigiContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
};

thisComponent.updateContext = (contextObj: object, internal?: object) => {
context = contextObj;
if (webcomponent) {
(thisComponent.getNoShadow() ? thisComponent : mainComponent)._luigi_mfe_webcomponent.context = contextObj;
} else {
Expand Down
15 changes: 11 additions & 4 deletions container/test-app/compound/compoundClientAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h3>
compound web component based microfrontend
</h3>
<button id="luigi-update-context" type="button">Update context</button>
<span id="cc-ctx" style="display: none"></span>

<!-- base scenario compound container-->
<span>Below is a compound container example for testing functionality</span>
Expand Down Expand Up @@ -171,13 +172,16 @@ <h3>
console.log(event.detail);
window.location.hash = event.detail.link;
});
compoundContainer.addEventListener(MFEventID.GO_BACK_REQUEST, event => {
compoundContainer.addEventListener(MFEventID.GO_BACK_REQUEST, (event) => {
console.log(event.detail);
alert(event.detail.goBackValue);
});
compoundContainer.addEventListener(MFEventID.UPDATE_TOP_NAVIGATION_REQUEST, event => {
alert("UPDATE_TOP_NAVIGATION_REQUEST event received");
});
compoundContainer.addEventListener(
MFEventID.UPDATE_TOP_NAVIGATION_REQUEST,
(event) => {
alert('UPDATE_TOP_NAVIGATION_REQUEST event received');
},
);
compoundContainer.addEventListener(MFEventID.ALERT_REQUEST, (event) => {
console.log(event.detail);
alert(event.detail.text);
Expand Down Expand Up @@ -316,6 +320,9 @@ <h3>

document.querySelector('#luigi-update-context').addEventListener('click', () => {
compoundContainer.updateContext({ newContextData: 'some data' });
document.querySelector('#cc-ctx').innerHTML = JSON.stringify(
compoundContainer.context,
);
});
</script>
</body>
Expand Down
4 changes: 4 additions & 0 deletions container/test-app/iframe/iframeContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h3>
</h3>
<button id="btn-1">Send Custom Message to iFrame Container</button>
<button id="update-ctx">Update Ctx</button>
<span id="container-ctx" style="display: none"></span>
<button id="update-view-url" type="button">Update viewUrl</button>
<button id="update-token">Update Access Token</button>

Expand Down Expand Up @@ -67,6 +68,9 @@ <h3>

updateContextButton.addEventListener('click', () => {
luigiContainer.updateContext({ myContext: 'some context data' });
document.querySelector('#container-ctx').innerHTML = JSON.stringify(
luigiContainer.context,
);
});

updateViewUrlButton.addEventListener('click', () => {
Expand Down
Loading