Skip to content

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

e2e2unit: Filter operators (#85719)

Nemanja Glumac04f3fd4526a4
diff --git a/e2e/test/scenarios/filters/operators.cy.spec.js b/e2e/test/scenarios/filters/operators.cy.spec.js
deleted file mode 100644
index d2320be8f5e..00000000000
--- a/e2e/test/scenarios/filters/operators.cy.spec.js
+++ /dev/null
@@ -1,203 +0,0 @@
-const { H } = cy;
-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
-
-const { PRODUCTS_ID, PEOPLE_ID } = SAMPLE_DATABASE;
-
-describe("operators in questions", () => {
- beforeEach(() => {
- H.restore();
- cy.signInAsNormalUser();
- });
-
- const expected = {
- text: {
- expected: [
- "Is",
- "Is not",
- "Contains",
- "Does not contain",
- "Is empty",
- "Not empty",
- "Starts with",
- "Ends with",
- ],
- unexpected: ["Is null", "Not null"],
- },
- number: {
- expected: [
- "Equal to",
- "Not equal to",
- "Greater than",
- "Less than",
- "Between",
- "Greater than or equal to",
- "Less than or equal to",
- "Is empty",
- "Not empty",
- ],
- unexpected: ["Is null", "Not null"],
- },
- relativeDates: {
- expected: ["Previous", "Next", "Current"],
- unexpected: ["Is null", "Not null"],
- },
- specificDates: {
- expected: ["Before", "After", "On", "Between"],
- unexpected: ["Is null", "Not null"],
- },
- excludeDates: {
- expected: [
- "Days of the week…",
- "Months of the year…",
- "Quarters of the year…",
- "Hours of the day…",
- "Empty values",
- "Not empty values",
- ],
- unexpected: ["Is null", "Not null"],
- },
- id: {
- expected: ["Is", "Is not", "Is empty", "Not empty"],
- unexpected: ["Is null", "Not null"],
- },
- geo: {
- expected: ["Is", "Is not"],
- unexpected: ["Is null", "Not null"],
- },
- };
-
- describe("fields have proper operators", () => {
- it("text, number and id operators", () => {
- setup(PRODUCTS_ID);
-
- cy.log("text");
- H.popover().within(() => {
- cy.findByText("Title").click();
- cy.findByText("Is").click();
- });
-
- cy.findByRole("menu").within(() => {
- expected.text.expected.map((e) => cy.findByText(e).should("exist"));
- expected.text.unexpected.map((e) => cy.contains(e).should("not.exist"));
- });
- reselectOperatorAndGoBack("Is");
-
- cy.log("number");
- H.popover().within(() => {
- cy.findByText("Price").click();
- cy.findByText("Between").click();
- });
-
- cy.findByRole("menu").within(() => {
- expected.number.expected.map((e) => cy.findByText(e).should("exist"));
- expected.number.unexpected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- });
- reselectOperatorAndGoBack("Between");
-
- cy.log("id");
- H.popover().within(() => {
- cy.findByText("ID").click();
- cy.findByText("Is").click();
- });
-
- cy.findByRole("menu").within(() => {
- expected.id.expected.map((e) => cy.findByText(e).should("exist"));
- expected.id.unexpected.map((e) => cy.contains(e).should("not.exist"));
- });
- });
-
- it("relative, specific and exclude date operators", () => {
- setup(PRODUCTS_ID);
-
- cy.log("relative dates");
- H.popover().within(() => {
- cy.findByText("Created At").click();
- cy.findByText("Relative date range…").click();
- cy.findByText("Previous").click();
- });
-
- H.clauseStepPopover().within(() => {
- expected.relativeDates.expected.map((e) =>
- cy.findByText(e).should("exist"),
- );
- expected.specificDates.expected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- expected.excludeDates.expected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- expected.relativeDates.unexpected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- cy.findByLabelText("Back").click();
- });
-
- cy.log("specific dates");
- H.popover().within(() => {
- cy.findByText("Fixed date range…").click();
- cy.findByText("Between").click();
- });
-
- H.popover().within(() => {
- expected.specificDates.expected.map((e) =>
- cy.findByText(e).should("exist"),
- );
- expected.relativeDates.expected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- expected.excludeDates.expected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- expected.specificDates.unexpected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- cy.findByLabelText("Back").click();
- });
-
- cy.log("exclude dates");
- H.popover().findByText("Exclude…").click();
-
- H.popover().within(() => {
- expected.excludeDates.expected.map((e) =>
- cy.findByText(e).should("exist"),
- );
- expected.relativeDates.expected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- expected.specificDates.expected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- expected.excludeDates.unexpected.map((e) =>
- cy.contains(e).should("not.exist"),
- );
- });
- });
-
- it("geo operators", () => {
- setup(PEOPLE_ID);
-
- H.popover().within(() => {
- cy.findByText("State").click({ force: true });
- cy.findByText("Is").click();
- });
-
- cy.findByRole("menu").within(() => {
- expected.geo.expected.map((e) => cy.findByText(e).should("exist"));
- expected.geo.unexpected.map((e) => cy.contains(e).should("not.exist"));
- });
- });
- });
-});
-
-function setup(tableId) {
- H.openTable({ table: tableId, mode: "notebook" });
- cy.findByRole("button", { name: "Filter" }).click();
-}
-
-function reselectOperatorAndGoBack(operator) {
- cy.findByRole("menu").findByText(operator).click();
- cy.findByRole("menu").should("not.exist");
- H.popover().findByLabelText("Back").click();
-}
diff --git a/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.unit.spec.tsx b/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.unit.spec.tsx
index 3d75e3d2141..7c2bdc97d12 100644
--- a/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.unit.spec.tsx
+++ b/frontend/src/metabase/querying/common/components/DatePicker/SpecificDatePicker/SpecificDatePicker.unit.spec.tsx
@@ -56,6 +56,18 @@ describe("SpecificDatePicker", () => {
jest.setSystemTime(new Date(2020, 0, 1));
});
+ it("should list operators", () => {
+ setup();
+
+ const tabs = screen.getAllByRole("tab");
+ expect(tabs.map((tab) => tab.textContent)).toEqual([
+ "Between",
+ "Before",
+ "On",
+ "After",
+ ]);
+ });
+
it('should be able to set "on" filter', async () => {
const { onChange } = setup();
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.unit.spec.tsx
index bd675411628..55b9dac1fa4 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.unit.spec.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.unit.spec.tsx
@@ -42,6 +42,18 @@ const EXPECTED_OPERATORS = [
"Not empty",
];
+const EXPECTED_KEY_OPERATORS = [
+ "Is",
+ "Is not",
+ "Between",
+ "Greater than",
+ "Greater than or equal to",
+ "Less than",
+ "Less than or equal to",
+ "Is empty",
+ "Not empty",
+];
+
type SetupOpts = {
query?: Lib.Query;
column?: Lib.ColumnMetadata;
@@ -133,6 +145,25 @@ describe("NumberFilterPicker", () => {
);
});
+ it.each([
+ ["primary", "ID"],
+ ["foreign", "PRODUCT_ID"],
+ ])("should list operators for a %s key column", async (_, columnName) => {
+ const query = createQuery();
+ const columns = Lib.filterableColumns(query, 0);
+ const column = columnFinder(query, columns)("ORDERS", columnName);
+ setup({ query, column });
+
+ await userEvent.click(screen.getByLabelText("Filter operator"));
+ const menu = await screen.findByRole("menu");
+ const menuItems = within(menu).getAllByRole("menuitem");
+
+ expect(menuItems).toHaveLength(EXPECTED_KEY_OPERATORS.length);
+ EXPECTED_KEY_OPERATORS.forEach((operatorName) =>
+ expect(within(menu).getByText(operatorName)).toBeInTheDocument(),
+ );
+ });
+
describe("with one value", () => {
it.each(NUMERIC_TEST_CASES)(
"should add a filter with a %s value",
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsx
index 08b6d96bd4d..e53de9a6275 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsx
@@ -20,6 +20,7 @@ import type { Database } from "metabase-types/api";
import { COMMON_DATABASE_FEATURES } from "metabase-types/api/mocks";
import {
PEOPLE,
+ PEOPLE_STATE_VALUES,
PRODUCT_CATEGORY_VALUES,
PRODUCT_VENDOR_VALUES,
createSampleDatabase,
@@ -74,7 +75,11 @@ function setup({
const onChange = jest.fn();
const onBack = jest.fn();
- setupFieldsValuesEndpoints([PRODUCT_CATEGORY_VALUES, PRODUCT_VENDOR_VALUES]);
+ setupFieldsValuesEndpoints([
+ PRODUCT_CATEGORY_VALUES,
+ PRODUCT_VENDOR_VALUES,
+ PEOPLE_STATE_VALUES,
+ ]);
setupDatabaseEndpoints(database);
const state = createMockState({
@@ -142,18 +147,28 @@ describe("StringFilterPicker", () => {
expect(screen.getByRole("button", { name: "Add filter" })).toBeDisabled();
});
- it("should list operators", async () => {
- setup();
+ it.each([
+ ["a text", "PRODUCTS", "DESCRIPTION"],
+ ["a location", "PEOPLE", "STATE"],
+ ])(
+ "should list operators for %s column",
+ async (_, tableName, columnName) => {
+ const query = createQuery();
+ setup({
+ query,
+ column: findStringColumn(query, tableName, columnName),
+ });
- await userEvent.click(screen.getByLabelText("Filter operator"));
- const menu = await screen.findByRole("menu");
- const menuItems = within(menu).getAllByRole("menuitem");
+ await userEvent.click(screen.getByLabelText("Filter operator"));
+ const menu = await screen.findByRole("menu");
+ const menuItems = within(menu).getAllByRole("menuitem");
- expect(menuItems).toHaveLength(EXPECTED_OPERATORS.length);
- EXPECTED_OPERATORS.forEach((operatorName) =>
- expect(within(menu).getByText(operatorName)).toBeInTheDocument(),
- );
- });
+ expect(menuItems).toHaveLength(EXPECTED_OPERATORS.length);
+ EXPECTED_OPERATORS.forEach((operatorName) =>
+ expect(within(menu).getByText(operatorName)).toBeInTheDocument(),
+ );
+ },
+ );
it("should handle fields with listable values", async () => {
const query = createQuery();