diff --git a/frontend/test/metabase/scenarios/embedding/embedding-native.cy.spec.js b/frontend/test/metabase/scenarios/embedding/embedding-native.cy.spec.js index 6378056bf5583ab467432c45f7c29f84c102955f..969e990aa8ca75c007aad93b4ef2728a7431906a 100644 --- a/frontend/test/metabase/scenarios/embedding/embedding-native.cy.spec.js +++ b/frontend/test/metabase/scenarios/embedding/embedding-native.cy.spec.js @@ -3,84 +3,10 @@ import { popover, filterWidget, visitEmbeddedPage, + visitIframe, } from "__support__/e2e/cypress"; -import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database"; - -const { ORDERS, PEOPLE } = SAMPLE_DATABASE; - -const query = ` -SELECT orders.id, orders.product_id, orders.created_at AS production_date, orders.total, people.state, people.name, people.source -FROM orders LEFT JOIN people ON orders.user_id = people.id -WHERE true - [[AND {{id}}]] - [[AND orders.product_id = {{product_id}}]] - [[AND {{created_at}}]] - [[AND {{total}}]] - [[AND {{state}}]] - AND [[people.source = {{source}} --]] people.source IN ('Affiliate', 'Organic') - LIMIT 15; -`; - -const questionDetails = { - name: "Native Quesiton With Multiple Filters - Embedding Test", - description: "FooBar", - native: { - "template-tags": { - id: { - id: "d404e93f-8155-e990-ff57-37122547406c", - name: "id", - "display-name": "Order ID", - type: "dimension", - dimension: ["field", ORDERS.ID, null], - "widget-type": "id", - default: null, - }, - created_at: { - id: "a21ca6d2-f742-a94a-da71-75adf379069c", - name: "created_at", - "display-name": "Created At", - type: "dimension", - dimension: ["field", ORDERS.CREATED_AT, null], - "widget-type": "date/quarter-year", - default: null, - }, - total: { - id: "68350949-02cc-f540-86cf-ddcda07529d8", - name: "total", - "display-name": "Total", - type: "dimension", - dimension: ["field", ORDERS.TOTAL, null], - "widget-type": "number/>=", - default: [0], - required: true, - }, - source: { - id: "44038e73-f909-1bed-0974-2a42ce8979e8", - name: "source", - "display-name": "Source", - type: "text", - }, - state: { - id: "88057a9e-91bd-4b2e-9327-afd92c259dc8", - name: "state", - "display-name": "State", - type: "dimension", - dimension: ["field", PEOPLE.STATE, null], - "widget-type": "string/!=", - default: null, - }, - product_id: { - id: "c967d72e-3687-aa01-8c47-458f7905305f", - name: "product_id", - "display-name": "Product ID", - type: "number", - default: null, - }, - }, - query, - type: "native", - }, -}; + +import { questionDetails } from "./embedding-native"; describe("scenarios > embedding > native questions", () => { beforeEach(() => { @@ -102,12 +28,7 @@ describe("scenarios > embedding > native questions", () => { assert.deepEqual(request.body.embedding_params, {}); }); - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - - cy.signOut(); - cy.visit(iframe.src); - }); + visitIframe(); cy.contains("Lora Cronin"); cy.contains("Organic"); @@ -150,12 +71,7 @@ describe("scenarios > embedding > native questions", () => { assert.deepEqual(actual, expected); }); - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - - cy.signOut(); - cy.visit(iframe.src); - }); + visitIframe(); cy.contains("Organic"); cy.contains("Twitter").should("not.exist"); diff --git a/frontend/test/metabase/scenarios/embedding/embedding-native.js b/frontend/test/metabase/scenarios/embedding/embedding-native.js new file mode 100644 index 0000000000000000000000000000000000000000..6aaf6529b74ff21d377861c895d29f32a93b07c0 --- /dev/null +++ b/frontend/test/metabase/scenarios/embedding/embedding-native.js @@ -0,0 +1,77 @@ +import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database"; + +const { ORDERS, PEOPLE } = SAMPLE_DATABASE; + +const query = ` +SELECT orders.id, orders.product_id, orders.created_at AS production_date, orders.total, people.state, people.name, people.source +FROM orders LEFT JOIN people ON orders.user_id = people.id +WHERE true + [[AND {{id}}]] + [[AND orders.product_id = {{product_id}}]] + [[AND {{created_at}}]] + [[AND {{total}}]] + [[AND {{state}}]] + AND [[people.source = {{source}} --]] people.source IN ('Affiliate', 'Organic') + LIMIT 15; +`; + +export const questionDetails = { + name: "Native Quesiton With Multiple Filters - Embedding Test", + description: "FooBar", + native: { + "template-tags": { + id: { + id: "d404e93f-8155-e990-ff57-37122547406c", + name: "id", + "display-name": "Order ID", + type: "dimension", + dimension: ["field", ORDERS.ID, null], + "widget-type": "id", + default: null, + }, + created_at: { + id: "a21ca6d2-f742-a94a-da71-75adf379069c", + name: "created_at", + "display-name": "Created At", + type: "dimension", + dimension: ["field", ORDERS.CREATED_AT, null], + "widget-type": "date/quarter-year", + default: null, + }, + total: { + id: "68350949-02cc-f540-86cf-ddcda07529d8", + name: "total", + "display-name": "Total", + type: "dimension", + dimension: ["field", ORDERS.TOTAL, null], + "widget-type": "number/>=", + default: [0], + required: true, + }, + source: { + id: "44038e73-f909-1bed-0974-2a42ce8979e8", + name: "source", + "display-name": "Source", + type: "text", + }, + state: { + id: "88057a9e-91bd-4b2e-9327-afd92c259dc8", + name: "state", + "display-name": "State", + type: "dimension", + dimension: ["field", PEOPLE.STATE, null], + "widget-type": "string/!=", + default: null, + }, + product_id: { + id: "c967d72e-3687-aa01-8c47-458f7905305f", + name: "product_id", + "display-name": "Product ID", + type: "number", + default: null, + }, + }, + query, + type: "native", + }, +}; diff --git a/frontend/test/metabase/scenarios/embedding/embedding-questions.cy.spec.js b/frontend/test/metabase/scenarios/embedding/embedding-questions.cy.spec.js index 2840e353c1d98d91f60078184c7e672202d1a3b0..067fa5e7464e1629b4247080db0fbe7c1083cb9f 100644 --- a/frontend/test/metabase/scenarios/embedding/embedding-questions.cy.spec.js +++ b/frontend/test/metabase/scenarios/embedding/embedding-questions.cy.spec.js @@ -1,4 +1,9 @@ -import { restore, visitQuestion, popover } from "__support__/e2e/cypress"; +import { + restore, + visitQuestion, + popover, + visitIframe, +} from "__support__/e2e/cypress"; import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database"; import { @@ -39,12 +44,7 @@ describe("scenarios > embedding > questions ", () => { cy.icon("share").click(); cy.findByText("Embed this question in an application").click(); - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - - cy.signOut(); - cy.visit(iframe.src); - }); + visitIframe(); cy.findByText(title); @@ -80,12 +80,7 @@ describe("scenarios > embedding > questions ", () => { cy.icon("share").click(); cy.findByText("Embed this question in an application").click(); - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - - cy.signOut(); - cy.visit(iframe.src); - }); + visitIframe(); assertOnXYAxisLabels({ xLabel: "Created At", yLabel: "Count" }); @@ -123,12 +118,7 @@ describe("scenarios > embedding > questions ", () => { cy.icon("share").click(); cy.findByText("Embed this question in an application").click(); - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - - cy.signOut(); - cy.visit(iframe.src); - }); + visitIframe(); // Global (Data model) settings should be preserved cy.findByText("Product ID as Title"); @@ -158,12 +148,7 @@ describe("scenarios > embedding > questions ", () => { cy.icon("share").click(); cy.findByText("Embed this question in an application").click(); - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - - cy.signOut(); - cy.visit(iframe.src); - }); + visitIframe(); // Base question assertions cy.findByText("Product ID as Title"); diff --git a/frontend/test/metabase/scenarios/embedding/embedding-smoketests.cy.spec.js b/frontend/test/metabase/scenarios/embedding/embedding-smoketests.cy.spec.js index 69aaad5218a14bffa1ce03c1d92a698b01a795fe..25f10d9855a2f7046837f93daaabf2a5d7f6a5c5 100644 --- a/frontend/test/metabase/scenarios/embedding/embedding-smoketests.cy.spec.js +++ b/frontend/test/metabase/scenarios/embedding/embedding-smoketests.cy.spec.js @@ -4,6 +4,7 @@ import { isEE, isOSS, visitDashboard, + visitIframe, } from "__support__/e2e/cypress"; const embeddingPage = "/admin/settings/embedding_in_other_applications"; @@ -138,6 +139,8 @@ describe("scenarios > embedding > smoke tests", () => { cy.contains("Powered by Metabase").should("not.exist"); } + cy.signInAsAdmin(); + cy.visit(embeddingPage); cy.wait("@currentlyEmbeddedObject"); @@ -162,6 +165,8 @@ describe("scenarios > embedding > smoke tests", () => { visitIframe(); cy.findByText("Embedding is not enabled for this object."); + cy.signInAsAdmin(); + cy.visit(embeddingPage); cy.wait("@currentlyEmbeddedObject"); @@ -219,13 +224,6 @@ function ensureEmbeddingIsDisabled() { ); } -function visitIframe() { - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - cy.visit(iframe.src); - }); -} - function visitAndEnableSharing(object) { if (object === "question") { visitQuestion("1"); diff --git a/frontend/test/metabase/scenarios/embedding/embedding-snippets.cy.spec.js b/frontend/test/metabase/scenarios/embedding/embedding-snippets.cy.spec.js index f96d58585bdeb21a1866d0483f926cd7a9c26cac..81a6921444f358f652034cc967021e1159a6413e 100644 --- a/frontend/test/metabase/scenarios/embedding/embedding-snippets.cy.spec.js +++ b/frontend/test/metabase/scenarios/embedding/embedding-snippets.cy.spec.js @@ -1,5 +1,7 @@ import { restore, popover, visitDashboard } from "__support__/e2e/cypress"; +import { JS_CODE, IFRAME_CODE } from "./embedding-snippets"; + describe("scenarios > embedding > code snippets", () => { beforeEach(() => { restore(); @@ -17,38 +19,6 @@ describe("scenarios > embedding > code snippets", () => { "Insert this code snippet in your server code to generate the signed embedding URL", ); - const JS_CODE = new RegExp( - `// you will need to install via 'npm install jsonwebtoken' or in your package.json - -var jwt = require("jsonwebtoken"); - -var METABASE_SITE_URL = "http://localhost:PORTPORTPORT"; -var METABASE_SECRET_KEY = "KEYKEYKEY"; -var payload = { - resource: { dashboard: 1 }, - params: {}, - exp: Math.round(Date.now() / 1000) + (10 * 60) // 10 minute expiration -}; -var token = jwt.sign(payload, METABASE_SECRET_KEY); - -var iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true&titled=true";` - .split("\n") - .join("") - .replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") - .replace("KEYKEYKEY", ".*") - .replace("PORTPORTPORT", ".*"), - ); - - const IFRAME_CODE = `<iframe - src="{{iframeUrl}}" - frameborder="0" - width="800" - height="600" - allowtransparency -></iframe>` - .split("\n") - .join(""); - cy.get(".ace_content") .first() .invoke("text") diff --git a/frontend/test/metabase/scenarios/embedding/embedding-snippets.js b/frontend/test/metabase/scenarios/embedding/embedding-snippets.js new file mode 100644 index 0000000000000000000000000000000000000000..eeea9e43e9271b89fd27ac8e8e62ad8e7c2e5dd0 --- /dev/null +++ b/frontend/test/metabase/scenarios/embedding/embedding-snippets.js @@ -0,0 +1,31 @@ +export const JS_CODE = new RegExp( + `// you will need to install via 'npm install jsonwebtoken' or in your package.json + +var jwt = require("jsonwebtoken"); + +var METABASE_SITE_URL = "http://localhost:PORTPORTPORT"; +var METABASE_SECRET_KEY = "KEYKEYKEY"; +var payload = { + resource: { dashboard: 1 }, + params: {}, + exp: Math.round(Date.now() / 1000) + (10 * 60) // 10 minute expiration +}; +var token = jwt.sign(payload, METABASE_SECRET_KEY); + +var iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true&titled=true";` + .split("\n") + .join("") + .replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + .replace("KEYKEYKEY", ".*") + .replace("PORTPORTPORT", ".*"), +); + +export const IFRAME_CODE = `<iframe + src="{{iframeUrl}}" + frameborder="0" + width="800" + height="600" + allowtransparency +></iframe>` + .split("\n") + .join(""); diff --git a/frontend/test/metabase/scenarios/embedding/reproductions/20438-dashboard-filter-single-value.cy.spec.js b/frontend/test/metabase/scenarios/embedding/reproductions/20438-dashboard-filter-single-value.cy.spec.js index 26a0eb8fff8b528c3eb715780baf8af008a4e96c..102396864452c9be5346313203fe7129a50fe897 100644 --- a/frontend/test/metabase/scenarios/embedding/reproductions/20438-dashboard-filter-single-value.cy.spec.js +++ b/frontend/test/metabase/scenarios/embedding/reproductions/20438-dashboard-filter-single-value.cy.spec.js @@ -3,6 +3,7 @@ import { filterWidget, popover, visitDashboard, + visitIframe, } from "__support__/e2e/cypress"; import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database"; @@ -82,10 +83,7 @@ describe("issue 20438", () => { cy.icon("share").click(); cy.findByText("Embed this dashboard in an application").click(); - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - cy.visit(iframe.src); - }); + visitIframe(); cy.wait("@getEmbed"); diff --git a/frontend/test/metabase/scenarios/embedding/reproductions/20634-locked-parameters-in-embedded-question.cy.spec.js b/frontend/test/metabase/scenarios/embedding/reproductions/20634-locked-parameters-in-embedded-question.cy.spec.js index b2bb4f9d771455d8acb6398333bf98838c5d06c1..7fdd9a78bf61e54ba56e37fade802e46bfb78738 100644 --- a/frontend/test/metabase/scenarios/embedding/reproductions/20634-locked-parameters-in-embedded-question.cy.spec.js +++ b/frontend/test/metabase/scenarios/embedding/reproductions/20634-locked-parameters-in-embedded-question.cy.spec.js @@ -1,4 +1,4 @@ -import { restore } from "__support__/e2e/cypress"; +import { restore, visitIframe } from "__support__/e2e/cypress"; describe("locked parameters in embedded question (metabase#20634)", () => { beforeEach(() => { @@ -49,10 +49,7 @@ describe("locked parameters in embedded question (metabase#20634)", () => { }); // directly navigate to the embedded question - cy.document().then(doc => { - const iframe = doc.querySelector("iframe"); - cy.visit(iframe.src); - }); + visitIframe(); // verify that the Text parameter doesn't show up but that its value is reflected in the dashcard cy.findByText("Text").should("not.exist"); diff --git a/frontend/test/metabase/scenarios/sharing/public.cy.spec.js b/frontend/test/metabase/scenarios/sharing/public.cy.spec.js index b87e1589810151ede79a51a07f038c17939a560d..d654b602f63e1c9be8679c04037de5026eb34b85 100644 --- a/frontend/test/metabase/scenarios/sharing/public.cy.spec.js +++ b/frontend/test/metabase/scenarios/sharing/public.cy.spec.js @@ -59,10 +59,8 @@ describe.skip("scenarios > public", () => { }); let questionPublicLink; - let questionEmbedUrl; let dashboardId; let dashboardPublicLink; - let dashboardEmbedUrl; describe("questions", () => { // Note: Test suite is sequential, so individual test cases can't be run individually @@ -140,29 +138,6 @@ describe.skip("scenarios > public", () => { }); }); - it("should allow users to create embedded questions", () => { - cy.request("PUT", "/api/setting/enable-embedding", { value: true }); - cy.request("PUT", "/api/setting/site-url", { - value: "http://localhost:4000/", // Cypress.config().baseUrl - }); - - visitQuestion(questionId); - - cy.icon("share").click(); - - cy.contains(".cursor-pointer", "Embed this question") - .should("not.be.disabled") - .click(); - cy.contains("Disabled").click(); - cy.contains("Editable").click(); - - cy.contains("Publish").click(); - - cy.get("iframe").then($iframe => { - questionEmbedUrl = $iframe[0].src; - }); - }); - it("should allow users to create public dashboards", () => { cy.request("PUT", "/api/setting/enable-public-sharing", { value: true }); @@ -184,29 +159,6 @@ describe.skip("scenarios > public", () => { }); }); - it("should allow users to create embedded dashboards", () => { - cy.request("PUT", "/api/setting/enable-embedding", { value: true }); - cy.request("PUT", "/api/setting/site-url", { - value: "http://localhost:4000/", // Cypress.config().baseUrl - }); - - visitDashboard(dashboardId); - - cy.icon("share").click(); - - cy.contains(".cursor-pointer", "Embed this dashboard") - .should("not.be.disabled") - .click(); - cy.contains("Disabled").click(); - cy.contains("Editable").click(); - - cy.contains("Publish").click(); - - cy.get("iframe").then($iframe => { - dashboardEmbedUrl = $iframe[0].src; - }); - }); - Object.entries(USERS).map(([userType, setUser]) => describe(`${userType}`, () => { beforeEach(setUser); @@ -222,18 +174,6 @@ describe.skip("scenarios > public", () => { cy.contains(COUNT_DOOHICKEY); }); - // [quarantine]: failing almost consistently in CI - it(`should be able to view embedded questions`, () => { - cy.visit(questionEmbedUrl); - cy.contains(COUNT_ALL); - - cy.contains("Category").click(); - cy.contains("Doohickey").click(); - cy.contains("Add filter").click(); - - cy.contains(COUNT_DOOHICKEY); - }); - it(`should be able to view public dashboards`, () => { cy.visit(dashboardPublicLink); cy.contains(COUNT_ALL); @@ -244,17 +184,6 @@ describe.skip("scenarios > public", () => { cy.contains(COUNT_DOOHICKEY); }); - - it(`should be able to view embedded dashboards`, () => { - cy.visit(dashboardEmbedUrl); - cy.contains(COUNT_ALL); - - cy.contains("Category").click(); - cy.contains("Doohickey").click(); - cy.contains("Add filter").click(); - - cy.contains(COUNT_DOOHICKEY); - }); }), ); }); diff --git a/frontend/test/metabase/scenarios/embedding/reproductions/20393-public-dashboard-nested-card-with-parameters.cy.spec.js b/frontend/test/metabase/scenarios/sharing/reproductions/20393-public-dashboard-nested-card-with-parameters.cy.spec.js similarity index 100% rename from frontend/test/metabase/scenarios/embedding/reproductions/20393-public-dashboard-nested-card-with-parameters.cy.spec.js rename to frontend/test/metabase/scenarios/sharing/reproductions/20393-public-dashboard-nested-card-with-parameters.cy.spec.js diff --git a/frontend/test/metabase/scenarios/visualizations/pivot_tables.cy.spec.js b/frontend/test/metabase/scenarios/visualizations/pivot_tables.cy.spec.js index da3c75cf26c805dd24f1eff408cfee2ff9e75ed5..ef9bb4b73056c8bff4f49c1d5d7ac981d0a05711 100644 --- a/frontend/test/metabase/scenarios/visualizations/pivot_tables.cy.spec.js +++ b/frontend/test/metabase/scenarios/visualizations/pivot_tables.cy.spec.js @@ -5,6 +5,7 @@ import { sidebar, visitQuestion, visitDashboard, + visitIframe, } from "__support__/e2e/cypress"; import { SAMPLE_DB_ID } from "__support__/e2e/cypress_data"; @@ -654,13 +655,14 @@ describe("scenarios > visualizations > pivot tables", () => { cy.findByText( /Embed this (question|dashboard) in an application/, ).click(); + cy.findByText("Publish").click(); + // visit the iframe src directly to ensure it's not sing preview endpoints - cy.get("iframe").then($iframe => { - cy.visit($iframe[0].src); - cy.get(".EmbedFrame-header").contains(test.subject); - assertOnPivotFields(); - }); + visitIframe(); + + cy.get(".EmbedFrame-header").contains(test.subject); + assertOnPivotFields(); }); }); });