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 @@