Skip to content

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

Consolidate filters e2e tests (#83282)

Nemanja Glumac94243e021794
diff --git a/e2e/support/helpers/e2e-downloads-helpers.ts b/e2e/support/helpers/e2e-downloads-helpers.ts
index 856805dce97..dc4b14660de 100644
--- a/e2e/support/helpers/e2e-downloads-helpers.ts
+++ b/e2e/support/helpers/e2e-downloads-helpers.ts
@@ -25,6 +25,8 @@ interface DownloadAndAssertParams {
assertStatusCode?: number;
/** Assert that parameters in request body match expected values */
assertParameters?: any[];
+ /** Assert on the downloaded file content (POST downloads only) */
+ assertResponseBody?: (body: string) => void;
waitForDismiss?: boolean;
}
@@ -75,6 +77,7 @@ export function downloadAndAssert({
pivoting,
assertStatusCode,
assertParameters,
+ assertResponseBody,
waitForDismiss = true,
}: DownloadAndAssertParams) {
const { method, endpoint } = downloadUrl
@@ -123,6 +126,8 @@ export function downloadAndAssert({
});
}
+ assertResponseBody?.(res.body);
+
// After assertions pass, redirect to prevent navigation
res.send({ statusCode: 302, headers: { location: "/foo" } });
});
diff --git a/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts b/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts
index 77349d4fec9..5aa0c8b2926 100644
--- a/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts
+++ b/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts
@@ -228,7 +228,7 @@ SELECT CAST('${POSITIVE_DECIMAL_VALUE}' AS DECIMAL) AS NUMBER`,
});
});
- it("dashboards + mbql query + id parameters", { tags: "external" }, () => {
+ it("dashboards + mbql query + id parameters", { tags: "@external" }, () => {
function setupDashboard({
tableName,
baseType,
@@ -1031,99 +1031,81 @@ SELECT CAST('${POSITIVE_DECIMAL_VALUE}' AS DECIMAL) AS NUMBER`,
},
);
- it("query builder + expression editor", { tags: "@external" }, () => {
- function setupQuestion({ tableName }: { tableName: string }) {
- const getQuestionDetails = (tableId: TableId) => ({
- database: WRITABLE_DB_ID,
- query: {
- "source-table": tableId,
- },
- });
-
- H.getTableId({ name: tableName }).then((tableId) => {
- H.createQuestion(getQuestionDetails(tableId), { visitQuestion: true });
- });
- }
+ it(
+ "query builder + object detail + expression editor",
+ { tags: "@external" },
+ () => {
+ function setupQuestion({ tableName }: { tableName: string }) {
+ const getQuestionDetails = (tableId: TableId) => ({
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ },
+ });
- function testExpression({ value }: { value: string }) {
- H.assertQueryBuilderRowCount(3);
+ H.getTableId({ name: tableName }).then((tableId) => {
+ H.createQuestion(getQuestionDetails(tableId), {
+ visitQuestion: true,
+ });
+ });
+ }
- H.openNotebook();
- H.getNotebookStep("data").button("Filter").click();
- H.popover().findByText("Custom Expression").click();
- H.enterCustomColumnDetails({ formula: `[ID] = ${value}` });
- cy.button("Done").click();
- H.visualize();
- H.assertQueryBuilderRowCount(1);
+ function testObjectDetail({
+ value,
+ nameValue,
+ }: {
+ value: string;
+ nameValue: string;
+ }) {
+ H.tableInteractive().findByText(value).click();
+ H.modal().within(() => {
+ cy.findAllByText(value).should("have.length.gte", 1);
+ cy.findAllByText(nameValue).should("have.length.gte", 1);
+ cy.findByLabelText("Close").click();
+ });
+ H.modal().should("not.exist");
+ }
- H.openNotebook();
- H.getNotebookStep("filter").findByText(`ID is ${value}`).click();
- H.popover().within(() => {
- cy.findByLabelText("Back").click();
- cy.findByText("Custom Expression").click();
- });
- H.enterCustomColumnDetails({ formula: `[ID] != ${value}` });
- cy.button("Update").click();
- H.visualize();
- H.assertQueryBuilderRowCount(2);
- }
+ function testExpression({ value }: { value: string }) {
+ H.assertQueryBuilderRowCount(3);
- cy.log("setup");
- setupTables();
+ H.openNotebook();
+ H.getNotebookStep("data").button("Filter").click();
+ H.popover().findByText("Custom Expression").click();
+ H.enterCustomColumnDetails({ formula: `[ID] = ${value}` });
+ cy.button("Done").click();
+ H.visualize();
+ H.assertQueryBuilderRowCount(1);
- cy.log("BIGINT");
- setupQuestion({ tableName: BIGINT_PK_TABLE_NAME });
- testExpression({ value: MAX_BIGINT_VALUE });
+ H.openNotebook();
+ H.getNotebookStep("filter").findByText(`ID is ${value}`).click();
+ H.popover().within(() => {
+ cy.findByLabelText("Back").click();
+ cy.findByText("Custom Expression").click();
+ });
+ H.enterCustomColumnDetails({ formula: `[ID] != ${value}` });
+ cy.button("Update").click();
+ H.visualize();
+ H.assertQueryBuilderRowCount(2);
+ }
- cy.log("DECIMAL");
- setupQuestion({ tableName: DECIMAL_PK_TABLE_NAME });
- testExpression({ value: NEGATIVE_DECIMAL_VALUE });
- });
+ cy.log("setup");
+ setupTables();
- it("query builder + object detail", { tags: "@external" }, () => {
- function setupQuestion({ tableName }: { tableName: string }) {
- H.getTableId({ name: tableName }).then((tableId) =>
- H.createQuestion(
- {
- database: WRITABLE_DB_ID,
- query: { "source-table": tableId },
- },
- { visitQuestion: true },
- ),
- );
- }
+ cy.log("BIGINT");
+ setupQuestion({ tableName: BIGINT_PK_TABLE_NAME });
+ testObjectDetail({ value: MAX_BIGINT_VALUE, nameValue: "Positive" });
+ testExpression({ value: MAX_BIGINT_VALUE });
- function testObjectDetail({
- idValue,
- nameValue,
- }: {
- idValue: string;
- nameValue: string;
- }) {
- H.tableInteractive().findByText(idValue).click();
- H.modal().within(() => {
- cy.findAllByText(idValue).should("have.length.gte", 1);
- cy.findAllByText(nameValue).should("have.length.gte", 1);
+ cy.log("DECIMAL");
+ setupQuestion({ tableName: DECIMAL_PK_TABLE_NAME });
+ testObjectDetail({
+ value: NEGATIVE_DECIMAL_VALUE,
+ nameValue: "Negative",
});
- }
-
- cy.log("setup");
- setupTables();
-
- cy.log("BIGINT");
- setupQuestion({ tableName: BIGINT_PK_TABLE_NAME });
- testObjectDetail({
- idValue: MAX_BIGINT_VALUE,
- nameValue: "Positive",
- });
-
- cy.log("DECIMAL");
- setupQuestion({ tableName: DECIMAL_PK_TABLE_NAME });
- testObjectDetail({
- idValue: NEGATIVE_DECIMAL_VALUE,
- nameValue: "Negative",
- });
- });
+ testExpression({ value: NEGATIVE_DECIMAL_VALUE });
+ },
+ );
it("query builder + drills", () => {
function setupQuestion({
@@ -1223,13 +1205,18 @@ SELECT CAST('${POSITIVE_DECIMAL_VALUE}' AS DECIMAL) AS NUMBER`,
});
}
- function testExport() {
+ function testExport({ values }: { values: string[] }) {
cy.get("@questionId").then((questionId) => {
H.downloadAndAssert({
fileType: "csv",
questionId: Number(questionId),
isDashboard: false,
enableFormatting: true,
+ assertResponseBody: (body) => {
+ // formatted numbers carry thousands separators
+ const digits = body.replaceAll(",", "");
+ values.forEach((value) => expect(digits).to.include(value));
+ },
});
});
}
@@ -1238,16 +1225,18 @@ SELECT CAST('${POSITIVE_DECIMAL_VALUE}' AS DECIMAL) AS NUMBER`,
setupTables();
cy.log("BIGINT");
+ const bigIntValues = [MIN_BIGINT_VALUE, MAX_BIGINT_VALUE];
setupTableQuestion({ tableName: BIGINT_PK_TABLE_NAME });
- testExport();
+ testExport({ values: bigIntValues });
setupNestedQuestion({ sourceQuestionDetails: bigIntQuestionDetails });
- testExport();
+ testExport({ values: bigIntValues });
cy.log("DECIMAL");
+ const decimalValues = [NEGATIVE_DECIMAL_VALUE, POSITIVE_DECIMAL_VALUE];
setupTableQuestion({ tableName: DECIMAL_PK_TABLE_NAME });
- testExport();
+ testExport({ values: decimalValues });
setupNestedQuestion({ sourceQuestionDetails: decimalQuestionDetails });
- testExport();
+ testExport({ values: decimalValues });
});
it("dashboards + click behavior", () => {
diff --git a/e2e/test/scenarios/filters/filter-bulk.cy.spec.js b/e2e/test/scenarios/filters/filter-bulk.cy.spec.js
index 60f803a366f..fabb2455765 100644
--- a/e2e/test/scenarios/filters/filter-bulk.cy.spec.js
+++ b/e2e/test/scenarios/filters/filter-bulk.cy.spec.js
@@ -146,9 +146,13 @@ describe("scenarios > filters > bulk filtering", () => {
H.queryBuilderFiltersPanel()
.findByText("Product → Category is Gadget")
.should("be.visible");
- H.queryBuilderFooter()
- .findByText("Showing first 2,000 rows")
- .should("be.visible");
+
+ H.summarize();
+ H.rightSidebar().button("Done").click();
+ cy.wait("@dataset");
+ H.queryBuilderMain()
+ .findByTestId("scalar-value")
+ .should("have.text", "4,939");
});
it("should update an existing filter", () => {
@@ -169,7 +173,6 @@ describe("scenarios > filters > bulk filtering", () => {
it("should remove an existing filter", () => {
H.visitQuestionAdhoc(filteredQuestionDetails);
- H.filter();
H.queryBuilderFiltersPanel()
.findByText("Quantity is less than 30")
.icon("close")
@@ -348,16 +351,6 @@ describe("scenarios > filters > bulk filtering", () => {
H.filter();
});
- it("should apply a boolean filter", () => {
- H.popover().within(() => {
- cy.findByText("boolean").click();
- cy.findByText("True").click();
- cy.button("Apply filter").click();
- });
- cy.wait("@dataset");
- H.assertQueryBuilderRowCount(2);
- });
-
it("should change a boolean filter", () => {
H.popover().within(() => {
cy.findByText("boolean").click();
@@ -586,7 +579,7 @@ describe("scenarios > filters > bulk filtering", () => {
H.filter();
});
- it("can search for a column", () => {
+ it("can search for a column and apply a filter from it", () => {
H.popover().within(() => {
cy.findByText("Category").should("be.visible");
cy.findByText("Vendor").should("be.visible");
@@ -594,12 +587,8 @@ describe("scenarios > filters > bulk filtering", () => {
cy.findByPlaceholderText("Find...").type("vend");
cy.findByText("Category").should("not.exist");
cy.findByText("Vendor").should("be.visible");
- });
- });
- it("can apply a filter from a searched column", () => {
- H.popover().within(() => {
- cy.findByPlaceholderText("Find...").type("price");
+ cy.findByPlaceholderText("Find...").clear().type("price");
cy.findByText("Category").should("not.exist");
cy.findByText("Price").click();
});
diff --git a/e2e/test/scenarios/filters/filter-types.cy.spec.js b/e2e/test/scenarios/filters/filter-types.cy.spec.js
index ec1f84de572..cd0b3175293 100644
--- a/e2e/test/scenarios/filters/filter-types.cy.spec.js
+++ b/e2e/test/scenarios/filters/filter-types.cy.spec.js
@@ -49,24 +49,29 @@ describe("scenarios > filters > filter types", () => {
cy.signInAsNormalUser();
});
- describe("date filters", () => {
- describe("shortcuts", () => {
- DATE_SHORTCUT_CASES.forEach(
- ({ title, shortcut, expectedDisplayName }) => {
- it(title, () => {
- H.openProductsTable({ mode: "notebook" });
- H.filter({ mode: "notebook" });
+ it("date filter shortcuts", () => {
+ H.openProductsTable({ mode: "notebook" });
- H.clauseStepPopover().within(() => {
- cy.findByText("Created At").click();
- cy.findByText(shortcut).click();
- });
- assertFilterName(expectedDisplayName);
- H.visualize();
- assertFiltersExist();
- });
- },
- );
+ 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");
});
});
});
@@ -76,7 +81,3 @@ function assertFilterName(filterName, options) {
.findByText(filterName)
.should("be.visible");
}
-
-function assertFiltersExist() {
- cy.findByTestId("qb-filters-panel").should("be.visible");
-}
diff --git a/e2e/test/scenarios/filters/filter.cy.spec.js b/e2e/test/scenarios/filters/filter.cy.spec.js
index 08d11b671ab..a0373af8676 100644
--- a/e2e/test/scenarios/filters/filter.cy.spec.js
+++ b/e2e/test/scenarios/filters/filter.cy.spec.js
@@ -40,6 +40,13 @@ describe("scenarios > question > filter", () => {
cy.contains("37.65").should("exist");
cy.findByText("3621077291879").should("not.exist"); // one of the "Gizmo" EANs
});
+
+ H.summarize();
+ H.rightSidebar().button("Done").click();
+ cy.wait("@dataset");
+ H.queryBuilderMain()
+ .findByTestId("scalar-value")
+ .should("have.text", "13,976");
});
it("should filter based on remapped values (metabase#13235)", () => {
@@ -102,16 +109,20 @@ describe("scenarios > question > filter", () => {
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText(AGGREGATED_FILTER);
+ cy.intercept("POST", "/api/dataset").as("dataset");
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText(/^Created At is after/i)
.find(".Icon-close")
.click();
+ cy.wait("@dataset");
cy.log(
"**Removing or changing filters shouldn't remove aggregated filter**",
);
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText(AGGREGATED_FILTER);
+ cy.findByText(AGGREGATED_FILTER).should("exist");
+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
+ cy.findByText(/^Created At is after/i).should("not.exist");
});
it("should display original custom expression filter with dates on subsequent click (metabase#12492)", () => {
@@ -158,24 +169,12 @@ describe("scenarios > question > filter", () => {
cy.findByText("Rating is greater than 2").should("not.exist");
});
- it("should offer case expression in the auto-complete suggestions", () => {
+ it("should offer case in the suggestions and highlight them with keyboard up and down arrows (metabase#16210)", () => {
openExpressionEditorFromFreshlyLoadedPage();
H.enterCustomColumnDetails({ formula: "c", blur: false });
H.CustomExpressionEditor.completions().should("contain", "case");
-
- H.CustomExpressionEditor.type("a");
-
- // "case" is still there after typing a bit
- H.CustomExpressionEditor.completions().should("contain", "case");
- });
-
- it("should enable highlighting suggestions with keyboard up and down arrows (metabase#16210)", () => {
- openExpressionEditorFromFreshlyLoadedPage();
-
- H.enterCustomColumnDetails({ formula: "c", blur: false });
-
H.CustomExpressionEditor.completion("case")
.parent()
.should("have.attr", "aria-selected", "true");
@@ -192,6 +191,11 @@ describe("scenarios > question > filter", () => {
H.CustomExpressionEditor.completion("case")
.parent()
.should("have.attr", "aria-selected", "false");
+
+ H.CustomExpressionEditor.type("a");
+
+ // "case" is still there after typing a bit
+ H.CustomExpressionEditor.completions().should("contain", "case");
});
it("should highlight the correct matching for suggestions", () => {
@@ -258,11 +262,14 @@ describe("scenarios > question > filter", () => {
cy.button("Done").should("not.be.disabled").click();
+ H.getNotebookStep("filter").within(() => {
+ cy.findByText(/Rating/).should("be.visible");
+ cy.findByText(/Reviewer/).should("be.visible");
+ });
+
// check that filter is applied and rows displayed
H.visualize();
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.contains("Showing 1,112 rows");
+ H.assertQueryBuilderRowCount(1112);
});
it("should convert 'is empty' on a text column to a custom expression using IsEmpty()", () => {
@@ -349,33 +356,6 @@ describe("scenarios > question > filter", () => {
cy.contains('doesNotContain([Title], "Wallet", "case-insensitive")');
});
- it("should convert negative filter to custom expression (metabase#14880)", () => {
- H.visitQuestionAdhoc({
- dataset_query: {
- type: "query",
- query: {
- "source-table": PRODUCTS_ID,
- filter: [
- "does-not-contain",
- ["field", PRODUCTS.TITLE, null],
- "Wallet",
- { "case-sensitive": false },
- ],
- },
- database: SAMPLE_DB_ID,
- },
- display: "table",
- });
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Title does not contain Wallet").click();
- cy.get(".Icon-chevronleft").click();
- H.popover().findByText("Custom Expression").click();
-
- // Before we implement this feature, we can only assert that the input field for custom expression doesn't show at all
- H.CustomExpressionEditor.focus().get().should("be.visible");
- });
-
it("should be able to convert time interval filter to custom expression (metabase#12457)", () => {
H.openOrdersTable({ mode: "notebook" });
@@ -444,7 +424,7 @@ describe("scenarios > question > filter", () => {
cy.findByText("wilma-muller");
});
- it("should reject a number literal", () => {
+ it("should reject number and string literals", () => {
H.openProductsTable({ mode: "notebook" });
H.filter({ mode: "notebook" });
H.popover().findByText("Custom Expression").click();
@@ -453,12 +433,13 @@ describe("scenarios > question > filter", () => {
cy.button("Done").should("be.disabled");
cy.findByText("Types are incompatible.").should("be.visible");
});
- });
- it("should reject a string literal", () => {
- H.openProductsTable({ mode: "notebook" });
- H.filter({ mode: "notebook" });
- H.popover().findByText("Custom Expression").click();
+ H.enterCustomColumnDetails({ formula: "[Price] > 1" });
+ H.popover().within(() => {
+ cy.button("Done").should("be.enabled");
+ cy.findByText("Types are incompatible.").should("not.exist");
+ });
+
H.enterCustomColumnDetails({ formula: '"TheAnswer"' });
H.popover().within(() => {
cy.button("Done").should("be.disabled");
@@ -481,7 +462,7 @@ describe("scenarios > question > filter", () => {
.should("be.visible");
});
- it("custom expression filter should allow the use of parentheses in combination with logical operators (metabase#15754)", () => {
+ it("custom expression filter should allow parentheses with logical operators and refuse a numeric value before an operator (metabase#15754, metabase#15893)", () => {
H.openOrdersTable({ mode: "notebook" });
H.filter({ mode: "notebook" });
@@ -496,16 +477,9 @@ describe("scenarios > question > filter", () => {
.should("not.exist");
H.expressionEditorWidget().button("Done").should("not.be.disabled");
- });
-
- it("custom expression filter should refuse to work with numeric value before an operator (metabase#15893)", () => {
- cy.intercept("POST", "/api/dataset").as("dataset");
-
- H.openOrdersTable({ mode: "notebook" });
-
- H.filter({ mode: "notebook" });
- H.popover().findByText("Custom Expression").click();
+ cy.log("should refuse a numeric value before an operator (metabase#15893)");
+ H.CustomExpressionEditor.clear();
H.CustomExpressionEditor.focus().type("0 < [ID]").blur();
H.expressionEditorWidget()
@@ -515,21 +489,6 @@ describe("scenarios > question > filter", () => {
H.expressionEditorWidget().button("Done").should("be.disabled");
});
- it("should not allow switching focus with Tab", () => {
- H.openOrdersTable({ mode: "notebook" });
-
- H.filter({ mode: "notebook" });
- H.popover().findByText("Custom Expression").click();
-
- H.CustomExpressionEditor.focus().type("[Tax] > 0");
-
- // Tab switches the focus to the "Cancel" button
- cy.realPress("Tab");
- cy.focused().should("have.attr", "role", "textbox");
-
- H.CustomExpressionEditor.value().should("equal", "[Tax] > 0 ");
- });
-
it("should allow choosing a suggestion with Tab", () => {
H.openOrdersTable({ mode: "notebook" });
@@ -548,7 +507,7 @@ describe("scenarios > question > filter", () => {
// Finish to complete a valid expression, i.e. [Tax] > 42
H.CustomExpressionEditor.type("> 42");
- // Tab switches the focus to the "Cancel" button
+ // Tab indents instead of moving the focus
cy.realPress("Tab");
cy.focused().should("have.attr", "role", "textbox");
@@ -745,7 +704,6 @@ describe("scenarios > question > filter", () => {
cy.button("Done").click();
});
- // cy.findByText(/^Total/);
// eslint-disable-next-line metabase/no-unsafe-element-filtering
cy.icon("add").last().click();
H.clauseStepPopover().findByText(/^ID$/i).click();
@@ -757,7 +715,15 @@ describe("scenarios > question > filter", () => {
.find(".Icon-close")
.click();
- H.visualize();
+ H.getNotebookStep("filter").within(() => {
+ cy.findByText("Total is equal to 123").should("not.exist");
+ cy.findByText(/^Total is less than/).should("be.visible");
+ cy.findByText("ID is 1").should("be.visible");
+ });
+
+ H.visualize((response) => {
+ expect(response.body.error).to.not.exist;
+ });
});
});
diff --git a/e2e/test/scenarios/filters/operators.cy.spec.js b/e2e/test/scenarios/filters/operators.cy.spec.js
index fdfc521fb05..d2320be8f5e 100644
--- a/e2e/test/scenarios/filters/operators.cy.spec.js
+++ b/e2e/test/scenarios/filters/operators.cy.spec.js
@@ -67,39 +67,51 @@ describe("operators in questions", () => {
};
describe("fields have proper operators", () => {
- it("text 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.contains(e).should("exist"));
+ expected.text.expected.map((e) => cy.findByText(e).should("exist"));
expected.text.unexpected.map((e) => cy.contains(e).should("not.exist"));
});
- });
-
- it("number operators", () => {
- setup(PRODUCTS_ID);
+ 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.contains(e).should("exist"));
+ 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 date operators", () => {
+ 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();
@@ -108,7 +120,7 @@ describe("operators in questions", () => {
H.clauseStepPopover().within(() => {
expected.relativeDates.expected.map((e) =>
- cy.contains(e).should("exist"),
+ cy.findByText(e).should("exist"),
);
expected.specificDates.expected.map((e) =>
cy.contains(e).should("not.exist"),
@@ -119,21 +131,18 @@ describe("operators in questions", () => {
expected.relativeDates.unexpected.map((e) =>
cy.contains(e).should("not.exist"),
);
+ cy.findByLabelText("Back").click();
});
- });
-
- it("specific date operators", () => {
- setup(PRODUCTS_ID);
+ cy.log("specific dates");
H.popover().within(() => {
- cy.findByText("Created At").click();
cy.findByText("Fixed date range…").click();
cy.findByText("Between").click();
});
H.popover().within(() => {
expected.specificDates.expected.map((e) =>
- cy.contains(e).should("exist"),
+ cy.findByText(e).should("exist"),
);
expected.relativeDates.expected.map((e) =>
cy.contains(e).should("not.exist"),
@@ -144,20 +153,15 @@ describe("operators in questions", () => {
expected.specificDates.unexpected.map((e) =>
cy.contains(e).should("not.exist"),
);
+ cy.findByLabelText("Back").click();
});
- });
-
- it("exclude date operators", () => {
- setup(PRODUCTS_ID);
- H.popover().within(() => {
- cy.findByText("Created At").click();
- cy.findByText("Exclude…").click();
- });
+ cy.log("exclude dates");
+ H.popover().findByText("Exclude…").click();
H.popover().within(() => {
expected.excludeDates.expected.map((e) =>
- cy.contains(e).should("exist"),
+ cy.findByText(e).should("exist"),
);
expected.relativeDates.expected.map((e) =>
cy.contains(e).should("not.exist"),
@@ -171,20 +175,6 @@ describe("operators in questions", () => {
});
});
- it("id operators", () => {
- setup(PRODUCTS_ID);
-
- H.popover().within(() => {
- cy.findByText("ID").click();
- cy.findByText("Is").click();
- });
-
- cy.findByRole("menu").within(() => {
- expected.id.expected.map((e) => cy.contains(e).should("exist"));
- expected.id.unexpected.map((e) => cy.contains(e).should("not.exist"));
- });
- });
-
it("geo operators", () => {
setup(PEOPLE_ID);
@@ -194,7 +184,7 @@ describe("operators in questions", () => {
});
cy.findByRole("menu").within(() => {
- expected.geo.expected.map((e) => cy.contains(e).should("exist"));
+ expected.geo.expected.map((e) => cy.findByText(e).should("exist"));
expected.geo.unexpected.map((e) => cy.contains(e).should("not.exist"));
});
});
@@ -205,3 +195,9 @@ 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/e2e/test/scenarios/filters/relative-datetime.cy.spec.js b/e2e/test/scenarios/filters/relative-datetime.cy.spec.js
index 5979e252ec9..e63e9c543b7 100644
--- a/e2e/test/scenarios/filters/relative-datetime.cy.spec.js
+++ b/e2e/test/scenarios/filters/relative-datetime.cy.spec.js
@@ -13,25 +13,21 @@ const STARTING_FROM_UNITS = [
];
describe("scenarios > question > relative-datetime", () => {
- const now = dayjs().utc();
-
beforeEach(() => {
H.restore();
cy.signInAsNormalUser();
});
describe("starting from", () => {
- const date = (values) =>
- values.reduce((val, [num, unit]) => val.add(num, unit), now.clone());
-
STARTING_FROM_UNITS.forEach((unit) =>
it(`should work with Past filters (${unit} ago)`, () => {
+ const now = dayjs().utc();
nativeSQL([
now,
- date([[-1, unit]]),
- date([[-14, unit]]),
- date([[-15, unit]]),
- date([[-30, unit]]),
+ now.add(-1, unit),
+ now.add(-14, unit),
+ now.add(-15, unit),
+ now.add(-30, unit),
]);
withStartingFrom("Previous", [10, unit], [10, unit]);
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
@@ -41,12 +37,13 @@ describe("scenarios > question > relative-datetime", () => {
STARTING_FROM_UNITS.forEach((unit) =>
it(`should work with Next filters (${unit} from now)`, () => {
+ const now = dayjs().utc();
nativeSQL([
now,
- date([[1, unit]]),
- date([[14, unit]]),
- date([[15, unit]]),
- date([[30, unit]]),
+ now.add(1, unit),
+ now.add(14, unit),
+ now.add(15, unit),
+ now.add(30, unit),
]);
withStartingFrom("Next", [10, unit], [10, unit]);
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
@@ -61,6 +58,7 @@ describe("scenarios > question > relative-datetime", () => {
H.popover().within(() => {
cy.findByText("Filter by this column").click();
+ cy.findByText("Previous 30 days").should("be.visible");
cy.icon("chevronleft").should("not.exist");
cy.findByText("Previous 30 days").click();
});
@@ -76,13 +74,20 @@ describe("scenarios > question > relative-datetime", () => {
addStartingFrom();
setStartingFromValue(2);
- H.popover().button("Update filter").should("be.enabled");
+ H.popover().button("Update filter").click();
+ cy.wait("@dataset");
+
+ cy.findByTestId("qb-filters-panel")
+ .findByText("Created At is in the previous year, starting 2 years ago")
+ .should("be.visible");
});
});
function assertOptions(expectedOptions) {
- cy.findAllByRole("option").each(($option, index) => {
- cy.wrap($option).should("have.text", expectedOptions[index]);
+ cy.findAllByRole("option").should(($options) => {
+ expect(Cypress._.map($options, "textContent")).to.deep.equal(
+ expectedOptions,
+ );
});
}
@@ -131,13 +136,19 @@ describe("scenarios > question > relative-datetime", () => {
});
});
- it("current filters should work (metabase#21977)", () => {
+ it("relative dates should default to past filter and current filters should work (metabase#22027, metabase#21977)", () => {
H.openOrdersTable();
H.tableHeaderClick("Created At");
H.popover().within(() => {
cy.findByText("Filter by this column").click();
cy.findByText("Relative date range…").click();
+ cy.findByDisplayValue("days").should("exist");
+ cy.findByText("Day").should("not.exist");
+ cy.findByText("Quarter").should("not.exist");
+ cy.findByText("Month").should("not.exist");
+ cy.findByText("Year").should("not.exist");
+
cy.findByText("Current").click();
cy.findByText("Year").click();
});
@@ -152,39 +163,16 @@ describe("scenarios > question > relative-datetime", () => {
.should("be.visible");
});
- it("Relative dates should default to past filter (metabase#22027)", () => {
- H.openOrdersTable();
-
- H.tableHeaderClick("Created At");
- H.popover().within(() => {
- cy.findByText("Filter by this column").click();
- cy.findByText("Relative date range…").click();
- cy.findByText("Day").should("not.exist");
- cy.findByText("Quarter").should("not.exist");
- cy.findByText("Month").should("not.exist");
- cy.findByText("Year").should("not.exist");
- cy.findByDisplayValue("days").should("exist");
- });
- });
-
- it("should change the starting from units to match (metabase#22222)", () => {
+ it("should match the starting from units and allow changing values with starting from (metabase#22222, metabase#22227)", () => {
H.openOrdersTable();
openCreatedAt("Previous");
addStartingFrom();
setRelativeDatetimeUnit("months");
H.clickActionsPopover().within(() => {
- cy.findByDisplayValue("days ago").should("not.exist");
cy.findByDisplayValue("months ago").should("exist");
+ cy.findByDisplayValue("days ago").should("not.exist");
});
- });
-
- it("should allow changing values with starting from (metabase#22227)", () => {
- H.openOrdersTable();
-
- openCreatedAt("Previous");
- addStartingFrom();
- setRelativeDatetimeUnit("months");
setRelativeDatetimeValue(1);
H.popover().button("Add filter").click();
cy.wait("@dataset");
diff --git a/e2e/test/scenarios/filters/time-series-chrome.cy.spec.ts b/e2e/test/scenarios/filters/time-series-chrome.cy.spec.ts
index e057a3cc9b8..1290ca1b190 100644
--- a/e2e/test/scenarios/filters/time-series-chrome.cy.spec.ts
+++ b/e2e/test/scenarios/filters/time-series-chrome.cy.spec.ts
@@ -27,7 +27,7 @@ describe("time-series chrome filter widget", () => {
});
});
- it("should properly display the component and all its operators", () => {
+ it("should display all operators and stay in sync with the relative date filter", () => {
const operators = [
"Previous",
"Next",
@@ -67,11 +67,10 @@ describe("time-series chrome filter widget", () => {
cy.findByLabelText(/^Include/).should("not.exist");
cy.button("Apply").should("not.be.disabled");
});
- });
- it("should stay in sync with the relative date filter", () => {
- cy.findByTestId("timeseries-filter-button").click();
- updateOperator("All time", "Previous");
+ cy.findByRole("listbox")
+ .findByRole("option", { name: "Previous" })
+ .click();
cy.log("Check the state of the time-series chrome");
cy.findByTestId("date-filter-picker").within(() => {
@@ -206,9 +205,10 @@ describe("time-series chrome filter widget", () => {
});
updateOperator("Next", "Current");
- cy.findByTestId("date-filter-picker")
- .findByLabelText("Include today")
- .should("not.exist");
+ cy.findByTestId("date-filter-picker").within(() => {
+ cy.findByDisplayValue("Current").should("be.visible");
+ cy.findByLabelText("Include this year").should("not.exist");
+ });
updateOperator("Current", "Previous");
cy.findByTestId("date-filter-picker").within(() => {
diff --git a/e2e/test/scenarios/filters/view.cy.spec.js b/e2e/test/scenarios/filters/view.cy.spec.js
index 32508d75a3e..04350650406 100644
--- a/e2e/test/scenarios/filters/view.cy.spec.js
+++ b/e2e/test/scenarios/filters/view.cy.spec.js
@@ -61,17 +61,15 @@ describe("scenarios > question > view", () => {
});
});
- it("should show filters by search for Vendor", () => {
+ it("should be able to filter Q by Vendor and Category as no data user (from Q link) (metabase#12654)", () => {
+ cy.log("admin sees filters by search for Vendor");
H.visitQuestion("@questionId");
-
cy.findAllByText("VENDOR").first().click();
H.popover().within(() => {
- cy.findByPlaceholderText("Search the list");
+ cy.findByPlaceholderText("Search the list").should("exist");
cy.findByText("Search the list").should("not.exist");
});
- });
- it("should be able to filter Q by Category as no data user (from Q link) (metabase#12654)", () => {
cy.signIn("nodata");
H.visitQuestion("@questionId");
@@ -94,11 +92,19 @@ describe("scenarios > question > view", () => {
// eslint-disable-next-line metabase/no-unsafe-element-filtering
cy.findAllByTestId("run-button").last().click();
- cy.findAllByText("Widget");
- cy.findAllByText("Gizmo").should("not.exist");
+ cy.get(".test-TableInteractive-cellWrapper--firstColumn").should(
+ "have.length",
+ 1,
+ );
+ cy.get(".CardVisualization").within(() => {
+ cy.findByText("Widget");
+ cy.findByText("Balistreri-Muller");
+ cy.findByText("Gizmo").should("not.exist");
+ cy.findByText("McClure-Lockman").should("not.exist");
+ });
});
- it("should be able to filter Q by Vendor as user (from Dashboard) (metabase#12654)", () => {
+ it("should be able to filter Q by Vendor and Category as no data user (from Dashboard) (metabase#12654)", () => {
// Navigate to Q from Dashboard
cy.signIn("nodata");
H.visitDashboard("@dashboardId");