Skip to content

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

Test coercion strategy (#67496)

Romeo Van Snick6f637ee0505f
diff --git a/e2e/test/scenarios/filters-reproductions/filters-reproductions.cy.spec.js b/e2e/test/scenarios/filters-reproductions/filters-reproductions.cy.spec.js
index b70be68d4b1..439ba07cb5b 100644
--- a/e2e/test/scenarios/filters-reproductions/filters-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/filters-reproductions/filters-reproductions.cy.spec.js
@@ -1498,6 +1498,7 @@ describe("issue QUE-2567", () => {
5,
"day",
],
+ Bar: ["datetime", "2025-12-24"],
},
},
},
@@ -1509,9 +1510,53 @@ describe("issue QUE-2567", () => {
cy.findByText("Foo").click();
cy.findByText("Previous 12 months").click();
});
+
+ H.filter();
+ H.popover().within(() => {
+ cy.findByText("Bar").click();
+ cy.findByText("Previous 12 months").click();
+ });
});
it("should be possible to edit a datetime filter that is based on a custom expression (QUE-2567)", () => {
+ cy.log("Editing the filter should show the date picker");
+ cy.findAllByTestId("filter-pill").should("have.length", 2).eq(0).click();
+ H.popover().within(() => {
+ cy.findByText("Previous").should("be.visible");
+ cy.findByText("Current").should("be.visible");
+ cy.findByText("Next").should("be.visible");
+ });
+
+ cy.log(
+ "Editing the filter should show the date picker for coerced datetime",
+ );
+ cy.findAllByTestId("filter-pill").should("have.length", 2).eq(1).click();
+ H.popover().within(() => {
+ cy.findByText("Previous").should("be.visible");
+ cy.findByText("Current").should("be.visible");
+ cy.findByText("Next").should("be.visible");
+ });
+ });
+});
+
+describe("issue QUE-2567 (bis)", () => {
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsAdmin();
+ cy.request("PUT", `/api/field/${ORDERS.QUANTITY}`, {
+ coercion_strategy: "Coercion/UNIXSeconds->DateTime",
+ semantic_type: null,
+ });
+ H.openOrdersTable();
+
+ H.filter();
+ H.popover().within(() => {
+ cy.findByText("Quantity").click();
+ cy.findByText("Previous 12 months").click();
+ });
+ });
+
+ it("should open the datetime filter for coerced columns", () => {
cy.log("Editing the filter should show the date picker");
cy.findByTestId("filter-pill").click();
H.popover().within(() => {
diff --git a/src/metabase/lib/util.cljc b/src/metabase/lib/util.cljc
index 4b383222a45..d32da633404 100644
--- a/src/metabase/lib/util.cljc
+++ b/src/metabase/lib/util.cljc
@@ -86,7 +86,7 @@
[expression typ]
(isa?
(or (and (clause? expression)
- ((some-fn :metabase.lib.field/original-effective-type :base-type) (lib.options/options expression)))
+ ((some-fn :metabase.lib.field/original-effective-type :effective-type :base-type) (lib.options/options expression)))
(lib.schema.expression/type-of expression))
typ))
diff --git a/test/metabase/lib/filter_test.cljc b/test/metabase/lib/filter_test.cljc
index 7b348a9b9cf..b6e730dd87e 100644
--- a/test/metabase/lib/filter_test.cljc
+++ b/test/metabase/lib/filter_test.cljc
@@ -926,7 +926,7 @@
(let [query (lib/native-query meta/metadata-provider "SELECT * FROM ORDERS;")]
(is (= "Created At is Jan 1 – Dec 31, 2023"
(lib/display-name query [:= {:lib/uuid "79e513f8-af80-4c15-96b6-e72eff7f37cc"}
- [:field {:effective-type :type/Integer
+ [:field {:effective-type :type/DateTime
:base-type :type/DateTime
:temporal-unit :year
:lib/uuid "1fe5dc66-54af-4368-9e4a-1e64a1fbe484"}