Skip to content

Commit

Permalink
Add defer init flag container test (#3792)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentUllal authored Jul 8, 2024
1 parent 061b9fe commit 5c35260
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ describe('Compound Container Tests', () => {
expect(stub.getCall(0)).to.be.calledWith('LuigiClient.getAnchor()="testAnchorCompound"');
});
});
it('defer-init flag for LuigiCompoundContainer', () => {
// the initialized webcomponent has id="defer-init-flag"
cy.get('#defer-init-flag').should('not.exist');
// click button that calls container.init()
cy.get('#init-button').click();

cy.get('#defer-init-flag').should('exist');
});
});
});
28 changes: 24 additions & 4 deletions container/cypress/e2e/test-app/iframe/iframe-container.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
describe('Iframe Container Test', () => {
it('navigation sent', () => {
beforeEach(() => {
cy.visit('http://localhost:8080/iframe/iframeContainer.html');
});

it('navigation sent', () => {
cy.get('[data-test-id="iframe-based-container-test"]')
.shadow()
.get('iframe')
Expand All @@ -21,8 +23,6 @@ describe('Iframe Container Test', () => {
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"]')
.shadow()
.get('iframe')
Expand All @@ -40,6 +40,26 @@ describe('Iframe Container Test', () => {
});
});

it('defer-init flag for iframe container', () => {
cy.get('#defer-init-test').then(iframe => {
const $body = iframe.contents().find('main');
expect($body.children()).to.have.length(0);

// click button that calls container.init()
cy.get('#init-button').click();

cy.get('#defer-init-test')
.shadow()
.get('iframe')
.then(iframe => {
const $body = iframe.contents().find('body');
cy.wrap($body)
.contains('defer-init test for iframes')
.should('exist');
});
});
});

it('set auth token', () => {
const stub = cy.stub();
cy.on('window:alert', stub);
Expand All @@ -64,4 +84,4 @@ describe('Iframe Container Test', () => {
});
});
});
});
});
10 changes: 10 additions & 0 deletions container/cypress/e2e/test-app/wc/wc-container.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ describe('Web Container Test', () => {
expect(stub.getCall(0)).to.be.calledWith('LuigiClient.getAnchor()="testanchor"');
});
});

it('defer-init flag for webcomponent container', () => {
// the initialized webcomponent has id="defer-init-flag"
cy.get('#defer-init-flag').should('not.exist');
// click button that calls container.init()
cy.get('#init-button').click();

cy.get('#defer-init-flag').should('exist');
});

it('LuigiClient API getCurrentRoute for LuigiContainer', () => {
const stub = cy.stub();
cy.on('window:alert', stub);
Expand Down
38 changes: 38 additions & 0 deletions container/test-app/compound/compoundClientAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ <h3>
This page is used to test Compound-Container Luigi CLient API functionalities for
web component based microfrontend
</h3>
<!-- base scenario compound container-->
<span>Below is a compound container example for testing functionality</span>
<div style="border:solid 1px blue">
<luigi-compound-container
data-test-id="luigi-client-api-test-compound-01"
Expand All @@ -32,6 +34,19 @@ <h3>
defer-init="false"
webcomponent="true"
></luigi-compound-container>
</div>

<!-- defer-init scenario wc container-->
<button id="init-button" style="margin: 25px 0 10px;">
container.init() - click to initialize defered compound wc
</button>
<div style="border:solid 1px red; height: 100px;">
<luigi-compound-container
id="defer-init-test"
webcomponent="true"
context='{"content":" -- defer-init test --"}'
defer-init="true"
></luigi-compound-container>

<!-- Used for testing dynamic compound container creation -->
<div class="content"></div>
Expand Down Expand Up @@ -204,6 +219,29 @@ <h3>
compoundContainer.addEventListener(MFEventID.SET_VIEW_GROUP_DATA_REQUEST, event => {
console.log('Set View Group Data Request received', event.detail, event);
});

const deferInitContainer = document.getElementById('defer-init-test');
const initButton = document.getElementById('init-button');
initButton.addEventListener('click', function() {
deferInitContainer.init();
});
deferInitContainer.compoundConfig = {
renderer: {
use: 'grid',
config: {
columns: '1fr 1fr',
gap: '20px'
}
},
children: [
{
viewUrl: './compound/defer-init-wc/compoundWCDeferInit1.js'
},
{
viewUrl: './compound/defer-init-wc/compoundWCDeferInit2.js'
}
]
};
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions container/test-app/compound/defer-init-wc/compoundWCDeferInit1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This class is used to test Compound Container defer-init functionality
*/
export default class extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `<section><h3 style="border: solid blue 2px;" id="defer-init-flag"> Hello From Web Component 1 </h3></section>`;
shadowRoot.appendChild(template.content.cloneNode(true));
this.$paragraph = shadowRoot.getElementById('defer-init-flag');
}

set context(ctx) {
this.$paragraph.innerHTML += ctx.content;
}
}
13 changes: 13 additions & 0 deletions container/test-app/compound/defer-init-wc/compoundWCDeferInit2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This class is used to test Compound Container defer-init functionality
*/
export default class extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
const template = document.createElement('template');
template.innerHTML = `<section><h3 style="border: solid blue 2px;" id="paragraph"> Hello From Web Component 2 </h3></section>`;
shadowRoot.appendChild(template.content.cloneNode(true));
this.$paragraph = shadowRoot.getElementById('paragraph');
}
}
20 changes: 17 additions & 3 deletions container/test-app/iframe/iframeContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,34 @@ <h3>
</h3>
<button id="btn-1">Send Custom Message to iFrame Container</button>
<button id="update-ctx">Update Ctx</button>
<button id="init-button">container.init() defer-init enabled</button>
<button id="update-token">Update Access Token</button>

<div style="border:solid 1px blue">
<div style="border:solid 1px blue; height: 400px">
<!-- Luigi Container to test general functionality-->
<luigi-container
data-test-id="iframe-based-container-test"
viewURL="./microfrontend.html"
context='{"title": "Projects", "content":" "}'
auth-data='{ "accessToken": "my-token" }'
>
</luigi-container>
></luigi-container>

<!-- Luigi Container to test defer-init flag-->
<luigi-container
id="defer-init-test"
data-test-id="defer-init-container"
viewURL="./microfrontend-defer-init.html"
defer-init="true"
></luigi-container>
</div>

<script type="module">
import Events from '../bundle.js';
const deferInitContainer = document.getElementById("defer-init-test");
const initButton = document.getElementById("init-button");
initButton.addEventListener("click", function() {
deferInitContainer.init();
});

const luigiContainer = document.querySelector('luigi-container');
luigiContainer.addEventListener(Events.NAVIGATION_REQUEST, event => {
Expand Down
14 changes: 14 additions & 0 deletions container/test-app/iframe/microfrontend-defer-init.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- This microfrontend HTML file is used to test defer init functionality -->
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8" />
</head>

<body style="border: solid blue 2px;">
<div>
<h1>defer-init test for iframes</h1>
</div>
</body>
</html>
6 changes: 1 addition & 5 deletions container/test-app/iframe/microfrontend.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<!-- This microfrontend HTML file is used to test a variety of functionality -->
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8" />
<link
href="https://fiddle.luigi-project.io/vendor/fundamental-styles/dist/fundamental-styles.css"
rel="stylesheet"
/>
<!-- <link href="https://fiddle.luigi-project.io/styles/styles.css" rel="stylesheet" /> -->
<script src="https://fiddle.luigi-project.io/vendor/luigi-client/luigi-client.js"></script>
<style>
html,
Expand Down
61 changes: 43 additions & 18 deletions container/test-app/wc/clientAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,43 @@ <h3>
This page is used to test Container Luigi CLient API functionalities for web
component based microfrontend
</h3>
<div style="height: fit-content; border:solid 1px blue">
<luigi-container
data-test-id="luigi-client-api-test-01"
viewURL="./wc/helloWorldWC.js"
webcomponent="true"
context='{"label": "Hello World WC", "title":"Hello World WC: Testing Container Web Component Features"}'
locale="en"
theme="sap_fiori_3"
active-feature-toggle-list='["ft1","ft2"]'
node-params='{"Luigi":"rocks from attri &<strong>asdf<strong> bute"}'
search-params='{"test":"searchParam1"}'
path-params='{"path":"param"}'
client-permissions='{"permission": "testPermission"}'
user-settings='{"language": "de", "date":""}'
anchor="testanchor"
dirty-status="true"
document-title="Perfect Title"
></luigi-container>
<div style="height: fit-content;">
<div style="border: 1px solid blue">
<!-- Luigi Container to test general functionalities, params etc-->
<luigi-container
data-test-id="luigi-client-api-test-01"
viewURL="./wc/helloWorldWC.js"
webcomponent="true"
context='{"label": "Hello World WC", "title":"Hello World WC: Testing Container Web Component Features"}'
locale="en"
theme="sap_fiori_3"
active-feature-toggle-list='["ft1","ft2"]'
node-params='{"Luigi":"rocks from attri &<strong>asdf<strong> bute"}'
search-params='{"test":"searchParam1"}'
path-params='{"path":"param"}'
client-permissions='{"permission": "testPermission"}'
user-settings='{"language": "de", "date":""}'
anchor="testanchor"
dirty-status="true"
document-title="Perfect Title"
></luigi-container>
</div>

<button id="init-button" style="margin: 25px 0 15px">
container.init() to initialize defered container
</button>
<div style="border: 1px solid red">
<!-- Luigi Container to test defer-init flag-->

<luigi-container
id="defer-init-test"
data-test-id="defer-init-container"
viewURL="./wc/myWebComponent.js"
webcomponent="true"
context='{"content":" -- defer-init test --"}'
defer-init="true"
></luigi-container>
</div>

<!-- Used for testing dynamic compound container creation -->
<div class="content"></div>
Expand All @@ -40,7 +59,13 @@ <h3>
</div>

<script type="module">
import '../bundle.js';
import MFEventID from '../bundle.js';
const deferInitContainer = document.getElementById('defer-init-test');
const initButton = document.getElementById('init-button');
initButton.addEventListener('click', function() {
deferInitContainer.init();
});

[...document.querySelectorAll('luigi-container')].forEach(luigiContainer => {
luigiContainer.addEventListener(MFEventID.NAVIGATION_REQUEST, event => {
Expand Down
17 changes: 17 additions & 0 deletions container/test-app/wc/myWebComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This class is used to test container defer-init functionality
*/
export default class extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open', delegatesFocus: false });
const template = document.createElement('template');
template.innerHTML = `<section><h2 style="border: solid blue 2px;" id="defer-init-flag"> This is a webcomponent based microfrontend container </h2></section>`;
shadowRoot.appendChild(template.content.cloneNode(true));
this.$paragraph = shadowRoot.getElementById('defer-init-flag');
}

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

0 comments on commit 5c35260

Please sign in to comment.