Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

5.6 KB
Raw Blame
import {
  FIRST_COLLECTION_ID,
  ORDERS_DASHBOARD_ID,
} from "e2e/support/cypress_sample_instance_data";

const { H } = cy;

describe("OSS", { tags: "@OSS" }, () => {
  describe("scenarios > embedding > Modular embedding (ex EAJS)", () => {
    beforeEach(() => {
      H.prepareSdkIframeEmbedTest({
        withToken: false,
        enabledAuthMethods: ["api-key"],
      });
      H.setupSMTP();
      cy.signOut();
    });

    describe("dashboards", () => {
      it("should not render a subscription button even with `with-subscriptions=true`", () => {
        cy.get<string>("@apiKey").then((apiKey) => {
          const frame = H.loadSdkIframeEmbedTestPage({
            elements: [
              {
                component: "metabase-dashboard",
                attributes: {
                  dashboardId: ORDERS_DASHBOARD_ID,
                  withSubscriptions: true,
                },
              },
            ],
            metabaseConfig: { apiKey },
          });

          frame.within(() => {
            cy.findByRole("button", { name: "Subscriptions" }).should(
              "not.exist",
            );
          });
        });
      });
    });
  });
});

describe("EE without license", () => {
  describe("scenarios > embedding > Modular embedding (EAJS)", () => {
    beforeEach(() => {
      H.prepareSdkIframeEmbedTest({
        withToken: "starter",
        enabledAuthMethods: ["api-key"],
      });
      H.setupSMTP();
      cy.signOut();
    });

    describe("dashboards", () => {
      it("should not render a subscription button even with `with-subscriptions=true`", () => {
        cy.get<string>("@apiKey").then((apiKey) => {
          const frame = H.loadSdkIframeEmbedTestPage({
            elements: [
              {
                component: "metabase-dashboard",
                attributes: {
                  dashboardId: ORDERS_DASHBOARD_ID,
                  withSubscriptions: true,
                },
              },
            ],
            metabaseConfig: { apiKey },
          });

          frame.within(() => {
            cy.findByRole("button", { name: "Subscriptions" }).should(
              "not.exist",
            );
          });
        });
      });
    });
  });
});

describe("EE", () => {
  describe("scenarios > embedding > Modular embedding (EAJS)", () => {
    beforeEach(() => {
      H.prepareSdkIframeEmbedTest({ withToken: "bleeding-edge" });
      H.setupSMTP();
      cy.signOut();
    });

    describe("dashboards", () => {
      it("should render a subscription button with `with-subscriptions=true`", () => {
        const frame = H.loadSdkIframeEmbedTestPage({
          elements: [
            {
              component: "metabase-dashboard",
              attributes: {
                dashboardId: ORDERS_DASHBOARD_ID,
                withSubscriptions: true,
              },
            },
          ],
        });

        frame.within(() => {
          cy.findByRole("button", { name: "Subscriptions" })
            .should("be.visible")
            .click();
          dashboardSidebar().within(() => {
            cy.log("set up the first subscription");
            cy.findByRole("button", { name: "Done" }).click();

            cy.log("set up the second subscription");
            cy.button("Set up a new schedule").click();
            cy.findByTestId("select-frequency").click();
          });

          H.popover().findByRole("option", { name: "daily" }).click();
          H.selectScheduleTime();
          cy.findByRole("button", { name: "Done" }).click();

          dashboardSidebar().within(() => {
            // Header
            cy.findByText("Subscriptions").should("be.visible");

            // Subscription list
            cy.findAllByText("Bobby Tables").should("have.length", 2);
            cy.findByText("Emailed hourly").should("be.visible");
            cy.findByText("Emailed daily at 8:00 AM").should("be.visible");
          });
        });
      });
    });
  });
});

function dashboardSidebar() {
  return cy.findByRole("complementary");
}

describe("scenarios > embedding > sdk iframe embed options passthrough", () => {
  beforeEach(() => {
    H.prepareSdkIframeEmbedTest();
  });

  it("renders the exploration template with isSaveEnabled=true, targetCollection, entityTypes", () => {
    const frame = H.loadSdkIframeEmbedTestPage({
      elements: [
        {
          component: "metabase-question",
          attributes: {
            questionId: "new",
            isSaveEnabled: true,
            targetCollection: FIRST_COLLECTION_ID,
            entityTypes: ["table"],
          },
        },
      ],
    });

    frame.within(() => {
      cy.findByText("Pick your starting data").should("be.visible");
      H.popover().findByText("Orders").click();

      // if we don't limit this query, layout shifts can push the first row out of the viewport
      cy.icon("list").click();
      cy.findByPlaceholderText("Enter a limit").type("5").blur({ force: true }); // blur hack
      H.visualize();

      cy.log("1. clicking on the filter should drill down");
      cy.findByText("37.65").should("be.visible").click();
      H.popover().within(() => {
        cy.findByText(/Filter by this value/).should("be.visible");
        cy.button("<").click();
      });
      cy.findAllByText("29.8").first().should("be.visible");
      cy.findByTestId("interactive-question-result-toolbar").should(
        "be.visible",
      );

      cy.log("2. saving should be enabled");
      cy.findByText("Save").click();

      cy.log(
        "3. we should not see the collection picker as we have a target collection",
      );
      cy.findByText("Where do you want to save this?").should("not.exist");
    });
  });
});