Skip to content

Commit

Permalink
Merge branch 'main' into 3791-switch-client-code-from-js-to-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
walmazacn authored Aug 9, 2024
2 parents 02f8f90 + a902c03 commit fe88774
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 42 deletions.
23 changes: 1 addition & 22 deletions container/cypress/e2e/test-app/iframe/iframe-container.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,13 @@ 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', () => {
cy.on('window:alert', stub);

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

cy.get('button[id="update-token"]').click();

cy.get('[data-test-id="iframe-based-container-test"]')
cy.get(containerSelector)
.shadow()
.get('iframe')
.then(iframe => {
Expand Down
53 changes: 53 additions & 0 deletions container/cypress/e2e/test-app/iframe/iframe-settings.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
describe('Iframe Container Test', () => {
let stub;

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

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 sandbox rules by property', () => {
cy.get('#init-button').click();
cy.get('button[id="sandbox-rules"]').click();

cy.get('#defer-init-test')
.shadow()
.get('iframe')
.then(elements => {
cy.get(elements.first())
.invoke('attr', 'sandbox')
.should('eq', 'allow-modals allow-popups');
});
});

it('set sandbox rules by attribute', () => {
cy.get('#sandbox-rules-test')
.shadow()
.get('iframe')
.then(elements => {
cy.get(elements.last())
.invoke('attr', 'sandbox')
.should('eq', 'allow-scripts allow-same-origin');
});
});
});
2 changes: 1 addition & 1 deletion container/test-app/compound/compoundClientAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<body>
<h3>
This page is used to test Compound-Container Luigi CLient API functionalities for
web component based microfrontend
compound web component based microfrontend
</h3>
<button id="luigi-update-context" type="button">Update context</button>

Expand Down
51 changes: 51 additions & 0 deletions container/test-app/iframe/iframe-settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<html>
<head>
<script type="module">
import '../bundle.js';
</script>
</head>
<body>
<h3>
This page is used to test Container Luigi CLient API functionalities for web
component based microfrontend
</h3>
<button id="init-button">container.init() defer-init enabled</button>
<button id="sandbox-rules">Set sandboxRules</button>

<!-- Luigi Container to test defer-init flag-->
<div style="border: solid 1px red; height: 100px">
<luigi-container
id="defer-init-test"
data-test-id="defer-init-container"
viewURL="./microfrontend-defer-init.html"
defer-init="true"
></luigi-container>
</div>

<!-- Luigi Container to test sandbox rules -->
<div style="border: solid 1px red; height: 100px">
<luigi-container
id="sandbox-rules-test"
viewURL="./microfrontend-sandbox-rules.html"
sandbox-rules='["allow-scripts", "allow-same-origin"]'
></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 sandboxRulesButton = document.getElementById('sandbox-rules');

sandboxRulesButton.addEventListener('click', () => {
deferInitContainer.sandboxRules = ['allow-modals', 'allow-popups'];
});
</script>
</body>
</html>
22 changes: 5 additions & 17 deletions container/test-app/iframe/iframeContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
</head>
<body>
<h3>
This page is used to test Container Luigi CLient API functionalities for web
component based microfrontend
This page is used to test Container Luigi CLient API functionalities for iframe
based microfrontend
</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; height: 400px">
Expand All @@ -22,25 +21,14 @@ <h3>
context='{"title": "Projects", "content":" "}'
auth-data='{ "accessToken": "my-token" }'
></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');
const luigiContainer = document.querySelector(
'[data-test-id="iframe-based-container-test"]'
);
luigiContainer.addEventListener(Events.NAVIGATION_REQUEST, event => {
console.log(event.detail);
window.location.hash = event.detail.link;
Expand Down
14 changes: 14 additions & 0 deletions container/test-app/iframe/microfrontend-sandbox-rules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- This microfrontend HTML file is used to test sandbox rules functionality -->
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8" />
</head>

<body style="border: solid blue 2px;">
<div>
<h1>sandbox rules test for iframes</h1>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions container/test-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ <h1>Container Test-App</h1>
</tr>
<tr>
<td><a href="#">-</a></td>
<td><a href="#">-</a></td>
<td><a href="compound/nested.html">Nested </a></td>
<td><a href="iframe/iframe-settings.html">iFrame Settings</a></td>
<td><a href="compound/nested.html">Nested</a></td>
</tr>
<!-- Add more rows as needed -->
</tbody>
Expand Down

0 comments on commit fe88774

Please sign in to comment.