Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Consolidate dashboard filter behavior e2e specs (#83692)

Nemanja Glumacfd95839a475d
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-chained-filters.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-chained-filters.cy.spec.js
index ff4f8e1e683..269f5b3c2f0 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-chained-filters.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-chained-filters.cy.spec.js
@@ -174,9 +174,11 @@ describe("scenarios > dashboard > chained filter", () => {
});
});
}
+});
+describe("scenarios > dashboard > chained filter > UUID primary key", () => {
it(
- "should work for all field types (metabase#15170)",
+ "should offer a UUID primary key column for an ID filter in 'Update a dashboard filter' click behavior (metabase#15170)",
{ tags: "@external" },
() => {
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filter-data-permissions.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filter-data-permissions.cy.spec.js
index 39d3f87f264..1903206f9b5 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filter-data-permissions.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filter-data-permissions.cy.spec.js
@@ -1,32 +1,22 @@
const { H } = cy;
import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";
-function filterDashboard(suggests = true) {
+function filterDashboard() {
H.visitDashboard(ORDERS_DASHBOARD_ID);
- cy.contains("Orders");
- cy.contains("Text").click();
-
- // We should get a suggested response and be able to click it if we're an admin
- if (suggests) {
- cy.findByPlaceholderText("Search the list").type("Main Street");
- cy.contains("100 Main Street").click();
- } else {
- cy.findByPlaceholderText("Search the list").type("100 Main Street").blur();
- cy.wait("@search").should(({ response }) => {
- expect(response.statusCode).to.equal(403);
- });
- }
- cy.contains("Add filter").click({ force: true });
- cy.contains("100 Main Street");
+ H.filterWidget().click();
+
+ cy.findByPlaceholderText("Search the list").type("Main Street");
+ cy.contains("100 Main Street").click();
+
+ H.dashboardParametersPopover().button("Add filter").click();
+ H.filterWidget().should("contain", "100 Main Street");
+ cy.location("search").should((search) =>
+ expect(new URLSearchParams(search).get("text")).to.eq("100 Main Street"),
+ );
}
describe("support > permissions (metabase#8472)", () => {
beforeEach(() => {
- cy.intercept(
- "GET",
- `/api/dashboard/${ORDERS_DASHBOARD_ID}/params/*/search/*").as("search`,
- );
-
H.restore();
cy.signInAsAdmin();
@@ -35,6 +25,11 @@ describe("support > permissions (metabase#8472)", () => {
H.editDashboard();
+ H.getDashboardCard(0)
+ .realHover()
+ .findByLabelText("Add a filter")
+ .should("be.visible");
+
H.setFilter("Text or Category", "Is");
// Filter the first card by User Address
@@ -47,16 +42,23 @@ describe("support > permissions (metabase#8472)", () => {
cy.contains("Done").click();
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.contains("Save").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.contains("Orders in a dashboard").click();
});
- it("should allow an admin user to select the filter", () => {
+ it("should let admin and nodata users use the filter, and hide filter mapping from nodata users in edit mode", () => {
filterDashboard();
- });
- it("should allow a nodata user to select the filter", () => {
cy.signIn("nodata");
filterDashboard();
+
+ H.editDashboard();
+
+ H.getDashboardCard(0)
+ .realHover()
+ .findByTestId("dashboardcard-actions-panel")
+ .should("be.visible");
+ H.getDashboardCard(0).findByLabelText("Add a filter").should("not.exist");
+
+ H.filterWidget({ isEditing: true }).click();
+ H.getDashboardCard(0).icon("key").should("be.visible");
});
});
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filter-defaults.cy.spec.ts b/e2e/test/scenarios/dashboard-filters/dashboard-filter-defaults.cy.spec.ts
index 3a19d944c03..78b217ab24f 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filter-defaults.cy.spec.ts
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filter-defaults.cy.spec.ts
@@ -41,7 +41,7 @@ describe("scenarios > dashboard > filters > reset", () => {
cy.signInAsAdmin();
});
- it("should reset a filters value when editing the default", () => {
+ it("should reset a filters value when editing the default, and leave other filters alone", () => {
H.createQuestionAndDashboard({
questionDetails: QUESTION,
dashboardDetails: DASHBOARD,
@@ -82,9 +82,7 @@ describe("scenarios > dashboard > filters > reset", () => {
cy.location("search").should("eq", "?filter_one=&filter_two=");
- cy.log(
- "Finally, when we remove dashboard filter's default value, the url should reflect that by removing the placeholder",
- );
+ cy.log("Replacing Filter Two's default value updates its value in the url");
H.editDashboard();
H.filterWidget({ name: "Filter Two", isEditing: true }).click();
@@ -104,47 +102,9 @@ describe("scenarios > dashboard > filters > reset", () => {
H.filterWidget().contains("Filter One").should("be.visible");
H.filterWidget().contains("Foo").should("be.visible");
- });
-
- it("should reset a filters value when editing the default, and leave other filters alone", () => {
- H.createQuestionAndDashboard({
- questionDetails: QUESTION,
- dashboardDetails: DASHBOARD,
- }).then(({ body: dashboardCard }) => {
- const { card_id, dashboard_id } = dashboardCard;
-
- H.editDashboardCard(dashboardCard, {
- parameter_mappings: [
- {
- parameter_id: FILTER_ONE.id,
- card_id,
- target: ["dimension", ["field", PRODUCTS.CATEGORY, null]],
- },
- {
- parameter_id: FILTER_TWO.id,
- card_id,
- target: ["dimension", ["field", PRODUCTS.TITLE, null]],
- },
- ],
- }).then(() => {
- H.visitDashboard(dashboard_id, {
- params: {
- filter_one: "",
- filter_two: "Bar",
- },
- });
- });
- });
-
- cy.log("Default dashboard filter");
-
- H.filterWidget().contains("Filter One").should("be.visible");
- H.filterWidget().contains("Bar").should("be.visible");
-
- cy.location("search").should("eq", "?filter_one=&filter_two=Bar");
cy.log(
- "Finally, when we remove dashboard filter's default value, the url should reflect that by removing the placeholder",
+ "Setting Filter One's default value leaves Filter Two's value alone",
);
H.editDashboard();
@@ -154,15 +114,15 @@ describe("scenarios > dashboard > filters > reset", () => {
cy.findByLabelText("Input box").click();
});
- setDefaultFilterValue("Foo");
+ setDefaultFilterValue("Baz");
- cy.location("search").should("eq", "?filter_one=Foo&filter_two=Bar");
+ cy.location("search").should("eq", "?filter_one=Baz&filter_two=Foo");
H.saveDashboard();
- cy.location("search").should("eq", "?filter_one=Foo&filter_two=Bar");
+ cy.location("search").should("eq", "?filter_one=Baz&filter_two=Foo");
- H.filterWidget().contains("Filter One").should("be.visible");
+ H.filterWidget().contains("Baz").should("be.visible");
H.filterWidget().contains("Foo").should("be.visible");
});
});
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-apply.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-apply.cy.spec.js
index db6b050bfb2..a743cfe08c8 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-apply.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-apply.cy.spec.js
@@ -31,8 +31,6 @@ function createDashboardDetails({ parameters }) {
};
}
-const TOAST_TIMEOUT = 16000;
-
const filterToggleLabel = "Auto-apply filters";
describe(
@@ -117,7 +115,7 @@ describe(
cy.get("@cardQuery.all").should("have.length", 4);
cy.log(
- "last applied parameter values should be used when disabling auto applying filters, even if previously there were draft parameter values",
+ "parameter values applied while auto-applying filters should be preserved when disabling auto applying filters",
);
H.filterWidget().findByText("Widget").click();
H.popover().within(() => {
@@ -134,13 +132,14 @@ describe(
H.closeDashboardSettingsSidebar();
H.filterWidget().findByText("2 selections").should("be.visible");
+ H.assertTableRowsCount(107);
cy.get("@cardQuery.all").should("have.length", 5);
cy.get("@updateDashboardSpy").should("have.callCount", 3);
});
});
- it("should not save filter state for dashboard parameter w/o auto-apply enabled", () => {
+ it("should not save unapplied filter state and allow resetting it", () => {
createDashboard({ dashboardDetails: { auto_apply_filters: false } });
openDashboard();
@@ -156,16 +155,16 @@ describe(
cy.log("verify filter value is not saved");
H.visitDashboard("@dashboardId");
- H.filterWidget().should("not.contain", "Gadget");
- });
+ H.filterWidget()
+ .should("contain", FILTER.name)
+ .and("not.contain", "Gadget");
- it("should allow resetting unapplied filter state", () => {
- createDashboard({ dashboardDetails: { auto_apply_filters: false } });
- openDashboard();
+ cy.log("verify unapplied filter value can be reset");
H.filterWidget().findByText(FILTER.name).click();
H.popover().within(() => {
- cy.findByText("Gadget").click();
+ cy.findByLabelText("Gadget").click();
+ cy.findByLabelText("Gadget").should("be.checked");
cy.button("Add filter").click();
});
@@ -177,12 +176,12 @@ describe(
H.filterWidget().findByText(FILTER.name).click();
H.popover().within(() => {
- cy.findByText("Gadget").should("not.be.checked");
+ cy.findByLabelText("Gadget").should("not.be.checked");
});
});
describe("modifying dashboard and dashboard cards", () => {
- it("should not preserve draft parameter values when editing the dashboard", () => {
+ it("should preserve draft parameter values when editing is cancelled but not when the dashboard is saved", () => {
createDashboard({ dashboardDetails: { auto_apply_filters: false } });
openDashboard();
@@ -193,6 +192,13 @@ describe(
});
H.applyFilterButton().should("be.visible");
+ cy.log("cancel editing");
+ H.editDashboard();
+ cy.findByTestId("edit-bar").button("Cancel").click();
+ H.filterWidget().findByText("Gadget").should("be.visible");
+ H.applyFilterButton().should("be.visible");
+
+ cy.log("edit and save the dashboard");
H.editDashboard();
H.setFilter("Text or Category", "Is");
@@ -213,25 +219,6 @@ describe(
});
});
- describe("modify nothing", () => {
- it("should preserve draft parameter values when editing of the dashboard was cancelled", () => {
- createDashboard({ dashboardDetails: { auto_apply_filters: false } });
- openDashboard();
-
- H.filterWidget().findByText(FILTER.name).click();
- H.popover().within(() => {
- cy.findByText("Gadget").click();
- cy.button("Add filter").click();
- });
- H.applyFilterButton().should("be.visible");
-
- H.editDashboard();
- cy.findByTestId("edit-bar").button("Cancel").click();
- H.filterWidget().findByText("Gadget").should("be.visible");
- H.applyFilterButton().should("be.visible");
- });
- });
-
describe("parameter with default values", () => {
beforeEach(() => {
createDashboard({ parameter: FILTER_WITH_DEFAULT_VALUE });
@@ -293,12 +280,12 @@ describe(
cy.signIn("readonly");
});
- it("should not be able to toggle auto-apply filters toggle", () => {
+ it("should not show dashboard settings with the auto-apply filters toggle", () => {
openDashboard();
cy.wait("@cardQuery");
- // shouldn't even show settings as an option for this user
H.dashboardHeader().icon("ellipsis").click();
+ H.popover().findByText("Enter fullscreen").should("be.visible");
H.popover().findByText("Edit settings").should("not.exist");
});
});
@@ -329,17 +316,6 @@ describe(
H.assertTableRowsCount(54);
});
});
-
- it("should not show toast", () => {
- createDashboard();
- cy.clock();
- openSlowPublicDashboard({ [FILTER.slug]: "Gadget" });
- H.filterWidget().findByText("Gadget").should("be.visible");
-
- cy.tick(TOAST_TIMEOUT);
- cy.wait("@cardQuery");
- H.undoToast().should("not.exist");
- });
});
describe("signed embeds", () => {
@@ -375,25 +351,6 @@ describe(
H.assertTableRowsCount(54);
});
});
-
- it("should not show toast", () => {
- createDashboard({
- dashboardDetails: {
- enable_embedding: true,
- embedding_params: {
- [FILTER.slug]: "enabled",
- },
- },
- });
-
- cy.clock();
- openSlowEmbeddingDashboard({ [FILTER.slug]: "Gadget" });
- H.filterWidget().findByText("Gadget").should("be.visible");
-
- cy.tick(TOAST_TIMEOUT);
- cy.wait("@cardQuery");
- H.undoToast().should("not.exist");
- });
});
describe("full-app embeddings", () => {
@@ -452,7 +409,7 @@ describe("scenarios > dashboards > filters > auto apply", () => {
H.expectNoBadSnowplowEvents();
});
- it("should send snowplow events when disabling auto-apply filters", () => {
+ it("should send snowplow events only when disabling auto-apply filters", () => {
createDashboard();
openDashboard();
cy.wait("@cardQuery");
@@ -465,20 +422,12 @@ describe("scenarios > dashboards > filters > auto apply", () => {
H.expectUnstructuredSnowplowEvent({
event: "auto_apply_filters_disabled",
});
- });
- });
-
- it("should not send snowplow events when enabling auto-apply filters", () => {
- createDashboard({ dashboardDetails: { auto_apply_filters: false } });
- openDashboard();
- cy.wait("@cardQuery");
- H.openDashboardSettingsSidebar();
- H.sidesheet().within(() => {
+ cy.log("enabling auto-apply filters should not send an event");
cy.findByLabelText(filterToggleLabel).click();
cy.wait("@updateDashboard");
cy.findByLabelText(filterToggleLabel).should("be.checked");
- H.assertNoUnstructuredSnowplowEvent({
+ H.expectUnstructuredSnowplowEvent({
event: "auto_apply_filters_disabled",
});
});
@@ -520,36 +469,6 @@ const openDashboard = (params = {}) => {
H.visitDashboard("@dashboardId", { params });
};
-const openSlowPublicDashboard = (params = {}) => {
- cy.intercept("GET", "/api/public/dashboard/*/dashcard/*/card/*").as(
- "cardQuery",
- );
-
- cy.get("@dashboardId").then((dashboardId) => {
- H.visitPublicDashboard(dashboardId, { params });
- });
-
- H.getDashboardCard().should("be.visible");
-};
-
-const openSlowEmbeddingDashboard = (params = {}) => {
- cy.intercept("GET", "/api/embed/dashboard/*/dashcard/*/card/*").as(
- "cardQuery",
- );
-
- cy.get("@dashboardId").then((dashboardId) => {
- const embeddingPayload = {
- resource: { dashboard: dashboardId },
- params: {},
- };
- H.visitEmbeddedPage(embeddingPayload, {
- setFilters: params,
- });
- });
-
- H.getDashboardCard().should("be.visible");
-};
-
const visitFullAppEmbeddingUrl = ({ url, qs }) => {
cy.visit({
url,
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js
index 149c4b6e69b..cf2a3be7fd8 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js
@@ -29,7 +29,6 @@ describe("dashboard filters auto-wiring", () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- cy.intercept("GET", "/api/dashboard/**").as("dashboard");
});
describe("parameter mapping", () => {
@@ -48,6 +47,7 @@ describe("dashboard filters auto-wiring", () => {
cy.findByText("User.Name").should("exist");
});
+ H.getDashboardCard(1).findByText("Select…").should("exist");
H.getDashboardCard(1).findByText("User.Name").should("not.exist");
H.undoToast()
@@ -77,9 +77,35 @@ describe("dashboard filters auto-wiring", () => {
cy.findByText("Auto-connected").should("not.exist");
cy.icon("sparkles").should("not.exist");
});
+
+ cy.log("verify auto-wire suggestion when a card is replaced");
+
+ goToFilterMapping();
+
+ H.getDashboardCard(1)
+ .realHover({ scrollBehavior: "bottom" })
+ .findByLabelText("Replace")
+ .click();
+
+ H.modal().findByText("Orders, Count").click();
+
+ H.undoToastList()
+ .contains("Auto-connect “Orders, Count” to “Text”?")
+ .closest("[data-testid='toast-undo']")
+ .button("Auto-connect")
+ .click();
+
+ H.undoToastList().should(
+ "contain",
+ "“Orders, Count” was auto-connected to “Text”.",
+ );
+
+ goToFilterMapping();
+
+ H.getDashboardCard(1).findByText("User.Name").should("exist");
});
- it("should not wire parameters to cards that already have a parameter, despite matching fields", () => {
+ it("should undo auto-wiring and not wire parameters to cards that already have a parameter, despite matching fields", () => {
createDashboardWithCards({ cards }).then((dashboardId) => {
H.visitDashboard(dashboardId);
});
@@ -102,9 +128,14 @@ describe("dashboard filters auto-wiring", () => {
.findByRole("button", { name: "Auto-connect" })
.click();
- H.getDashboardCard(1).within(() => {
- cy.findByLabelText("close icon").click();
- });
+ H.getDashboardCard(0).findByText("User.Name").should("exist");
+ H.getDashboardCard(1).findByText("User.Name").should("exist");
+
+ cy.log("verify undo functionality");
+ H.undoToast().findByRole("button", { name: "Undo" }).click();
+
+ H.getDashboardCard(0).findByText("User.Name").should("exist");
+ H.getDashboardCard(1).findByText("Select…").should("exist");
H.selectDashboardFilter(H.getDashboardCard(1), "Address");
@@ -116,7 +147,7 @@ describe("dashboard filters auto-wiring", () => {
cy.findByText("User.Address").should("exist");
});
- H.undoToast().should("contain", "Undo");
+ H.undoToast().should("not.exist");
});
it("should not suggest to wire parameters to cards that don't have a matching field", () => {
@@ -152,41 +183,12 @@ describe("dashboard filters auto-wiring", () => {
H.selectDashboardFilter(H.getDashboardCard(0), "Name");
- H.undoToast().should("not.exist");
- });
-
- it("should undo parameter wiring when 'Undo' is clicked", () => {
- createDashboardWithCards({ cards }).then((dashboardId) => {
- H.visitDashboard(dashboardId);
- });
-
- H.editDashboard();
-
- H.setFilter("Text or Category", "Is");
- addCardToDashboard();
- goToFilterMapping();
-
- H.selectDashboardFilter(H.getDashboardCard(0), "Name");
-
- H.undoToast().findByRole("button", { name: "Auto-connect" }).click();
-
- H.getDashboardCard(0).findByText("User.Name").should("exist");
-
- for (let i = 0; i < cards.length; i++) {
- H.getDashboardCard(i).findByText("User.Name").should("exist");
- }
-
- H.undoToast().findByRole("button", { name: "Undo" }).click();
-
H.getDashboardCard(0).findByText("User.Name").should("exist");
- for (let i = 1; i < cards.length; i++) {
- H.getDashboardCard(i).findByText("Select…").should("exist");
- }
+ H.undoToast().should("not.exist");
});
- it("in case of two auto-wiring undo toast, the second one should last the default timeout of 12s", () => {
- // The auto-wiring undo toasts use the same id, a bug in the undo logic caused the second toast to be dismissed by the
- // timeout set by the first. See https://github.com/metabase/metabase/pull/35461#pullrequestreview-1731776862
+ it("should dismiss suggestion toasts after 12s, restarting for a second suggestion, and the undo toast after 8s", () => {
+ // A second auto-wiring suggestion toast must not be dismissed by the timeout set for the first one.
const cardTemplate = {
card_id: ORDERS_BY_YEAR_QUESTION_ID,
row: 0,
@@ -234,6 +236,21 @@ describe("dashboard filters auto-wiring", () => {
cy.tick(2000);
H.undoToast().should("not.exist");
+
+ cy.log("verify the undo toast after auto-connect lasts 8s");
+
+ removeFilterFromDashCard(0);
+
+ H.selectDashboardFilter(H.getDashboardCard(0), "Name");
+ cy.tick(1000);
+
+ H.undoToast().findByRole("button", { name: "Auto-connect" }).click();
+
+ cy.tick(7000);
+ H.undoToast().should("exist");
+
+ cy.tick(2000);
+ H.undoToast().should("not.exist");
});
describe("multiple tabs", () => {
@@ -274,7 +291,7 @@ describe("dashboard filters auto-wiring", () => {
});
describe("add a card", () => {
- it("should wire parameters to cards that are added to the dashboard", () => {
+ it("should wire parameters to cards that are added to the dashboard and undo it", () => {
createDashboardWithCards({ cards }).then((dashboardId) => {
H.visitDashboard(dashboardId);
});
@@ -291,8 +308,7 @@ describe("dashboard filters auto-wiring", () => {
}
addCardToDashboard();
-
- cy.log("verify toast text and enable auto-connect");
+ goToFilterMapping();
H.undoToastList()
.eq(1)
@@ -300,49 +316,10 @@ describe("dashboard filters auto-wiring", () => {
.findByRole("button", { name: "Auto-connect" })
.click();
- cy.log("verify toast text after auto-connect");
-
H.undoToastList()
.eq(1)
.should("contain", "“Orders Model” was auto-connected to “Text”.");
- goToFilterMapping();
-
- for (let i = 0; i < cards.length + 1; i++) {
- H.getDashboardCard(i).findByText("User.Name").should("exist");
- }
-
- H.undoToastList()
- .eq(1)
- .findByText("“Orders Model” was auto-connected to “Text”.")
- .should("be.visible");
- });
-
- it("should undo parameter wiring when 'Undo' is clicked", () => {
- createDashboardWithCards({ cards }).then((dashboardId) => {
- H.visitDashboard(dashboardId);
- });
-
- H.editDashboard();
-
- H.setFilter("Text or Category", "Is");
-
- H.selectDashboardFilter(H.getDashboardCard(0), "Name");
- H.undoToast().findByRole("button", { name: "Auto-connect" }).click();
-
- for (let i = 0; i < cards.length; i++) {
- H.getDashboardCard(i).findByText("User.Name").should("exist");
- }
-
- addCardToDashboard();
- goToFilterMapping();
-
- H.undoToastList()
- .eq(1)
- .should("contain", "Auto-connect “Orders Model” to “Text”?")
- .findByRole("button", { name: "Auto-connect" })
- .click();
-
for (let i = 0; i < cards.length + 1; i++) {
H.getDashboardCard(i).findByText("User.Name").should("exist");
}
@@ -414,49 +391,8 @@ describe("dashboard filters auto-wiring", () => {
});
});
- describe("replace a card", () => {
- it("should show auto-wire suggestion toast when a card is replaced", () => {
- createDashboardWithCards({ cards }).then((dashboardId) => {
- H.visitDashboard(dashboardId);
- });
-
- H.editDashboard();
-
- H.setFilter("Text or Category", "Is");
-
- H.selectDashboardFilter(H.getDashboardCard(0), "Name");
-
- H.undoToast().findByText("Auto-connect").click();
-
- goToFilterMapping();
-
- H.getDashboardCard(1)
- .realHover({ scrollBehavior: "bottom" })
- .findByLabelText("Replace")
- .click();
-
- H.modal().findByText("Orders, Count").click();
-
- H.undoToastList()
- .eq(2)
- .should("contain", "Auto-connect “Orders, Count” to “Text”?")
- .button("Auto-connect")
- .click();
-
- H.undoToastList()
- .eq(2)
- .should("contain", "“Orders, Count” was auto-connected to “Text”.");
- });
- });
-
describe("adding cards with foreign keys to the dashboard (metabase#36275)", () => {
beforeEach(() => {
- cy.intercept(
- "POST",
- "/api/dashboard/*/dashcard/*/card/*/query",
- cy.spy().as("cardQueryRequest"),
- ).as("cardQuery");
-
H.createQuestion({
name: "Products Question",
query: { "source-table": PRODUCTS_ID, limit: 1 },
@@ -497,8 +433,6 @@ describe("dashboard filters auto-wiring", () => {
addCardToDashboard(["Orders Question", "Reviews Question"]);
- cy.wait("@cardQuery");
-
goToFilterMapping("ID");
// The two auto-wire suggestion toasts stack and briefly overlap while the
@@ -526,23 +460,27 @@ describe("dashboard filters auto-wiring", () => {
H.dashboardParametersContainer().findByText("ID").click();
+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(
+ "filteredCardQuery",
+ );
+
H.dashboardParametersPopover().within(() => {
- H.fieldValuesCombobox().type("1,");
+ H.fieldValuesCombobox().type("3,");
cy.button("Add filter").click();
});
- cy.wait("@cardQuery");
+ cy.wait("@filteredCardQuery");
H.getDashboardCard(0).within(() => {
- getTableCell("ID", 0).should("contain", "1");
+ getTableCell("ID", 0).should("have.text", "3");
});
H.getDashboardCard(1).within(() => {
- getTableCell("Product ID", 0).should("contain", "1");
+ getTableCell("Product ID", 0).should("have.text", "3");
});
H.getDashboardCard(2).within(() => {
- getTableCell("Product ID", 0).should("contain", "1");
+ getTableCell("Product ID", 0).should("have.text", "3");
});
});
@@ -564,8 +502,6 @@ describe("dashboard filters auto-wiring", () => {
});
});
- cy.wait("@cardQuery");
-
goToFilterMapping("ID");
H.getDashboardCard(0).findByText("Products.ID").should("exist");
@@ -576,23 +512,27 @@ describe("dashboard filters auto-wiring", () => {
H.dashboardParametersContainer().findByText("ID").click();
+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(
+ "filteredCardQuery",
+ );
+
H.dashboardParametersPopover().within(() => {
- H.fieldValuesCombobox().type("1,");
+ H.fieldValuesCombobox().type("3,");
cy.button("Add filter").click();
});
- cy.wait("@cardQuery");
+ cy.wait("@filteredCardQuery");
H.getDashboardCard(0).within(() => {
- getTableCell("ID", 0).should("contain", "1");
+ getTableCell("ID", 0).should("have.text", "3");
});
H.getDashboardCard(1).within(() => {
- getTableCell("Product ID", 0).should("contain", "1");
+ getTableCell("Product ID", 0).should("have.text", "3");
});
H.getDashboardCard(2).within(() => {
- getTableCell("Product ID", 0).should("contain", "1");
+ getTableCell("Product ID", 0).should("have.text", "3");
});
});
});
@@ -645,42 +585,6 @@ describe("dashboard filters auto-wiring", () => {
.should("have.length", 1)
.should("contain", "Removed card");
});
-
- it("should dismiss toasts on timeout", () => {
- createDashboardWithCards({ cards }).then((dashboardId) => {
- H.visitDashboard(dashboardId);
- });
-
- H.editDashboard();
- H.setFilter("Text or Category", "Is");
-
- cy.clock();
- H.selectDashboardFilter(H.getDashboardCard(0), "Name");
-
- cy.tick(1000);
-
- H.undoToast().should("be.visible");
-
- // AUTO_WIRE_TOAST_TIMEOUT
- cy.tick(12000);
-
- H.undoToast().should("not.exist");
-
- removeFilterFromDashCard(0);
-
- H.selectDashboardFilter(H.getDashboardCard(0), "Name");
- cy.tick(1000);
-
- // cy.clock();
- H.undoToast().findByRole("button", { name: "Auto-connect" }).click();
-
- cy.tick(1000);
- H.undoToast().should("be.visible");
-
- // AUTO_WIRE_UNDO_TOAST_TIMEOUT
- cy.tick(8000);
- H.undoToast().should("not.exist");
- });
});
it("should auto-wire a new card to correct parameter targets (metabase#44720)", () => {
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-clear-and-restore.cy.spec.ts b/e2e/test/scenarios/dashboard-filters/dashboard-filters-clear-and-restore.cy.spec.ts
deleted file mode 100644
index ba8c6bfac0d..00000000000
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-clear-and-restore.cy.spec.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-const { H } = cy;
-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
-
-const { ORDERS_ID } = SAMPLE_DATABASE;
-
-describe("dashboard filters values source config clearing and restoring", () => {
- beforeEach(() => {
- H.restore();
- cy.signInAsAdmin();
- cy.intercept("POST", "/api/dataset").as("dataset");
- });
-
- it("should clear and restore parameter static-list values when the type changes", () => {
- H.createQuestionAndDashboard({
- questionDetails: {
- display: "scalar",
- query: {
- "source-table": ORDERS_ID,
- aggregation: [["count"]],
- },
- },
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
-
- H.editDashboard();
- H.setFilter("Number", "Equal to", "Foo");
- mapFilterToQuestion();
- H.setFilterListSource({
- values: [["10", "Ten"], ["20", "Twenty"], "30"],
- });
- H.saveDashboard();
-
- H.editDashboard();
- editFilter("Foo");
-
- editFilterType("Text or Category", "Is");
- H.checkFilterListSourceHasValue({ values: [] });
-
- mapFilterToQuestion("Email");
- setFilterSourceFromConnectedFields();
-
- editFilterType("Number", "Equal to");
- H.checkFilterListSourceHasValue({
- values: [["10", "Ten"], ["20", "Twenty"], "30"],
- });
- });
- });
-});
-
-function setFilterSourceFromConnectedFields() {
- H.sidebar().findByText("Edit").click();
- H.modal().within(() => {
- cy.findByText("From connected fields").click();
- cy.button("Done").click();
- });
-}
-
-const mapFilterToQuestion = (column = "Quantity") => {
- cy.findByText("Select…").click();
- H.popover().within(() => cy.findByText(column).click());
-};
-
-function editFilter(name: string) {
- cy.findByTestId("edit-dashboard-parameters-widget-container")
- .findByText(name)
- .click();
-}
-
-function editFilterType(type: string, subType: string) {
- H.sidebar().findByText("Filter or parameter type").next().click();
- H.selectDropdown().findByText(type).click();
-
- H.sidebar().findByText("Filter operator").next().click();
- H.selectDropdown().findByText(subType).click();
-}
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-management.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-management.cy.spec.js
index b7818d2e028..fb6c0d6f420 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-management.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-management.cy.spec.js
@@ -110,13 +110,16 @@ describe("scenarios > dashboard > filters > management", () => {
});
describe("change parameter type", () => {
- it("should reset existing filter mappings and default value", () => {
+ it("should reset existing filter mappings and default value, and preselect the default operator for every type", () => {
createDashboardWithFilterAndQuestionMapped();
selectFilter("Text");
H.getDashboardCard().should("contain", "People.Name");
+ cy.log("verify Text default value: Is");
+ H.sidebar().findByDisplayValue("Is").should("exist");
+
cy.log("change filter type");
H.sidebar().within(() => {
@@ -131,26 +134,12 @@ describe("scenarios > dashboard > filters > management", () => {
// verifies no default value
cy.findByText("No default").should("exist");
});
- H.getDashboardCard().should("not.contain", "People.Name");
-
- H.saveDashboard();
- H.filterWidget().should("not.exist");
- });
-
- it("should preselect default value for every type of filter", () => {
- createDashboardWithFilterAndQuestionMapped();
-
- selectFilter("Text");
-
- cy.log("verify Text default value: Is");
- H.sidebar().findByDisplayValue("Is").should("exist");
-
- changeFilterType("Number");
-
- cy.log("verify Number default value: Between");
+ cy.log("verify Number default value: Equal to");
verifyOperatorValue("Equal to");
+ H.getDashboardCard().should("not.contain", "People.Name");
+
changeFilterType("ID");
cy.log("verify ID default value: Numeric ID");
@@ -163,11 +152,15 @@ describe("scenarios > dashboard > filters > management", () => {
changeFilterType("Location");
- cy.log("verify Date default value: Is");
+ cy.log("verify Location default value: Is");
verifyOperatorValue("Is");
+
+ H.saveDashboard();
+
+ H.filterWidget().should("not.exist");
});
- it("should use saved parameter value when user switches back to the saved filter type", () => {
+ it("should restore the saved parameter value and mappings when user switches back to the saved filter type", () => {
const textFilter = createMockParameter({
name: "Text Text",
slug: "string",
@@ -213,11 +206,16 @@ describe("scenarios > dashboard > filters > management", () => {
H.sidebar().findByDisplayValue("Does not contain").should("exist");
+ H.getDashboardCard().should("contain", "People.Name");
+
changeFilterType("Number");
// default value for a number type
H.sidebar().findByDisplayValue("Equal to").should("exist");
+ cy.log("verify that mapping is cleared");
+ H.getDashboardCard().should("not.contain", "People.Name");
+
changeFilterType("Text or Category");
cy.log("verify the saved parameter value is restored");
@@ -226,62 +224,6 @@ describe("scenarios > dashboard > filters > management", () => {
cy.findByDisplayValue("Text or Category").should("exist");
cy.findByDisplayValue("Text Text").should("exist");
});
- });
-
- it("should restore parameter mappings when user switches back to the saved parameter type", () => {
- const textFilter = createMockParameter({
- name: "Text Text",
- slug: "string",
- id: "5aefc726",
- type: "string/does-not-contain",
- sectionId: "string",
- });
-
- const peopleQuestionDetails = {
- query: { "source-table": PEOPLE_ID, limit: 5 },
- };
-
- H.createDashboardWithQuestions({
- dashboardDetails: {
- parameters: [textFilter],
- },
- questions: [peopleQuestionDetails],
- }).then(({ dashboard, questions: cards }) => {
- const [peopleCard] = cards;
-
- H.updateDashboardCards({
- dashboard_id: dashboard.id,
- cards: [
- {
- card_id: peopleCard.id,
- parameter_mappings: [
- {
- parameter_id: textFilter.id,
- card_id: peopleCard.id,
- target: ["dimension", ["field", PEOPLE.NAME, null]],
- },
- ],
- },
- ],
- });
-
- H.visitDashboard(dashboard.id);
- });
-
- H.editDashboard();
-
- selectFilter("Text Text");
-
- H.sidebar().findByDisplayValue("Does not contain").should("exist");
-
- H.getDashboardCard().should("contain", "People.Name");
-
- changeFilterType("Number");
-
- cy.log("verify that mapping is cleared");
- H.getDashboardCard().should("not.contain", "People.Name");
-
- changeFilterType("Text or Category");
cy.log("verify that mapping is restored");
H.getDashboardCard().should("contain", "People.Name");
@@ -301,11 +243,11 @@ describe("scenarios > dashboard > filters > management", () => {
changeOperator("Contains");
- H.getDashboardCard().should("contain", "People.Name");
-
// verifies default value does not exist
H.sidebar().findByText("No default").should("exist");
+ H.getDashboardCard().should("contain", "People.Name");
+
H.saveDashboard();
H.filterWidget().should("contain", "Text");
@@ -354,6 +296,8 @@ function createDashboardWithFilterAndQuestionMapped() {
H.visitDashboard(dashboard.id);
});
+ H.filterWidget().should("contain", "Text");
+
H.editDashboard();
}
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-number-source.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-number-source.cy.spec.js
index eb6604170d3..99e4d8c38d7 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-number-source.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-number-source.cy.spec.js
@@ -18,7 +18,7 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {
cy.signInAsAdmin();
});
- it("should be able to use a static list source with a dropdown or a search box", () => {
+ it("should be able to use a static list source with a dropdown or a search box, and restore it when the type changes back", () => {
H.createQuestionAndDashboard({
questionDetails: targetQuestion,
}).then(({ body: { dashboard_id } }) => {
@@ -52,6 +52,21 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {
H.filterWidget().eq(1).findByText("Twenty").should("be.visible");
H.getDashboardCard().findByText("4").should("be.visible");
+
+ cy.log("static list values are cleared and restored when the type changes");
+ H.editDashboard();
+ editFilter("Number");
+
+ editFilterType("Text or Category", "Is");
+ H.checkFilterListSourceHasValue({ values: [] });
+
+ mapFilterToQuestion("Email");
+ setFilterSourceFromConnectedFields();
+
+ editFilterType("Number", "Equal to");
+ H.checkFilterListSourceHasValue({
+ values: [["10", "Ten"], ["20", "Twenty"], "30"],
+ });
});
it("should allow to use a card source with numeric columns and single or multiple values", () => {
@@ -126,6 +141,28 @@ const mapFilterToQuestion = (column = "Quantity") => {
H.popover().within(() => cy.findByText(column).click());
};
+function setFilterSourceFromConnectedFields() {
+ H.sidebar().findByText("Edit").click();
+ H.modal().within(() => {
+ cy.findByText("From connected fields").click();
+ cy.button("Done").click();
+ });
+}
+
+function editFilter(name) {
+ cy.findByTestId("edit-dashboard-parameters-widget-container")
+ .findByText(name)
+ .click();
+}
+
+function editFilterType(type, subType) {
+ H.sidebar().findByText("Filter or parameter type").next().click();
+ H.selectDropdown().findByText(type).click();
+
+ H.sidebar().findByText("Filter operator").next().click();
+ H.selectDropdown().findByText(subType).click();
+}
+
const filterDashboard = ({ index, isLabeled = false, isDropdown = false }) => {
// eslint-disable-next-line metabase/no-unsafe-element-filtering
H.filterWidget().eq(index).click();
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-reset-clear.cy.spec.ts b/e2e/test/scenarios/dashboard-filters/dashboard-filters-reset-clear.cy.spec.ts
index 8c9cf47fc6f..0d479f014a8 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-reset-clear.cy.spec.ts
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-reset-clear.cy.spec.ts
@@ -152,6 +152,19 @@ describe("scenarios > dashboard > filters > reset & clear", () => {
H.popover().findByText(value).click();
},
});
+
+ cy.log("chevron icons are aligned in temporal unit parameter sidebar");
+ editFilter(NO_DEFAULT_NON_REQUIRED);
+ H.dashboardParameterSidebar()
+ .findAllByLabelText("chevrondown icon")
+ .should("have.length", 2)
+ .then(([$firstChevron, $secondChevron]) => {
+ const firstRect = $firstChevron.getBoundingClientRect();
+ const secondRect = $secondChevron.getBoundingClientRect();
+
+ expect(firstRect.left, "left").to.eq(secondRect.left);
+ expect(firstRect.right, "right").to.eq(secondRect.right);
+ });
});
it("time parameters", () => {
@@ -486,7 +499,7 @@ describe("scenarios > dashboard > filters > reset & clear", () => {
});
});
- it("number parameters - multiple values", () => {
+ it("number parameters - range", () => {
createDashboardWithParameters(PEOPLE_QUESTION, PEOPLE_ID_FIELD, [
{
name: NO_DEFAULT_NON_REQUIRED,
@@ -605,10 +618,28 @@ describe("scenarios > dashboard > filters > reset & clear", () => {
},
]);
+ cy.log("required filter can be set to default after deselecting all");
+ filter(DEFAULT_REQUIRED).click();
+ H.popover().within(() => {
+ cy.findAllByRole("listitem").contains("Gizmo").click();
+ cy.button("Update filter").click();
+ });
+ filter(DEFAULT_REQUIRED).should("contain.text", "Gadget");
+ checkStatusIcon(DEFAULT_REQUIRED, "reset");
+
+ filter(DEFAULT_REQUIRED).click();
+ H.popover().within(() => {
+ cy.findAllByRole("listitem").contains("Select all").click();
+ cy.findAllByRole("listitem").contains("Select all").click();
+ cy.button("Set to default").click();
+ });
+ filter(DEFAULT_REQUIRED).should("contain.text", "2 selections");
+ checkStatusIcon(DEFAULT_REQUIRED, "none");
+
checkDashboardParameters({
defaultValueFormatted: "2 selections",
- otherValue: "Doohickey,Widget,",
- otherValueFormatted: "2 selections",
+ otherValue: "Doohickey,Gizmo,Widget,",
+ otherValueFormatted: "3 selections",
setValue: (label, value) => {
filter(label).click();
H.popover().within(() => {
@@ -619,7 +650,6 @@ describe("scenarios > dashboard > filters > reset & clear", () => {
cy.findAllByRole("listitem").contains(value).click();
});
});
- // H.popover().findByRole("textbox").type(value);
H.popover().button("Add filter").click();
},
updateValue: (label, value) => {
@@ -639,37 +669,6 @@ describe("scenarios > dashboard > filters > reset & clear", () => {
},
});
});
-
- it("chevron icons are aligned in temporal unit parameter sidebar", () => {
- createDashboardWithParameters(
- ORDERS_COUNT_OVER_TIME,
- ORDERS_CREATED_AT_FIELD,
- [
- {
- name: "Time grouping",
- slug: "unit-of-time",
- id: "fed1b910",
- type: "temporal-unit",
- sectionId: "temporal-unit",
- },
- ],
- );
- H.editDashboard();
- editFilter("Time grouping");
-
- H.dashboardParameterSidebar()
- .findAllByLabelText("chevrondown icon")
- .then(([$firstChevron, ...$otherChevrons]) => {
- const firstRect = $firstChevron.getBoundingClientRect();
-
- for (const $chevron of $otherChevrons) {
- const rect = $chevron.getBoundingClientRect();
-
- expect(firstRect.left, "left").to.eq(rect.left);
- expect(firstRect.right, "right").to.eq(rect.right);
- }
- });
- });
});
describe("scenarios > dashboard > filters > reset all filters", () => {
@@ -720,79 +719,44 @@ describe("scenarios > dashboard > filters > reset all filters", () => {
});
});
- describe("issue 46177", () => {
- beforeEach(() => {
- H.restore();
- cy.signInAsAdmin();
- });
-
- it("should update value inside popover when resetting value to default (metabase#46177)", () => {
- const ORDERS_QUESTION = {
- name: "Orders question",
- query: {
- "source-table": ORDERS_ID,
- limit: 5,
- },
- };
-
- const targetField: LocalFieldReference = ["field", ORDERS.TAX, null];
- const numberFilter = {
- name: "Number filter",
- slug: "number_filter",
- id: "10c0d4bc",
- type: "number/=",
- sectionId: "number",
- default: 2.9,
- };
+ it("should update value inside popover when resetting value to default (metabase#46177)", () => {
+ const ORDERS_QUESTION = {
+ name: "Orders question",
+ query: {
+ "source-table": ORDERS_ID,
+ limit: 5,
+ },
+ };
- createDashboardWithParameters(ORDERS_QUESTION, targetField, [
- numberFilter,
- ]);
+ const targetField: LocalFieldReference = ["field", ORDERS.TAX, null];
+ const numberFilter = {
+ name: "Number filter",
+ slug: "number_filter",
+ id: "10c0d4bc",
+ type: "number/=",
+ sectionId: "number",
+ default: 2.9,
+ };
- cy.log("update filter value");
+ createDashboardWithParameters(ORDERS_QUESTION, targetField, [numberFilter]);
- filter(numberFilter.name).click();
- cy.findByTestId("token-field").findByLabelText("Remove").click();
- cy.findByTestId("token-field").findByRole("combobox").type("3");
- cy.realPress("Tab");
- H.popover().findByText("Update filter").click();
+ cy.log("update filter value");
- filter(numberFilter.name).findByText("3").should("exist");
+ filter(numberFilter.name).click();
+ cy.findByTestId("token-field").findByLabelText("Remove").click();
+ cy.findByTestId("token-field").findByRole("combobox").type("3");
+ cy.realPress("Tab");
+ H.popover().findByText("Update filter").click();
- cy.log("reset value to default with filter widget open");
- filter(numberFilter.name).click();
- cy.findByRole("dialog").should("be.visible");
- filter(numberFilter.name).icon("revert").click();
+ filter(numberFilter.name).findByText("3").should("exist");
- filter(numberFilter.name)
- .findByText(numberFilter.default)
- .should("exist");
- cy.findByRole("dialog").should("not.exist");
- });
- });
+ cy.log("reset value to default with filter widget open");
+ filter(numberFilter.name).click();
+ cy.findByRole("dialog").should("be.visible");
+ filter(numberFilter.name).icon("revert").click();
- describe("issue 57388", () => {
- it("should be possible to reset a required text filter to it's default value (metabase#57388)", () => {
- const textFilter = {
- name: "Filter",
- slug: "filter",
- id: "75d67d39",
- type: "string/=",
- required: true,
- sectionId: "string",
- default: ["Gizmo", "Gadget", "Widget", "Doohickey"],
- };
- createDashboardWithParameters(ORDERS_QUESTION, PRODUCTS_CATEGORY_FIELD, [
- textFilter,
- ]);
-
- filter(textFilter.name).click();
- H.popover().within(() => {
- cy.findByText("Select all").click();
- cy.findByText("Set to default").click();
- });
- H.filterWidget().eq(0).should("contain.text", "4 selections");
- });
+ filter(numberFilter.name).findByText(numberFilter.default).should("exist");
+ cy.findByRole("dialog").should("not.exist");
});
});
@@ -948,6 +912,7 @@ function checkDashboardParameters<T = string>({
checkResetAllFiltersHidden();
cy.log("has default value, required, value same as default");
+ filter(DEFAULT_REQUIRED).should("contain.text", defaultValueFormatted);
checkStatusIcon(DEFAULT_REQUIRED, "none");
checkResetAllFiltersHidden();
@@ -1200,6 +1165,7 @@ function checkResetAllFiltersShown() {
function checkResetAllFiltersHidden() {
cy.findByLabelText("Move, trash, and more…").click();
+ H.popover().findByText("Enter fullscreen").should("be.visible");
H.popover().findByText("Reset all filters").should("not.exist");
cy.findByLabelText("Move, trash, and more…").click();
}
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-source.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-source.cy.spec.js
index ede1dac2cfb..4850817efd3 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-source.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-source.cy.spec.js
@@ -33,12 +33,18 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- cy.intercept("POST", "/api/dataset").as("dataset");
});
- describe("structured question source", () => {
- it("should be able to use a structured question source", () => {
- H.createQuestion(structuredSourceQuestion, { wrapId: true });
+ describe("question source", () => {
+ it("should be able to use structured and native question sources", () => {
+ H.createQuestion(structuredSourceQuestion, {
+ wrapId: true,
+ idAlias: "structuredSourceQuestionId",
+ });
+ H.createNativeQuestion(nativeSourceQuestion, {
+ wrapId: true,
+ idAlias: "nativeSourceQuestionId",
+ });
H.createQuestionAndDashboard({
questionDetails: targetQuestion,
}).then(({ body: { dashboard_id } }) => {
@@ -46,35 +52,44 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {
});
H.editDashboard();
- H.setFilter("Text or Category", "Is");
+
+ H.setFilter("Text or Category", "Contains", "GUI Contains");
mapFilterToQuestion();
+ H.setDropdownFilterType();
H.setFilterQuestionSource({ question: "GUI source", field: "Category" });
- H.saveDashboard();
- filterDashboard();
- cy.get("@questionId").then(H.visitQuestion);
- archiveQuestion();
- });
-
- it("should be able to use a structured question source with string/contains parameter", () => {
- H.createQuestion(structuredSourceQuestion, { wrapId: true });
- H.createQuestionAndDashboard({
- questionDetails: targetQuestion,
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
- });
-
- H.editDashboard();
- H.setFilter("Text or Category", "Contains");
+ H.setFilter("Text or Category", "Is", "GUI Is");
mapFilterToQuestion();
- H.setDropdownFilterType();
H.setFilterQuestionSource({ question: "GUI source", field: "Category" });
+
+ H.setFilter("Text or Category", "Is", "SQL Is");
+ mapFilterToQuestion();
+ H.setFilterQuestionSource({ question: "SQL source", field: "CATEGORY" });
+
H.saveDashboard();
+
+ cy.log("structured question source with string/contains parameter");
H.getDashboardCard().findByText("200").should("be.visible");
- H.filterWidget().click();
+ H.filterWidget({ name: "GUI Contains" }).click();
H.popover().findByText("Gizmo").click();
H.popover().button("Add filter").click();
H.getDashboardCard().findByText("51").should("be.visible");
+
+ cy.log("structured question source with string/= parameter");
+ filterDashboard({ name: "GUI Is" });
+
+ cy.log("native question source");
+ filterDashboard({ name: "SQL Is" });
+
+ cy.get("@structuredSourceQuestionId").then(H.visitQuestion);
+ archiveQuestion(
+ "It will also be removed from the 2 filters that use it to populate values.",
+ );
+
+ cy.get("@nativeSourceQuestionId").then(H.visitQuestion);
+ archiveQuestion(
+ "It will also be removed from the filter that uses it to populate values.",
+ );
});
});
@@ -95,8 +110,9 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {
},
};
- it("should remap a string value to a string label (string/string)", () => {
- H.createNativeQuestion(stringLabelSource, { wrapId: true });
+ it("should remap string, number and id values to string labels", () => {
+ H.createNativeQuestion(stringLabelSource);
+ H.createNativeQuestion(numberLabelSource);
H.createQuestionAndDashboard({
questionDetails: targetQuestion,
}).then(({ body: { dashboard_id } }) => {
@@ -104,100 +120,92 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {
});
H.editDashboard();
- H.setFilter("Text or Category", "Is");
+
+ H.setFilter("Text or Category", "Is", "String label");
mapFilterToQuestion();
H.setFilterQuestionSource({
question: "String label source",
field: "CATEGORY",
labelField: "LABEL",
});
- H.saveDashboard();
-
- cy.log("the dropdown shows the labels instead of the raw values");
- H.filterWidget().click();
- H.popover().within(() => {
- cy.findByText("Gadget Label").should("be.visible");
- cy.findByText("Gizmo Label").should("be.visible");
- cy.findByText("Gizmo").should("not.exist");
- cy.findByText("Gizmo Label").click();
- cy.button("Add filter").click();
- });
- cy.log("the selected value is shown remapped to its label");
- H.filterWidget().findByText("Gizmo Label").should("be.visible");
- });
-
- it("should remap a number value to a string label (number/string)", () => {
- H.createNativeQuestion(numberLabelSource, { wrapId: true });
- H.createQuestionAndDashboard({
- questionDetails: targetQuestion,
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
+ H.setFilter("Number", "Equal to", "Number label");
+ mapFilterToQuestion("Rating");
+ H.setFilterQuestionSource({
+ question: "Number label source",
+ field: "ID",
+ labelField: "TITLE",
});
- H.editDashboard();
- H.setFilter("Number", "Equal to", "Number");
-
- mapFilterToQuestion("Rating");
+ H.setFilter("ID", undefined, "ID label");
+ mapFilterToQuestion("ID");
H.setFilterQuestionSource({
question: "Number label source",
field: "ID",
labelField: "TITLE",
});
+
H.saveDashboard();
cy.log(
- "the dropdown shows the product titles instead of the numeric ids",
+ "string/string: the dropdown shows the labels instead of the raw values",
);
- H.filterWidget().click();
+ H.filterWidget({ name: "String label" }).click();
H.popover().within(() => {
- cy.findByText("Rustic Paper Wallet").should("be.visible");
- cy.findByText("Rustic Paper Wallet").click();
+ cy.findByText("Gadget Label").should("be.visible");
+ cy.findByText("Gizmo Label").should("be.visible");
+ cy.findByText("Gizmo").should("not.exist");
+ cy.findByText("Gizmo Label").click();
cy.button("Add filter").click();
});
- cy.log("the selected value is shown remapped to its label");
- H.filterWidget().findByText("Rustic Paper Wallet").should("be.visible");
- });
+ cy.log(
+ "string/string: the selected value is shown remapped to its label",
+ );
+ H.filterWidget({ name: "String label" })
+ .findByText("Gizmo Label")
+ .should("be.visible");
- it("should remap an id value to a string label (id/string)", () => {
- H.createNativeQuestion(numberLabelSource, { wrapId: true });
- H.createQuestionAndDashboard({
- questionDetails: targetQuestion,
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
+ cy.log(
+ "number/string: the dropdown shows the product titles instead of the numeric ids",
+ );
+ H.filterWidget({ name: "Number label" }).click();
+ H.popover().within(() => {
+ cy.findByText("Rustic Paper Wallet").should("be.visible");
+ cy.findByText("1").should("not.exist");
+ cy.findByText("Rustic Paper Wallet").click();
+ cy.button("Add filter").click();
});
- H.editDashboard();
- H.setFilter("ID");
-
- mapFilterToQuestion("ID");
- H.setFilterQuestionSource({
- question: "Number label source",
- field: "ID",
- labelField: "TITLE",
- });
- H.saveDashboard();
+ cy.log(
+ "number/string: the selected value is shown remapped to its label",
+ );
+ H.filterWidget({ name: "Number label" })
+ .findByText("Rustic Paper Wallet")
+ .should("be.visible");
cy.log(
- "the dropdown shows the product titles instead of the numeric ids",
+ "id/string: the dropdown shows the product titles instead of the numeric ids",
);
- H.filterWidget().click();
+ H.filterWidget({ name: "ID label" }).click();
H.popover().within(() => {
cy.findByText("Rustic Paper Wallet").should("be.visible");
cy.findByText("Rustic Paper Wallet").click();
cy.button("Add filter").click();
});
- cy.log("the selected value and the remapped label are shown");
- H.filterWidget().findByText("- 1").should("be.visible");
- H.filterWidget().findByText("Rustic Paper Wallet").should("be.visible");
+ cy.log("id/string: the selected value and the remapped label are shown");
+ H.filterWidget({ name: "ID label" })
+ .findByText("- 1")
+ .should("be.visible");
+ H.filterWidget({ name: "ID label" })
+ .findByText("Rustic Paper Wallet")
+ .should("be.visible");
});
});
- describe("native question source", () => {
- it("should be able to use a native question source", () => {
- H.createNativeQuestion(nativeSourceQuestion, { wrapId: true });
+ describe("static list and field sources", () => {
+ it("should be able to use static list sources and a search box with fields configured for list", () => {
H.createQuestionAndDashboard({
questionDetails: targetQuestion,
}).then(({ body: { dashboard_id } }) => {
@@ -205,72 +213,37 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {
});
H.editDashboard();
- H.setFilter("Text or Category", "Is");
- mapFilterToQuestion();
- H.setFilterQuestionSource({ question: "SQL source", field: "CATEGORY" });
- H.saveDashboard();
- filterDashboard();
- cy.get("@questionId").then(H.visitQuestion);
- archiveQuestion();
- });
- });
-
- describe("static list source (dropdown)", () => {
- it("should be able to use a static list source", () => {
- H.createQuestionAndDashboard({
- questionDetails: targetQuestion,
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
- });
-
- H.editDashboard();
- H.setFilter("Text or Category", "Is");
+ H.setFilter("Text or Category", "Is", "List dropdown");
mapFilterToQuestion();
H.setFilterListSource({
values: [["Gadget"], ["Gizmo", "Gizmo Label"], "Widget"],
});
- H.saveDashboard();
- filterDashboard({ isLabeled: true });
- H.filterWidget().findByText("Gizmo Label").should("be.visible");
- });
- });
- describe("static list source (search)", () => {
- it("should be able to use a static list source (search)", () => {
- H.createQuestionAndDashboard({
- questionDetails: targetQuestion,
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
- });
-
- H.editDashboard();
- H.setFilter("Text or Category", "Is");
+ H.setFilter("Text or Category", "Is", "List search");
mapFilterToQuestion();
H.sidebar().findByText("Search box").click();
H.setFilterListSource({
values: [["Gadget"], ["Gizmo", "Gizmo Label"], "Widget"],
});
- H.saveDashboard();
- setSearchFilter("Gizmo Label");
- });
- });
-
- describe("field source", () => {
- it("should be able to use search box with fields configured for list", () => {
- H.createQuestionAndDashboard({
- questionDetails: targetQuestion,
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
- });
-
- H.editDashboard();
- H.setFilter("Text or Category", "Is");
+ H.setFilter("Text or Category", "Is", "Field search");
mapFilterToQuestion();
H.setSearchBoxFilterType();
+
H.saveDashboard();
- filterDashboard({ isField: true });
+
+ cy.log("static list source (dropdown)");
+ filterDashboard({ name: "List dropdown", isLabeled: true });
+ H.filterWidget({ name: "List dropdown" })
+ .findByText("Gizmo Label")
+ .should("be.visible");
+
+ cy.log("static list source (search)");
+ setSearchFilter({ name: "List search", label: "Gizmo Label" });
+
+ cy.log("field source (search box)");
+ filterDashboard({ name: "Field search", isField: true });
});
});
});
@@ -313,9 +286,10 @@ describe(
);
});
- it("should be possible to use custom labels on IP address columns", () => {
+ it("should be possible to use custom labels on IP address columns and type/Quantity fields", () => {
H.editDashboard();
- H.setFilter("Text or Category", "Is");
+
+ H.setFilter("Text or Category", "Is", "IP address");
mapFilterToQuestion("Inet");
H.setFilterListSource({
values: [
@@ -324,9 +298,17 @@ describe(
"0.0.0.1/0",
],
});
+
+ H.setFilter("Text or Category", "Is", "Quantity");
+ mapFilterToQuestion("Count");
+ H.setFilterListSource({
+ values: [["10", "Ten"], ["20", "Twenty"], "30"],
+ });
+
H.saveDashboard();
- openFilter();
+ cy.log("IP address column");
+ openFilter("IP address");
H.popover().within(() => {
cy.findByText("Router").should("be.visible");
cy.findByText("Localhost").should("be.visible");
@@ -336,19 +318,10 @@ describe(
cy.button("Add filter").click();
});
- cy.findByTestId("fixed-width-filters").should("contain", "Router");
- });
-
- it("should be possible to use custom labels on type/Quantity fields", () => {
- H.editDashboard();
- H.setFilter("Text or Category", "Is");
- mapFilterToQuestion("Count");
- H.setFilterListSource({
- values: [["10", "Ten"], ["20", "Twenty"], "30"],
- });
- H.saveDashboard();
+ H.filterWidget({ name: "IP address" }).should("contain", "Router");
- openFilter();
+ cy.log("type/Quantity field");
+ openFilter("Quantity");
H.popover().within(() => {
cy.findByText("Ten").should("be.visible");
cy.findByText("Twenty").should("be.visible");
@@ -358,7 +331,7 @@ describe(
cy.button("Add filter").click();
});
- cy.findByTestId("fixed-width-filters").should("contain", "Twenty");
+ H.filterWidget({ name: "Quantity" }).should("contain", "Twenty");
});
},
);
@@ -368,8 +341,8 @@ const mapFilterToQuestion = (column = "Category") => {
H.popover().within(() => cy.findByText(column).click());
};
-const filterDashboard = ({ isField = false, isLabeled = false } = {}) => {
- cy.findByText("Text").click();
+const filterDashboard = ({ name, isField = false, isLabeled = false }) => {
+ openFilter(name);
H.popover().within(() => {
const GIZMO = isLabeled ? "Gizmo Label" : "Gizmo";
@@ -389,20 +362,20 @@ const filterDashboard = ({ isField = false, isLabeled = false } = {}) => {
});
};
-function openFilter() {
- cy.findByText("Text").click();
+function openFilter(name) {
+ H.filterWidget({ name }).click();
}
-const archiveQuestion = () => {
+const archiveQuestion = (filterWarning) => {
H.openQuestionActions();
cy.findByTestId("archive-button").click();
cy.findByText(
- "This question will be removed from any dashboards or alerts using it. It will also be removed from the filter that uses it to populate values.",
+ `This question will be removed from any dashboards or alerts using it. ${filterWarning}`,
);
};
-function setSearchFilter(label) {
- H.filterWidget().click();
+function setSearchFilter({ name, label }) {
+ H.filterWidget({ name }).click();
H.popover().within(() => {
H.fieldValuesCombobox().type(label);
});
@@ -414,5 +387,5 @@ function setSearchFilter(label) {
cy.button("Add filter").click();
});
- H.filterWidget().findByText(label).should("be.visible");
+ H.filterWidget({ name }).findByText(label).should("be.visible");
}
diff --git a/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js b/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js
index d3148adb5ff..bfd86b3a06a 100644
--- a/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js
@@ -134,6 +134,8 @@ describe("scenarios > dashboard > parameters", () => {
},
);
+ H.tableInteractiveBody().findByText("37.65").should("be.visible");
+
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText(startsWith.name).click();
cy.findByPlaceholderText("Enter some text").type("G");
@@ -148,8 +150,9 @@ describe("scenarios > dashboard > parameters", () => {
cy.button("Add filter").click();
expectSearchParams({ [endsWith.slug]: "", [startsWith.slug]: "G" });
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("37.65").should("not.exist");
+ H.tableInteractiveBody().findByText("110.93").should("be.visible");
+ H.tableInteractiveBody().findByText("52.72").should("be.visible");
+ H.tableInteractiveBody().findByText("37.65").should("not.exist");
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText(endsWith.name).click();
@@ -163,8 +166,8 @@ describe("scenarios > dashboard > parameters", () => {
cy.button("Add filter").click();
expectSearchParams({ [endsWith.slug]: "zmo", [startsWith.slug]: "G" });
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("52.72").should("not.exist");
+ H.tableInteractiveBody().findByText("110.93").should("be.visible");
+ H.tableInteractiveBody().findByText("52.72").should("not.exist");
// Remove filter (metabase#17933)
cy.icon("pencil").click();
@@ -188,6 +191,7 @@ describe("scenarios > dashboard > parameters", () => {
"There should only be one filter remaining and its value is preserved",
);
+ H.filterWidget().should("have.length", 1);
H.filterWidget().contains(new RegExp(`${endsWith.name}`, "i"));
expectSearchParams({ [endsWith.slug]: "zmo" });
@@ -420,15 +424,15 @@ describe("scenarios > dashboard > parameters", () => {
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("2 selections").click();
- // Even after we reopen the dropdown, it shouldn't send additional requests for values (metabase#16103)
- cy.get("@fetchAllCategories").should("have.been.calledOnce");
-
// As a sanity check, make sure we can deselect the filter by clicking on it
H.popover().within(() => {
cy.findByText("Gizmo").click();
isFilterSelected("Gizmo", false);
});
+ // Even after we reopen the dropdown, it shouldn't send additional requests for values (metabase#16103)
+ cy.get("@fetchAllCategories").should("have.been.calledOnce");
+
cy.button("Update filter").click();
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("2 selections").should("not.exist");
@@ -461,47 +465,12 @@ describe("scenarios > dashboard > parameters", () => {
H.tableInteractiveBody().findAllByRole("row").should("have.length", 1);
});
- describe("when the user does not have self-service data permissions", () => {
- beforeEach(() => {
- H.visitDashboard(ORDERS_DASHBOARD_ID);
- H.tableInteractiveHeader("Created At");
-
- H.editDashboard();
- H.setFilter("ID");
-
- H.selectDashboardFilter(H.getDashboardCard(), "User ID");
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Save").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("You're editing this dashboard.").should("not.exist");
-
- cy.signIn("nodata");
- H.visitDashboard(ORDERS_DASHBOARD_ID);
- });
-
- it("should not see mapping options", () => {
- cy.icon("pencil").click();
- H.filterWidget({ isEditing: true }).click();
-
- cy.icon("key");
- });
- });
-
describe("when parameters are (dis)connected to dashcards", () => {
beforeEach(() => {
createDashboardWithCards({ cards }).then((dashboardId) =>
H.visitDashboard(dashboardId),
);
- // create a disconnected filter + a default value
- H.editDashboard();
- H.setFilter("Date picker", "Relative Date");
-
- H.sidebar().findByText("Default value").next().click();
- H.popover().contains("Previous 7 days").click({ force: true });
- H.saveDashboard();
-
const { interceptor } = H.spyRequestFinished("dashcardRequestSpy");
cy.intercept(
@@ -509,29 +478,26 @@ describe("scenarios > dashboard > parameters", () => {
"/api/dashboard/*/dashcard/*/card/*/query",
interceptor,
);
- });
-
- it("should not fetch dashcard data when filter is disconnected", () => {
- cy.get("@dashcardRequestSpy").should("not.have.been.called");
- });
- it("should fetch dashcard data after save when parameter is mapped", () => {
- // Connect filter to 2 cards
+ // create a disconnected filter + a default value
H.editDashboard();
+ H.setFilter("Date picker", "Relative Date");
- cy.findByTestId("edit-dashboard-parameters-widget-container")
- .findByText("Date")
- .click();
+ H.sidebar().findByText("Default value").next().click();
+ H.popover().contains("Previous 7 days").click({ force: true });
+ H.saveDashboard();
+ });
- H.selectDashboardFilter(H.getDashboardCard(0), "Created At");
- H.selectDashboardFilter(H.getDashboardCard(1), "Created At");
+ it("should fetch dashcard data on save only when parameter mappings change", () => {
+ cy.log("Saving a disconnected filter does not fetch dashcard data");
+ cy.get("@dashcardRequestSpy").should("not.have.been.called");
- H.saveDashboard();
+ cy.log("Saving without changes does not fetch dashcard data");
+ H.editDashboard();
+ H.saveDashboard({ awaitRequest: false });
- cy.get("@dashcardRequestSpy").should("have.callCount", 2);
- });
+ cy.get("@dashcardRequestSpy").should("have.callCount", 0);
- it("should fetch dashcard data when parameter mapping is removed", () => {
cy.log("Connect filter to 1 card only");
H.editDashboard();
@@ -556,13 +522,20 @@ describe("scenarios > dashboard > parameters", () => {
H.saveDashboard();
cy.get("@dashcardRequestSpy").should("have.callCount", 2);
- });
- it("should not fetch dashcard data when nothing changed on save", () => {
+ cy.log("Connect filter to 2 cards");
H.editDashboard();
- H.saveDashboard({ awaitRequest: false });
- cy.get("@dashcardRequestSpy").should("have.callCount", 0);
+ cy.findByTestId("edit-dashboard-parameters-widget-container")
+ .findByText("Date")
+ .click();
+
+ H.selectDashboardFilter(H.getDashboardCard(0), "Created At");
+ H.selectDashboardFilter(H.getDashboardCard(1), "Created At");
+
+ H.saveDashboard();
+
+ cy.get("@dashcardRequestSpy").should("have.callCount", 4);
});
});
@@ -610,7 +583,7 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- it("should retain the last used value for a dashboard filter", () => {
+ it("should retain the last used value for a dashboard filter and allow resetting it", () => {
cy.intercept("GET", "/api/**/items?pinned-state*").as("getPinnedItems");
H.filterWidget().click();
@@ -641,31 +614,6 @@ describe("scenarios > dashboard > parameters", () => {
H.getDashboardCard()
.findByText("761 Fish Hill Road")
.should("be.visible");
- });
-
- it("should allow resetting last used value", () => {
- H.filterWidget().click();
-
- H.dashboardParametersPopover().within(() => {
- H.fieldValuesCombobox().type("Antwan Fisher");
- cy.button("Add filter").click();
- });
-
- H.getDashboardCard()
- .findByText("7750 Michalik Lane")
- .should("be.visible");
-
- cy.log("reset filter values from url by visiting dashboard by id");
-
- cy.get("@dashboardId").then((dashboardId) =>
- H.visitDashboard(dashboardId),
- );
-
- H.filterWidget().icon("close").click();
-
- H.getDashboardCard()
- .findByText("761 Fish Hill Road")
- .should("be.visible");
cy.log("verify filter value is not specified after reload");
@@ -676,6 +624,7 @@ describe("scenarios > dashboard > parameters", () => {
H.getDashboardCard()
.findByText("761 Fish Hill Road")
.should("be.visible");
+ H.filterWidget().should("not.contain", "Antwan Fisher");
});
});
@@ -722,7 +671,11 @@ describe("scenarios > dashboard > parameters", () => {
H.addHeadingWhileEditing("Heading");
H.setDashCardFilter(1, "Text or Category", null, "Category");
H.selectDashboardFilter(H.getDashboardCard(0), "Category");
- H.getDashboardCard(0).within(() => {
+ H.dashboardParameterSidebar().button("Done").click();
+ H.getDashboardCard(1).within(() => {
+ H.filterWidget({ isEditing: true })
+ .contains("Category")
+ .should("be.visible");
// Ensure filters are not draggable
cy.icon("grabber").should("not.exist");
});
@@ -773,9 +726,7 @@ describe("scenarios > dashboard > parameters", () => {
.findByText(/No results/)
.should("exist");
- cy.location().should(({ search }) => {
- expect(search).to.eq("?category=Gadget&count=6000");
- });
+ expectSearchParams({ category: "Gadget", count: "6000" });
H.getDashboardCard(1).within(() => {
H.clearFilterWidget(1);
@@ -788,9 +739,7 @@ describe("scenarios > dashboard > parameters", () => {
cy.findByText("Widget").should("not.exist");
});
- cy.location().should(({ search }) => {
- expect(search).to.eq("?category=Gadget&count=");
- });
+ expectSearchParams({ category: "Gadget", count: "" });
});
it("should be able to edit filters", () => {
@@ -952,60 +901,6 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- it("should remove filters when removing a dashcard", () => {
- cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");
-
- H.createQuestionAndDashboard({
- questionDetails: ordersCountByCategory,
- dashboardDetails: {
- parameters: [categoryParameter],
- },
- }).then(({ body: dashcard }) => {
- H.updateDashboardCards({
- dashboard_id: dashcard.dashboard_id,
- cards: [
- createMockHeadingDashboardCard({
- inline_parameters: [categoryParameter.id],
- size_x: 24,
- size_y: 1,
- }),
- {
- id: dashcard.id,
- row: 1,
- size_x: 12,
- size_y: 6,
- parameter_mappings: [
- {
- parameter_id: categoryParameter.id,
- card_id: dashcard.card_id,
- target: [
- "dimension",
- categoryFieldRef,
- { "stage-number": 0 },
- ],
- },
- ],
- },
- ],
- });
- H.visitDashboard(dashcard.dashboard_id);
- H.editDashboard();
- });
-
- H.getDashboardCard(0).findByText("Heading Text").should("exist");
- H.removeDashboardCard(0);
- H.saveDashboard();
-
- cy.wait("@updateDashboard").then((xhr) => {
- const { body: dashboard } = xhr.request;
- expect(dashboard.parameters).to.have.length(0);
- dashboard.dashcards.forEach((dashcard) => {
- expect(dashcard.inline_parameters).to.have.length(0);
- expect(dashcard.parameter_mappings).to.have.length(0);
- });
- });
- });
-
it("should not use inline filters for auto-wiring", () => {
H.createQuestion({
name: "Average total by category",
@@ -1154,9 +1049,7 @@ describe("scenarios > dashboard > parameters", () => {
cy.findByText("Doohickey").should("exist");
cy.findByText("Gizmo").should("not.exist");
});
- cy.location().should(({ search }) => {
- expect(search).to.eq("?category=Doohickey&category_1=");
- });
+ expectSearchParams({ category: "Doohickey", category_1: "" });
H.getDashboardCard(2).within(() => {
H.filterWidget().contains("Category 1").click();
@@ -1169,9 +1062,7 @@ describe("scenarios > dashboard > parameters", () => {
H.getDashboardCard(1)
.findByText(/No results/)
.should("exist");
- cy.location().should(({ search }) => {
- expect(search).to.eq("?category=Doohickey&category_1=Gizmo");
- });
+ expectSearchParams({ category: "Doohickey", category_1: "Gizmo" });
H.getDashboardCard(0).within(() => H.clearFilterWidget());
@@ -1179,9 +1070,7 @@ describe("scenarios > dashboard > parameters", () => {
cy.findByText("Doohickey").should("not.exist");
cy.findByText("Gizmo").should("exist");
});
- cy.location().should(({ search }) => {
- expect(search).to.eq("?category=&category_1=Gizmo");
- });
+ expectSearchParams({ category: "", category_1: "Gizmo" });
});
it("should duplicate filters when duplicating a dashboard", () => {
@@ -1255,7 +1144,9 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- it("should correctly undo dashcard removal (VIZ-1236)", () => {
+ it("should correctly undo dashcard removal and remove filters with the dashcard (VIZ-1236)", () => {
+ cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");
+
H.createQuestionAndDashboard({
questionDetails: ordersCountByCategory,
dashboardDetails: {
@@ -1305,6 +1196,22 @@ describe("scenarios > dashboard > parameters", () => {
.findByTestId("parameter-mapper-container")
.findByText(/Category/)
.should("exist");
+ H.dashboardParameterSidebar().button("Done").click();
+
+ cy.log("Removing the heading dashcard removes its filters");
+ H.removeDashboardCard(0);
+ H.saveDashboard();
+
+ cy.wait("@updateDashboard").then((xhr) => {
+ const { body: dashboard } = xhr.request;
+ expect(dashboard.parameters).to.have.length(0);
+ expect(dashboard.dashcards).to.have.length(1);
+ expect(dashboard.dashcards[0].card_id).to.not.equal(null);
+ dashboard.dashcards.forEach((dashcard) => {
+ expect(dashcard.inline_parameters).to.have.length(0);
+ expect(dashcard.parameter_mappings).to.have.length(0);
+ });
+ });
});
it("should not display a parameter widget if there are no linked with it cards after a text card variable is removed (UXW-751)", () => {
@@ -1342,7 +1249,7 @@ describe("scenarios > dashboard > parameters", () => {
});
H.filterWidget({ isEditing: false }).contains("Category").should("exist");
- H.filterWidget({ isEditing: false }).contains("Category").should("exist");
+ H.filterWidget({ isEditing: false }).contains("Count").should("exist");
H.editDashboard();
@@ -1405,7 +1312,7 @@ describe("scenarios > dashboard > parameters", () => {
},
{
parameter_id: countParameter.id,
- card_id: ORDERS_BY_YEAR_QUESTION_ID,
+ card_id: dashcard.card_id,
target: [
"dimension",
["field", "count", { "base-type": "type/Integer" }],
@@ -1425,6 +1332,7 @@ describe("scenarios > dashboard > parameters", () => {
cy.findByText("Gizmo").should("be.visible");
cy.findByText("Gadget").should("be.visible");
cy.findByText("Widget").should("be.visible");
+ H.filterWidget().contains("Count").should("be.visible");
});
H.getDashboardCard(0).within(() => {
@@ -1442,9 +1350,7 @@ describe("scenarios > dashboard > parameters", () => {
cy.findByText("Widget").should("not.exist");
});
- cy.location().should(({ search }) => {
- expect(search).to.eq("?category=Gadget&count=");
- });
+ expectSearchParams({ category: "Gadget", count: "" });
// Verify filter doesn't show up in the dashboard header
H.dashboardParametersContainer().should("not.exist");
@@ -1656,6 +1562,13 @@ describe("scenarios > dashboard > parameters", () => {
cy.findByText("Heading Text").should("exist");
cy.findByText("Category").should("not.exist");
});
+
+ H.getDashboardCard(1).within(() => {
+ cy.findByText("Doohickey").should("be.visible");
+ cy.findByText("Gizmo").should("be.visible");
+ cy.findByText("Gadget").should("be.visible");
+ cy.findByText("Widget").should("be.visible");
+ });
});
it("should work correctly when parameter is locked", () => {
@@ -1885,11 +1798,15 @@ describe("scenarios > dashboard > parameters", () => {
});
// Update header filter, verify no changes
+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(
+ "dashcardQuery",
+ );
H.dashboardParametersContainer().within(() => H.filterWidget().click());
H.popover().within(() => {
cy.findByLabelText("Gadget").click();
cy.button("Update filter").click();
});
+ cy.wait("@dashcardQuery");
H.dashboardParametersContainer()
.findByText("3 selections")
.should("exist");
@@ -1901,7 +1818,7 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- it("should be able to edit filters", () => {
+ it("should be able to edit filters and remove them with the dashcard", () => {
H.createQuestionAndDashboard({
questionDetails: ordersCountByCategory,
dashboardDetails: {
@@ -1967,9 +1884,22 @@ describe("scenarios > dashboard > parameters", () => {
cy.location().should(({ search }) => {
expect(search).to.eq("?count=4000");
});
+
+ cy.log("Removing the dashcard removes its filters");
+ cy.intercept("PUT", "/api/dashboard/*").as("removeDashcardSave");
+ H.editDashboard();
+ H.getDashboardCard(0).findByText("Doohickey").should("exist");
+ H.removeDashboardCard(0);
+ H.saveDashboard();
+
+ cy.wait("@removeDashcardSave").then((xhr) => {
+ const { body: dashboard } = xhr.request;
+ expect(dashboard.parameters).to.have.length(0);
+ expect(dashboard.dashcards).to.have.length(0);
+ });
});
- it("should remove filters correctly", () => {
+ it("should show all inline parameters while editing one and remove filters correctly", () => {
cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");
H.createQuestionAndDashboard({
@@ -2011,6 +1941,34 @@ describe("scenarios > dashboard > parameters", () => {
H.editDashboard();
+ cy.log("All inline parameters stay visible while editing one of them");
+ H.getDashboardCard(0).within(() => {
+ H.filterWidget({ isEditing: true, name: "Category" }).should(
+ "be.visible",
+ );
+ H.filterWidget({ isEditing: true, name: "Count" }).should("be.visible");
+
+ H.filterWidget({ isEditing: true, name: "Category" }).click();
+ });
+ H.sidebar().findByLabelText("Label").should("have.value", "Category");
+ H.getDashboardCard(0).within(() => {
+ H.filterWidget({ isEditing: true, name: "Category" }).should(
+ "be.visible",
+ );
+ H.filterWidget({ isEditing: true, name: "Count" }).should("be.visible");
+
+ H.filterWidget({ isEditing: true, name: "Count" }).click();
+ });
+ H.sidebar().findByLabelText("Label").should("have.value", "Count");
+ H.getDashboardCard(0).within(() => {
+ H.filterWidget({ isEditing: true, name: "Category" }).should(
+ "be.visible",
+ );
+ H.filterWidget({ isEditing: true, name: "Count" }).should("be.visible");
+ });
+ H.dashboardParameterSidebar().button("Done").click();
+
+ cy.log("Remove both inline parameters");
H.getDashboardCard(0)
.findAllByText("Count")
.filter(":visible")
@@ -2043,53 +2001,6 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- it("should remove filters when removing a dashcard", () => {
- cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");
-
- H.createQuestionAndDashboard({
- questionDetails: ordersCountByCategory,
- dashboardDetails: {
- parameters: [categoryParameter],
- },
- }).then(({ body: dashcard }) => {
- H.updateDashboardCards({
- dashboard_id: dashcard.dashboard_id,
- cards: [
- {
- id: dashcard.id,
- inline_parameters: [categoryParameter.id],
- parameter_mappings: [
- {
- parameter_id: categoryParameter.id,
- card_id: dashcard.card_id,
- target: [
- "dimension",
- categoryFieldRef,
- { "stage-number": 0 },
- ],
- },
- ],
- },
- ],
- });
- H.visitDashboard(dashcard.dashboard_id);
- H.editDashboard();
- });
-
- H.getDashboardCard(0).findByText("Doohickey").should("exist");
- H.removeDashboardCard(0);
- H.saveDashboard();
-
- cy.wait("@updateDashboard").then((xhr) => {
- const { body: dashboard } = xhr.request;
- expect(dashboard.parameters).to.have.length(0);
- dashboard.dashcards.forEach((dashcard) => {
- expect(dashcard.inline_parameters).to.have.length(0);
- expect(dashcard.parameter_mappings).to.have.length(0);
- });
- });
- });
-
it("should not use inline filters for auto-wiring", () => {
H.createQuestion({
name: "Average total by category",
@@ -2142,6 +2053,9 @@ describe("scenarios > dashboard > parameters", () => {
H.getDashboardCard(0).within(() => {
H.filterWidget({ isEditing: true }).contains("Category").click();
});
+ H.getDashboardCard(1)
+ .findByText("This filter can only connect to its own card.")
+ .should("be.visible");
H.getDashboardCard(1)
.findByTestId("parameter-mapper-container")
.findByText(/Category/)
@@ -2152,6 +2066,9 @@ describe("scenarios > dashboard > parameters", () => {
H.getDashboardCard(0).click(); // click to stop dragging a card
H.disconnectDashboardFilter(H.getDashboardCard(0), "Category");
H.selectDashboardFilter(H.getDashboardCard(0), "Category");
+ H.getDashboardCard(1)
+ .findByText("This filter can only connect to its own card.")
+ .should("be.visible");
H.getDashboardCard(1)
.findByTestId("parameter-mapper-container")
.findByText(/Category/)
@@ -2193,7 +2110,6 @@ describe("scenarios > dashboard > parameters", () => {
H.visitDashboard(dashcard.dashboard_id);
H.editDashboard();
});
- cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");
cy.log("Wait for the dashcard to finish rendering before editing");
H.getDashboardCard(0)
@@ -2236,6 +2152,9 @@ describe("scenarios > dashboard > parameters", () => {
.should("exist")
.click();
});
+ H.getDashboardCard(1)
+ .findByText("This filter can only connect to its own card.")
+ .should("be.visible");
H.getDashboardCard(1)
.findByTestId("parameter-mapper-container")
.findByText(/Category/)
@@ -2302,10 +2221,10 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- cy.location().should(({ search }) => {
- expect(search).to.eq(
- "?category=Widget&category_1=Doohickey&count=5000",
- );
+ expectSearchParams({
+ category: "Widget",
+ category_1: "Doohickey",
+ count: "5000",
});
});
@@ -2373,7 +2292,7 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- it("should not allow connecting inline parameters to cards on a different tab", () => {
+ it("should allow connecting inline parameters only to their own card, not to cards on another tab", () => {
H.createQuestionAndDashboard({
questionDetails: ordersCountByCategory,
}).then(({ body: dashcard }) => {
@@ -2383,6 +2302,7 @@ describe("scenarios > dashboard > parameters", () => {
// Add a second card
H.openQuestionsSidebar();
H.sidebar().findByText("Orders, Count").click();
+ H.getDashboardCard(1).findByText("Count").should("exist");
// Add a second tab
H.createNewTab();
@@ -2397,35 +2317,17 @@ describe("scenarios > dashboard > parameters", () => {
H.setDashCardFilter(0, "Text or Category", null, "Category");
H.selectDashboardFilter(H.getDashboardCard(0), "Category");
- H.goToTab("Tab 2");
+ // Ensure the filter can't be connected to the second card on the same tab
+ H.getDashboardCard(1)
+ .findByText("This filter can only connect to its own card.")
+ .should("be.visible");
- // Ensure the filter can't be connected to the second card
+ // Ensure the filter can't be connected to the card on the other tab
+ H.goToTab("Tab 2");
H.getDashboardCard(0)
.findByText("The selected filter is on another tab.")
.should("be.visible");
- });
- });
-
- it("should allow connecting inline parameters only to their own card", () => {
- H.createQuestionAndDashboard({
- questionDetails: ordersCountByCategory,
- }).then(({ body: dashcard }) => {
- H.visitDashboard(dashcard.dashboard_id);
- H.editDashboard();
-
- // Add a second card
- H.openQuestionsSidebar();
- H.sidebar().findByText("Orders, Count").click();
- H.getDashboardCard(1).findByText("Count").should("exist");
-
- // Add a filter to the first card
- H.setDashCardFilter(0, "Text or Category", null, "Category");
- H.selectDashboardFilter(H.getDashboardCard(0), "Category");
-
- // Ensure the filter can't be connected to the second card
- H.getDashboardCard(1)
- .findByText("This filter can only connect to its own card.")
- .should("be.visible");
+ H.goToTab("Tab 1");
// Disconnect the filter from the first card
H.sidebar().findByText("Disconnect from card").click();
@@ -2436,122 +2338,6 @@ describe("scenarios > dashboard > parameters", () => {
.should("be.visible");
});
});
-
- it("should show all inline parameters when editing one parameter mapping", () => {
- const categoryFilter = createMockParameter({
- id: "category123",
- name: "Category",
- type: "string/=",
- slug: "category",
- sectionId: "string",
- });
-
- const countFilter = createMockParameter({
- id: "count456",
- name: "Count",
- type: "number/=",
- slug: "count",
- sectionId: "number",
- });
-
- H.createQuestionAndDashboard({
- questionDetails: ordersCountByCategory,
- dashboardDetails: {
- parameters: [categoryFilter, countFilter],
- },
- }).then(({ body: dashcard }) => {
- // Update the dashcard to have inline parameters
- H.updateDashboardCards({
- dashboard_id: dashcard.dashboard_id,
- cards: [
- {
- id: dashcard.id,
- inline_parameters: [categoryFilter.id, countFilter.id],
- parameter_mappings: [
- {
- parameter_id: categoryFilter.id,
- card_id: dashcard.card_id,
- target: [
- "dimension",
- categoryFieldRef,
- { "stage-number": 0 },
- ],
- },
- ],
- },
- ],
- });
-
- H.visitDashboard(dashcard.dashboard_id);
- H.editDashboard();
-
- // Both filters should be visible
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true, name: "Category" }).should(
- "be.visible",
- );
- H.filterWidget({ isEditing: true, name: "Count" }).should(
- "be.visible",
- );
- });
-
- // Click on Category filter to open its mapping sidebar
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true, name: "Category" }).click();
- });
-
- // Verify the sidebar opened for Category parameter
- H.sidebar().findByLabelText("Label").should("have.value", "Category");
-
- // Both filters should still be visible during mapping mode
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true, name: "Category" }).should(
- "be.visible",
- );
- H.filterWidget({ isEditing: true, name: "Count" }).should(
- "be.visible",
- );
- });
-
- // Should be able to click on Count filter while Category mapping is open
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true, name: "Count" }).click();
- });
-
- // The sidebar should now show Count parameter settings
- H.sidebar().findByLabelText("Label").should("have.value", "Count");
-
- // Both filters should still be visible
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true, name: "Category" }).should(
- "be.visible",
- );
- H.filterWidget({ isEditing: true, name: "Count" }).should(
- "be.visible",
- );
- });
- });
- });
-
- it("should not show add filter button for users with no data editing permissions", () => {
- H.createQuestionAndDashboard({
- questionDetails: ordersCountByCategory,
- }).then(({ body: { dashboard_id } }) => {
- cy.signIn("nodata");
- H.visitDashboard(dashboard_id);
- H.editDashboard();
-
- H.getDashboardCard(0)
- .realHover()
- .findByTestId("dashboardcard-actions-panel")
- .should("be.visible");
-
- // Ensure the "Add a filter" button is not present
- H.getDashboardCard(0)
- .findByLabelText("Add a filter")
- .should("not.exist");
- });
- });
});
describe("moving filters", () => {
@@ -2577,7 +2363,7 @@ describe("scenarios > dashboard > parameters", () => {
{ "source-field": ORDERS.PRODUCT_ID },
];
- it("should allow moving filters on a single tab dashboard", () => {
+ it("should allow moving filters and undoing moves on a single tab dashboard", () => {
H.createQuestionAndDashboard({
dashboardDetails: {
parameters: [categoryParameter, countParameter],
@@ -2610,7 +2396,40 @@ describe("scenarios > dashboard > parameters", () => {
});
H.selectDashboardFilter(H.getDashboardCard(0), "Category");
+ cy.log("Undo moving the card filter to the header");
+ H.moveDashboardFilter("Top of page");
+ H.undo();
+ H.getDashboardCard(0).within(() => {
+ H.filterWidget({ isEditing: true })
+ .contains("Category")
+ .should("exist");
+ });
+ H.editingDashboardParametersContainer().within(() => {
+ H.filterWidget({ isEditing: true })
+ .contains("Category")
+ .should("not.exist");
+ });
+
+ cy.log("Undo moving the header filter to the card");
+ H.editingDashboardParametersContainer().within(() => {
+ H.filterWidget({ isEditing: true }).contains("Count").click();
+ });
+ H.moveDashboardFilter("test question");
+ H.dashboardParameterSidebar().button("Done").click();
+ H.undo();
+ H.getDashboardCard(0).within(() => {
+ H.filterWidget({ isEditing: true })
+ .contains("Count")
+ .should("not.exist");
+ });
+ H.editingDashboardParametersContainer().within(() => {
+ H.filterWidget({ isEditing: true }).contains("Count").should("exist");
+ });
+
// Move card filter to the header
+ H.getDashboardCard(0).within(() => {
+ H.filterWidget({ isEditing: true }).contains("Category").click();
+ });
H.moveDashboardFilter("Top of page");
H.getDashboardCard(0).findByText("Category").should("not.exist");
@@ -2732,72 +2551,6 @@ describe("scenarios > dashboard > parameters", () => {
});
});
- it("should allow undoing a move", () => {
- H.createQuestionAndDashboard({
- dashboardDetails: {
- parameters: [categoryParameter, countParameter],
- },
- questionDetails: {
- display: "bar",
- query: {
- "source-table": ORDERS_ID,
- aggregation: [["count"]],
- breakout: [categoryFieldRef],
- },
- },
- cardDetails: {
- inline_parameters: [categoryParameter.id],
- size_x: 18,
- },
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
- H.editDashboard();
- });
-
- // Move card filter to the header
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true }).contains("Category").click();
- });
- H.dashboardParameterSidebar()
- .findByPlaceholderText("Move filter")
- .click();
- H.popover().findByText("Top of page").click();
-
- // Undo
- H.undo();
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true })
- .contains("Category")
- .should("exist");
- });
- H.editingDashboardParametersContainer().within(() => {
- H.filterWidget({ isEditing: true })
- .contains("Category")
- .should("not.exist");
- });
-
- // Move header filter to the card
- H.editingDashboardParametersContainer().within(() => {
- H.filterWidget({ isEditing: true }).contains("Count").click();
- });
- H.dashboardParameterSidebar()
- .findByPlaceholderText("Move filter")
- .click();
- H.popover().findByText("test question").click();
- H.dashboardParameterSidebar().button("Done").click();
-
- // Undo
- H.undo();
- H.getDashboardCard(0).within(() => {
- H.filterWidget({ isEditing: true })
- .contains("Count")
- .should("not.exist");
- });
- H.editingDashboardParametersContainer().within(() => {
- H.filterWidget({ isEditing: true }).contains("Count").should("exist");
- });
- });
-
it("should provide a way to 'focus' the recently moved filter", () => {
const TAB_1 = { id: 1, name: "Tab 1" };
const TAB_2 = { id: 2, name: "Tab 2" };
@@ -2862,6 +2615,7 @@ describe("scenarios > dashboard > parameters", () => {
// Move filter to top nav and assert the "Show filter" button isn't displayed
H.moveDashboardFilter("Top of page");
+ H.undoToast().should("contain", "Filter moved");
H.undoToast().button("Show filter").should("not.exist");
});
});
@@ -2879,7 +2633,7 @@ describe("scenarios > dashboard > parameters", () => {
H.expectNoBadSnowplowEvents();
});
- it("should track dashboard_filter_created event when adding a filter", () => {
+ it("should track dashboard_filter_created and dashboard_filter_moved events", () => {
H.visitDashboard(ORDERS_DASHBOARD_ID);
H.editDashboard();
@@ -2918,66 +2672,30 @@ describe("scenarios > dashboard > parameters", () => {
event_detail: "id",
target_id: ORDERS_DASHBOARD_ID,
});
- });
- it("should track dashboard_filter_moved event when moving a filter", () => {
- H.createQuestionAndDashboard({
- dashboardDetails: {
- parameters: [
- createMockParameter({
- id: "1b9cd9f1",
- name: "Category",
- type: "string/=",
- slug: "category",
- sectionId: "string",
- }),
- ],
- },
- questionDetails: {
- display: "bar",
- query: {
- "source-table": ORDERS_ID,
- aggregation: [["count"]],
- breakout: [
- ["field", PRODUCTS.CATEGORY, { "source-field": ORDERS.PRODUCT_ID }],
- ],
- },
- },
- }).then(({ body: { dashboard_id } }) => {
- H.visitDashboard(dashboard_id);
- H.editDashboard();
- H.addHeadingWhileEditing("heading card");
- cy.wrap(dashboard_id).as("dashboardId");
+ cy.log("Track dashboard_filter_moved when moving the header filter");
+ H.moveDashboardFilter("Orders");
+ H.expectUnstructuredSnowplowEvent({
+ event: "dashboard_filter_moved",
+ triggered_from: null,
+ event_detail: "table",
+ target_id: ORDERS_DASHBOARD_ID,
});
- H.editingDashboardParametersContainer().within(() => {
- H.filterWidget({ isEditing: true }).contains("Category").click();
+ H.moveDashboardFilter("Heading Text");
+ H.expectUnstructuredSnowplowEvent({
+ event: "dashboard_filter_moved",
+ triggered_from: "table",
+ event_detail: "heading",
+ target_id: ORDERS_DASHBOARD_ID,
});
- cy.get("@dashboardId").then((dashboardId) => {
- H.moveDashboardFilter("test question");
- H.expectUnstructuredSnowplowEvent({
- event: "dashboard_filter_moved",
- triggered_from: null,
- event_detail: "bar",
- target_id: dashboardId,
- });
-
- H.moveDashboardFilter("heading card");
- H.expectUnstructuredSnowplowEvent({
- event: "dashboard_filter_moved",
- triggered_from: "bar",
- event_detail: "heading",
- target_id: dashboardId,
- });
-
- H.moveDashboardFilter("Top of page");
- H.expectUnstructuredSnowplowEvent({
- event: "dashboard_filter_moved",
- triggered_from: "heading",
- event_detail: null,
- target_id: dashboardId,
- });
+ H.moveDashboardFilter("Top of page");
+ H.expectUnstructuredSnowplowEvent({
+ event: "dashboard_filter_moved",
+ triggered_from: "heading",
+ event_detail: null,
+ target_id: ORDERS_DASHBOARD_ID,
});
});
});
diff --git a/e2e/test/scenarios/dashboard-filters/temporal-unit-parameters.cy.spec.js b/e2e/test/scenarios/dashboard-filters/temporal-unit-parameters.cy.spec.js
index 8c8679dbe64..7597fd28d83 100644
--- a/e2e/test/scenarios/dashboard-filters/temporal-unit-parameters.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/temporal-unit-parameters.cy.spec.js
@@ -114,12 +114,10 @@ const binningBreakoutQuestionDetails = {
},
};
-const nativeQuestionDetails = {
- name: "SQL query",
- display: "table",
- native: {
- query: "SELECT * FROM ORDERS",
- },
+const singleBreakoutModelDetails = {
+ ...singleBreakoutQuestionDetails,
+ name: "Single breakout model",
+ type: "model",
};
const nativeQuestionWithTextParameterDetails = {
@@ -175,6 +173,31 @@ const nativeTimeQuestionDetails = {
},
};
+const nativeTemporalUnitQuestionDetails = {
+ name: "Saved question with time grouping",
+ native: {
+ query: `
+ SELECT
+ count(*),
+ {{unit}} as unit
+ FROM
+ ORDERS
+ GROUP BY
+ unit
+ `,
+ "template-tags": {
+ unit: {
+ type: "temporal-unit",
+ name: "unit",
+ id: "eb345703-001c-4b2a-b7d5-71cb3efe4beb",
+ "display-name": "Unit",
+ dimension: ["field", ORDERS.CREATED_AT, null],
+ required: true,
+ },
+ },
+ },
+};
+
const getNativeTimeQuestionBasedQuestionDetails = (card) => ({
query: {
"source-table": `card__${card.id}`,
@@ -219,13 +242,14 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
});
describe("mapping targets", () => {
- it("should connect a parameter to a question and drill thru", () => {
+ it("should connect a parameter to a question or model and drill thru", () => {
H.createQuestion(noBreakoutQuestionDetails);
H.createQuestion(singleBreakoutQuestionDetails);
H.createQuestion(multiBreakoutQuestionDetails);
H.createQuestion(multiStageQuestionDetails);
H.createQuestion(expressionBreakoutQuestionDetails);
H.createQuestion(binningBreakoutQuestionDetails);
+ H.createQuestion(singleBreakoutModelDetails);
H.createNativeQuestion(nativeQuestionWithDateParameterDetails);
H.createDashboard(dashboardDetails).then(({ body: dashboard }) =>
H.visitDashboard(dashboard.id),
@@ -330,6 +354,13 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
H.dashboardParametersDoneButton().click();
removeQuestion();
+ cy.log("MBQL model");
+ addQuestion(singleBreakoutModelDetails.name);
+ editParameter(parameterDetails.name);
+ H.getDashboardCard().findByText("No valid fields").should("be.visible");
+ H.dashboardParametersDoneButton().click();
+ removeQuestion();
+
cy.log("native query");
addQuestion(nativeQuestionWithDateParameterDetails.name);
editParameter(parameterDetails.name);
@@ -338,23 +369,6 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
.should("be.visible");
});
- it("should connect a parameter to a model", () => {
- H.createQuestion({ ...singleBreakoutQuestionDetails, type: "model" });
- H.createNativeQuestion({ ...nativeQuestionDetails, type: "model" });
- H.createDashboard(dashboardDetails).then(({ body: dashboard }) =>
- H.visitDashboard(dashboard.id),
- );
- H.editDashboard();
- addTemporalUnitParameter();
-
- cy.log("MBQL model");
- addQuestion(singleBreakoutQuestionDetails.name);
- editParameter(parameterDetails.name);
- H.getDashboardCard().findByText("No valid fields").should("be.visible");
- H.dashboardParametersDoneButton().click();
- removeQuestion();
- });
-
it("should connect a parameter to a metric", () => {
H.createQuestion({
...singleBreakoutQuestionDetails,
@@ -426,7 +440,7 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
});
});
- it("should connect multiple parameters to the same column in a card and drill thru, with the last parameter taking priority", () => {
+ it("should connect multiple parameters to the same column in a card and drill thru", () => {
H.createQuestion(singleBreakoutQuestionDetails);
H.createDashboard(dashboardDetails).then(({ body: dashboard }) =>
H.visitDashboard(dashboard.id),
@@ -445,8 +459,7 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
H.filterWidget().eq(1).click();
H.popover().findByText("Year").click();
H.getDashboardCard().within(() => {
- // metabase#44684
- // should be "Created At: Year" and "2025" because the last parameter is "Year"
+ // the card applies the first parameter, the drill applies the last one
cy.findByText("Created At: Quarter").should("be.visible");
cy.findByText("Q2 2025").should("be.visible");
cy.findByText(singleBreakoutQuestionDetails.name).click();
@@ -714,23 +727,6 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
});
describe("auto-wiring", () => {
- it("should not auto-wire to cards without breakout columns", () => {
- H.createDashboardWithQuestions({
- dashboardDetails,
- questions: [noBreakoutQuestionDetails, singleBreakoutQuestionDetails],
- }).then(({ dashboard }) => H.visitDashboard(dashboard.id));
- H.editDashboard();
- addTemporalUnitParameter();
-
- cy.log("new mapping");
- H.selectDashboardFilter(H.getDashboardCard(1), "Created At");
- H.undoToast().should("not.exist");
-
- cy.log("new card");
- addQuestion(noBreakoutQuestionDetails.name);
- H.undoToast().should("not.exist");
- });
-
it("should auto-wire to cards with breakouts on column selection", () => {
H.createDashboardWithQuestions({
dashboardDetails,
@@ -753,7 +749,7 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
H.getDashboardCard(2).findByText("Created At: Year").should("exist");
});
- it("should auto-wire to cards with breakouts after a new card is added", () => {
+ it("should auto-wire only to new cards with breakouts", () => {
H.createQuestion(multiBreakoutQuestionDetails);
H.createDashboardWithQuestions({
dashboardDetails,
@@ -762,16 +758,35 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
H.editDashboard();
addTemporalUnitParameter();
+ cy.log("new mapping does not suggest cards without breakouts");
H.selectDashboardFilter(H.getDashboardCard(1), "Created At");
H.undoToast().should("not.exist");
- addQuestion(multiBreakoutQuestionDetails.name);
+
+ cy.log("only the new card with breakouts gets a suggestion");
+ addQuestion(noBreakoutQuestionDetails.name);
+ // the add-card sidebar stays open, so pick the next card from it
+ cy.findByTestId("add-card-sidebar")
+ .findByText(multiBreakoutQuestionDetails.name)
+ .click();
+ H.undoToastList()
+ .should("have.length", 1)
+ .and("contain.text", multiBreakoutQuestionDetails.name);
H.undoToast().button("Auto-connect").click();
H.saveDashboard();
H.filterWidget().click();
H.popover().findByText("Year").click();
- H.getDashboardCard(1).findByText("Created At: Year").should("exist");
- H.getDashboardCard(2).findByText("Created At: Year").should("exist");
+ // after save, dashcards are ordered by layout position, not by when they were added
+ [
+ singleBreakoutQuestionDetails.name,
+ multiBreakoutQuestionDetails.name,
+ ].forEach((name) =>
+ cy
+ .findAllByTestId("dashcard")
+ .filter(`:contains("${name}")`)
+ .findByText("Created At: Year")
+ .should("exist"),
+ );
});
it("should not overwrite parameter mappings for a card when doing auto-wiring", () => {
@@ -783,9 +798,6 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
multiBreakoutQuestionDetails,
],
}).then(({ dashboard }) => H.visitDashboard(dashboard.id));
- H.getDashboardCard(1).within(() => {
- cy.findByText("199").should("not.exist");
- });
H.editDashboard();
cy.log("add a regular parameter");
@@ -812,6 +824,10 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
cy.findByText("199").should("exist"); // sample filtered data
cy.findByText("Created At: Year").should("be.visible");
});
+ H.getDashboardCard(2).within(() => {
+ cy.findByText("118").should("exist"); // sample filtered data
+ cy.findByText("Created At: Year").should("exist");
+ });
cy.log("verify data without the first parameter");
H.filterWidget().eq(0).icon("close").click();
@@ -819,19 +835,44 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
cy.findByText("199").should("not.exist"); // sample filtered data
cy.findByText("Created At: Year").should("be.visible");
});
+ H.getDashboardCard(2).within(() => {
+ cy.findByText("458").should("exist"); // sample unfiltered data
+ cy.findByText("118").should("not.exist");
+ });
});
});
describe("parameter settings", () => {
- it("should be able to set available temporal units", () => {
+ it("should set available temporal units and clear a default value outside of them", () => {
createDashboardWithMappedQuestion().then((dashboard) =>
H.visitDashboard(dashboard.id),
);
H.editDashboard();
editParameter(parameterDetails.name);
+
+ cy.log("set the default value");
+ H.dashboardParameterSidebar().findByText("No default").click();
+ H.popover().findByText("Year").click();
+
+ cy.log("exclude an unrelated temporal unit");
H.dashboardParameterSidebar().findByText("All").click();
+ H.popover().findByLabelText("Month").click();
+ H.popover().findByLabelText("Month").should("not.be.checked");
+ H.dashboardParameterSidebar()
+ .findByLabelText("Default value")
+ .should("contain.text", "Year");
+
+ cy.log("exclude the temporal unit used for the default value");
+ H.popover().findByLabelText("Year").click();
+ H.dashboardParameterSidebar()
+ .findByText("No default")
+ .should("be.visible");
+
+ cy.log("allow only months and years");
H.popover().within(() => {
+ // the first click selects all units, the second one clears them
+ cy.findByLabelText("Select all").click();
cy.findByLabelText("Select all").click();
cy.findByLabelText("Month").click();
cy.findByLabelText("Year").click();
@@ -848,31 +889,6 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
H.getDashboardCard().findByText("Created At: Year").should("be.visible");
});
- it("should clear the default value if it is no longer within the allowed unit list", () => {
- createDashboardWithMappedQuestion().then((dashboard) =>
- H.visitDashboard(dashboard.id),
- );
-
- cy.log("set the default value");
- H.editDashboard();
- editParameter(parameterDetails.name);
- H.dashboardParameterSidebar().findByText("No default").click();
- H.popover().findByText("Year").click();
-
- cy.log("exclude an unrelated temporal unit");
- H.dashboardParameterSidebar().findByText("All").click();
- H.popover().findByLabelText("Month").click();
- H.dashboardParameterSidebar()
- .findByText("No default")
- .should("not.exist");
-
- cy.log("exclude the temporal unit used for the default value");
- H.popover().findByLabelText("Year").click();
- H.dashboardParameterSidebar()
- .findByText("No default")
- .should("be.visible");
- });
-
it("should be able to set the default value and make it required", () => {
createDashboardWithMappedQuestion().then((dashboard) =>
cy.wrap(dashboard.id).as("dashboardId"),
@@ -947,15 +963,9 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
});
describe("query string parameters", () => {
- it("should be able to parse the parameter value from the url", () => {
- createDashboardWithMappedQuestion().then((dashboard) => {
- H.visitDashboard(dashboard.id, { params: { unit_of_time: "year" } });
- });
- H.getDashboardCard().findByText("Created At: Year").should("be.visible");
- });
-
- it("should ignore invalid temporal unit values from the url", () => {
+ it("should parse valid and ignore invalid temporal unit values from the url", () => {
createDashboardWithMappedQuestion().then((dashboard) => {
+ cy.wrap(dashboard.id).as("dashboardId");
H.visitDashboard(dashboard.id, { params: { unit_of_time: "invalid" } });
});
H.filterWidget().within(() => {
@@ -963,6 +973,12 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
cy.findByText(/invalid/i).should("not.exist");
});
H.getDashboardCard().findByText("Created At: Month").should("be.visible");
+
+ // a valid url value is saved as the last used value, so it goes last
+ cy.get("@dashboardId").then((dashboardId) =>
+ H.visitDashboard(dashboardId, { params: { unit_of_time: "year" } }),
+ );
+ H.getDashboardCard().findByText("Created At: Year").should("be.visible");
});
it("should accept temporal units outside of the allowlist if they are otherwise valid values from the url", () => {
@@ -984,7 +1000,7 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
});
describe("permissions", () => {
- it("should add a temporal unit parameter and connect it to a card and drill thru", () => {
+ it("should let a user without data access use a temporal unit parameter and drill thru", () => {
createDashboardWithMappedQuestion().then((dashboard) => {
cy.signIn("nodata");
H.visitDashboard(dashboard.id);
@@ -999,125 +1015,11 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
});
});
- describe("embedding", () => {
- beforeEach(() => {
- cy.signInAsAdmin();
- H.updateSetting("enable-public-sharing", true);
- });
-
- it("should be able to use temporal unit parameters in a public dashboard", () => {
- createDashboardWithMappedQuestion().then((dashboard) => {
- cy.request("POST", `/api/dashboard/${dashboard.id}/public_link`).then(
- ({ body: { uuid } }) => {
- cy.signOut();
- cy.visit(`/public/dashboard/${uuid}`);
- },
- );
- });
-
- H.filterWidget().click();
- H.popover().findByText("Year").click();
- H.getDashboardCard().findByText("Created At: Year").should("be.visible");
- });
-
- it("should be able to use temporal unit parameters in a embedded dashboard", () => {
- createDashboardWithMappedQuestion({
- dashboardDetails: {
- enable_embedding: true,
- embedding_params: {
- [parameterDetails.slug]: "enabled",
- },
- },
- }).then((dashboard) => {
- H.visitEmbeddedPage({
- resource: { dashboard: dashboard.id },
- params: {},
- });
- });
-
- H.filterWidget().click();
- H.popover().findByText("Year").click();
- H.getDashboardCard().findByText("Created At: Year").should("be.visible");
- });
- });
-
describe("native queries", () => {
- it("should be able to use temporal unit parameters in a native query", () => {
- const questionWithoutDefaultValue = {
- name: "Saved question with time grouping",
- native: {
- query: `
- SELECT
- count(*),
- {{unit}} as unit
- FROM
- ORDERS
- GROUP BY
- unit
- `,
- "template-tags": {
- unit: {
- type: "temporal-unit",
- name: "unit",
- id: "eb345703-001c-4b2a-b7d5-71cb3efe4beb",
- "display-name": "Unit",
- dimension: ["field", ORDERS.CREATED_AT, null],
- required: true,
- },
- },
- },
- };
-
- H.createDashboardWithQuestions({
- dashboardDetails,
- questions: [questionWithoutDefaultValue],
- }).then(({ dashboard }) => H.visitDashboard(dashboard.id));
-
- H.getDashboardCard().should(
- "contain",
- "There was a problem displaying this chart.",
- );
-
- H.editDashboard();
- addTemporalUnitParameter();
- H.selectDashboardFilter(H.getDashboardCard(), "Unit");
-
- H.dashboardParameterSidebar().findByLabelText("Default value").click();
-
- H.popover().findByText("Year").click();
- H.saveDashboard();
- H.getDashboardCard().should("contain", "January 1, 2025");
- });
-
- it("should not be able to use temporal unit parameter with a filter of a different type", () => {
- const questionWithoutDefaultValue = {
- name: "Saved question with time grouping",
- native: {
- query: `
- SELECT
- count(*),
- {{unit}} as unit
- FROM
- ORDERS
- GROUP BY
- unit
- `,
- "template-tags": {
- unit: {
- type: "temporal-unit",
- name: "unit",
- id: "eb345703-001c-4b2a-b7d5-71cb3efe4beb",
- "display-name": "Unit",
- dimension: ["field", ORDERS.CREATED_AT, null],
- required: true,
- },
- },
- },
- };
-
+ it("should use temporal unit parameters only with matching variables in a native query", () => {
H.createDashboardWithQuestions({
dashboardDetails,
- questions: [questionWithoutDefaultValue],
+ questions: [nativeTemporalUnitQuestionDetails],
}).then(({ dashboard }) => H.visitDashboard(dashboard.id));
H.getDashboardCard().should(
@@ -1155,6 +1057,15 @@ describe("scenarios > dashboard > temporal unit parameters", () => {
"Add a variable to this question to connect it to a dashboard filter.",
)
.should("not.contain", "Select…");
+
+ addTemporalUnitParameter();
+ H.selectDashboardFilter(H.getDashboardCard(), "Unit");
+
+ H.dashboardParameterSidebar().findByLabelText("Default value").click();
+
+ H.popover().findByText("Year").click();
+ H.saveDashboard();
+ H.getDashboardCard().should("contain", "January 1, 2025");
});
});
});