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
Consolidate static embed parameter e2e tests (#84007)
Chris Vandoodewaard1ab558f7e7b9
diff --git a/e2e/support/helpers/e2e-embedding-helpers.js b/e2e/support/helpers/e2e-embedding-helpers.jsindex f8f8da7c65c..a3e84964ac4 100644--- a/e2e/support/helpers/e2e-embedding-helpers.js+++ b/e2e/support/helpers/e2e-embedding-helpers.js@@ -88,7 +88,13 @@ export function getEmbeddedPageUrl(payload,{setFilters = {},- additionalHashOptions: { hideFilters = [], locale, font, theme } = {},+ additionalHashOptions: {+ hideFilters = [],+ locale,+ font,+ theme,+ background,+ } = {},pageStyle = {},onBeforeLoad,qs,@@ -114,6 +120,7 @@ export function getEmbeddedPageUrl(...(locale && { locale }),...(font && { font }),...(theme && { theme }),+ ...(background !== undefined && { background }),},hiddenFilters,);diff --git a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.jsindex 3caa6795d60..f71bce08100 100644--- a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js+++ b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js@@ -1,6 +1,7 @@const { H } = cy;import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";+import { defer } from "metabase/utils/promise";import { createMockParameter } from "metabase-types/api/mocks";import { addWidgetStringFilter } from "../native/helpers/e2e-field-filter-helpers";@@ -12,7 +13,8 @@ import {questionDetailsWithDefaults,} from "./shared/embedding-dashboard";-const { ORDERS, PEOPLE, PEOPLE_ID, PRODUCTS, ORDERS_ID } = SAMPLE_DATABASE;+const { ORDERS, PEOPLE, PEOPLE_ID, PRODUCTS, PRODUCTS_ID, ORDERS_ID } =+ SAMPLE_DATABASE;describe("scenarios > embedding > static embedding dashboard", () => {beforeEach(() => {@@ -23,8 +25,28 @@ describe("scenarios > embedding > static embedding dashboard", () => {});});- it("should not call `GET /api/database` (metabase#63310)", () => {+ it("should not call `GET /api/database` and should return cache headers for the js bundle (metabase#63310, metabase#50373)", () => {cy.intercept("GET", "/api/database").as("getDatabases");+ cy.intercept(+ {+ method: "GET",+ url: /^\/app\/dist\/(.*)\.js$/,+ },+ (req) => {+ // When running in development (e.g. with `bun run dev`),+ // the *.hot.bundle.js hot-reloaded file is served by the dev server.+ if (req.url.includes("hot.bundle.js")) {+ return;+ }++ req.on("response", (res) => {+ expect(+ res.headers["cache-control"],+ `Invalid Cache-Control header for ${req.url}`,+ ).to.equal("public, max-age=31536000");+ });+ },+ );const payload = {resource: { dashboard: ORDERS_DASHBOARD_ID },params: {},@@ -37,6 +59,48 @@ describe("scenarios > embedding > static embedding dashboard", () => {cy.log("GET /api/database should not be called");cy.get("@getDatabases.all").should("have.length", 0);});++ it("static dashboard content shouldn't overflow its container (metabase#40660)", () => {+ const questionDetails = {+ name: "Products",+ query: { "source-table": PRODUCTS_ID, limit: 2 },+ };++ const dashboardDetails = {+ name: "long dashboard",+ enable_embedding: true,+ };++ H.createQuestionAndDashboard({+ questionDetails,+ dashboardDetails,+ }).then(({ body: { card_id, dashboard_id } }) => {+ H.updateDashboardCards({+ dashboard_id,+ cards: [{ card_id }, { card_id }, { card_id }],+ });++ H.visitDashboard(dashboard_id);++ H.openLegacyStaticEmbeddingModal({+ resource: "dashboard",+ resourceId: dashboard_id,+ activeTab: "parameters",+ previewMode: "preview",+ });+ });++ H.getIframeBody().within(() => {+ cy.findByText(dashboardDetails.name).should("be.visible");+ cy.findByTestId("loading-indicator").should("not.exist");+ cy.findAllByText("1018947080336").should("have.length", 3);+ cy.findByTestId("embed-frame").scrollTo("bottom");++ cy.findByRole("link", { name: "Powered by Metabase" })+ .scrollIntoView()+ .should("be.visible");+ });+ });});describe("scenarios > embedding > dashboard parameters", () => {@@ -68,6 +132,14 @@ describe("scenarios > embedding > dashboard parameters", () => {it("should be disabled by default but able to be set to editable and/or locked (metabase#20357)", () => {H.visitDashboard("@dashboardId");+ cy.log(+ "should render cursor pointer on hover over a toggle (metabase#46223)",+ );+ cy.findAllByTestId("parameter-value-widget-target")+ .first()+ .realHover()+ .should("have.css", "cursor", "pointer");+cy.get("@dashboardId").then((dashboardId) => {H.openLegacyStaticEmbeddingModal({resource: "dashboard",@@ -177,53 +249,42 @@ describe("scenarios > embedding > dashboard parameters", () => {H.visitIframe();- H.filterWidget().should("not.exist");-cy.findByTestId("scalar-value").invoke("text").should("eq", "2,500");++ H.filterWidget().should("not.exist");});- it("should only display filters mapped to cards on the selected tab", () => {+ it("should (dis)allow setting parameters as required for a published embedding", () => {+ H.visitDashboard("@dashboardId");+cy.get("@dashboardId").then((dashboardId) => {- cy.request("PUT", `/api/dashboard/${dashboardId}`, {- embedding_params: {- id: "enabled",- name: "enabled",- source: "enabled",- user_id: "enabled",- },- enable_embedding: true,+ H.openLegacyStaticEmbeddingModal({+ resource: "dashboard",+ resourceId: dashboardId,+ activeTab: "parameters",});-- const payload = {- resource: { dashboard: dashboardId },- params: {},- };-- H.visitEmbeddedPage(payload);-- // wait for the results to load- cy.contains("Test Dashboard");- cy.contains("2,500");});- H.dashboardParametersContainer().within(() => {- cy.findByText("Id").should("be.visible");- cy.findByText("Name").should("be.visible");- cy.findByText("Source").should("be.visible");- cy.findByText("User").should("be.visible");- cy.findByText("Not Used Filter").should("not.exist");+ H.setEmbeddingParameter("Name", "Editable");+ H.setEmbeddingParameter("Source", "Locked");+ H.publishChanges("dashboard", ({ request }) => {+ assert.deepEqual(request.body.embedding_params, {+ id: "disabled",+ name: "enabled",+ source: "locked",+ user_id: "disabled",+ not_used: "disabled",+ });});- H.goToTab("Tab 2");+ H.closeStaticEmbeddingModal();+ H.editDashboard();- H.dashboardParametersContainer().should("not.exist");- cy.findByTestId("embed-frame").within(() => {- cy.findByText("Id").should("not.exist");- cy.findByText("Name").should("not.exist");- cy.findByText("Source").should("not.exist");- cy.findByText("User").should("not.exist");- cy.findByText("Not Used Filter").should("not.exist");- });+ assertRequiredEnabledForName({ name: "Name", enabled: true });+ assertRequiredEnabledForName({ name: "Source", enabled: true });+ assertRequiredEnabledForName({ name: "Id", enabled: false });+ assertRequiredEnabledForName({ name: "User", enabled: false });+ assertRequiredEnabledForName({ name: "Not Used Filter", enabled: false });});it("should handle required parameters", () => {@@ -317,55 +378,10 @@ describe("scenarios > embedding > dashboard parameters", () => {.invoke("attr", "class").should("not.contain", "IsSticky");});-- it("should (dis)allow setting parameters as required for a published embedding", () => {- H.visitDashboard("@dashboardId");-- cy.get("@dashboardId").then((dashboardId) => {- H.openLegacyStaticEmbeddingModal({- resource: "dashboard",- resourceId: dashboardId,- activeTab: "parameters",- });- });-- // Set an "editable" and "locked" parameters and leave the rest "disabled"- H.setEmbeddingParameter("Name", "Editable");- H.setEmbeddingParameter("Source", "Locked");- H.publishChanges("dashboard", ({ request }) => {- assert.deepEqual(request.body.embedding_params, {- id: "disabled",- name: "enabled",- source: "locked",- user_id: "disabled",- not_used: "disabled",- });- });-- H.closeStaticEmbeddingModal();- H.editDashboard();-- // Check each parameter's required state- assertRequiredEnabledForName({ name: "Name", enabled: true });- assertRequiredEnabledForName({ name: "Source", enabled: true });- // The rest must be disabled- assertRequiredEnabledForName({ name: "Id", enabled: false });- assertRequiredEnabledForName({ name: "User", enabled: false });- assertRequiredEnabledForName({ name: "Not Used Filter", enabled: false });- });-- it("should render cursor pointer on hover over a toggle (metabase#46223)", () => {- H.visitDashboard("@dashboardId");-- cy.findAllByTestId("parameter-value-widget-target")- .first()- .realHover()- .should("have.css", "cursor", "pointer");- });});context("API", () => {- beforeEach(() => {+ it("should work for all filters", () => {cy.get("@dashboardId").then((dashboardId) => {cy.request("PUT", `/api/dashboard/${dashboardId}`, {embedding_params: {@@ -377,20 +393,74 @@ describe("scenarios > embedding > dashboard parameters", () => {enable_embedding: true,});+ cy.log(+ "should render error message when `params` is not an object (metabase#14474)",+ );+ const invalidParamsValue = [];+ H.visitEmbeddedPage({+ resource: { dashboard: dashboardId },+ params: invalidParamsValue,+ });++ H.getDashboardCard()+ .findByText("There was a problem displaying this chart.")+ .should("be.visible");++ cy.log("should send 'X-Metabase-Client' header for api requests");+ cy.intercept("GET", "api/embed/dashboard/*").as("getEmbeddedDashboard");+const payload = {resource: { dashboard: dashboardId },params: {},};+ H.visitEmbeddedPage(payload, {+ onBeforeLoad: (window) => {+ window.Cypress = undefined;+ },+ });++ cy.wait("@getEmbeddedDashboard").then(({ request }) => {+ expect(request?.headers?.["x-metabase-client"]).to.equal(+ "embedding-iframe-static",+ );+ });+H.visitEmbeddedPage(payload);// wait for the results to loadcy.contains("Test Dashboard");cy.contains("2,500");});- });- it("should work for all filters", () => {+ cy.log("should only display filters mapped to cards on the selected tab");+ H.dashboardParametersContainer().within(() => {+ cy.findByText("Id").should("be.visible");+ cy.findByText("Name").should("be.visible");+ cy.findByText("Source").should("be.visible");+ cy.findByText("User").should("be.visible");+ cy.findByText("Not Used Filter").should("not.exist");+ });++ cy.log(+ "should hide filters that are not mapped to cards on the selected tab",+ );+ H.goToTab("Tab 2");+ H.assertTabSelected("Tab 2");++ H.dashboardParametersContainer().should("not.exist");+ cy.findByTestId("embed-frame").within(() => {+ cy.findByText("Id").should("not.exist");+ cy.findByText("Name").should("not.exist");+ cy.findByText("Source").should("not.exist");+ cy.findByText("User").should("not.exist");+ cy.findByText("Not Used Filter").should("not.exist");+ });++ H.goToTab("Tab 1");+ H.assertTabSelected("Tab 1");+ H.dashboardParametersContainer().findByText("Id").should("be.visible");+cy.log("should allow searching PEOPLE.ID by PEOPLE.NAME");openFilterOptions("Id");@@ -447,33 +517,7 @@ describe("scenarios > embedding > dashboard parameters", () => {cy.visit(`${location.origin}${location.pathname}?id=1&id=3`),);- cy.findByTestId("scalar-value").contains("2");- });- });-- it("should render error message when `params` is not an object (metabase#14474)", () => {- cy.get("@dashboardId").then((dashboardId) => {- cy.request("PUT", `/api/dashboard/${dashboardId}`, {- embedding_params: {- id: "enabled",- name: "enabled",- source: "enabled",- user_id: "enabled",- },- enable_embedding: true,- });-- const invalidParamsValue = [];- const payload = {- resource: { dashboard: dashboardId },- params: invalidParamsValue,- };-- H.visitEmbeddedPage(payload);-- H.getDashboardCard()- .findByText("There was a problem displaying this chart.")- .should("be.visible");+ cy.findByTestId("scalar-value").invoke("text").should("eq", "2");});});@@ -610,34 +654,6 @@ describe("scenarios > embedding > dashboard parameters", () => {cy.findByTestId("export-as-pdf-button").should("be.visible").click();});-- it("should send 'X-Metabase-Client' header for api requests", () => {- cy.intercept("GET", "api/embed/dashboard/*").as("getEmbeddedDashboard");-- cy.get("@dashboardId").then((dashboardId) => {- cy.request("PUT", `/api/dashboard/${dashboardId}`, {- embedding_params: {},- enable_embedding: true,- });-- const payload = {- resource: { dashboard: dashboardId },- params: {},- };-- H.visitEmbeddedPage(payload, {- onBeforeLoad: (window) => {- window.Cypress = undefined;- },- });-- cy.wait("@getEmbeddedDashboard").then(({ request }) => {- expect(request?.headers?.["x-metabase-client"]).to.equal(- "embedding-iframe-static",- );- });- });- });});describe("scenarios > embedding > dashboard parameters with defaults", () => {@@ -679,6 +695,26 @@ describe("scenarios > embedding > dashboard parameters with defaults", () => {});});+ cy.log(+ "locked parameters should still render results in the preview by default (metabase#47570)",+ );+ H.visitDashboard("@dashboardId");++ cy.get("@dashboardId").then((dashboardId) => {+ H.openLegacyStaticEmbeddingModal({+ resource: "dashboard",+ resourceId: dashboardId,+ activeTab: "parameters",+ unpublishBeforeOpen: false,+ });+ });++ H.visitIframe();++ H.getDashboardCard().findByText("2").should("be.visible");+ H.getDashboardCard().findByText("test question").should("be.visible");++ cy.log("card parameter defaults should apply only for disabled parameters");cy.get("@dashboardId").then((dashboardId) => {const payload = {resource: { dashboard: dashboardId },@@ -687,8 +723,6 @@ describe("scenarios > embedding > dashboard parameters with defaults", () => {H.visitEmbeddedPage(payload);- // wait for the results to load-// The ID default (1 and 2) should apply, because it is disabled.// The Name default ('Lina Heaney') should not apply, because the Name param is editable and unset// The Source default ('Facebook') should not apply because the param is locked but the value is unset@@ -697,63 +731,103 @@ describe("scenarios > embedding > dashboard parameters with defaults", () => {cy.contains("Test Dashboard");cy.findByTestId("scalar-value").invoke("text").should("eq", "2");});- //visitIframe();++ cy.log("locked parameters require a value to be specified in the JWT");+ cy.get("@dashboardId").then((dashboardId) => {+ const payload = {+ resource: { dashboard: dashboardId },+ params: { source: null },+ };++ H.visitEmbeddedPage(payload);+ });++ // The Source parameter is 'locked', and no value has been specified in the token,+ // thus the API responds with "You must specify a value for :source in the JWT."+ // and the card will not display.+ H.getDashboardCard()+ .findByText("There was a problem displaying this chart.")+ .should("be.visible");});+});- it("locked parameters require a value to be specified in the JWT", () => {- const nameParameter = dashboardDetails.parameters.find(- (parameter) => parameter.name === "Name",- );- const sourceParameter = dashboardDetails.parameters.find(- (parameter) => parameter.name === "Source",- );+describe("issue 20438", () => {+ const questionDetails = {+ name: "20438",+ native: {+ query:+ "SELECT * FROM PRODUCTS\nWHERE true\n [[AND {{CATEGORY}}]]\n limit 30",+ "template-tags": {+ CATEGORY: {+ id: "24f69111-29f8-135f-9321-1ff94bbb31ad",+ name: "CATEGORY",+ "display-name": "Category",+ type: "dimension",+ dimension: ["field", PRODUCTS.CATEGORY, null],+ "widget-type": "string/=",+ default: null,+ },+ },+ },+ };- cy.get("@dashboardId").then((dashboardId) => {- cy.request("PUT", `api/dashboard/${dashboardId}`, {+ const filter = {+ name: "Text",+ slug: "text",+ id: "b555d25b",+ type: "string/=",+ sectionId: "string",+ };++ const dashboardDetails = {+ parameters: [filter],+ };++ beforeEach(() => {+ cy.intercept("GET", "/api/embed/dashboard/**").as("getEmbed");++ H.restore();+ cy.signInAsAdmin();++ H.createNativeQuestionAndDashboard({+ questionDetails,+ dashboardDetails,+ }).then(({ body: { id, card_id, dashboard_id } }) => {+ // Connect filter to the card+ cy.request("PUT", `/api/dashboard/${dashboard_id}`, {+ dashcards: [+ {+ id,+ card_id,+ row: 0,+ col: 0,+ size_x: 24,+ size_y: 8,+ parameter_mappings: [+ {+ parameter_id: filter.id,+ card_id,+ target: ["dimension", ["template-tag", "CATEGORY"]],+ },+ ],+ },+ ],+ });++ // Enable embedding and enable the "Text" filter+ cy.request("PUT", `/api/dashboard/${dashboard_id}`, {enable_embedding: true,- embedding_params: {- [nameParameter.slug]: "enabled",- [sourceParameter.slug]: "locked",- },+ embedding_params: { [filter.slug]: "enabled" },});- const payload = {- resource: { dashboard: dashboardId },- params: { source: null },- };+ cy.wrap(card_id).as("questionId");+ cy.wrap(dashboard_id).as("dashboardId");- H.visitEmbeddedPage(payload);+ H.visitDashboard(dashboard_id);});-- // The Source parameter is 'locked', and no value has been specified in the token,- // thus the API responds with "You must specify a value for :source in the JWT."- // and the card will not display.-- H.getDashboardCard()- .findByText("There was a problem displaying this chart.")- .should("be.visible");});- it("locked parameters should still render results in the preview by default (metabase#47570)", () => {- const nameParameter = dashboardDetails.parameters.find(- (parameter) => parameter.name === "Name",- );- const sourceParameter = dashboardDetails.parameters.find(- (parameter) => parameter.name === "Source",- );-- cy.get("@dashboardId").then((dashboardId) => {- cy.request("PUT", `api/dashboard/${dashboardId}`, {- enable_embedding: true,- embedding_params: {- [nameParameter.slug]: "enabled",- [sourceParameter.slug]: "locked",- },- });- });-- H.visitDashboard("@dashboardId");-+ it("dashboard filter connected to the field filter should work with a single value in embedded dashboards (metabase#20438)", () => {cy.get("@dashboardId").then((dashboardId) => {H.openLegacyStaticEmbeddingModal({resource: "dashboard",@@ -765,9 +839,129 @@ describe("scenarios > embedding > dashboard parameters with defaults", () => {H.visitIframe();- cy.log("should show card results by default");- H.getDashboardCard().findByText("2").should("be.visible");- H.getDashboardCard().findByText("test question").should("be.visible");+ cy.wait("@getEmbed");++ H.filterWidget().click();+ cy.wait("@getEmbed");++ H.popover().contains("Doohickey").click();+ cy.wait("@getEmbed");++ cy.button("Add filter").click();+ cy.wait("@getEmbed");++ cy.findAllByRole("gridcell")+ // One of product titles for Doohickey+ .should("contain", "Small Marble Shoes")+ // One of product titles for Gizmo+ .and("not.contain", "Rustic Paper Wallet");+ });+});++describe("scenarios > embedding > dashboard locked numeric parameters (metabase#25031)", () => {+ const dashboardFilter = {+ name: "Equal to",+ slug: "equal_to",+ id: "c269ebe1",+ type: "number/=",+ sectionId: "number",+ };++ const dashboardDetails = {+ name: "25031",+ parameters: [dashboardFilter],+ enable_embedding: true,+ embedding_params: {+ [dashboardFilter.slug]: "locked",+ },+ };++ function getQuestionDetails(defaultValue = undefined) {+ return {+ name: "20845",+ native: {+ "template-tags": {+ qty_locked: {+ id: "6bd8d7be-bd5b-382c-cfa2-683461891663",+ name: "qty_locked",+ "display-name": "Qty locked",+ type: "number",+ required: defaultValue ? true : false,+ default: defaultValue,+ },+ },+ query:+ "select count(*) from orders where true [[AND quantity={{qty_locked}}]]",+ },+ };+ }++ function createDashboard(defaultValue, alias) {+ H.createNativeQuestionAndDashboard({+ questionDetails: getQuestionDetails(defaultValue),+ dashboardDetails,+ }).then(({ body: { id, dashboard_id, card_id } }) => {+ cy.wrap(dashboard_id).as(alias);++ cy.request("PUT", `/api/dashboard/${dashboard_id}`, {+ dashcards: [+ {+ card_id,+ id,+ row: 0,+ col: 0,+ size_x: 16,+ size_y: 10,+ parameter_mappings: [+ {+ parameter_id: dashboardFilter.id,+ card_id,+ target: ["variable", ["template-tag", "qty_locked"]],+ },+ ],+ },+ ],+ });+ });+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("locked parameter should work with numeric values, with and without a required filter with a default value", () => {+ createDashboard(undefined, "dashboardId");+ createDashboard("10", "requiredDashboardId");++ [+ { alias: "@dashboardId", label: "without a default value" },+ { alias: "@requiredDashboardId", label: "with a required default value" },+ ].forEach(({ alias, label }) => {+ cy.get(alias).then((dashboardId) => {+ // This issue is not possible to reproduce using UI from this point on.+ // We have to manually send the payload in order to make sure it works for both strings and integers.+ ["string", "integer"].forEach((type) => {+ cy.log(+ `Make sure it works with ${type.toUpperCase()} in the payload ${label}`,+ );++ const payload = {+ resource: { dashboard: dashboardId },+ params: {+ [dashboardFilter.slug]: type === "string" ? "15" : 15, // IMPORTANT: integer+ },+ };++ H.visitEmbeddedPage(payload);++ // wait for the results to load+ cy.contains(dashboardDetails.name);+ cy.get(".CardVisualization").should("contain", "COUNT(*)");+ cy.get(".CardVisualization").findByText("5").should("be.visible");+ });+ });+ });});});@@ -1122,26 +1316,50 @@ describe("scenarios > embedding > dashboard appearance", () => {});});- it("should allow to set locale from the `#locale` hash parameter (metabase#50182)", () => {+ it("should apply the `#locale`, `#font`, `#background` and `#theme` hash parameters to a static dashboard embed (metabase#50182, metabase#62391, metabase#66253)", () => {+ const visitOrdersDashboard = (additionalHashOptions, onBeforeLoad) => {+ H.visitEmbeddedPage(+ {+ resource: { dashboard: ORDERS_DASHBOARD_ID },+ params: {},+ },+ { additionalHashOptions, onBeforeLoad },+ );+ };++ const visitWithTheme = (theme) => {+ cy.clearLocalStorage();++ visitOrdersDashboard({ theme }, (win) => {+ // a bit gross but other stub techniques don't reliably work in Cypress+ cy.stub(win, "matchMedia").callsFake((query) => {+ return {+ matches: query === "(prefers-color-scheme: dark)",+ media: query,+ addEventListener: cy.stub(),+ removeEventListener: cy.stub(),+ addListener: cy.stub(), // deprecated but sometimes needed+ removeListener: cy.stub(),+ dispatchEvent: cy.stub(),+ };+ });+ });+ };+cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {enable_embedding: true,});cy.signOut();+ cy.log("Test `#locale`, `#font` and `#background=false` without an iframe");// We don't have a de-CH.json file, so it should fallback to de.json, see metabase#51039 for more detailscy.intercept("GET", "**/locale-de-json*.js").as("deLocale");- H.visitEmbeddedPage(- {- resource: { dashboard: ORDERS_DASHBOARD_ID },- params: {},- },- {- additionalHashOptions: {- locale: "de-CH",- },- },- );+ visitOrdersDashboard({+ locale: "de-CH",+ font: "Roboto",+ background: "false",+ });cy.wait("@deLocale");@@ -1152,132 +1370,44 @@ describe("scenarios > embedding > dashboard appearance", () => {}).should("exist");cy.url().should("include", "locale=de");- });-- it("should allow to set font from the `font` hash parameter", () => {- cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {- enable_embedding: true,- });- cy.signOut();-- H.visitEmbeddedPage(- {- resource: { dashboard: ORDERS_DASHBOARD_ID },- params: {},- },- {- additionalHashOptions: {- font: "Roboto",- },- },- );H.main().should("have.css","font-family",'Roboto, "Noto Sans", sans-serif',);- });-- it("should disable background via `#background=false` hash parameter when rendered inside an iframe (metabase#62391)", () => {- cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {- enable_embedding: true,- });- cy.signOut();-- H.visitEmbeddedPage(- {- resource: { dashboard: ORDERS_DASHBOARD_ID },- params: {},- },- {- additionalHashOptions: {- background: "false",- },- onBeforeLoad: (window) => {- window.overrideIsWithinIframe = true;- },- },- );cy.findByTestId("embed-frame").should("exist");cy.get("body.mb-wrapper").should(- "have.css",+ "not.have.css","background-color","rgba(0, 0, 0, 0)",);- cy.window().then((win) => {- delete win.overrideIsWithinIframe;- });- });+ cy.log("Test `#background=false` inside an iframe");+ cy.visit("/");- it("should not disable background via `#background=false` hash parameter when rendered without an iframe", () => {- cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {- enable_embedding: true,+ visitOrdersDashboard({ background: "false" }, (window) => {+ window.overrideIsWithinIframe = true;});- cy.signOut();-- H.visitEmbeddedPage(- {- resource: { dashboard: ORDERS_DASHBOARD_ID },- params: {},- },- {- additionalHashOptions: {- background: "false",- },- },- );cy.findByTestId("embed-frame").should("exist");cy.get("body.mb-wrapper").should(- "not.have.css",+ "have.css","background-color","rgba(0, 0, 0, 0)",);- });-- it("should apply theme hash parameter to static dashboard embed (metabase#66253)", () => {- const visit = (theme) => {- cy.clearLocalStorage();-- H.visitEmbeddedPage(- {- resource: { dashboard: ORDERS_DASHBOARD_ID },- params: {},- },- {- additionalHashOptions: {- theme,- },- onBeforeLoad: (win) => {- // a bit gross but other stub techniques don't reliably work in Cypress- cy.stub(win, "matchMedia").callsFake((query) => {- return {- matches: query === "(prefers-color-scheme: dark)",- media: query,- addEventListener: cy.stub(),- removeEventListener: cy.stub(),- addListener: cy.stub(), // deprecated but sometimes needed- removeListener: cy.stub(),- dispatchEvent: cy.stub(),- };- });- },- },- );- };- cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {- enable_embedding: true,+ cy.window().then((win) => {+ delete win.overrideIsWithinIframe;});- cy.signOut();++ cy.visit("/");cy.log("Test default light theme behavior");- visit();+ visitWithTheme();// Test core functionality works with default themecy.get("[data-testid=embed-frame]").should("be.visible");@@ -1285,7 +1415,7 @@ describe("scenarios > embedding > dashboard appearance", () => {cy.get('html[data-metabase-theme="light"]').should("exist");cy.log("Test explicit light theme via hash parameter");- visit("light");+ visitWithTheme("light");// Test functionality still works with theme parametercy.get("[data-testid=embed-frame]").should("be.visible");@@ -1296,7 +1426,7 @@ describe("scenarios > embedding > dashboard appearance", () => {cy.location("hash").should("include", "theme=light");cy.log("Test explicit dark theme via hash parameter");- visit("dark");+ visitWithTheme("dark");// Test functionality still works with theme parametercy.get("[data-testid=embed-frame]").should("be.visible");@@ -1476,6 +1606,223 @@ describe("scenarios > embedding > dashboard appearance", () => {});});+describe("issue 8490", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");++ H.createDashboardWithQuestions({+ dashboardDetails: {+ name: "Dashboard to test locale",+ enable_embedding: true,+ },+ questions: [+ {+ name: "Line chart",+ query: {+ "source-table": PRODUCTS_ID,+ aggregation: [["count"]],+ breakout: [+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ [+ "field",+ PRODUCTS.CREATED_AT,+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ],+ ],+ filter: [+ "between",+ ["field", PRODUCTS.CREATED_AT, { "base-type": "type/DateTime" }],+ "2027-01-01",+ "2028-01-01",+ ],+ },+ limit: 100,+ visualization_settings: {+ "graph.dimensions": ["CREATED_AT", "CATEGORY"],+ "graph.metrics": ["count"],+ },+ display: "bar",+ enable_embedding: true,+ },+ {+ name: "Order quantity trend",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "sum",+ ["field", ORDERS.QUANTITY, { "base-type": "type/Integer" }],+ ],+ ],+ breakout: [+ [+ "field",+ ORDERS.CREATED_AT,+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ],+ ],+ filter: [+ "and",+ [+ "between",+ ["field", ORDERS.CREATED_AT, { "base-type": "type/DateTime" }],+ "2027-10-01",+ "2027-12-01",+ ],+ [+ "=",+ [+ "field",+ PRODUCTS.VENDOR,+ {+ "base-type": "type/Text",+ "source-field": ORDERS.PRODUCT_ID,+ },+ ],+ "Alfreda Konopelski II Group",+ ],+ ],+ },+ display: "smartscalar",+ },+ {+ name: "Pie chart",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ PRODUCTS.VENDOR,+ { "base-type": "type/Text", "source-field": ORDERS.PRODUCT_ID },+ ],+ ],+ limit: 5,+ },+ visualization_settings: {+ "pie.slice_threshold": 20,+ },+ display: "pie",+ },+ ],+ cards: [{}, { col: 12 }],+ }).then(({ dashboard, questions: [lineChartQuestion] }) => {+ cy.wrap(dashboard.id).as("dashboardId");+ cy.wrap(lineChartQuestion.id).as("lineChartQuestionId");+ });+ });++ it("static embeddings should respect `#locale` hash parameter (metabase#8490, metabase#50182)", () => {+ cy.log("test a static embedded dashboard");+ const {+ promise: dashboardLoaderPromise,+ resolve: resolveDashboardLoaderPromise,+ } = defer();+ cy.intercept(+ {+ method: "GET",+ url: "/api/embed/dashboard/*",+ },+ () => dashboardLoaderPromise,+ ).as("dashboardRequest");++ cy.get("@dashboardId").then((dashboardId) => {+ H.visitEmbeddedPage(+ {+ resource: { dashboard: dashboardId },+ params: {},+ },+ {+ additionalHashOptions: {+ locale: "ko",+ },+ },+ );+ });++ cy.findByTestId("embed-frame").within(() => {+ cy.log(+ "static embeddings with `#locale` should show a translated the loading message",+ );+ // Loading...+ cy.findByText("로드 중...")+ .should("be.visible")+ .then(resolveDashboardLoaderPromise);++ cy.log("assert the line chart");+ H.getDashboardCard(0).within(() => {+ // X-axis labels: Jan 2024 (or some other year)+ cy.findByText(/^1월 20\d\d\b/).should("be.visible");+ // Aggregation "count"+ cy.findByText("카운트").should("be.visible");+ });+ });++ cy.findByTestId("embed-frame").within(() => {+ cy.log("assert the trend chart");+ H.getDashboardCard(2).within(() => {+ // N/A (the comparison row combines it with the comparison description)+ cy.findByText(/해당 없음/).should("be.visible");+ // (No data)+ cy.findByText("(데이터 없음)").should("be.visible");+ });++ cy.log("assert the pie chart");+ H.getDashboardCard(1).within(() => {+ // Total+ cy.findByText("합계").should("be.visible");+ // Other+ cy.findByTestId("chart-legend").findByText("기타").should("be.visible");+ });+ });++ cy.log("test a static embedded question");+ const {+ promise: questionLoaderPromise,+ resolve: resolveQuestionLoaderPromise,+ } = defer();+ cy.intercept(+ {+ method: "GET",+ url: "/api/embed/card/*",+ },+ () => questionLoaderPromise,+ ).as("questionRequest");++ cy.log("assert the line chart");+ cy.get("@lineChartQuestionId").then((lineChartQuestionId) => {+ H.visitEmbeddedPage(+ {+ resource: { question: lineChartQuestionId },+ params: {},+ },+ {+ additionalHashOptions: {+ locale: "ko",+ },+ },+ );+ });++ cy.findByTestId("embed-frame").within(() => {+ cy.log(+ "static embeddings with `#locale` should show a translated the loading message",+ );+ // Loading...+ cy.findByText("로딩...")+ .should("be.visible")+ .then(resolveQuestionLoaderPromise);++ // X-axis labels: Jan 2023 (or some other year)+ cy.findByText(/11월 20\d\d\b/).should("be.visible");+ // Aggregation "count"+ cy.findByText("카운트").should("be.visible");+ });+ });+});+function openFilterOptions(name) {H.filterWidget().contains(name).click();}diff --git a/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js b/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.jsindex 1f9ede19018..7214dd88e8e 100644--- a/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js+++ b/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js@@ -1,4 +1,5 @@const { H } = cy;+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import {guiDashboard,@@ -9,6 +10,8 @@ import {nativeQuestionDetails,} from "./shared/embedding-linked-filters";+const { PRODUCTS, PRODUCTS_ID, FEEDBACK, FEEDBACK_ID } = SAMPLE_DATABASE;+describe("scenarios > embedding > dashboard > linked filters (metabase#13639, metabase#13868)", () => {beforeEach(() => {H.restore();@@ -36,41 +39,23 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me});});- it("works when both filters are enabled and their values are set through UI", () => {+ it("works when main filter's value is set through URL, hidden, or set through UI", () => {+ cy.log("works when main filter's value is set through URL");cy.get("@dashboardId").then((dashboard_id) => {const payload = {resource: { dashboard: dashboard_id },params: {},};- H.visitEmbeddedPage(payload);+ H.visitEmbeddedPage(payload, {+ setFilters: { state: "AK" },+ });});- cy.findByRole("heading", { name: nativeDashboardDetails.name });- H.getDashboardCard().contains(nativeQuestionDetails.name);-- H.chartPathWithFillColor("#509EE3").should("have.length", 49);-- assertOnXYAxisLabels({ xLabel: "STATE", yLabel: "count" });-- H.echartsContainer()- .get("text")- .should("contain", "TX")- .and("contain", "AK");-- openFilterOptions("State");-- H.popover().findByText("AK").click();- H.popover().button("Add filter").click();-- cy.location("search").should("eq", "?city=&state=AK");-- H.echartsContainer()- .get("text")- .should("contain", "AK")- .and("not.contain", "TX");+ H.filterWidget().should("have.length", 2);H.chartPathWithFillColor("#509EE3").should("have.length", 1).realHover();+H.assertEChartsTooltip({header: "AK",rows: [{ color: "#509EE3", name: "count", value: "68" }],@@ -97,52 +82,24 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, meheader: "AK",rows: [{ color: "#509EE3", name: "count", value: "1" }],});- });- it("works when both filters are enabled and their values are set through UI with auto-apply filters disabled", () => {+ cy.log(+ "works when main filter's value is set through URL and when it is hidden at the same time",+ );cy.get("@dashboardId").then((dashboard_id) => {const payload = {resource: { dashboard: dashboard_id },params: {},};- cy.request("PUT", `/api/dashboard/${dashboard_id}`, {- auto_apply_filters: false,+ H.visitEmbeddedPage(payload, {+ setFilters: { state: "AK" },+ additionalHashOptions: {+ hideFilters: ["state"],+ },});-- H.visitEmbeddedPage(payload);});- cy.findByRole("heading", { name: nativeDashboardDetails.name });- H.getDashboardCard().contains(nativeQuestionDetails.name);-- assertOnXYAxisLabels({ xLabel: "STATE", yLabel: "count" });-- H.chartPathWithFillColor("#509EE3").should("have.length", 49);- H.echartsContainer()- .get("text")- .should("contain", "AK")- .and("contain", "TX");-- openFilterOptions("State");-- H.applyFilterToast().should("not.exist");-- H.popover().findByText("AK").click();- H.popover().button("Add filter").click();-- H.chartPathWithFillColor("#509EE3").should("have.length", 49);-- H.applyFilterButton().click();- H.applyFilterToast().should("not.exist");-- cy.location("search").should("eq", "?city=&state=AK");-- H.echartsContainer()- .get("text")- .should("contain", "AK")- .and("not.contain", "TX");-H.chartPathWithFillColor("#509EE3").should("have.length", 1).realHover();H.assertEChartsTooltip({@@ -151,7 +108,7 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, meblurAfter: true,});- openFilterOptions("City");+ H.filterWidget().should("have.length", 1).and("contain", "City").click();searchFieldValuesFilter();@@ -162,9 +119,6 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me});H.popover().button("Add filter").click();- H.applyFilterButton().click();- H.applyFilterToast().should("not.exist");-cy.location("search").should("eq", "?city=Anchorage&state=AK");H.chartPathWithFillColor("#509EE3").should("have.length", 1).realHover();@@ -173,24 +127,44 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, meheader: "AK",rows: [{ color: "#509EE3", name: "count", value: "1" }],});- });- it("works when main filter's value is set through URL", () => {+ cy.log(+ "works when both filters are enabled and their values are set through UI",+ );cy.get("@dashboardId").then((dashboard_id) => {const payload = {resource: { dashboard: dashboard_id },params: {},};- H.visitEmbeddedPage(payload, {- setFilters: { state: "AK" },- });+ H.visitEmbeddedPage(payload);});- H.filterWidget().should("have.length", 2);+ cy.findByRole("heading", { name: nativeDashboardDetails.name });+ H.getDashboardCard().contains(nativeQuestionDetails.name);- H.chartPathWithFillColor("#509EE3").should("have.length", 1).realHover();+ H.chartPathWithFillColor("#509EE3").should("have.length", 49);++ assertOnXYAxisLabels({ xLabel: "STATE", yLabel: "count" });++ H.echartsContainer()+ .get("text")+ .should("contain", "TX")+ .and("contain", "AK");++ openFilterOptions("State");++ H.popover().findByText("AK").click();+ H.popover().button("Add filter").click();+ cy.location("search").should("eq", "?city=&state=AK");++ H.echartsContainer()+ .get("text")+ .should("contain", "AK")+ .and("not.contain", "TX");++ H.chartPathWithFillColor("#509EE3").should("have.length", 1).realHover();H.assertEChartsTooltip({header: "AK",rows: [{ color: "#509EE3", name: "count", value: "68" }],@@ -219,21 +193,53 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me});});- it("works when main filter's value is set through URL and when it is hidden at the same time", () => {+ it("works with auto-apply filters disabled and when main filter is locked", () => {+ cy.log(+ "works when both filters are enabled and their values are set through UI with auto-apply filters disabled",+ );cy.get("@dashboardId").then((dashboard_id) => {const payload = {resource: { dashboard: dashboard_id },params: {},};- H.visitEmbeddedPage(payload, {- setFilters: { state: "AK" },- additionalHashOptions: {- hideFilters: ["state"],- },+ cy.request("PUT", `/api/dashboard/${dashboard_id}`, {+ auto_apply_filters: false,});++ H.visitEmbeddedPage(payload);});+ cy.findByRole("heading", { name: nativeDashboardDetails.name });+ H.getDashboardCard().contains(nativeQuestionDetails.name);++ assertOnXYAxisLabels({ xLabel: "STATE", yLabel: "count" });++ H.chartPathWithFillColor("#509EE3").should("have.length", 49);+ H.echartsContainer()+ .get("text")+ .should("contain", "AK")+ .and("contain", "TX");++ openFilterOptions("State");++ H.applyFilterToast().should("not.exist");++ H.popover().findByText("AK").click();+ H.popover().button("Add filter").click();++ H.chartPathWithFillColor("#509EE3").should("have.length", 49);++ H.applyFilterButton().click();+ H.applyFilterToast().should("not.exist");++ cy.location("search").should("eq", "?city=&state=AK");++ H.echartsContainer()+ .get("text")+ .should("contain", "AK")+ .and("not.contain", "TX");+H.chartPathWithFillColor("#509EE3").should("have.length", 1).realHover();H.assertEChartsTooltip({@@ -242,7 +248,7 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, meblurAfter: true,});- H.filterWidget().should("have.length", 1).and("contain", "City").click();+ openFilterOptions("City");searchFieldValuesFilter();@@ -253,6 +259,9 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me});H.popover().button("Add filter").click();+ H.applyFilterButton().click();+ H.applyFilterToast().should("not.exist");+cy.location("search").should("eq", "?city=Anchorage&state=AK");H.chartPathWithFillColor("#509EE3").should("have.length", 1).realHover();@@ -261,11 +270,12 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, meheader: "AK",rows: [{ color: "#509EE3", name: "count", value: "1" }],});- });- it("works when main filter is locked", () => {+ cy.log("works when main filter is locked");+ cy.signInAsAdmin();cy.get("@dashboardId").then((dashboard_id) => {cy.request("PUT", `/api/dashboard/${dashboard_id}`, {+ auto_apply_filters: true,embedding_params: {city: "enabled",state: "locked",@@ -315,7 +325,10 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me});});- it("works when both filters are enabled and their values are set through UI", () => {+ it("works when filter values are set through UI or URL, and when the default filter is hidden or locked", () => {+ cy.log(+ "works when both filters are enabled and their values are set through UI",+ );cy.get("@guiDashboardId").then((dashboard_id) => {const payload = {resource: { dashboard: dashboard_id },@@ -345,9 +358,8 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me.findAllByRole("row").should("have.length", 1).and("contain", "Gizmo");- });- it("works when main filter's value is set through URL", () => {+ cy.log("works when main filter's value is set through URL");cy.get("@guiDashboardId").then((dashboard_id) => {const payload = {resource: { dashboard: dashboard_id },@@ -424,9 +436,8 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, mecy.findByText("Widget").should("not.exist");});});- });- it("works when the default filter is hidden", () => {+ cy.log("works when the default filter is hidden");cy.get("@guiDashboardId").then((dashboard_id) => {const payload = {resource: { dashboard: dashboard_id },@@ -456,9 +467,9 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, mecy.findByText("Gadget").should("not.exist");cy.findByText("Widget").should("not.exist");});- });- it("works when the default filter is locked", () => {+ cy.log("works when the default filter is locked");+ cy.signInAsAdmin();cy.get("@guiDashboardId").then((dashboard_id) => {cy.request("PUT", `/api/dashboard/${dashboard_id}`, {embedding_params: {@@ -495,6 +506,319 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me});});+describe("dashboard preview", () => {+ const questionDetails = {+ name: "Products",+ query: { "source-table": PRODUCTS_ID },+ };++ const filter3 = {+ name: "Text 2",+ slug: "text_2",+ id: "b0665b6a",+ type: "string/=",+ sectionId: "string",+ };++ const filter2 = {+ name: "Text 1",+ slug: "text_1",+ id: "d4c9f2e5",+ type: "string/=",+ sectionId: "string",+ };++ const filter = {+ filteringParameters: [filter2.id],+ name: "Text",+ slug: "text",+ id: "d1b69627",+ type: "string/=",+ sectionId: "string",+ };++ beforeEach(() => {+ cy.intercept("GET", "/api/preview_embed/dashboard/**").as(+ "previewDashboard",+ );+ cy.intercept("GET", "/api/preview_embed/dashboard/**/params/**/values").as(+ "previewValues",+ );++ H.restore();+ cy.signInAsAdmin();+ });++ it("dashboard linked filters values don't work in static embed preview (metabase#37914)", () => {+ const dashboardDetails = {+ parameters: [filter, filter2, filter3],+ enable_embedding: true,+ embedding_params: {+ [filter.slug]: "enabled",+ [filter2.slug]: "enabled",+ [filter3.slug]: "enabled",+ },+ };+ H.createQuestionAndDashboard({+ questionDetails,+ dashboardDetails,+ }).then(({ body: { card_id, dashboard_id } }) => {+ H.addOrUpdateDashboardCard({+ dashboard_id,+ card_id,+ card: {+ parameter_mappings: [+ {+ card_id,+ parameter_id: filter.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ {+ card_id,+ parameter_id: filter2.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ {+ card_id,+ parameter_id: filter3.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ ],+ },+ });++ H.visitDashboard(dashboard_id);++ H.openLegacyStaticEmbeddingModal({+ resource: "dashboard",+ resourceId: dashboard_id,+ activeTab: "parameters",+ previewMode: "preview",+ });+ });++ H.modal().within(() => {+ // Makes it less likely to flake.+ cy.wait("@previewDashboard");++ H.getIframeBody().within(() => {+ cy.log(+ "Set filter 2 value, so filter 1 should be filtered by filter 2",+ );+ cy.button(filter2.name).click();+ cy.wait("@previewValues");+ H.popover().within(() => {+ cy.findByText("Gadget").should("be.visible");+ cy.findByText("Gizmo").should("be.visible");+ cy.findByText("Widget").should("be.visible");+ cy.findByText("Doohickey").click();+ cy.button("Add filter").click();+ });++ cy.log("Assert filter 1");+ cy.button(filter.name).click();+ H.popover().within(() => {+ cy.findByText("Doohickey").should("be.visible");+ cy.findByText("Gadget").should("not.exist");+ cy.findByText("Gizmo").should("not.exist");+ cy.findByText("Widget").should("not.exist");+ });+ });+ });+ });++ it("dashboard linked filters values in embed preview don't behave like embedding (metabase#41635)", () => {+ const dashboardDetails = {+ parameters: [filter, filter2, filter3],+ enable_embedding: true,+ embedding_params: {+ [filter.slug]: "enabled",+ [filter2.slug]: "locked",+ [filter3.slug]: "locked",+ },+ };+ H.createQuestionAndDashboard({+ questionDetails,+ dashboardDetails,+ }).then(({ body: { card_id, dashboard_id } }) => {+ H.addOrUpdateDashboardCard({+ dashboard_id,+ card_id,+ card: {+ parameter_mappings: [+ {+ card_id,+ parameter_id: filter.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ {+ card_id,+ parameter_id: filter2.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ {+ card_id,+ parameter_id: filter3.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ ],+ },+ });++ H.visitDashboard(dashboard_id);++ H.openLegacyStaticEmbeddingModal({+ resource: "dashboard",+ resourceId: dashboard_id,+ activeTab: "parameters",+ previewMode: "preview",+ });+ });++ // Makes it less likely to flake.+ cy.wait("@previewDashboard");++ cy.log("Set the first locked parameter values");+ H.modal()+ .findByRole("generic", { name: "Previewing locked parameters" })+ .findByText("Text 1")+ .click();+ H.popover().within(() => {+ cy.findByText("Doohickey").click();+ cy.button("Add filter").click();+ });++ cy.log("Set the second locked parameter values");+ H.modal()+ .findByRole("generic", { name: "Previewing locked parameters" })+ .findByText("Text 2")+ .click();+ H.popover().within(() => {+ cy.findByText("Doohickey").click();+ cy.findByText("Gizmo").click();+ cy.findByText("Gadget").click();+ cy.button("Add filter").click();+ });++ // Wait for the iframe to load+ H.getIframeBody().within(() => {+ cy.button(filter.name).should("not.exist");+ });++ H.getIframeBody().within(() => {+ cy.log("Assert filter 1");+ cy.button(filter.name).click();+ H.popover().within(() => {+ cy.findByText("Doohickey").should("be.visible");+ cy.findByText("Gadget").should("not.exist");+ cy.findByText("Gizmo").should("not.exist");+ cy.findByText("Widget").should("not.exist");+ });+ });+ });+});++describe("issue 57028", () => {+ const lockedContainsBodyFilter = {+ name: "locked_contains_body",+ slug: "locked_contains_body",+ id: "e6588080",+ type: "string/contains",+ sectionId: "string",+ isMultiSelect: true,+ values_query_type: "none",+ };++ const emailFilter = {+ name: "Email",+ slug: "email",+ id: "d31e550f",+ type: "string/=",+ sectionId: "string",+ values_query_type: "list",+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("static embedded editable filter should load dropdown values when a string/contains locked param has multiple values (metabase#57028)", () => {+ H.createQuestionAndDashboard({+ questionDetails: {+ name: "Feedback",+ query: { "source-table": FEEDBACK_ID },+ },+ dashboardDetails: {+ parameters: [lockedContainsBodyFilter, emailFilter],+ enable_embedding: true,+ embedding_params: {+ [lockedContainsBodyFilter.slug]: "locked",+ [emailFilter.slug]: "enabled",+ },+ },+ }).then(({ body: { card_id, dashboard_id } }) => {+ H.addOrUpdateDashboardCard({+ dashboard_id,+ card_id,+ card: {+ parameter_mappings: [+ {+ card_id,+ parameter_id: lockedContainsBodyFilter.id,+ target: ["dimension", ["field", FEEDBACK.BODY, null]],+ },+ {+ card_id,+ parameter_id: emailFilter.id,+ target: ["dimension", ["field", FEEDBACK.EMAIL, null]],+ },+ ],+ },+ });++ cy.intercept(+ "GET",+ `/api/embed/dashboard/*/params/${emailFilter.id}/values`,+ ).as("emailValues");++ H.visitEmbeddedPage({+ resource: { dashboard: dashboard_id },+ params: {+ [lockedContainsBodyFilter.slug]: ["March", "damp", "somewhat"],+ },+ });+ });++ H.filterWidget().contains("Email").click();++ cy.wait("@emailValues").its("response.statusCode").should("eq", 200);++ H.popover().within(() => {+ cy.findByPlaceholderText("Search the list").should("be.visible");+ cy.findAllByRole("checkbox").its("length").should("be.greaterThan", 0);+ });+ });+});+function openFilterOptions(name) {H.filterWidget().contains(name).click();}diff --git a/e2e/test/scenarios/embedding/embedding-native.cy.spec.js b/e2e/test/scenarios/embedding/embedding-native.cy.spec.jsindex 1e64a902c08..94826582596 100644--- a/e2e/test/scenarios/embedding/embedding-native.cy.spec.js+++ b/e2e/test/scenarios/embedding/embedding-native.cy.spec.js@@ -67,9 +67,45 @@ describe("scenarios > embedding > native questions", () => {it("should display and work with enabled parameters while hiding the locked one", () => {createAndVisitQuestion();+ cy.log(+ "should (dis)allow setting parameters as required for a published embedding",+ );H.setEmbeddingParameter("Order ID", "Editable");- H.setEmbeddingParameter("Created At", "Editable");H.setEmbeddingParameter("Total", "Locked");++ H.publishChanges("card");+ H.closeStaticEmbeddingModal();++ cy.findByTestId("native-query-editor-container")+ .findByText("Open Editor")+ .click();++ cy.findByTestId("native-query-editor-action-buttons")+ .icon("variable")+ .click();++ assertRequiredEnabledForName({ name: "id", enabled: true });+ assertRequiredEnabledForName({ name: "total", enabled: true });+ assertRequiredEnabledForName({ name: "created_at", enabled: false });+ assertRequiredEnabledForName({ name: "source", enabled: false });+ assertRequiredEnabledForName({ name: "state", enabled: false });+ assertRequiredEnabledForName({ name: "product_id", enabled: false });++ cy.log("should display and work with enabled parameters");+ H.visitQuestion("@questionId");++ cy.get("@questionId").then((questionId) => {+ H.openLegacyStaticEmbeddingModal({+ resource: "question",+ resourceId: questionId,+ activeTab: "parameters",+ unpublishBeforeOpen: false,+ });+ });++ H.assertEmbeddingParameter("Order ID", "Editable");+ H.assertEmbeddingParameter("Total", "Locked");+ H.setEmbeddingParameter("Created At", "Editable");H.setEmbeddingParameter("State", "Editable");H.setEmbeddingParameter("Product ID", "Editable");@@ -156,18 +192,24 @@ describe("scenarios > embedding > native questions", () => {H.assertEmbeddingParameter("Total", "Editable");+ cy.log(+ "should let the user lock a text parameter to a specific value (metabase#20634)",+ );+ H.setEmbeddingParameter("Source", "Locked");+ H.modal().findByPlaceholderText("Source").type("Organic{enter}");+H.publishChanges("card", ({ request }) => {const actual = request.body.embedding_params;// We only expect total to be "enabled" because the rest- // weren't touched and therefore aren't changed, whereas- // "enabled" must be set by default for required params.+ // (except the locked source) weren't touched and therefore aren't changed,+ // whereas "enabled" must be set by default for required params.const expected = {id: "disabled",state: "disabled",created_at: "disabled",total: "enabled",- source: "disabled",+ source: "locked",product_id: "disabled",};@@ -177,38 +219,14 @@ describe("scenarios > embedding > native questions", () => {H.visitIframe();// Filter widget must be visible- H.filterWidget().contains("Total");+ H.filterWidget().should("have.length", 1).and("contain", "Total");// And its default value must be in the URLcy.location("search").should("eq", "?total=100");- });- it("should (dis)allow setting parameters as required for a published embedding", () => {- createAndVisitQuestion();- // Make one parameter editable and one locked- H.setEmbeddingParameter("Order ID", "Editable");- H.setEmbeddingParameter("Total", "Locked");-- H.publishChanges("card");- H.closeStaticEmbeddingModal();-- cy.findByTestId("native-query-editor-container")- .findByText("Open Editor")- .click();-- // Open variable editor- cy.findByTestId("native-query-editor-action-buttons")- .icon("variable")- .click();-- // Now check that all disabled parameters can't be required and the rest can- assertRequiredEnabledForName({ name: "id", enabled: true });- assertRequiredEnabledForName({ name: "total", enabled: true });- // disabled parameters- assertRequiredEnabledForName({ name: "created_at", enabled: false });- assertRequiredEnabledForName({ name: "source", enabled: false });- assertRequiredEnabledForName({ name: "state", enabled: false });- assertRequiredEnabledForName({ name: "product_id", enabled: false });+ H.tableInteractiveBody()+ .should("contain", "Organic")+ .and("not.contain", "Affiliate");});});@@ -219,7 +237,8 @@ describe("scenarios > embedding > native questions", () => {});});- it("should hide filters via url", () => {+ it("should hide filters, set filter values via url and lock all parameters", () => {+ cy.log("should hide filters via url");cy.get("@questionId").then((questionId) => {cy.request("PUT", `/api/card/${questionId}`, {enable_embedding: true,@@ -251,9 +270,9 @@ describe("scenarios > embedding > native questions", () => {H.filterWidget().should("not.exist");});- });- it("should set multiple filter values via url", () => {+ cy.log("should set multiple filter values via url");+ cy.signInAsAdmin();cy.get("@questionId").then((questionId) => {cy.request("PUT", `/api/card/${questionId}`, {enable_embedding: true,@@ -296,9 +315,9 @@ describe("scenarios > embedding > native questions", () => {cy.contains("35.7").should("not.exist");});- });- it("should lock all parameters", () => {+ cy.log("should lock all parameters");+ cy.signInAsAdmin();cy.get("@questionId").then((questionId) => {cy.request("PUT", `/api/card/${questionId}`, {enable_embedding: true,@@ -355,7 +374,25 @@ describe("scenarios > embedding > native questions", () => {});});- it("locked parameters require a value to be specified in the JWT", () => {+ it("locked parameters should still render results in the preview by default and require a value in the JWT (metabase#47570)", () => {+ H.visitQuestion("@questionId").then((id) => {+ H.openLegacyStaticEmbeddingModal({+ resource: "question",+ resourceId: id,+ activeTab: "parameters",+ unpublishBeforeOpen: false,+ });+ });++ H.visitIframe();++ cy.log("should show card results by default");+ cy.findByTestId("visualization-root")+ .findByText("2,500")+ .should("be.visible");+ cy.findByRole("heading", { name: "test question" }).should("be.visible");++ cy.log("locked parameters require a value to be specified in the JWT");cy.get("@questionId").then((questionId) => {const payload = {resource: { question: questionId },@@ -370,24 +407,70 @@ describe("scenarios > embedding > native questions", () => {"be.visible",);});+ });- it("locked parameters should still render results in the preview by default (metabase#47570)", () => {- H.visitQuestion("@questionId").then((id) => {- H.openLegacyStaticEmbeddingModal({- resource: "question",- resourceId: id,- activeTab: "parameters",- unpublishBeforeOpen: false,- });- });+ describe("locked numeric parameters (metabase#20845)", () => {+ function getQuestionDetails(defaultValue = undefined) {+ return {+ name: "20845",+ native: {+ "template-tags": {+ qty_locked: {+ id: "6bd8d7be-bd5b-382c-cfa2-683461891663",+ name: "qty_locked",+ "display-name": "Qty locked",+ type: "number",+ required: defaultValue ? true : false,+ default: defaultValue,+ },+ },+ query:+ "select count(*) from orders where true [[AND quantity={{qty_locked}}]]",+ },+ enable_embedding: true,+ embedding_params: {+ qty_locked: "locked",+ },+ };+ }- H.visitIframe();+ it("locked parameter should work with numeric values, with and without a required filter with a default value", () => {+ H.createNativeQuestion(getQuestionDetails(), {+ wrapId: true,+ idAlias: "questionId",+ });+ H.createNativeQuestion(getQuestionDetails("10"), {+ wrapId: true,+ idAlias: "requiredQuestionId",+ });- cy.log("should show card results by default");- cy.findByTestId("visualization-root")- .findByText("2,500")- .should("be.visible");- cy.findByRole("heading", { name: "test question" }).should("be.visible");+ [+ { alias: "@questionId", label: "without a default value" },+ {+ alias: "@requiredQuestionId",+ label: "with a required default value",+ },+ ].forEach(({ alias, label }) => {+ cy.get(alias).then((questionId) => {+ // This issue is not possible to reproduce using UI from this point on.+ // We have to manually send the payload in order to make sure it works for both strings and integers.+ ["string", "integer"].forEach((type) => {+ cy.log(+ `Make sure it works with ${type.toUpperCase()} in the payload ${label}`,+ );++ H.visitEmbeddedPage({+ resource: { question: questionId },+ params: {+ qty_locked: type === "string" ? "15" : 15, // IMPORTANT: integer+ },+ });++ H.tableInteractiveHeader("COUNT(*)");+ cy.findByRole("gridcell").should("have.text", "5");+ });+ });+ });});});});@@ -449,3 +532,167 @@ function assertRequiredEnabledForName({ name, enabled }) {);});}++// TODO:+// - Add tests for embedding previews in both cases+// - Add tests for disabled, editable and locked parameters in both cases+// BONUS: Ideally add tests for email subscriptions with the filter applied+describe("issue 27643", { tags: "@external" }, () => {+ const PG_DB_ID = 2;+ const TEMPLATE_TAG_NAME = "expected_invoice";+ const getQuestionDetails = (fieldId) => {+ return {+ name: "27643",+ database: PG_DB_ID,+ native: {+ query:+ "SELECT * FROM INVOICES [[ where {{ expected_invoice }} ]] limit 1",+ "template-tags": {+ [TEMPLATE_TAG_NAME]: {+ id: "3cfb3686-0d13-48db-ab5b-100481a3a830",+ dimension: ["field", fieldId, null],+ name: TEMPLATE_TAG_NAME,+ "display-name": "Expected Invoice",+ type: "dimension",+ "widget-type": "string/=",+ },+ },+ },+ enable_embedding: true,+ embedding_params: {+ [TEMPLATE_TAG_NAME]: "enabled",+ },+ };+ };++ beforeEach(() => {+ // This issue was only reproducible against the Postgres database.+ H.restore("postgres-12");+ cy.signInAsAdmin();+ H.withDatabase(PG_DB_ID, ({ INVOICES }) => {+ cy.wrap(INVOICES.EXPECTED_INVOICE).as(+ "postgresInvoicesExpectedInvoiceId",+ );+ });+ });++ describe("should allow a dashboard filter to map to a boolean field filter parameter (metabase#27643)", () => {+ beforeEach(() => {+ const dashboardParameter = {+ id: "2850aeab",+ name: "Text filter for boolean field",+ slug: "text_filter_for_boolean_field",+ type: "string/=",+ };++ const dashboardDetails = {+ name: "Dashboard with card with boolean field filter",+ enable_embedding: true,+ embedding_params: {+ [dashboardParameter.slug]: "enabled",+ },+ parameters: [dashboardParameter],+ };++ cy.get("@postgresInvoicesExpectedInvoiceId")+ .then((fieldId) => {+ H.createNativeQuestionAndDashboard({+ questionDetails: getQuestionDetails(fieldId),+ dashboardDetails,+ });+ })+ .then(({ body: dashboardCard }) => {+ const { card_id, dashboard_id } = dashboardCard;++ cy.wrap(dashboard_id).as("dashboardId");+ cy.wrap(card_id).as("questionId");++ const mapFilterToCard = {+ parameter_mappings: [+ {+ parameter_id: dashboardParameter.id,+ card_id,+ target: ["dimension", ["template-tag", TEMPLATE_TAG_NAME]],+ },+ ],+ };++ H.editDashboardCard(dashboardCard, mapFilterToCard);+ });+ });++ it("in static embedding and in public dashboard scenarios (metabase#27643-1)", () => {+ cy.log("Test the dashboard");+ H.visitDashboard("@dashboardId");+ H.getDashboardCard().should("contain", "true");+ H.toggleFilterWidgetValues(["false"]);+ H.getDashboardCard().should("contain", "false");++ cy.log("Test the embedded dashboard");+ cy.get("@dashboardId").then((dashboard) => {+ H.visitEmbeddedPage({+ resource: { dashboard },+ params: {},+ });++ H.getDashboardCard().should("contain", "true");+ H.toggleFilterWidgetValues(["false"]);+ H.getDashboardCard().should("contain", "false");+ });++ cy.log("Test the public dashboard");+ cy.get("@dashboardId").then((dashboardId) => {+ // We were signed out due to the previous visitEmbeddedPage+ cy.signInAsAdmin();+ H.visitPublicDashboard(dashboardId);++ H.getDashboardCard().should("contain", "true");+ H.toggleFilterWidgetValues(["false"]);+ H.getDashboardCard().should("contain", "false");+ });+ });+ });++ describe("should allow a native question filter to map to a boolean field filter parameter (metabase#27643)", () => {+ beforeEach(() => {+ cy.get("@postgresInvoicesExpectedInvoiceId").then((fieldId) => {+ H.createNativeQuestion(getQuestionDetails(fieldId), {+ wrapId: true,+ idAlias: "questionId",+ });+ });+ });++ it("in static embedding and in public question scenarios (metabase#27643-2)", () => {+ cy.log("Test the question");+ H.visitQuestion("@questionId");+ cy.findAllByRole("gridcell").should("contain", "true");+ H.toggleFilterWidgetValues(["false"]);+ H.queryBuilderMain().button("Get Answer").click();+ cy.findAllByRole("gridcell").should("contain", "false");++ cy.log("Test the embedded question");+ cy.get("@questionId").then((question) => {+ H.visitEmbeddedPage({+ resource: { question },+ params: {},+ });++ cy.findAllByRole("gridcell").should("contain", "true");+ H.toggleFilterWidgetValues(["false"]);+ cy.findAllByRole("gridcell").should("contain", "false");+ });++ cy.log("Test the public question");+ cy.get("@questionId").then((questionId) => {+ // We were signed out due to the previous visitEmbeddedPage+ cy.signInAsAdmin();+ H.visitPublicQuestion(questionId);++ cy.findAllByRole("gridcell").should("contain", "true");+ H.toggleFilterWidgetValues(["false"]);+ cy.findAllByRole("gridcell").should("contain", "false");+ });+ });+ });+});diff --git a/e2e/test/scenarios/embedding/embedding-questions.cy.spec.js b/e2e/test/scenarios/embedding/embedding-questions.cy.spec.jsindex b698176ed21..a8bc5dcfdaa 100644--- a/e2e/test/scenarios/embedding/embedding-questions.cy.spec.js+++ b/e2e/test/scenarios/embedding/embedding-questions.cy.spec.js@@ -7,11 +7,12 @@ import {import {joinedQuestion,+ questionAsPinMapWithTiles,questionWithAggregation,regularQuestion,} from "./shared/embedding-questions";-const { ORDERS, PRODUCTS } = SAMPLE_DATABASE;+const { ORDERS, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;describe("scenarios > embedding > questions", () => {beforeEach(() => {@@ -251,7 +252,7 @@ describe("scenarios [EE] > embedding > questions", () => {});});- it("should display according to `#locale` hash parameter (metabase#22561, metabase#50182)", () => {+ it("should display according to `#locale` and `#font` hash parameters (metabase#22561, metabase#50182, metabase#45638)", () => {cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {enable_embedding: true,});@@ -267,6 +268,7 @@ describe("scenarios [EE] > embedding > questions", () => {{additionalHashOptions: {locale: "de-CH",+ font: "Roboto",},},);@@ -276,24 +278,6 @@ describe("scenarios [EE] > embedding > questions", () => {H.main().findByText("Februar 11, 2028, 9:40 PM").realHover();cy.findByRole("button", { name: "Ergebnis downloaden" }).should("exist");cy.url().should("include", "locale=de");- });-- it("should display according to `#font` hash parameter (metabase#45638)", () => {- cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {- enable_embedding: true,- });-- H.visitEmbeddedPage(- {- resource: { question: ORDERS_QUESTION_ID },- params: {},- },- {- additionalHashOptions: {- font: "Roboto",- },- },- );H.main().should("have.css",@@ -308,3 +292,89 @@ function assertOnXYAxisLabels({ xLabel, yLabel } = {}) {H.echartsContainer().get("text").contains(yLabel);}++describe("issue 30535", () => {+ const questionDetails = {+ name: "3035",+ query: {+ "source-table": PRODUCTS_ID,+ limit: 10,+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");++ cy.sandboxTable({+ table_id: PRODUCTS_ID,+ attribute_remappings: {+ attr_cat: ["dimension", ["field", PRODUCTS.CATEGORY, null]],+ },+ });++ H.createQuestion(questionDetails).then(({ body: { id } }) => {+ cy.request("PUT", `/api/card/${id}`, { enable_embedding: true });++ H.visitQuestion(id);++ H.openLegacyStaticEmbeddingModal({+ resource: "question",+ resourceId: id,+ activeTab: "parameters",+ previewMode: "preview",+ unpublishBeforeOpen: false,+ });+ });+ });++ it("user session should not apply sandboxing to a signed embedded question (metabase#30535)", () => {+ cy.document().then((doc) => {+ const iframe = doc.querySelector("iframe");++ cy.signOut();+ cy.signInAsSandboxedUser();++ cy.visit(iframe.src);+ });++ cy.findByRole("grid").within(() => {+ // The sandboxed user has an attribute cat="Widget"+ cy.findAllByText("Widget");+ // Sandboxing shouldn't affect results so we should see other product categories as well+ cy.findAllByText("Gizmo");+ });+ });+});++describe("issue 63687", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should properly display pin map tiles without auth errors for a valid JWT token", () => {+ H.createNativeQuestion(questionAsPinMapWithTiles, {+ visitQuestion: true,+ wrapId: true,+ });++ cy.get("@questionId").then((questionId) => {+ H.openLegacyStaticEmbeddingModal({+ resource: "question",+ resourceId: questionId,+ activeTab: "parameters",+ unpublishBeforeOpen: false,+ });+ });++ cy.intercept("/api/embed/tiles/**").as("getTiles");++ H.visitIframe();++ cy.wait("@getTiles").then(({ response: tileResponse }) => {+ expect(tileResponse?.statusCode).to.equal(200);+ });+ });+});diff --git a/e2e/test/scenarios/embedding/embedding-reproductions.cy.spec.js b/e2e/test/scenarios/embedding/embedding-reproductions.cy.spec.jsdeleted file mode 100644index 1dc3e0e0e75..00000000000--- a/e2e/test/scenarios/embedding/embedding-reproductions.cy.spec.js+++ /dev/null@@ -1,1470 +0,0 @@-const { H } = cy;-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";-import { questionAsPinMapWithTiles } from "e2e/test/scenarios/embedding/shared/embedding-questions";-import { defer } from "metabase/utils/promise";-const { PRODUCTS, PRODUCTS_ID, ORDERS, ORDERS_ID, FEEDBACK, FEEDBACK_ID } =- SAMPLE_DATABASE;--describe("issue 20438", () => {- const questionDetails = {- name: "20438",- native: {- query:- "SELECT * FROM PRODUCTS\nWHERE true\n [[AND {{CATEGORY}}]]\n limit 30",- "template-tags": {- CATEGORY: {- id: "24f69111-29f8-135f-9321-1ff94bbb31ad",- name: "CATEGORY",- "display-name": "Category",- type: "dimension",- dimension: ["field", PRODUCTS.CATEGORY, null],- "widget-type": "string/=",- default: null,- },- },- },- };-- const filter = {- name: "Text",- slug: "text",- id: "b555d25b",- type: "string/=",- sectionId: "string",- };-- const dashboardDetails = {- parameters: [filter],- };-- beforeEach(() => {- cy.intercept("GET", "/api/embed/dashboard/**").as("getEmbed");-- H.restore();- cy.signInAsAdmin();-- H.createNativeQuestionAndDashboard({- questionDetails,- dashboardDetails,- }).then(({ body: { id, card_id, dashboard_id } }) => {- // Connect filter to the card- cy.request("PUT", `/api/dashboard/${dashboard_id}`, {- dashcards: [- {- id,- card_id,- row: 0,- col: 0,- size_x: 24,- size_y: 8,- parameter_mappings: [- {- parameter_id: filter.id,- card_id,- target: ["dimension", ["template-tag", "CATEGORY"]],- },- ],- },- ],- });-- // Enable embedding and enable the "Text" filter- cy.request("PUT", `/api/dashboard/${dashboard_id}`, {- enable_embedding: true,- embedding_params: { [filter.slug]: "enabled" },- });-- cy.wrap(card_id).as("questionId");- cy.wrap(dashboard_id).as("dashboardId");-- H.visitDashboard(dashboard_id);- });- });-- it("dashboard filter connected to the field filter should work with a single value in embedded dashboards (metabase#20438)", () => {- cy.get("@dashboardId").then((dashboardId) => {- H.openLegacyStaticEmbeddingModal({- resource: "dashboard",- resourceId: dashboardId,- activeTab: "parameters",- unpublishBeforeOpen: false,- });- });-- H.visitIframe();-- cy.wait("@getEmbed");-- H.filterWidget().click();- cy.wait("@getEmbed");-- H.popover().contains("Doohickey").click();- cy.wait("@getEmbed");-- cy.button("Add filter").click();- cy.wait("@getEmbed");-- cy.findAllByRole("gridcell")- // One of product titles for Doohickey- .should("contain", "Small Marble Shoes")- // One of product titles for Gizmo- .and("not.contain", "Rustic Paper Wallet");- });-});--describe("locked parameters in embedded question (metabase#20634)", () => {- beforeEach(() => {- cy.intercept("PUT", "/api/card/*").as("publishChanges");-- H.restore();- cy.signInAsAdmin();-- H.createNativeQuestion(- {- name: "20634",- native: {- query: "select {{text}}",- "template-tags": {- text: {- id: "abc-123",- name: "text",- "display-name": "Text",- type: "text",- default: null,- },- },- },- },- {- visitQuestion: true,- wrapId: true,- },- );- });-- it("should let the user lock parameters to specific values", () => {- cy.get("@questionId").then((questionId) => {- H.openLegacyStaticEmbeddingModal({- resource: "question",- resourceId: questionId,- activeTab: "parameters",- unpublishBeforeOpen: false,- });- });-- H.modal().within(() => {- // open the visibility dropdown for the Text parameter so that we can set the value to "Locked"- cy.findByLabelText("Text").click();- });-- H.selectDropdown().findByText("Locked").click();-- H.modal().within(() => {- // set a parameter value- cy.findByPlaceholderText("Text").type("foo{enter}");-- // publish the embedded question so that we can directly navigate to its url- cy.findByText("Publish changes").click();- cy.wait("@publishChanges");- });-- // directly navigate to the embedded question- H.visitIframe();-- // verify that the Text parameter doesn't show up but that its value is reflected in the dashcard- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Text").should("not.exist");- cy.get(".CardVisualization").within(() => {- cy.contains("foo");- });- });-});--describe("issues 20845, 25031", () => {- /**- * @param {string} defaultValue - The default value for the defined filter- * @returns object- */- function getQuestionDetails(defaultValue = undefined) {- return {- name: "20845",- native: {- "template-tags": {- qty_locked: {- id: "6bd8d7be-bd5b-382c-cfa2-683461891663",- name: "qty_locked",- "display-name": "Qty locked",- type: "number",- required: defaultValue ? true : false,- default: defaultValue,- },- },- query:- "select count(*) from orders where true [[AND quantity={{qty_locked}}]]",- },- };- }- const defaultFilterValues = [undefined, "10"];- defaultFilterValues.forEach((value) => {- const conditionalPartOfTestTitle = value- ? "and the required filter with the default value"- : "";- const dashboardFilter = {- name: "Equal to",- slug: "equal_to",- id: "c269ebe1",- type: "number/=",- sectionId: "number",- };-- const dashboardDetails = {- name: "25031",- parameters: [dashboardFilter],- };-- beforeEach(() => {- cy.intercept("PUT", "/api/card/*").as("publishChanges");-- H.restore();- cy.signInAsAdmin();-- const questionDetails = getQuestionDetails(value);-- H.createNativeQuestionAndDashboard({- questionDetails,- dashboardDetails,- }).then(({ body: { id, dashboard_id, card_id } }) => {- cy.wrap(card_id).as("questionId");- cy.wrap(dashboard_id).as("dashboardId");-- H.visitQuestion(card_id);-- // Connect dashbaord filter to the card- cy.request("PUT", `/api/dashboard/${dashboard_id}`, {- dashcards: [- {- card_id,- id,- row: 0,- col: 0,- size_x: 16,- size_y: 10,- parameter_mappings: [- {- parameter_id: dashboardFilter.id,- card_id,- target: ["variable", ["template-tag", "qty_locked"]],- },- ],- },- ],- });- });- });-- it(`QUESTION: locked parameter should work with numeric values ${conditionalPartOfTestTitle} (metabase#20845)`, () => {- cy.get("@questionId").then((questionId) => {- cy.request("PUT", `/api/card/${questionId}`, {- enable_embedding: true,- embedding_params: {- qty_locked: "locked",- },- });-- // This issue is not possible to reproduce using UI from this point on.- // We have to manually send the payload in order to make sure it works for both strings and integers.- ["string", "integer"].forEach((type) => {- cy.log(- `Make sure it works with ${type.toUpperCase()} in the payload`,- );-- H.visitEmbeddedPage({- resource: { question: questionId },- params: {- qty_locked: type === "string" ? "15" : 15, // IMPORTANT: integer- },- });- });-- H.tableInteractiveHeader("COUNT(*)");- cy.findByRole("gridcell").should("contain", "5");- });- });-- it(`DASHBOARD: locked parameter should work with numeric values ${conditionalPartOfTestTitle} (metabase#25031)`, () => {- cy.get("@dashboardId").then((dashboardId) => {- H.visitDashboard(dashboardId);- cy.request("PUT", `/api/dashboard/${dashboardId}`, {- enable_embedding: true,- embedding_params: {- [dashboardFilter.slug]: "locked",- },- });-- // This issue is not possible to reproduce using UI from this point on.- // We have to manually send the payload in order to make sure it works for both strings and integers.- ["string", "integer"].forEach((type) => {- cy.log(- `Make sure it works with ${type.toUpperCase()} in the payload`,- );-- const payload = {- resource: { dashboard: dashboardId },- params: {- [dashboardFilter.slug]: type === "string" ? "15" : 15, // IMPORTANT: integer- },- };-- H.visitEmbeddedPage(payload);-- // wait for the results to load- cy.contains(dashboardDetails.name);- cy.get(".CardVisualization")- .should("contain", "COUNT(*)")- .and("contain", "5");- });- });- });- });-});--// TODO:-// - Add tests for embedding previews in both cases-// - Add tests for disabled, editable and locked parameters in both cases-// BONUS: Ideally add tests for email subscriptions with the filter applied-describe("issue 27643", { tags: "@external" }, () => {- const PG_DB_ID = 2;- const TEMPLATE_TAG_NAME = "expected_invoice";- const getQuestionDetails = (fieldId) => {- return {- name: "27643",- database: PG_DB_ID,- native: {- query:- "SELECT * FROM INVOICES [[ where {{ expected_invoice }} ]] limit 1",- "template-tags": {- [TEMPLATE_TAG_NAME]: {- id: "3cfb3686-0d13-48db-ab5b-100481a3a830",- dimension: ["field", fieldId, null],- name: TEMPLATE_TAG_NAME,- "display-name": "Expected Invoice",- type: "dimension",- "widget-type": "string/=",- },- },- },- enable_embedding: true,- embedding_params: {- [TEMPLATE_TAG_NAME]: "enabled",- },- };- };-- beforeEach(() => {- // This issue was only reproducible against the Postgres database.- H.restore("postgres-12");- cy.signInAsAdmin();- H.withDatabase(PG_DB_ID, ({ INVOICES }) => {- cy.wrap(INVOICES.EXPECTED_INVOICE).as(- "postgresInvoicesExpectedInvoiceId",- );- });- });-- describe("should allow a dashboard filter to map to a boolean field filter parameter (metabase#27643)", () => {- beforeEach(() => {- const dashboardParameter = {- id: "2850aeab",- name: "Text filter for boolean field",- slug: "text_filter_for_boolean_field",- type: "string/=",- };-- const dashboardDetails = {- name: "Dashboard with card with boolean field filter",- enable_embedding: true,- embedding_params: {- [dashboardParameter.slug]: "enabled",- },- parameters: [dashboardParameter],- };-- cy.get("@postgresInvoicesExpectedInvoiceId")- .then((fieldId) => {- H.createNativeQuestionAndDashboard({- questionDetails: getQuestionDetails(fieldId),- dashboardDetails,- });- })- .then(({ body: dashboardCard }) => {- const { card_id, dashboard_id } = dashboardCard;-- cy.wrap(dashboard_id).as("dashboardId");- cy.wrap(card_id).as("questionId");-- const mapFilterToCard = {- parameter_mappings: [- {- parameter_id: dashboardParameter.id,- card_id,- target: ["dimension", ["template-tag", TEMPLATE_TAG_NAME]],- },- ],- };-- H.editDashboardCard(dashboardCard, mapFilterToCard);- });- });-- it("in static embedding and in public dashboard scenarios (metabase#27643-1)", () => {- cy.log("Test the dashboard");- H.visitDashboard("@dashboardId");- H.getDashboardCard().should("contain", "true");- H.toggleFilterWidgetValues(["false"]);- H.getDashboardCard().should("contain", "false");-- cy.log("Test the embedded dashboard");- cy.get("@dashboardId").then((dashboard) => {- H.visitEmbeddedPage({- resource: { dashboard },- params: {},- });-- H.getDashboardCard().should("contain", "true");- H.toggleFilterWidgetValues(["false"]);- H.getDashboardCard().should("contain", "false");- });-- cy.log("Test the public dashboard");- cy.get("@dashboardId").then((dashboardId) => {- // We were signed out due to the previous visitEmbeddedPage- cy.signInAsAdmin();- H.visitPublicDashboard(dashboardId);-- H.getDashboardCard().should("contain", "true");- H.toggleFilterWidgetValues(["false"]);- H.getDashboardCard().should("contain", "false");- });- });- });-- describe("should allow a native question filter to map to a boolean field filter parameter (metabase#27643)", () => {- beforeEach(() => {- cy.get("@postgresInvoicesExpectedInvoiceId").then((fieldId) => {- H.createNativeQuestion(getQuestionDetails(fieldId), {- wrapId: true,- idAlias: "questionId",- });- });- });-- it("in static embedding and in public question scenarios (metabase#27643-2)", () => {- cy.log("Test the question");- H.visitQuestion("@questionId");- cy.findAllByRole("gridcell").should("contain", "true");- H.toggleFilterWidgetValues(["false"]);- H.queryBuilderMain().button("Get Answer").click();- cy.findAllByRole("gridcell").should("contain", "false");-- cy.log("Test the embedded question");- cy.get("@questionId").then((question) => {- H.visitEmbeddedPage({- resource: { question },- params: {},- });-- cy.findAllByRole("gridcell").should("contain", "true");- H.toggleFilterWidgetValues(["false"]);- cy.findAllByRole("gridcell").should("contain", "false");- });-- cy.log("Test the public question");- cy.get("@questionId").then((questionId) => {- // We were signed out due to the previous visitEmbeddedPage- cy.signInAsAdmin();- H.visitPublicQuestion(questionId);-- cy.findAllByRole("gridcell").should("contain", "true");- H.toggleFilterWidgetValues(["false"]);- cy.findAllByRole("gridcell").should("contain", "false");- });- });- });-});--describe("issue 30535", () => {- const questionDetails = {- name: "3035",- query: {- "source-table": PRODUCTS_ID,- limit: 10,- },- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");-- cy.sandboxTable({- table_id: PRODUCTS_ID,- attribute_remappings: {- attr_cat: ["dimension", ["field", PRODUCTS.CATEGORY, null]],- },- });-- H.createQuestion(questionDetails).then(({ body: { id } }) => {- cy.request("PUT", `/api/card/${id}`, { enable_embedding: true });-- H.visitQuestion(id);-- H.openLegacyStaticEmbeddingModal({- resource: "question",- resourceId: id,- activeTab: "parameters",- previewMode: "preview",- unpublishBeforeOpen: false,- });- });- });-- it("user session should not apply sandboxing to a signed embedded question (metabase#30535)", () => {- cy.document().then((doc) => {- const iframe = doc.querySelector("iframe");-- cy.signOut();- cy.signInAsSandboxedUser();-- cy.visit(iframe.src);- });-- cy.findByRole("grid").within(() => {- // The sandboxed user has an attribute cat="Widget"- cy.findAllByText("Widget");- // Sandboxing shouldn't affect results so we should see other product categories as well- cy.findAllByText("Gizmo");- });- });-});--describe("dashboard preview", () => {- const questionDetails = {- name: "Products",- query: { "source-table": PRODUCTS_ID },- };-- const filter3 = {- name: "Text 2",- slug: "text_2",- id: "b0665b6a",- type: "string/=",- sectionId: "string",- };-- const filter2 = {- name: "Text 1",- slug: "text_1",- id: "d4c9f2e5",- type: "string/=",- sectionId: "string",- };-- const filter = {- filteringParameters: [filter2.id],- name: "Text",- slug: "text",- id: "d1b69627",- type: "string/=",- sectionId: "string",- };-- beforeEach(() => {- cy.intercept("GET", "/api/preview_embed/dashboard/**").as(- "previewDashboard",- );- cy.intercept("GET", "/api/preview_embed/dashboard/**/params/**/values").as(- "previewValues",- );-- H.restore();- cy.signInAsAdmin();- });-- it("dashboard linked filters values don't work in static embed preview (metabase#37914)", () => {- const dashboardDetails = {- parameters: [filter, filter2, filter3],- enable_embedding: true,- embedding_params: {- [filter.slug]: "enabled",- [filter2.slug]: "enabled",- [filter3.slug]: "enabled",- },- };- H.createQuestionAndDashboard({- questionDetails,- dashboardDetails,- }).then(({ body: { card_id, dashboard_id } }) => {- H.addOrUpdateDashboardCard({- dashboard_id,- card_id,- card: {- parameter_mappings: [- {- card_id,- parameter_id: filter.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- {- card_id,- parameter_id: filter2.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- {- card_id,- parameter_id: filter3.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- ],- },- });-- H.visitDashboard(dashboard_id);-- H.openLegacyStaticEmbeddingModal({- resource: "dashboard",- resourceId: dashboard_id,- activeTab: "parameters",- previewMode: "preview",- });- });-- H.modal().within(() => {- // Makes it less likely to flake.- cy.wait("@previewDashboard");-- H.getIframeBody().within(() => {- cy.log(- "Set filter 2 value, so filter 1 should be filtered by filter 2",- );- cy.button(filter2.name).click();- cy.wait("@previewValues");- H.popover().within(() => {- cy.findByText("Gadget").should("be.visible");- cy.findByText("Gizmo").should("be.visible");- cy.findByText("Widget").should("be.visible");- cy.findByText("Doohickey").click();- cy.button("Add filter").click();- });-- cy.log("Assert filter 1");- cy.button(filter.name).click();- H.popover().within(() => {- cy.findByText("Gadget").should("not.exist");- cy.findByText("Gizmo").should("not.exist");- cy.findByText("Widget").should("not.exist");- cy.findByText("Doohickey").should("be.visible");- });- });- });- });-- it("dashboard linked filters values in embed preview don't behave like embedding (metabase#41635)", () => {- const dashboardDetails = {- parameters: [filter, filter2, filter3],- enable_embedding: true,- embedding_params: {- [filter.slug]: "enabled",- [filter2.slug]: "locked",- [filter3.slug]: "locked",- },- };- H.createQuestionAndDashboard({- questionDetails,- dashboardDetails,- }).then(({ body: { card_id, dashboard_id } }) => {- H.addOrUpdateDashboardCard({- dashboard_id,- card_id,- card: {- parameter_mappings: [- {- card_id,- parameter_id: filter.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- {- card_id,- parameter_id: filter2.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- {- card_id,- parameter_id: filter3.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- ],- },- });-- H.visitDashboard(dashboard_id);-- H.openLegacyStaticEmbeddingModal({- resource: "dashboard",- resourceId: dashboard_id,- activeTab: "parameters",- previewMode: "preview",- });- });-- // Makes it less likely to flake.- cy.wait("@previewDashboard");-- cy.log("Set the first locked parameter values");- H.modal()- .findByRole("generic", { name: "Previewing locked parameters" })- .findByText("Text 1")- .click();- H.popover().within(() => {- cy.findByText("Doohickey").click();- cy.button("Add filter").click();- });-- cy.log("Set the second locked parameter values");- H.modal()- .findByRole("generic", { name: "Previewing locked parameters" })- .findByText("Text 2")- .click();- H.popover().within(() => {- cy.findByText("Doohickey").click();- cy.findByText("Gizmo").click();- cy.findByText("Gadget").click();- cy.button("Add filter").click();- });-- // Wait for the iframe to load- H.getIframeBody().within(() => {- cy.button(filter.name).should("not.exist");- });-- H.getIframeBody().within(() => {- cy.log("Assert filter 1");- cy.button(filter.name).click();- H.popover().within(() => {- cy.findByText("Gadget").should("not.exist");- cy.findByText("Gizmo").should("not.exist");- cy.findByText("Widget").should("not.exist");- cy.findByText("Doohickey").should("be.visible");- });- });- });-});--describe("issue 40660", () => {- const questionDetails = {- name: "Products",- query: { "source-table": PRODUCTS_ID, limit: 2 },- };-- const dashboardDetails = {- name: "long dashboard",- enable_embedding: true,- };-- beforeEach(() => {- cy.intercept("GET", "/api/preview_embed/dashboard/**").as(- "previewDashboard",- );-- H.restore();- cy.signInAsAdmin();- });-- it("static dashboard content shouldn't overflow its container (metabase#40660)", () => {- H.createQuestionAndDashboard({- questionDetails,- dashboardDetails,- }).then(({ body: { id, card_id, dashboard_id } }) => {- H.updateDashboardCards({- dashboard_id,- cards: [{ card_id }, { card_id }, { card_id }],- });-- H.visitDashboard(dashboard_id);-- H.openLegacyStaticEmbeddingModal({- resource: "dashboard",- resourceId: dashboard_id,- activeTab: "parameters",- previewMode: "preview",- });- });-- H.getIframeBody().within(() => {- cy.findByText(dashboardDetails.name).should("be.visible");- cy.findByTestId("loading-indicator").should("not.exist");- cy.findAllByText("1018947080336").should("have.length", 3);- cy.findByTestId("embed-frame").scrollTo("bottom");-- cy.findByRole("link", { name: "Powered by Metabase" })- .scrollIntoView()- .should("be.visible");- });- });-});--describe("issue 8490", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");-- H.createDashboardWithQuestions({- dashboardDetails: {- name: "Dashboard to test locale",- enable_embedding: true,- },- questions: [- {- name: "Line chart",- query: {- "source-table": PRODUCTS_ID,- aggregation: [["count"]],- breakout: [- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- [- "field",- PRODUCTS.CREATED_AT,- { "base-type": "type/DateTime", "temporal-unit": "month" },- ],- ],- filter: [- "between",- ["field", PRODUCTS.CREATED_AT, { "base-type": "type/DateTime" }],- "2027-01-01",- "2028-01-01",- ],- },- limit: 100,- visualization_settings: {- "graph.dimensions": ["CREATED_AT", "CATEGORY"],- "graph.metrics": ["count"],- },- display: "bar",- enable_embedding: true,- },- {- name: "Order quantity trend",- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "sum",- ["field", ORDERS.QUANTITY, { "base-type": "type/Integer" }],- ],- ],- breakout: [- [- "field",- ORDERS.CREATED_AT,- { "base-type": "type/DateTime", "temporal-unit": "month" },- ],- ],- filter: [- "and",- [- "between",- ["field", ORDERS.CREATED_AT, { "base-type": "type/DateTime" }],- "2027-10-01",- "2027-12-01",- ],- [- "=",- [- "field",- PRODUCTS.VENDOR,- {- "base-type": "type/Text",- "source-field": ORDERS.PRODUCT_ID,- },- ],- "Alfreda Konopelski II Group",- ],- ],- },- display: "smartscalar",- },- {- name: "Pie chart",- query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- breakout: [- [- "field",- PRODUCTS.VENDOR,- { "base-type": "type/Text", "source-field": ORDERS.PRODUCT_ID },- ],- ],- limit: 5,- },- visualization_settings: {- "pie.slice_threshold": 20,- },- display: "pie",- },- ],- cards: [{}, { col: 12 }],- }).then(({ dashboard, questions: [lineChartQuestion] }) => {- cy.wrap(dashboard.id).as("dashboardId");- cy.wrap(lineChartQuestion.id).as("lineChartQuestionId");- });- });-- it("static embeddings with `#locale` should show translate the loading message (metabase#50182)", () => {- cy.intercept(- {- method: "GET",- url: "/api/embed/dashboard/*",- middleware: true,- },- (req) => {- req.on("response", (res) => {- const MINUTE = 60 * 1000;- res.setDelay(MINUTE);- });- },- ).as("dashboardRequest");- cy.intercept(- {- method: "GET",- url: "/api/embed/card/*",- middleware: true,- },- (req) => {- req.on("response", (res) => {- const MINUTE = 60 * 1000;- res.setDelay(MINUTE);- });- },- ).as("questionRequest");-- cy.log("test a static embedded dashboard");- cy.get("@dashboardId").then((dashboardId) => {- H.visitEmbeddedPage(- {- resource: { dashboard: dashboardId },- params: {},- },- {- additionalHashOptions: {- locale: "ko",- },- },- );- });-- // Loading...- cy.findByTestId("embed-frame")- .findByText("로드 중...")- .should("be.visible");-- cy.log("test a static embedded question");- cy.get("@lineChartQuestionId").then((lineChartQuestionId) => {- H.visitEmbeddedPage(- {- resource: { question: lineChartQuestionId },- params: {},- },- {- additionalHashOptions: {- locale: "ko",- },- },- );- });-- // Loading...- cy.findByTestId("embed-frame").findByText("로딩...").should("be.visible");- });-- it("static embeddings should respect `#locale` hash parameter (metabase#8490, metabase#50182)", () => {- cy.log("test a static embedded dashboard");- const {- promise: dashboardLoaderPromise,- resolve: resolveDashboardLoaderPromise,- } = defer();- cy.intercept(- {- method: "GET",- url: "/api/embed/dashboard/*",- },- () => dashboardLoaderPromise,- ).as("dashboardRequest");-- cy.get("@dashboardId").then((dashboardId) => {- H.visitEmbeddedPage(- {- resource: { dashboard: dashboardId },- params: {},- },- {- additionalHashOptions: {- locale: "ko",- },- },- );- });-- cy.findByTestId("embed-frame").within(() => {- cy.log(- "static embeddings with `#locale` should show a translated the loading message",- );- // Loading...- cy.findByText("로드 중...")- .should("be.visible")- .then(resolveDashboardLoaderPromise);-- cy.log("assert the line chart");- H.getDashboardCard(0).within(() => {- // X-axis labels: Jan 2024 (or some other year)- cy.findByText(/^1월 20\d\d\b/).should("be.visible");- // Aggregation "count"- cy.findByText("카운트").should("be.visible");- });- });-- cy.findByTestId("embed-frame").within(() => {- cy.log("assert the trend chart");- H.getDashboardCard(2).within(() => {- // N/A (the comparison row combines it with the comparison description)- cy.findByText(/해당 없음/).should("be.visible");- // (No data)- cy.findByText("(데이터 없음)").should("be.visible");- });-- cy.log("assert the pie chart");- H.getDashboardCard(1).within(() => {- // Total- cy.findByText("합계").should("be.visible");- // Other- cy.findByTestId("chart-legend").findByText("기타").should("be.visible");- });- });-- cy.log("test a static embedded question");- const {- promise: questionLoaderPromise,- resolve: resolveQuestionLoaderPromise,- } = defer();- cy.intercept(- {- method: "GET",- url: "/api/embed/card/*",- },- () => questionLoaderPromise,- ).as("questionRequest");-- cy.log("assert the line chart");- cy.get("@lineChartQuestionId").then((lineChartQuestionId) => {- H.visitEmbeddedPage(- {- resource: { question: lineChartQuestionId },- params: {},- },- {- additionalHashOptions: {- locale: "ko",- },- },- );- });-- cy.findByTestId("embed-frame").within(() => {- cy.log(- "static embeddings with `#locale` should show a translated the loading message",- );- // Loading...- cy.findByText("로딩...")- .should("be.visible")- .then(resolveQuestionLoaderPromise);-- // X-axis labels: Jan 2023 (or some other year)- cy.findByText(/11월 20\d\d\b/).should("be.visible");- // Aggregation "count"- cy.findByText("카운트").should("be.visible");- });- });-});--describe("issue 50373", () => {- it("should return cache headers in production for js bundle", () => {- cy.intercept(- {- method: "GET",- url: /^\/app\/dist\/(.*)\.js$/,- },- (req) => {- // When running in development (e.g. with `bun run dev`),- // the *.hot.bundle.js hot-reloaded file is served by the dev server.- if (req.url.includes("hot.bundle.js")) {- return;- }-- req.on("response", (res) => {- expect(- res.headers["cache-control"],- `Invalid Cache-Control header for ${req.url}`,- ).to.equal("public, max-age=31536000");- });- },- );-- H.visitEmbeddedPage({ resource: { dashboard: ORDERS_DASHBOARD_ID } });- });-});--describe("issue 51934 (EMB-189)", () => {- const COLLECTION_NAME = "Model Collection";- const MODEL_IN_ROOT_NAME = "Products Model";- const MODEL_IN_COLLECTION_NAME = "QA Postgres12 Orders Model";- const QUESTION_IN_COLLECTION_NAME = "Orders Question";-- beforeEach(() => {- H.restore("postgres-12");- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.createModelFromTableName({- tableName: "products",- modelName: MODEL_IN_ROOT_NAME,- });- H.createCollection({- name: COLLECTION_NAME,- alias: "collectionId",- });- H.createModelFromTableName({- tableName: "orders",- modelName: MODEL_IN_COLLECTION_NAME,- idAlias: "modelId",- });- moveToCollection({- collectionIdAlias: "collectionId",- cardIdAlias: "modelId",- });- H.createQuestion(- {- name: QUESTION_IN_COLLECTION_NAME,- query: {- "source-table": ORDERS_ID,- },- },- {- wrapId: true,- idAlias: "questionId",- },- );- moveToCollection({- collectionIdAlias: "collectionId",- cardIdAlias: "questionId",- });- });-- it("should set the starting join step based on the query source", () => {- startNewEmbeddingQuestion();- const QA_DB_NAME = "QA Postgres12";- const DATA_SOURCE_NAME = "Orders";-- // Before the picker can auto-navigate into the data source's collection it- // resolves the target path asynchronously: a card-metadata fetch plus one- // `listCollectionItems` request per collection level (root -> Model- // Collection). On a throttled CI runner that serial chain routinely outlasts- // Cypress's default 4 s command timeout, so the picker is still showing the- // parent (root) collections when a default-timeout query gives up — the- // dominant "cannot find menuitem '...' (only the root collections are- // present)" flake. Wait for the loader to clear, then give the item lookup a- // generous timeout so it waits for the path to finish resolving, and assert- // it is visible (positive anchor) before clicking.- const PICKER_ITEM_TIMEOUT = 15000;- const clickPickerItem = (name) => {- cy.get('[data-testid="mini-picker-list-loader"]').should("not.exist");- cy.findByRole("menuitem", { name }, { timeout: PICKER_ITEM_TIMEOUT })- .should("be.visible")- .click();- };-- // The data-source picker and the join picker are both rendered by the same- // embedding DataSourceSelector, so a generic popover query could not tell- // them apart. When a click swaps one for the other they can briefly overlap- // (the outgoing one is still in its close transition while the incoming one- // is already mounted), which made matching ambiguous and flaky on slow CI- // runners.- //- // Each picker now carries its trigger's label as the dropdown's accessible- // name (`aria-label`), so we can target each popover deterministically by- // name regardless of any transition overlap. `.filter(":visible").last()`- // guards against a same-named popover that is still animating closed.- const pickerPopover = (name) =>- cy- .get(`[data-element-id=mantine-popover][aria-label="${name}"]`)- .filter(":visible")- .should("have.length.at.least", 1)- .last();- const dataSourcePopover = () => pickerPopover("Pick your starting data");- const joinPopover = () => pickerPopover("Pick data to join");-- cy.log("select a table as a data source");- dataSourcePopover().within(() => {- cy.findByText("Raw Data").click();- });- dataSourcePopover().within(() => {- cy.findByRole("heading", { name: QA_DB_NAME }).click();- });- dataSourcePopover().within(() => {- cy.findByRole("option", { name: DATA_SOURCE_NAME }).click();- });- H.getNotebookStep("data").button("Join data").click();-- cy.log(- 'select the "Join" step when the data source is a table will open a table in the same database',- );- joinPopover().within(() => {- cy.findByText(QA_DB_NAME).should("be.visible");- cy.findByRole("option", { name: "Orders" }).should("be.visible");- });-- cy.log(- "changing the data source while not selecting the join step should refresh the data picker on the join step",- );- H.getNotebookStep("data").findByText(DATA_SOURCE_NAME).click();-- cy.log('go back to the "Bucket" step');- dataSourcePopover().within(() => {- cy.icon("chevronleft").click();- });- dataSourcePopover().within(() => {- cy.icon("chevronleft").click();- });-- cy.log(- "select a question as a data source should open the saved question step in the same collection as the data source (metabase#58357)",- );- dataSourcePopover().within(() => {- cy.findByText("Saved Questions").click();- });- dataSourcePopover().within(() => clickPickerItem(COLLECTION_NAME));- dataSourcePopover().within(() =>- clickPickerItem(QUESTION_IN_COLLECTION_NAME),- );-- cy.log("the join popover is automatically opened");- joinPopover().within(() => {- cy.log("the collection of the data source should be selected");- cy.findByRole("menuitem", { name: COLLECTION_NAME }).should(- "have.css",- "background-color",- // brand color- "rgb(80, 158, 226)",- );- clickPickerItem(QUESTION_IN_COLLECTION_NAME);- });-- cy.log(- "select a model as a data source should open the model step in the same collection as the data source",- );- H.getNotebookStep("data").findByText(QUESTION_IN_COLLECTION_NAME).click();-- // Go back to the "Bucket" step- dataSourcePopover().within(() => {- cy.findByText("Saved Questions").click();- });- // We're now at the "Bucket" step- dataSourcePopover().within(() => {- cy.findByText("Models").click();- });- dataSourcePopover().within(() => clickPickerItem(MODEL_IN_COLLECTION_NAME));-- cy.log("the join popover is automatically opened");- joinPopover().within(() => {- cy.log("the collection of the data source should be selected");- cy.findByRole("menuitem", { name: COLLECTION_NAME }).should(- "have.css",- "background-color",- // brand color- "rgb(80, 158, 226)",- );- clickPickerItem(MODEL_IN_COLLECTION_NAME);- });-- cy.log(- "select a data source after selecting a join step should refresh the data picker on the join step",- );- H.getNotebookStep("data").findByText(MODEL_IN_COLLECTION_NAME).click();- dataSourcePopover().within(() => clickPickerItem("Our analytics"));- dataSourcePopover().within(() => clickPickerItem(MODEL_IN_ROOT_NAME));-- joinPopover().within(() => {- cy.log("the collection of the new data source should be selected");- cy.findByRole("menuitem", { name: "Our analytics" }).should(- "have.css",- "background-color",- // brand color- "rgb(80, 158, 226)",- );- cy.findByRole("menuitem", { name: MODEL_IN_ROOT_NAME }).should(- "be.visible",- );- });- });-- function startNewEmbeddingQuestion() {- H.visitFullAppEmbeddingUrl({- url: "/question/notebook",- qs: {- data_picker: "staged",- entity_types: "table,model,question",- },- });- }-- function moveToCollection({ collectionIdAlias, cardIdAlias }) {- cy.get(`@${collectionIdAlias}`).then((collectionId) => {- cy.get(`@${cardIdAlias}`).then((cardId) => {- cy.request("PUT", `/api/card/${cardId}`, {- collection_id: collectionId,- });- });- });- }-});--describe("issue 63687", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should properly display pin map tiles without auth errors for a valid JWT token", () => {- H.createNativeQuestion(questionAsPinMapWithTiles, {- visitQuestion: true,- wrapId: true,- });-- cy.get("@questionId").then((questionId) => {- H.openLegacyStaticEmbeddingModal({- resource: "question",- resourceId: questionId,- activeTab: "parameters",- unpublishBeforeOpen: false,- });- });-- cy.intercept("/api/embed/tiles/**").as("getTiles");-- H.visitIframe();-- cy.wait("@getTiles").then(({ response: tileResponse }) => {- expect(tileResponse?.statusCode).to.equal(200);- });- });-});--describe("issue 57028", () => {- const lockedContainsBodyFilter = {- name: "locked_contains_body",- slug: "locked_contains_body",- id: "e6588080",- type: "string/contains",- sectionId: "string",- isMultiSelect: true,- values_query_type: "none",- };-- const emailFilter = {- name: "Email",- slug: "email",- id: "d31e550f",- type: "string/=",- sectionId: "string",- values_query_type: "list",- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("static embedded editable filter should load dropdown values when a string/contains locked param has multiple values (metabase#57028)", () => {- H.createQuestionAndDashboard({- questionDetails: {- name: "Feedback",- query: { "source-table": FEEDBACK_ID },- },- dashboardDetails: {- parameters: [lockedContainsBodyFilter, emailFilter],- enable_embedding: true,- embedding_params: {- [lockedContainsBodyFilter.slug]: "locked",- [emailFilter.slug]: "enabled",- },- },- }).then(({ body: { card_id, dashboard_id } }) => {- H.addOrUpdateDashboardCard({- dashboard_id,- card_id,- card: {- parameter_mappings: [- {- card_id,- parameter_id: lockedContainsBodyFilter.id,- target: ["dimension", ["field", FEEDBACK.BODY, null]],- },- {- card_id,- parameter_id: emailFilter.id,- target: ["dimension", ["field", FEEDBACK.EMAIL, null]],- },- ],- },- });-- cy.intercept(- "GET",- `/api/embed/dashboard/*/params/${emailFilter.id}/values`,- ).as("emailValues");-- H.visitEmbeddedPage({- resource: { dashboard: dashboard_id },- params: {- [lockedContainsBodyFilter.slug]: ["March", "damp", "somewhat"],- },- });- });-- H.filterWidget().contains("Email").click();-- cy.wait("@emailValues").its("response.statusCode").should("eq", 200);-- H.popover().within(() => {- cy.findByPlaceholderText("Search the list").should("be.visible");- cy.findAllByRole("checkbox").its("length").should("be.greaterThan", 0);- });- });-});diff --git a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.jsindex 9f3c25b8a24..f8cb7b55b77 100644--- a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js+++ b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js@@ -1742,3 +1742,216 @@ const signInForCollectionCase = ({ user, readCollectionIds }) => {}cy.signIn(user);};++describe("issue 51934 (EMB-189)", () => {+ const COLLECTION_NAME = "Model Collection";+ const MODEL_IN_ROOT_NAME = "Products Model";+ const MODEL_IN_COLLECTION_NAME = "QA Postgres12 Orders Model";+ const QUESTION_IN_COLLECTION_NAME = "Orders Question";++ beforeEach(() => {+ H.restore("postgres-12");+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ H.createModelFromTableName({+ tableName: "products",+ modelName: MODEL_IN_ROOT_NAME,+ });+ H.createCollection({+ name: COLLECTION_NAME,+ alias: "collectionId",+ });+ H.createModelFromTableName({+ tableName: "orders",+ modelName: MODEL_IN_COLLECTION_NAME,+ idAlias: "modelId",+ });+ moveToCollection({+ collectionIdAlias: "collectionId",+ cardIdAlias: "modelId",+ });+ H.createQuestion(+ {+ name: QUESTION_IN_COLLECTION_NAME,+ query: {+ "source-table": ORDERS_ID,+ },+ },+ {+ wrapId: true,+ idAlias: "questionId",+ },+ );+ moveToCollection({+ collectionIdAlias: "collectionId",+ cardIdAlias: "questionId",+ });+ });++ it("should set the starting join step based on the query source", () => {+ startNewEmbeddingQuestion();+ const QA_DB_NAME = "QA Postgres12";+ const DATA_SOURCE_NAME = "Orders";++ // Before the picker can auto-navigate into the data source's collection it+ // resolves the target path asynchronously: a card-metadata fetch plus one+ // `listCollectionItems` request per collection level (root -> Model+ // Collection). On a throttled CI runner that serial chain routinely outlasts+ // Cypress's default 4 s command timeout, so the picker is still showing the+ // parent (root) collections when a default-timeout query gives up — the+ // dominant "cannot find menuitem '...' (only the root collections are+ // present)" flake. Wait for the loader to clear, then give the item lookup a+ // generous timeout so it waits for the path to finish resolving, and assert+ // it is visible (positive anchor) before clicking.+ const PICKER_ITEM_TIMEOUT = 15000;+ const clickPickerItem = (name) => {+ cy.get('[data-testid="mini-picker-list-loader"]').should("not.exist");+ cy.findByRole("menuitem", { name }, { timeout: PICKER_ITEM_TIMEOUT })+ .should("be.visible")+ .click();+ };++ // The data-source picker and the join picker are both rendered by the same+ // embedding DataSourceSelector, so a generic popover query could not tell+ // them apart. When a click swaps one for the other they can briefly overlap+ // (the outgoing one is still in its close transition while the incoming one+ // is already mounted), which made matching ambiguous and flaky on slow CI+ // runners.+ //+ // Each picker now carries its trigger's label as the dropdown's accessible+ // name (`aria-label`), so we can target each popover deterministically by+ // name regardless of any transition overlap. `.filter(":visible").last()`+ // guards against a same-named popover that is still animating closed.+ const pickerPopover = (name) =>+ cy+ .get(`[data-element-id=mantine-popover][aria-label="${name}"]`)+ .filter(":visible")+ .should("have.length.at.least", 1)+ .last();+ const dataSourcePopover = () => pickerPopover("Pick your starting data");+ const joinPopover = () => pickerPopover("Pick data to join");++ cy.log("select a table as a data source");+ dataSourcePopover().within(() => {+ cy.findByText("Raw Data").click();+ });+ dataSourcePopover().within(() => {+ cy.findByRole("heading", { name: QA_DB_NAME }).click();+ });+ dataSourcePopover().within(() => {+ cy.findByRole("option", { name: DATA_SOURCE_NAME }).click();+ });+ H.getNotebookStep("data").button("Join data").click();++ cy.log(+ 'select the "Join" step when the data source is a table will open a table in the same database',+ );+ joinPopover().within(() => {+ cy.findByText(QA_DB_NAME).should("be.visible");+ cy.findByRole("option", { name: "Orders" }).should("be.visible");+ });++ cy.log(+ "changing the data source while not selecting the join step should refresh the data picker on the join step",+ );+ H.getNotebookStep("data").findByText(DATA_SOURCE_NAME).click();++ cy.log('go back to the "Bucket" step');+ dataSourcePopover().within(() => {+ cy.icon("chevronleft").click();+ });+ dataSourcePopover().within(() => {+ cy.icon("chevronleft").click();+ });++ cy.log(+ "select a question as a data source should open the saved question step in the same collection as the data source (metabase#58357)",+ );+ dataSourcePopover().within(() => {+ cy.findByText("Saved Questions").click();+ });+ dataSourcePopover().within(() => clickPickerItem(COLLECTION_NAME));+ dataSourcePopover().within(() =>+ clickPickerItem(QUESTION_IN_COLLECTION_NAME),+ );++ cy.log("the join popover is automatically opened");+ joinPopover().within(() => {+ cy.log("the collection of the data source should be selected");+ cy.findByRole("menuitem", { name: COLLECTION_NAME }).should(+ "have.css",+ "background-color",+ // brand color+ "rgb(80, 158, 226)",+ );+ clickPickerItem(QUESTION_IN_COLLECTION_NAME);+ });++ cy.log(+ "select a model as a data source should open the model step in the same collection as the data source",+ );+ H.getNotebookStep("data").findByText(QUESTION_IN_COLLECTION_NAME).click();++ // Go back to the "Bucket" step+ dataSourcePopover().within(() => {+ cy.findByText("Saved Questions").click();+ });+ // We're now at the "Bucket" step+ dataSourcePopover().within(() => {+ cy.findByText("Models").click();+ });+ dataSourcePopover().within(() => clickPickerItem(MODEL_IN_COLLECTION_NAME));++ cy.log("the join popover is automatically opened");+ joinPopover().within(() => {+ cy.log("the collection of the data source should be selected");+ cy.findByRole("menuitem", { name: COLLECTION_NAME }).should(+ "have.css",+ "background-color",+ // brand color+ "rgb(80, 158, 226)",+ );+ clickPickerItem(MODEL_IN_COLLECTION_NAME);+ });++ cy.log(+ "select a data source after selecting a join step should refresh the data picker on the join step",+ );+ H.getNotebookStep("data").findByText(MODEL_IN_COLLECTION_NAME).click();+ dataSourcePopover().within(() => clickPickerItem("Our analytics"));+ dataSourcePopover().within(() => clickPickerItem(MODEL_IN_ROOT_NAME));++ joinPopover().within(() => {+ cy.log("the collection of the new data source should be selected");+ cy.findByRole("menuitem", { name: "Our analytics" }).should(+ "have.css",+ "background-color",+ // brand color+ "rgb(80, 158, 226)",+ );+ cy.findByRole("menuitem", { name: MODEL_IN_ROOT_NAME }).should(+ "be.visible",+ );+ });+ });++ function startNewEmbeddingQuestion() {+ H.visitFullAppEmbeddingUrl({+ url: "/question/notebook",+ qs: {+ data_picker: "staged",+ entity_types: "table,model,question",+ },+ });+ }++ function moveToCollection({ collectionIdAlias, cardIdAlias }) {+ cy.get(`@${collectionIdAlias}`).then((collectionId) => {+ cy.get(`@${cardIdAlias}`).then((cardId) => {+ cy.request("PUT", `/api/card/${cardId}`, {+ collection_id: collectionId,+ });+ });+ });+ }+});