Skip to content

Commit

Permalink
Port some metric v1 e2e tests (#42002)
Browse files Browse the repository at this point in the history
* Port notebook e2e test
* Port nested metric e2e test
* Fix #41929.
  • Loading branch information
metamben committed Apr 30, 2024
1 parent cd7404e commit e2f8625
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion e2e/support/helpers/e2e-question-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const question = (
cy.wrap(body.id).as(idAlias);
}

if (type === "model" || enable_embedding) {
if (type === "model" || type === "metric" || enable_embedding) {
cy.request("PUT", `/api/card/${body.id}`, {
type,
enable_embedding,
Expand Down
17 changes: 10 additions & 7 deletions e2e/test/scenarios/question/nested.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
filterField,
chartPathWithFillColor,
} from "e2e/support/helpers";
import { createMetric } from "e2e/support/helpers/e2e-table-metadata-helpers";

const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID, PEOPLE } = SAMPLE_DATABASE;

Expand Down Expand Up @@ -149,26 +148,30 @@ describe("scenarios > question > nested", () => {
cy.findAllByText("13");
});

// FIXME metrics v2
it.skip("should apply metrics including filter to the nested question (metabase#12507)", () => {
it("should apply metrics including filter to the nested question (metabase#12507)", () => {
const metric = {
name: "Sum of discounts",
description: "Discounted orders.",
table_id: ORDERS_ID,
definition: {
type: "metric",
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
filter: ["!=", ["field", ORDERS.DISCOUNT, null], 0],
},
};

cy.log("Create a metric with a filter");
createMetric(metric).then(({ body: { id: metricId } }) => {
cy.createQuestion(metric, {
wrapId: true,
idAlias: "metricId",
});

cy.get("@metricId").then(metricId => {
// "capture" the original query because we will need to re-use it later in a nested question as "source-query"
const baseQuestionDetails = {
name: "12507",
query: {
"source-table": ORDERS_ID,
"source-table": `card__${metricId}`,
aggregation: [["metric", metricId]],
breakout: [
["field", ORDERS.TOTAL, { binning: { strategy: "default" } }],
Expand Down
45 changes: 26 additions & 19 deletions e2e/test/scenarios/question/notebook.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
visualize,
createQuestion,
} from "e2e/support/helpers";
import { createMetric } from "e2e/support/helpers/e2e-table-metadata-helpers";

const { ORDERS, ORDERS_ID, PEOPLE, PEOPLE_ID, PRODUCTS, PRODUCTS_ID } =
SAMPLE_DATABASE;
Expand Down Expand Up @@ -808,35 +807,43 @@ describe("scenarios > question > notebook", { tags: "@slow" }, () => {
});
});

// FIXME metrics v2
it.skip("should not crash notebook when metric is used as an aggregation and breakout is applied (metabase#40553)", () => {
createMetric({
name: "Revenue",
description: "Sum of orders subtotal",
table_id: ORDERS_ID,
definition: {
"source-table": ORDERS_ID,
aggregation: [["sum", ["field", ORDERS.SUBTOTAL, null]]],
it("should not crash notebook when metric is used as an aggregation and breakout is applied (metabase#40553)", () => {
cy.createQuestion(
{
query: {
"source-table": ORDERS_ID,
aggregation: [["sum", ["field", ORDERS.SUBTOTAL, null]]],
},
type: "metric",
name: "Revenue",
},
}).then(({ body }) => {
const metricId = body.id;
{
wrapId: true,
idAlias: "metricId",
},
);

cy.get("@metricId").then(metricId => {
const questionDetails = {
query: {
"source-table": ORDERS_ID,
breakout: [["field", ORDERS.CREATED_AT, null]],
aggregation: [["metric", metricId]],
"source-table": `card__${metricId}`,
breakout: [
["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],
],
aggregation: ["metric", metricId],
},
};

createQuestion(questionDetails, { visitQuestion: true });
});

openNotebook();
openNotebook();

getNotebookStep("summarize").contains("Revenue").click();
getNotebookStep("summarize").contains("Revenue").click();

popover().findByTestId("expression-editor-textfield").contains("[Revenue]");
popover()
.findByTestId("expression-editor-textfield")
.contains("[Revenue]");
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/metabase/api/card.clj
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@

(defn- check-if-card-can-be-saved
[dataset-query card-type]
(when (= card-type :metric)
(when (and dataset-query (= card-type :metric))
(let [pMBQL-query (-> dataset-query compatibility/normalize-dataset-query lib.convert/->pMBQL)
metadata-provider (lib.metadata.jvm/application-database-metadata-provider (:database pMBQL-query))]
(when-not (lib/can-save (lib/query metadata-provider pMBQL-query) card-type)
Expand Down

0 comments on commit e2f8625

Please sign in to comment.