Skip to content
Snippets Groups Projects
Unverified Commit b3c72d9c authored by Mahatthana (Kelvin) Nomsawadi's avatar Mahatthana (Kelvin) Nomsawadi Committed by GitHub
Browse files

Fix iframe resizer not working (#47115)

parent 6a5faa8b
Branches
Tags
No related merge requests found
......@@ -107,18 +107,24 @@ export function visitEmbeddedPage(
}
}
export function getIframeUrl() {
modal().findByText("Preview").click();
return cy.document().then(doc => {
const iframe = doc.querySelector("iframe");
return iframe.src;
});
}
/**
* Grab an iframe `src` via UI and open it,
* but make sure user is signed out.
*/
export function visitIframe() {
modal().findByText("Preview").click();
cy.document().then(doc => {
const iframe = doc.querySelector("iframe");
getIframeUrl().then(iframeUrl => {
cy.signOut();
cy.visit(iframe.src);
cy.visit(iframeUrl);
});
}
......
......@@ -13,6 +13,7 @@ import {
filterWidget,
getDashboardCard,
getIframeBody,
getIframeUrl,
getRequiredToggle,
goToTab,
modal,
......@@ -884,6 +885,60 @@ describeEE("scenarios > embedding > dashboard appearance", () => {
cy.get("@previewEmbedSpy").should("have.callCount", 1);
});
});
it("should resize iframe to dashboard content size (metabase#47061)", () => {
const dashboardDetails = {
name: "dashboard name",
enable_embedding: true,
};
const questionDetails = {
name: "Orders",
query: {
"source-table": ORDERS_ID,
},
};
createQuestion(questionDetails)
.then(({ body: { id: card_id } }) => {
createDashboardWithTabs({
...dashboardDetails,
dashcards: [
{
id: -1,
card_id,
row: 0,
col: 0,
size_x: 8,
size_y: 20,
},
],
});
})
.then(dashboard => {
visitDashboard(dashboard.id);
});
openStaticEmbeddingModal({
activeTab: "parameters",
previewMode: "preview",
// EE users don't have to accept terms
acceptTerms: false,
});
getIframeUrl().then(iframeUrl => {
Cypress.config("baseUrl", null);
cy.visit(
`e2e/test/scenarios/embedding/embedding-dashboard.html?iframeUrl=${iframeUrl}`,
);
});
getIframeBody().findByText("Rows 1-21 of first 2000").should("exist");
cy.get("#iframe").then($iframe => {
const [iframe] = $iframe;
expect(iframe.clientHeight).to.be.greaterThan(1000);
});
});
});
function openFilterOptions(name) {
......
<script src="http://localhost:4000/app/iframeResizer.js"></script>
<iframe
id="iframe"
onload="iFrameResize({checkOrigin: false}, this)"
style="width: 100%; border: 0"
></iframe>
<script>
document.getElementById("iframe").src = new URLSearchParams(
location.search,
).get("iframeUrl");
</script>
......@@ -495,23 +495,10 @@ export function initializeIframeResizer(onReady = () => {}) {
onReady,
};
// FIXME: Crimes
// This is needed so the FE test framework which runs in node
// without the avaliability of require.ensure skips over this part
// which is for external purposes only.
//
// Ideally that should happen in the test config, but it doesn't
// seem to want to play nice when messing with require
if (typeof require.ensure !== "function") {
return false;
}
// Make iframe-resizer avaliable to the embed
// We only care about contentWindow so require that minified file
require.ensure([], require => {
require("iframe-resizer/js/iframeResizer.contentWindow.js");
});
import("iframe-resizer/js/iframeResizer.contentWindow.js");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment