From 5c35260232c0eec5acd0e1c6c38a2f8ad5bb5743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Tomoaki=20=C3=96ller?= <85555471+VincentUllal@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:45:21 +0200 Subject: [PATCH] Add defer init flag container test (#3792) --- .../compound/wc-compound-container.cy.js | 8 +++ .../test-app/iframe/iframe-container.cy.js | 28 +++++++-- .../e2e/test-app/wc/wc-container.cy.js | 10 +++ .../test-app/compound/compoundClientAPI.html | 38 ++++++++++++ .../defer-init-wc/compoundWCDeferInit1.js | 17 ++++++ .../defer-init-wc/compoundWCDeferInit2.js | 13 ++++ .../test-app/iframe/iframeContainer.html | 20 +++++- .../iframe/microfrontend-defer-init.html | 14 +++++ container/test-app/iframe/microfrontend.html | 6 +- container/test-app/wc/clientAPI.html | 61 +++++++++++++------ container/test-app/wc/myWebComponent.js | 17 ++++++ 11 files changed, 202 insertions(+), 30 deletions(-) create mode 100644 container/test-app/compound/defer-init-wc/compoundWCDeferInit1.js create mode 100644 container/test-app/compound/defer-init-wc/compoundWCDeferInit2.js create mode 100644 container/test-app/iframe/microfrontend-defer-init.html create mode 100644 container/test-app/wc/myWebComponent.js 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 f273fa7e7e..958f9af56e 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 @@ -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'); + }); }); }); diff --git a/container/cypress/e2e/test-app/iframe/iframe-container.cy.js b/container/cypress/e2e/test-app/iframe/iframe-container.cy.js index 74724c4ef6..1690e98b65 100644 --- a/container/cypress/e2e/test-app/iframe/iframe-container.cy.js +++ b/container/cypress/e2e/test-app/iframe/iframe-container.cy.js @@ -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') @@ -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') @@ -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); @@ -64,4 +84,4 @@ describe('Iframe Container Test', () => { }); }); }); -}); +}); \ No newline at end of file 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 47aaf81bd5..41b1b25147 100644 --- a/container/cypress/e2e/test-app/wc/wc-container.cy.js +++ b/container/cypress/e2e/test-app/wc/wc-container.cy.js @@ -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); diff --git a/container/test-app/compound/compoundClientAPI.html b/container/test-app/compound/compoundClientAPI.html index 5dad9b3eec..8f0c13a777 100644 --- a/container/test-app/compound/compoundClientAPI.html +++ b/container/test-app/compound/compoundClientAPI.html @@ -18,6 +18,8 @@

This page is used to test Compound-Container Luigi CLient API functionalities for web component based microfrontend

+ + Below is a compound container example for testing functionality
defer-init="false" webcomponent="true" > +
+ + + +
+
@@ -204,6 +219,29 @@

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' + } + ] + }; diff --git a/container/test-app/compound/defer-init-wc/compoundWCDeferInit1.js b/container/test-app/compound/defer-init-wc/compoundWCDeferInit1.js new file mode 100644 index 0000000000..475af7ab20 --- /dev/null +++ b/container/test-app/compound/defer-init-wc/compoundWCDeferInit1.js @@ -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 = `

Hello From Web Component 1

`; + shadowRoot.appendChild(template.content.cloneNode(true)); + this.$paragraph = shadowRoot.getElementById('defer-init-flag'); + } + + set context(ctx) { + this.$paragraph.innerHTML += ctx.content; + } +} diff --git a/container/test-app/compound/defer-init-wc/compoundWCDeferInit2.js b/container/test-app/compound/defer-init-wc/compoundWCDeferInit2.js new file mode 100644 index 0000000000..fcc3380f12 --- /dev/null +++ b/container/test-app/compound/defer-init-wc/compoundWCDeferInit2.js @@ -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 = `

Hello From Web Component 2

`; + shadowRoot.appendChild(template.content.cloneNode(true)); + this.$paragraph = shadowRoot.getElementById('paragraph'); + } +} diff --git a/container/test-app/iframe/iframeContainer.html b/container/test-app/iframe/iframeContainer.html index f3e252cdfc..8fcf7cb6ad 100644 --- a/container/test-app/iframe/iframeContainer.html +++ b/container/test-app/iframe/iframeContainer.html @@ -11,20 +11,34 @@

+ -
+
+ - + > + + +