The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
const { H } = cy;
import {
ORDERS_DASHBOARD_ID,
ORDERS_QUESTION_ID,
} from "e2e/support/cypress_sample_instance_data";
import { IFRAME_CODE, getEmbeddingJsCode } from "./shared/embedding-snippets";
const tokens = ["starter", "pro-self-hosted"];
function codeBlock() {
return cy.get(".cm-content");
}
function highlightedTexts() {
return cy.findAllByTestId("highlighted-text");
}
tokens.forEach((token) => {
describe(`[plans=${token}] scenarios > embedding > code snippets`, () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
H.activateToken(token);
});
it("dashboard and question should have the correct embed snippets", () => {
const defaultDownloadsValue =
token === "pro-self-hosted" ? true : undefined;
cy.log("Dashboard");
H.visitDashboard(ORDERS_DASHBOARD_ID);
H.openLegacyStaticEmbeddingModal({
resource: "dashboard",
resourceId: ORDERS_DASHBOARD_ID,
});
H.modal().within(() => {
cy.findByText(
"To embed this dashboard in your application you’ll just need to publish it, and paste these code snippets in the proper places in your app.",
);
cy.findByText(
"Insert this code snippet in your server code to generate the signed embedding URL",
);
codeBlock()
.first()
.invoke("text")
.should(
"match",
getEmbeddingJsCode({
type: "dashboard",
id: ORDERS_DASHBOARD_ID,
downloads: defaultDownloadsValue,
}),
);
cy.findAllByTestId("embed-backend-select-button")
.should("have.value", "Node.js")
.click();
});
H.selectDropdown()
.should("contain", "Node.js")
.and("contain", "Ruby")
.and("contain", "Python")
.and("contain", "Clojure");
// eslint-disable-next-line metabase/no-unsafe-element-filtering
codeBlock().last().should("have.text", IFRAME_CODE);
H.modal()
.findAllByTestId("embed-frontend-select-button")
.should("have.value", "Pug / Jade")
.click();
H.selectDropdown()
.should("contain", "Mustache")
.and("contain", "Pug / Jade")
.and("contain", "ERB")
.and("contain", "JSX");
H.modal().within(() => {
cy.findByRole("tab", { name: "Look and Feel" }).click();
// set transparent background metabase#23477
cy.findByLabelText("Dashboard background").click();
codeBlock()
.first()
.invoke("text")
.should(
"match",
getEmbeddingJsCode({
type: "dashboard",
id: ORDERS_DASHBOARD_ID,
background: false,
downloads: defaultDownloadsValue,
}),
);
if (token === "pro-self-hosted") {
// Disable both download options
cy.findByLabelText("Export to PDF").click();
cy.findByLabelText("Results (csv, xlsx, json, png)").click();
codeBlock()
.first()
.invoke("text")
.should(
"match",
getEmbeddingJsCode({
type: "dashboard",
id: ORDERS_DASHBOARD_ID,
background: false,
downloads: false,
}),
);
// Verify that switching tabs keeps the highlighted texts
highlightedTexts().should("have.length", 1);
cy.findByRole("tab", { name: "Parameters" }).click();
cy.findByRole("tab", { name: "Look and Feel" }).click();
highlightedTexts().should("have.length", 1);
}
});
cy.log("Question");
H.visitQuestion(ORDERS_QUESTION_ID);
H.openLegacyStaticEmbeddingModal({
resource: "question",
resourceId: ORDERS_QUESTION_ID,
});
H.modal().within(() => {
cy.findByText(
"To embed this question in your application you’ll just need to publish it, and paste these code snippets in the proper places in your app.",
);
cy.findByText(
"Insert this code snippet in your server code to generate the signed embedding URL",
);
codeBlock()
.first()
.invoke("text")
.should(
"match",
getEmbeddingJsCode({
type: "question",
id: ORDERS_QUESTION_ID,
downloads: defaultDownloadsValue,
}),
);
cy.findByRole("tab", { name: "Look and Feel" }).click();
// hide download button for pro/enterprise users metabase#23477
if (token === "pro-self-hosted") {
cy.findByLabelText("Download (csv, xlsx, json, png)").click();
codeBlock()
.first()
.invoke("text")
.should(
"match",
getEmbeddingJsCode({
type: "question",
id: ORDERS_QUESTION_ID,
downloads: false,
}),
);
}
cy.findByTestId("embed-backend-select-button")
.should("have.value", "Node.js")
.click();
});
H.selectDropdown()
.should("contain", "Node.js")
.and("contain", "Ruby")
.and("contain", "Python")
.and("contain", "Clojure");
if (token === "pro-self-hosted") {
// Verify that switching tabs keeps the highlighted texts
highlightedTexts().should("have.length", 1);
cy.findByRole("tab", { name: "Parameters" }).click();
cy.findByRole("tab", { name: "Look and Feel" }).click();
highlightedTexts().should("have.length", 1);
}
});
});
});