The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
e2e2unit: Filter types (#85720)
Nemanja Glumac47835b6c27a3
diff --git a/e2e/test/scenarios/filters/filter-types.cy.spec.js b/e2e/test/scenarios/filters/filter-types.cy.spec.jsdeleted file mode 100644index cd0b3175293..00000000000--- a/e2e/test/scenarios/filters/filter-types.cy.spec.js+++ /dev/null@@ -1,83 +0,0 @@-const { H } = cy;--const DATE_SHORTCUT_CASES = [- {- title: "today",- shortcut: "Today",- expectedDisplayName: "Created At is today",- },- {- title: "yesterday",- shortcut: "Yesterday",- expectedDisplayName: "Created At is yesterday",- },- {- title: "previous week",- shortcut: "Previous week",- expectedDisplayName: "Created At is in the previous week",- },- {- title: "previous 7 days",- shortcut: "Previous 7 days",- expectedDisplayName: "Created At is in the previous 7 days",- },- {- title: "previous 30 days",- shortcut: "Previous 30 days",- expectedDisplayName: "Created At is in the previous 30 days",- },- {- title: "previous month",- shortcut: "Previous month",- expectedDisplayName: "Created At is in the previous month",- },- {- title: "previous 3 months",- shortcut: "Previous 3 months",- expectedDisplayName: "Created At is in the previous 3 months",- },- {- title: "previous 12 months",- shortcut: "Previous 12 months",- expectedDisplayName: "Created At is in the previous 12 months",- },-];--describe("scenarios > filters > filter types", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("date filter shortcuts", () => {- H.openProductsTable({ mode: "notebook" });-- DATE_SHORTCUT_CASES.forEach(({ title, shortcut, expectedDisplayName }) => {- cy.log(title);- H.filter({ mode: "notebook" });-- H.clauseStepPopover().within(() => {- cy.findByText("Created At").click();- cy.findByText(shortcut).click();- });- assertFilterName(expectedDisplayName);- H.visualize();- H.queryBuilderFiltersPanel()- .findByText(expectedDisplayName)- .should("be.visible");-- H.openNotebook();- H.getNotebookStep("filter")- .findByText(expectedDisplayName)- .icon("close")- .click();- H.getNotebookStep("filter").should("not.exist");- });- });-});--function assertFilterName(filterName, options) {- H.getNotebookStep("filter", options)- .findByText(filterName)- .should("be.visible");-}diff --git a/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.unit.spec.tsx b/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.unit.spec.tsxindex 4636459e469..6b64cc48b67 100644--- a/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.unit.spec.tsx@@ -7,6 +7,7 @@ import {DATE_PICKER_SHORTCUTS,} from "metabase/querying/common/constants";import type {+ DateFilterValue,DatePickerOperator,DatePickerShortcut,RelativeIntervalDirection,@@ -41,16 +42,48 @@ function setup({return { onChange, onSelectType };}+type ShortcutCase = {+ label: string;+ value: DateFilterValue;+};+describe("DateShortcutPicker", () => {- it("should be able to create a filter via shortcuts", async () => {- const { onChange } = setup();- await userEvent.click(screen.getByText("Today"));- expect(onChange).toHaveBeenCalledWith({- type: "relative",- value: 0,- unit: "day",- });- });+ it.each<ShortcutCase>([+ { label: "Today", value: { type: "relative", value: 0, unit: "day" } },+ { label: "Yesterday", value: { type: "relative", value: -1, unit: "day" } },+ {+ label: "Previous week",+ value: { type: "relative", value: -1, unit: "week" },+ },+ {+ label: "Previous 7 days",+ value: { type: "relative", value: -7, unit: "day" },+ },+ {+ label: "Previous 30 days",+ value: { type: "relative", value: -30, unit: "day" },+ },+ {+ label: "Previous month",+ value: { type: "relative", value: -1, unit: "month" },+ },+ {+ label: "Previous 3 months",+ value: { type: "relative", value: -3, unit: "month" },+ },+ {+ label: "Previous 12 months",+ value: { type: "relative", value: -12, unit: "month" },+ },+ ])(+ "should be able to create a filter via the $label shortcut",+ async ({ label, value }) => {+ const { onChange } = setup();+ await userEvent.click(screen.getByText(label));+ expect(onChange).toHaveBeenCalledTimes(1);+ expect(onChange).toHaveBeenCalledWith(value);+ },+ );it("should be able to navigate to a more specific filter type", async () => {const { onSelectType } = setup();diff --git a/frontend/src/metabase/querying/filters/utils/dates.unit.spec.ts b/frontend/src/metabase/querying/filters/utils/dates.unit.spec.tsindex cc05ac2d7ff..b0d4cc112f9 100644--- a/frontend/src/metabase/querying/filters/utils/dates.unit.spec.ts+++ b/frontend/src/metabase/querying/filters/utils/dates.unit.spec.ts@@ -76,6 +76,34 @@ describe("getDateFilterClause", () => {value: { type: "relative", value: 0, unit: "day" },displayName: "Created At is today",},+ {+ value: { type: "relative", value: -1, unit: "day" },+ displayName: "Created At is yesterday",+ },+ {+ value: { type: "relative", value: -1, unit: "week" },+ displayName: "Created At is in the previous week",+ },+ {+ value: { type: "relative", value: -7, unit: "day" },+ displayName: "Created At is in the previous 7 days",+ },+ {+ value: { type: "relative", value: -30, unit: "day" },+ displayName: "Created At is in the previous 30 days",+ },+ {+ value: { type: "relative", value: -1, unit: "month" },+ displayName: "Created At is in the previous month",+ },+ {+ value: { type: "relative", value: -3, unit: "month" },+ displayName: "Created At is in the previous 3 months",+ },+ {+ value: { type: "relative", value: -12, unit: "month" },+ displayName: "Created At is in the previous 12 months",+ },{value: { type: "relative", value: -2, unit: "year" },displayName: "Created At is in the previous 2 years",