Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port metric v1 e2e tests #42125

Merged
merged 8 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 73 additions & 0 deletions e2e/test/scenarios/question/notebook.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,79 @@ describe("scenarios > question > notebook", { tags: "@slow" }, () => {
.contains("[Revenue]");
});
});

it("should be possible to sort by metric (metabase#8283)", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scavenged from the admin metrics tests.

cy.createQuestion(
{
name: "Revenue",
description: "Sum of orders subtotal",
type: "metric",
query: {
"source-table": ORDERS_ID,
aggregation: [["sum", ["field", ORDERS.SUBTOTAL, null]]],
},
},
{
wrapId: true,
idAlias: "metricId",
},
);

cy.get("@metricId").then(metricId => {
const questionDetails = {
query: {
"source-table": `card__${metricId}`,
aggregation: ["metric", metricId],
},
};

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

openNotebook();

// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Pick a column to group by").click();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Created At").click();

// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Sort").click();

// Sorts ascending by default
// Revenue appears twice, but it's the only integer column to order by
popover().icon("int").click();

// Let's make sure it's possible to sort descending as well
cy.icon("arrow_up").click();

cy.icon("arrow_down").parent().contains("Revenue");

visualize();
// Visualization will render line chart by default. Switch to the table.
cy.icon("table2").click();

cy.findAllByRole("grid").as("table");
cy.get("@table")
.first()
.as("tableHeader")
.within(() => {
cy.get("[data-testid=cell-data]")
.eq(1)
.invoke("text")
.should("eq", "Revenue");
});

cy.get("@table")
.last()
.as("tableBody")
.within(() => {
cy.get("[data-testid=cell-data]")
.eq(1)
.invoke("text")
.should("eq", "50,072.98");
});
});
});
});

function assertTableRowCount(expectedCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
visitQuestion,
cartesianChartCircle,
} from "e2e/support/helpers";
import { createMetric as apiCreateMetric } from "e2e/support/helpers/e2e-table-metadata-helpers";

const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;

Expand All @@ -16,30 +15,29 @@ describe("issue 6010", () => {
cy.intercept("POST", "/api/dataset").as("dataset");
});

// FIXME metrics v2
it.skip("should apply the filter from a metric when drilling through (metabase#6010)", () => {
it("should apply the filter from a metric when drilling through (metabase#6010)", () => {
createMetric()
.then(({ body: { id } }) => createQuestion(id))
.then(({ body: { id } }) => visitQuestion(id));

cartesianChartCircle().eq(0).click();

popover().findByText("See these Orders").click();
popover().findByText("See these Metrics").click();
cy.wait("@dataset");

cy.findByTestId("qb-filters-panel").within(() => {
cy.findByText("Total is greater than 150").should("be.visible");
cy.findByText("Created At is Jan 1–31, 2024").should("be.visible");
});
// FIXME metrics v2 -- check that the values in column Total are above 150
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to do this best. Ideally, we would like to check that the filter is still in effect, but I don't think it should be listed as it's part of the metric which is still the source.

});
});

const createMetric = () => {
return apiCreateMetric({
return cy.createQuestion({
name: "Metric",
description: "Metric with a filter",
table_id: ORDERS_ID,
definition: {
type: "metric",
query: {
"source-table": ORDERS_ID,
filter: [">", ORDERS.TOTAL, 150],
aggregation: [["count"]],
Expand All @@ -52,7 +50,7 @@ const createQuestion = metric_id => {
name: "Question",
display: "line",
query: {
"source-table": ORDERS_ID,
"source-table": `card__${metric_id}`,
breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],
aggregation: [["metric", metric_id]],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ describe("parameters/utils/mapping-options", () => {
});
});

// FIXME metrics v2
// eslint-disable-next-line jest/no-disabled-tests
it.skip("should return fields from the model question's virtual card table, as though it is already nested", () => {
it("should return fields from the model question's virtual card table, as though it is already nested", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how this is related to metrics, so I think it should pass.

const options = getParameterMappingOptions(
new Question(dataset.card(), metadata),
{ type: "date/single" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ describe("QueryBuilder - unsaved changes warning", () => {
expect(screen.getByTestId("leave-confirmation")).toBeInTheDocument();
});

// FIXME metrics v2
// eslint-disable-next-line jest/no-disabled-tests
it.skip("does not show custom warning modal when saving new model", async () => {
it("does not show custom warning modal when saving new model", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how this is related to metrics, so I think it should pass.

await setup({
card: null,
initialRoute: "/model/new",
Expand Down
5 changes: 4 additions & 1 deletion src/metabase/lib/fe_util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@

(mu/defn dependent-metadata :- [:sequential DependentItem]
"Return the IDs and types of entities the metadata about is required
for the FE to function properly."
for the FE to function properly. `card-id` is provided
when editing the card with that ID and in this case `a-query` is its
definition (i.e., the dataset-query). `card-type` specifies the type
of the card being created or edited."
[query :- ::lib.schema/query
card-id :- [:maybe ::lib.schema.id/card]
card-type :- ::lib.schema.metadata/card.type]
Expand Down