From 4a04d150636e4e76dfbbe9e24341e174dfa526ab Mon Sep 17 00:00:00 2001 From: Michele Cardone Date: Sun, 22 Dec 2024 20:21:30 +0100 Subject: [PATCH] fix: allow filtering using 'Not blank' operator (#78) --- cypress/e2e/ag-grid-data.cy.js | 37 +++++++++++++++++++++++++++++++ src/agGrid/agGridInteractions.js | 15 ++++++++----- src/agGrid/filterOperator.enum.js | 2 +- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/cypress/e2e/ag-grid-data.cy.js b/cypress/e2e/ag-grid-data.cy.js index fcaff49..17ec3b6 100644 --- a/cypress/e2e/ag-grid-data.cy.js +++ b/cypress/e2e/ag-grid-data.cy.js @@ -474,6 +474,43 @@ describe("ag-grid get data scenarios", () => { }); + it("able to filter by 'Not blank'", () => { + const expectedTableData = [ + { Year: "2020", Make: "Toyota", Model: "Celica", Condition: "fair", Price: "35000" }, + { Year: "2020", Make: "Ford", Model: "Mondeo", Condition: "excellent", Price: "32000" }, + { Year: "2020", Make: "Porsche", Model: "Boxter", Condition: "good", Price: "72000" }, + { Year: "2020", Make: "BMW", Model: "3-series", Condition: "fair", Price: "45000" }, + { Year: "2020", Make: "Mercedes", Model: "GLC300", Condition: "good", Price: "53000" }, + { Year: "2020", Make: "Honda", Model: "Civic", Condition: "poor", Price: "22000" }, + { Year: "2020", Make: "Honda", Model: "Accord", Condition: "poor", Price: "32000" }, + { Year: "2020", Make: "Ford", Model: "Taurus", Condition: "excellent", Price: "19000" }, + { Year: "2020", Make: "Hyundai", Model: "Elantra", Condition: "good", Price: "22000" }, + { Year: "2020", Make: "Toyota", Model: "Celica", Condition: "poor", Price: "5000" }, + { Year: "2020", Make: "Ford", Model: "Mondeo", Condition: "good", Price: "25000" }, + { Year: "2020", Make: "Porsche", Model: "Boxter", Condition: "good", Price: "99000" }, + { Year: "2020", Make: "BMW", Model: "3-series", Condition: "poor", Price: "32000" }, + { Year: "2020", Make: "Mercedes", Model: "GLC300", Condition: "excellent", Price: "35000" }, + { Year: "2011", Make: "Honda", Model: "Civic", Condition: "good", Price: "9000" }, + { Year: "2020", Make: "Honda", Model: "Accord", Condition: "good", Price: "34000" }, + { Year: "1990", Make: "Ford", Model: "Taurus", Condition: "excellent", Price: "900" }, + { Year: "2020", Make: "Hyundai", Model: "Elantra", Condition: "fair", Price: "3000" }, + { Year: "2020", Make: "BMW", Model: "2002", Condition: "excellent", Price: "88001" } + ] + + cy.get(agGridSelector).agGridColumnFilterTextMenu({ + searchCriteria: { + columnName: "Price", + operator: filterOperator.notBlank, + }, + hasApplyButton: true, + }); + cy.get(agGridSelector) + .getAgGridData() + .then((actualTableData) => { + cy.agGridValidateRowsSubset(actualTableData, expectedTableData); + }); + }); + it('able to filter by agTextColumnFilter with join operator', () => { const expectedTableData = [ { Year: "2020", Make: "Toyota", Model: "Celica", Condition: "fair", Price: "35000" }, diff --git a/src/agGrid/agGridInteractions.js b/src/agGrid/agGridInteractions.js index 1ab6649..cfdcb0c 100644 --- a/src/agGrid/agGridInteractions.js +++ b/src/agGrid/agGridInteractions.js @@ -329,11 +329,16 @@ function filterBySearchTerm(agGridElement, options) { .click(); } // Input filter term and allow grid a moment to render the results - cy.get(agGridElement) - .find(".ag-popup-child") - .find("input") - .filter(":visible") - .as("filterInput"); + if ( + operator !== filterOperator.blank && + operator !== filterOperator.notBlank + ) { + cy.get(agGridElement) + .find(".ag-popup-child") + .find("input") + .filter(":visible") + .as("filterInput"); + } // If it's a multi filter, de-select the 'select-all' checkbox if (isMultiFilter) { diff --git a/src/agGrid/filterOperator.enum.js b/src/agGrid/filterOperator.enum.js index 0eaded7..a0ae872 100644 --- a/src/agGrid/filterOperator.enum.js +++ b/src/agGrid/filterOperator.enum.js @@ -11,5 +11,5 @@ export const filterOperator = { greaterThanOrEquals: "Greater than or equal to", inRange: "Between", blank: "Blank", - notBlank: "Not Blank" + notBlank: "Not blank" }