Skip to content

Commit e2f8625

Browse files
authored
Port some metric v1 e2e tests (#42002)
* Port notebook e2e test * Port nested metric e2e test * Fix #41929.
1 parent cd7404e commit e2f8625

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

e2e/support/helpers/e2e-question-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const question = (
184184
cy.wrap(body.id).as(idAlias);
185185
}
186186

187-
if (type === "model" || enable_embedding) {
187+
if (type === "model" || type === "metric" || enable_embedding) {
188188
cy.request("PUT", `/api/card/${body.id}`, {
189189
type,
190190
enable_embedding,

e2e/test/scenarios/question/nested.cy.spec.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
filterField,
1414
chartPathWithFillColor,
1515
} from "e2e/support/helpers";
16-
import { createMetric } from "e2e/support/helpers/e2e-table-metadata-helpers";
1716

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

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

152-
// FIXME metrics v2
153-
it.skip("should apply metrics including filter to the nested question (metabase#12507)", () => {
151+
it("should apply metrics including filter to the nested question (metabase#12507)", () => {
154152
const metric = {
155153
name: "Sum of discounts",
156154
description: "Discounted orders.",
157-
table_id: ORDERS_ID,
158-
definition: {
155+
type: "metric",
156+
query: {
159157
"source-table": ORDERS_ID,
160158
aggregation: [["count"]],
161159
filter: ["!=", ["field", ORDERS.DISCOUNT, null], 0],
162160
},
163161
};
164162

165163
cy.log("Create a metric with a filter");
166-
createMetric(metric).then(({ body: { id: metricId } }) => {
164+
cy.createQuestion(metric, {
165+
wrapId: true,
166+
idAlias: "metricId",
167+
});
168+
169+
cy.get("@metricId").then(metricId => {
167170
// "capture" the original query because we will need to re-use it later in a nested question as "source-query"
168171
const baseQuestionDetails = {
169172
name: "12507",
170173
query: {
171-
"source-table": ORDERS_ID,
174+
"source-table": `card__${metricId}`,
172175
aggregation: [["metric", metricId]],
173176
breakout: [
174177
["field", ORDERS.TOTAL, { binning: { strategy: "default" } }],

e2e/test/scenarios/question/notebook.cy.spec.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
visualize,
2525
createQuestion,
2626
} from "e2e/support/helpers";
27-
import { createMetric } from "e2e/support/helpers/e2e-table-metadata-helpers";
2827

2928
const { ORDERS, ORDERS_ID, PEOPLE, PEOPLE_ID, PRODUCTS, PRODUCTS_ID } =
3029
SAMPLE_DATABASE;
@@ -808,35 +807,43 @@ describe("scenarios > question > notebook", { tags: "@slow" }, () => {
808807
});
809808
});
810809

811-
// FIXME metrics v2
812-
it.skip("should not crash notebook when metric is used as an aggregation and breakout is applied (metabase#40553)", () => {
813-
createMetric({
814-
name: "Revenue",
815-
description: "Sum of orders subtotal",
816-
table_id: ORDERS_ID,
817-
definition: {
818-
"source-table": ORDERS_ID,
819-
aggregation: [["sum", ["field", ORDERS.SUBTOTAL, null]]],
810+
it("should not crash notebook when metric is used as an aggregation and breakout is applied (metabase#40553)", () => {
811+
cy.createQuestion(
812+
{
813+
query: {
814+
"source-table": ORDERS_ID,
815+
aggregation: [["sum", ["field", ORDERS.SUBTOTAL, null]]],
816+
},
817+
type: "metric",
818+
name: "Revenue",
820819
},
821-
}).then(({ body }) => {
822-
const metricId = body.id;
820+
{
821+
wrapId: true,
822+
idAlias: "metricId",
823+
},
824+
);
823825

826+
cy.get("@metricId").then(metricId => {
824827
const questionDetails = {
825828
query: {
826-
"source-table": ORDERS_ID,
827-
breakout: [["field", ORDERS.CREATED_AT, null]],
828-
aggregation: [["metric", metricId]],
829+
"source-table": `card__${metricId}`,
830+
breakout: [
831+
["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],
832+
],
833+
aggregation: ["metric", metricId],
829834
},
830835
};
831836

832837
createQuestion(questionDetails, { visitQuestion: true });
833-
});
834838

835-
openNotebook();
839+
openNotebook();
836840

837-
getNotebookStep("summarize").contains("Revenue").click();
841+
getNotebookStep("summarize").contains("Revenue").click();
838842

839-
popover().findByTestId("expression-editor-textfield").contains("[Revenue]");
843+
popover()
844+
.findByTestId("expression-editor-textfield")
845+
.contains("[Revenue]");
846+
});
840847
});
841848
});
842849

src/metabase/api/card.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423

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

0 commit comments

Comments
 (0)