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

Adds Cypress tests for 'updateContext' method #3788

Merged
merged 22 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be45372
Adds Cypress tests for 'updateContext' method
walmazacn Jun 20, 2024
e4aad81
Adds formatting fixes
walmazacn Jun 20, 2024
5e5a1b9
Merge branch 'main' into 3786-cypress-test-for-container-updatecontext
walmazacn Jun 20, 2024
36d2406
Fixes failing spec
walmazacn Jun 20, 2024
27bb630
Merge branch '3786-cypress-test-for-container-updatecontext' of https…
walmazacn Jun 20, 2024
8080270
Fixes code review issues
walmazacn Jun 21, 2024
24d3a4f
Adds formatting fix
walmazacn Jun 21, 2024
fa8eb5f
Resolves conflicts
walmazacn Jun 26, 2024
5aa1217
Fixes formatting
walmazacn Jun 26, 2024
955797a
Merge branch 'main' into 3786-cypress-test-for-container-updatecontext
walmazacn Jun 26, 2024
96576f1
Resolves conflict
walmazacn Jun 28, 2024
c05a5a8
Merge branch 'main' into 3786-cypress-test-for-container-updatecontext
walmazacn Jul 2, 2024
51cad18
Removes not needed logic
walmazacn Jul 3, 2024
c346682
Merge branch 'main' into 3786-cypress-test-for-container-updatecontext
walmazacn Jul 3, 2024
5835155
Fixes code review issue
walmazacn Jul 3, 2024
4b0751c
Fixes linter issues
walmazacn Jul 3, 2024
27cad25
Merge branch 'main' into 3786-cypress-test-for-container-updatecontext
walmazacn Jul 4, 2024
c384d44
Resolves conflict
walmazacn Jul 4, 2024
1efde05
Merge branch 'main' into 3786-cypress-test-for-container-updatecontext
walmazacn Jul 5, 2024
b937908
Merge branch 'main' into 3786-cypress-test-for-container-updatecontext
ndricimrr Jul 9, 2024
b0d0e8c
Fix merge conflict
ndricimrr Jul 9, 2024
ad31bc5
Fix merge conflict
ndricimrr Jul 9, 2024
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
@@ -1,26 +1,29 @@
describe('Compound Container Tests', () => {
describe('LuigiClient API - LuigiCompoundContainer', () => {
const container = '[data-test-id="luigi-client-api-test-compound-01"]';
walmazacn marked this conversation as resolved.
Show resolved Hide resolved
let stub;

beforeEach(() => {
cy.visit('http://localhost:8080/compound/compoundClientAPI.html');
stub = cy.stub();
});

it('LuigiClient API getUserSettings for LuigiCompoundContainer', () => {
const stub = cy.stub();
cy.on('window:alert', stub);
cy.get('[data-test-id="luigi-client-api-test-compound-01"]')

cy.get(container)
.shadow()
.contains('getUserSettings')
.click()
.then(() => {
expect(stub.getCall(0)).to.be.calledWith('LuigiClient.getUserSettings()={"language":"it","date":""}');
});
});

it('LuigiClient API getAnchor for LuigiCompoundContainer', () => {
const stub = cy.stub();
cy.on('window:alert', stub);
cy.get('[data-test-id="luigi-client-api-test-compound-01"]')

cy.get(container)
.shadow()
.contains('getAnchor')
.click()
Expand Down
40 changes: 34 additions & 6 deletions container/cypress/e2e/test-app/iframe/iframe-container.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
describe('Iframe Container Test', () => {
it('navigation sent', () => {
const container = '[data-test-id="iframe-based-container-test"]';
let stub;

beforeEach(() => {
cy.visit('http://localhost:8080/iframe/iframeContainer.html');
stub = cy.stub();
});

cy.get('[data-test-id="iframe-based-container-test"]')
it('navigation sent', () => {
cy.get(container)
.shadow()
.get('iframe')
.then(iframe => {
Expand All @@ -18,12 +24,9 @@ describe('Iframe Container Test', () => {
});

it('custom message sent', () => {
const stub = cy.stub();
cy.on('window:alert', stub);

cy.visit('http://localhost:8080/iframe/iframeContainer.html');

cy.get('[data-test-id="iframe-based-container-test"]')
cy.get(container)
.shadow()
.get('iframe')
.then(iframe => {
Expand All @@ -39,4 +42,29 @@ describe('Iframe Container Test', () => {
});
});
});

it('updateContext', () => {
cy.on('window:alert', stub);

cy.get('#update-ctx')
.click()
.then(() => {
cy.get(container)
.shadow()
.get('iframe')
.then(iframe => {
const $body = iframe.contents().find('body');

cy.wrap($body)
.contains('Get Context')
.click()
.then(() => {
cy.wrap(stub).should(
'have.been.calledWith',
'Custom message recieved: {"id":"my.contextMessage","_metaData":{},"data":{"myContext":"some context data"}}'
);
});
});
});
});
});
39 changes: 27 additions & 12 deletions container/cypress/e2e/test-app/wc/wc-container.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe('Web Container Test', () => {
describe('LuigiClient API LuigiContainer', () => {
const container = '[data-test-id="luigi-client-api-test-01"]';
let stub;

beforeEach(() => {
cy.visit('http://localhost:8080/wc/clientAPI.html');
stub = cy.stub();
Expand All @@ -9,7 +11,7 @@ describe('Web Container Test', () => {
it('getCurrentLocale, getActiveFeatureToggles, getCurrentTheme', () => {
cy.on('window:alert', stub);

cy.get('[data-test-id="luigi-client-api-test-01"]')
cy.get(container)
.shadow()
.contains('Click me')
.click()
Expand All @@ -21,11 +23,9 @@ describe('Web Container Test', () => {
});

it('getCoreSearchParams', () => {
const stub = cy.stub();

cy.on('window:alert', stub);

cy.get('[data-test-id="luigi-client-api-test-01"]')
cy.get(container)
.shadow()
.contains('getCoreSearchParams')
.click()
Expand All @@ -35,10 +35,9 @@ describe('Web Container Test', () => {
});

it('getPathParams', () => {
const stub = cy.stub();
cy.on('window:alert', stub);

cy.get('[data-test-id="luigi-client-api-test-01"]')
cy.get(container)
.shadow()
.contains('getPathParams')
.click()
Expand All @@ -48,9 +47,9 @@ describe('Web Container Test', () => {
});

it('getClientPermissions', () => {
const stub = cy.stub();
cy.on('window:alert', stub);
cy.get('[data-test-id="luigi-client-api-test-01"]')

cy.get(container)
.shadow()
.contains('getClientPermissions')
.click()
Expand All @@ -60,10 +59,9 @@ describe('Web Container Test', () => {
});

it('LuigiClient API getUserSettings for LuigiContainer', () => {
const stub = cy.stub();
cy.on('window:alert', stub);

cy.get('[data-test-id="luigi-client-api-test-01"]')
cy.get(container)
.shadow()
.contains('getUserSettings')
.click()
Expand All @@ -73,17 +71,17 @@ describe('Web Container Test', () => {
});

it('LuigiClient API getAnchor for LuigiContainer', () => {
const stub = cy.stub();
cy.on('window:alert', stub);

cy.get('[data-test-id="luigi-client-api-test-01"]')
cy.get(container)
.shadow()
.contains('getAnchor')
.click()
.then(() => {
expect(stub.getCall(0)).to.be.calledWith('LuigiClient.getAnchor()="testanchor"');
});
});

it('LuigiClient API getCurrentRoute for LuigiContainer', () => {
const stub = cy.stub();
cy.on('window:alert', stub);
Expand All @@ -95,5 +93,22 @@ describe('Web Container Test', () => {
expect(stub.getCall(0)).to.be.calledWith('current route: /wc/clientAPI.html');
});
});

it('updateContext', () => {
cy.on('window:alert', stub);

cy.wait(500);
cy.get('#luigi-update-context')
.click()
.then(() => {
cy.get(container)
.shadow()
.contains('updateContext')
.click()
.then(() => {
expect(stub.getCall(0)).to.be.calledWith('WC.ctx={"newContextData":"some data"}');
});
});
});
});
});
2 changes: 1 addition & 1 deletion container/src/LuigiCompoundContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
anchor &&
dirtyStatus &&
hasBack &&
documentTitle &&
documentTitle &&
noShadow
);
};
Expand Down
2 changes: 1 addition & 1 deletion container/test-app/compound/compoundClientAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ <h3>
console.log('params', params);
});
compoundContainer.addEventListener(MFEventID.SET_ANCHOR_LINK_REQUEST, event => {
console.log('anhor', event.detail);
console.log('anchor', event.detail);
});

// uxManager(). closeUserSettings openUserSettings collapseLeftSideNav
Expand Down
8 changes: 8 additions & 0 deletions container/test-app/compound/helloWorldWC.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
export default class extends HTMLElement {
constructor() {
super();

this.ctx = {};

const template = document.createElement('template');
template.innerHTML = `<section><p>Hello World!</p></section>`;

Expand Down Expand Up @@ -262,7 +265,12 @@ export default class extends HTMLElement {
});
}

get context() {
return this.ctx;
}

set context(ctx) {
this.ctx = ctx;
this.$paragraph.innerHTML = ctx.title;
}
}
7 changes: 4 additions & 3 deletions container/test-app/iframe/microfrontend.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ <h1 id="title">Multi purpose demo page</h1>
}

function testGetContext() {
alert(
'LuigiClient.getContext()() called' + JSON.stringify(LuigiClient.getContext())
);
LuigiClient.sendCustomMessage({
id: 'my.contextMessage',
...LuigiClient.getContext()
});
}

function testSetCurrentLocale() {
Expand Down
11 changes: 10 additions & 1 deletion container/test-app/wc/clientAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ <h3>
This page is used to test Container Luigi CLient API functionalities for web
component based microfrontend
</h3>
<button id="luigi-update-context" type="button">Update context</button>

<div style="height: fit-content; border:solid 1px blue">
<luigi-container
data-test-id="luigi-client-api-test-01"
Expand Down Expand Up @@ -79,7 +81,7 @@ <h3>
console.log('params', params);
});
luigiContainer.addEventListener(MFEventID.SET_ANCHOR_LINK_REQUEST, event => {
console.log('anhor', event.detail);
console.log('anchor', event.detail);
});

// uxManager(). closeUserSettings openUserSettings collapseLeftSideNav
Expand Down Expand Up @@ -124,6 +126,13 @@ <h3>
event.callback(window.location.pathname);
});
});

// update container context
document.querySelector('#luigi-update-context').addEventListener('click', () => {
document
.querySelector('[data-test-id="luigi-client-api-test-01"]')
.updateContext({ newContextData: 'some data' });
});
</script>
</body>
</html>
32 changes: 29 additions & 3 deletions container/test-app/wc/helloWorldWC.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
export default class extends HTMLElement {
constructor() {
super();

this.ctx = {};

const template = document.createElement('template');
template.innerHTML = `<section><p>Hello World!</p></section>`;

Expand Down Expand Up @@ -46,6 +49,9 @@ export default class extends HTMLElement {
const getDirtyStatusBtn = document.createElement('template');
getDirtyStatusBtn.innerHTML = '<button id="getDirtyStatus">getDirtyStatus</button>';

const updateContextBtn = document.createElement('template');
updateContextBtn.innerHTML = '<button id="updateContext">updateContext</button>';

const getCurrentRouteBtn = document.createElement('template');
getCurrentRouteBtn.innerHTML = '<button id="getCurrentRoute">getCurrentRoute</button>';

Expand Down Expand Up @@ -95,6 +101,7 @@ export default class extends HTMLElement {
this._shadowRoot.appendChild(getUserSettingsBtn.content.cloneNode(true));
this._shadowRoot.appendChild(getAnchorBtn.content.cloneNode(true));
this._shadowRoot.appendChild(getDirtyStatusBtn.content.cloneNode(true));
this._shadowRoot.appendChild(updateContextBtn.content.cloneNode(true));
this._shadowRoot.appendChild(uxManagerMultipleRequestsBtn.content.cloneNode(true));
this._shadowRoot.appendChild(linkManagerChainedFunctionsRequestsBtn.content.cloneNode(true));
this._shadowRoot.appendChild(linkManagerOpenAsRequestsBtn.content.cloneNode(true));
Expand Down Expand Up @@ -204,6 +211,14 @@ export default class extends HTMLElement {
});
});

this.$updateContextBtn = this._shadowRoot.querySelector('#updateContext');
this.$updateContextBtn.addEventListener('click', () => {
this.LuigiClient.uxManager().showAlert({
text: `WC.ctx=${JSON.stringify(this.ctx)}`,
type: 'info'
});
});

this.$uxManagerManyRequests = this._shadowRoot.querySelector('#uxManagerManyRequests');
this.$uxManagerManyRequests.addEventListener('click', () => {
this.LuigiClient.uxManager().closeUserSettings();
Expand Down Expand Up @@ -236,9 +251,15 @@ export default class extends HTMLElement {

this.$linkManagerOpenAsRequests = this._shadowRoot.querySelector('#linkManagerOpenAsRequests');
this.$linkManagerOpenAsRequests.addEventListener('click', () => {
this.LuigiClient.linkManager().openAsDrawer('hello-world-wc', { size: 's' });
this.LuigiClient.linkManager().openAsModal('hello-world-wc', { size: 'm' });
this.LuigiClient.linkManager().openAsSplitView('hello-world-wc', { size: 'l' });
this.LuigiClient.linkManager().openAsDrawer('hello-world-wc', {
size: 's'
});
this.LuigiClient.linkManager().openAsModal('hello-world-wc', {
size: 'm'
});
this.LuigiClient.linkManager().openAsSplitView('hello-world-wc', {
size: 'l'
});
});

this.$linkManagerUpdateTopPathExistsBack = this._shadowRoot.querySelector('#linkManagerUpdateTopPathExistsBack');
Expand Down Expand Up @@ -276,7 +297,12 @@ export default class extends HTMLElement {
});
}

get context() {
return this.ctx;
}

set context(ctx) {
this.ctx = ctx;
this.$paragraph.innerHTML = ctx.title;
}
}