cypress-ag-grid 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -6
- package/app/grid-basic.js +1 -1
- package/cypress/e2e/ag-grid-data.cy.js +24 -0
- package/package.json +1 -1
- package/src/agGrid/agGridInteractions.js +39 -9
- package/src/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@ Cypress plugin for interacting with and validating against ag grid.
|
|
|
9
9
|
- [Getting Select Row Data](#getting-select-row-data)
|
|
10
10
|
- [Getting Elements From the Grid](#getting-elements-from-the-grid)
|
|
11
11
|
- [Sorting Columns](#sorting-columns)
|
|
12
|
+
+ [Grid Filtering](#)
|
|
13
|
+
- [Filter Options](#filter-options)
|
|
12
14
|
- [Filter by Text - Column Menu](#filter-by-text---column-menu)
|
|
13
15
|
- [Filterby Text - Floating Filter](#filterby-text---floating-filter)
|
|
14
16
|
- [Filter by Checkbox - Column Menu](#filter-by-checkbox---column-menu)
|
|
@@ -121,6 +123,34 @@ cy.get("#myGrid").agGridSortColumn("Model", "descending");
|
|
|
121
123
|
</br>
|
|
122
124
|
</br>
|
|
123
125
|
|
|
126
|
+
### Filter Options
|
|
127
|
+
|
|
128
|
+
The below filtering commands takes an `options` parameter comprised of the following properties:
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
options: {
|
|
132
|
+
searchCriteria: [{
|
|
133
|
+
columnName: string;
|
|
134
|
+
filterValue: string;
|
|
135
|
+
operator?: string;
|
|
136
|
+
}];
|
|
137
|
+
hasApplyButton?: boolean;
|
|
138
|
+
noMenuTab?: boolean;
|
|
139
|
+
selectAllLocaleText: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
- options.searchCriteria JSON with search properties and options
|
|
144
|
+
- options.searchCriteria.columnName name of the column to filter
|
|
145
|
+
- options.searchCriteria.filterValue value to input into the filter textbox
|
|
146
|
+
- options.searchCriteria.searchInputIndex [Optional] Uses 0 by default. Index of which filter box to use in event of having multiple search conditionals
|
|
147
|
+
- options.searchCriteria.operator [Optional] Use if using a search operator (i.e. Less Than, Equals, etc...use filterOperator.enum values).
|
|
148
|
+
- options.hasApplyButton [Optional] True if "Apply" button is used, false if filters by text input automatically.
|
|
149
|
+
- options.noMenuTabs [Optional] True if you use, for example, the community edition of ag-grid, which has no menu tabs
|
|
150
|
+
- options.selectAllLocaleText [Optional] Pass in the locale text value of "Select All" for when you are filtering by checkbox - this wil first deselect the "Select All" option before selecting your filter value
|
|
151
|
+
*/
|
|
152
|
+
```
|
|
153
|
+
|
|
124
154
|
### Filter by Text - Column Menu
|
|
125
155
|
This command will filter a column by a text value from its menu. In the options, you must specify a `searchCriteria` objects containing one or more objects with `columnName`, `filterValue`, and optionally `operator` (i.e. Contains, Not contains, Equals, etc.).
|
|
126
156
|
|
|
@@ -286,7 +316,7 @@ Example:
|
|
|
286
316
|
cy.get("#myGrid")
|
|
287
317
|
.getAgGridData()
|
|
288
318
|
.then((actualTableData) => {
|
|
289
|
-
cy.
|
|
319
|
+
cy.agGridValidateRowsExactOrder(actualTableData, expectedTableData);
|
|
290
320
|
});
|
|
291
321
|
```
|
|
292
322
|
<br/>
|
|
@@ -309,7 +339,7 @@ Example:
|
|
|
309
339
|
cy.get(agGridSelector)
|
|
310
340
|
.getAgGridData({ onlyColumns: ["Year", "Make", "Model"] })
|
|
311
341
|
.then((actualTableData) => {
|
|
312
|
-
cy.
|
|
342
|
+
cy.agGridValidateRowsSubset(actualTableData, expectedTableData);
|
|
313
343
|
});
|
|
314
344
|
});
|
|
315
345
|
```
|
|
@@ -326,13 +356,13 @@ Example:
|
|
|
326
356
|
cy.get(agGridSelector)
|
|
327
357
|
.getAgGridData()
|
|
328
358
|
.then((actualTableData) => {
|
|
329
|
-
cy.
|
|
359
|
+
cy.agGridValidateEmptyTable(actualTableData);
|
|
330
360
|
});
|
|
331
361
|
```
|
|
332
362
|
|
|
333
363
|
## Limitations
|
|
334
|
-
* Unable to validate deeply nested row groups
|
|
335
|
-
* Unable to validate deeply nested column groups
|
|
364
|
+
* ~~Unable to validate deeply nested row groups~~ As of v2.x, using `.getAgGridElements()` you should be able to accomplish this.
|
|
365
|
+
* ~~Unable to validate deeply nested column groups~~ As of v2.x, using `.getAgGridElements()` you should be able to accomplish this.
|
|
336
366
|
* Unable to validate the entirety of an unlimited scrolling grid.
|
|
337
367
|
* Unable to validate data that is out of view. The DOM will register the ag grid data as it's scrolled into view.
|
|
338
368
|
* To combat this, in your code where the ag grid is called, check if the Cypress window is controlling the app and set the ag grid object to `.sizeColumnsToFit()`. You can see an example of this in the `app/grid.js` file of this repository. Read more [here](https://www.ag-grid.com/javascript-grid/column-sizing/#size-columns-to-fit)
|
|
@@ -343,4 +373,4 @@ Example:
|
|
|
343
373
|
}
|
|
344
374
|
```
|
|
345
375
|
## Credit
|
|
346
|
-
A portion of the logic to retrieve table data was expanded upon from the project [Cypress-Get-Table](https://github.com/roggerfe/cypress-get-table) by [Rogger Fernandez](https://github.com/roggerfe).
|
|
376
|
+
A portion of the logic to retrieve table data was expanded upon from the project [Cypress-Get-Table](https://github.com/roggerfe/cypress-get-table) by [Rogger Fernandez](https://github.com/roggerfe).
|
package/app/grid-basic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// specify the columns
|
|
2
2
|
const columnDefs = [
|
|
3
|
-
{ field: "year", pinned: "left"
|
|
3
|
+
{ field: "year", pinned: "left"},
|
|
4
4
|
{ field: "make", rowGroup: false, pinned: "left" },
|
|
5
5
|
{ field: "model", filter: true },
|
|
6
6
|
{ field: "price", pinned: "right", floatingFilter: false, sortable: false, editable: true, cellEditor: 'agTextCellEditor' },
|
|
@@ -260,6 +260,30 @@ describe("ag-grid get data scenarios", () => {
|
|
|
260
260
|
});
|
|
261
261
|
});
|
|
262
262
|
|
|
263
|
+
it("able to filter by text - floating filter - multi filter", () => {
|
|
264
|
+
const expectedTableData = [
|
|
265
|
+
{ Year: "2020", Make: "Ford", Model: "Taurus", Price: "19000" },
|
|
266
|
+
{ Year: "1990", Make: "Ford", Model: "Taurus", Price: "900" },
|
|
267
|
+
];
|
|
268
|
+
cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
|
|
269
|
+
cy.get(agGridSelector).agGridColumnFilterTextFloating({
|
|
270
|
+
searchCriteria: [
|
|
271
|
+
{
|
|
272
|
+
columnName: "Model",
|
|
273
|
+
filterValue: "Taurus",
|
|
274
|
+
isMultiFilter: true
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
hasApplyButton: true,
|
|
278
|
+
});
|
|
279
|
+
cy.get(agGridSelector)
|
|
280
|
+
.getAgGridData()
|
|
281
|
+
.then((actualTableData) => {
|
|
282
|
+
cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
|
|
263
287
|
it("able to validate empty table", () => {
|
|
264
288
|
//Search for an entry that does not exist
|
|
265
289
|
cy.get(agGridSelector).agGridColumnFilterTextMenu({
|
package/package.json
CHANGED
|
@@ -236,6 +236,7 @@ function getFilterColumnButtonElement(
|
|
|
236
236
|
const filterValue = options.searchCriteria.filterValue;
|
|
237
237
|
const operator = options.searchCriteria.operator;
|
|
238
238
|
const searchInputIndex = options.searchCriteria.searchInputIndex || 0;
|
|
239
|
+
const isMultiFilter = options.searchCriteria.isMultiFilter;
|
|
239
240
|
const noMenuTabs = options.noMenuTabs;
|
|
240
241
|
|
|
241
242
|
// Navigate to the filter tab
|
|
@@ -261,10 +262,32 @@ function getFilterColumnButtonElement(
|
|
|
261
262
|
.find(".ag-popup-child")
|
|
262
263
|
.find("input")
|
|
263
264
|
.filter(":visible")
|
|
264
|
-
.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
.as("filterInput")
|
|
266
|
+
|
|
267
|
+
// If it's a multi filter, de-select the 'select-all' checkbox
|
|
268
|
+
if(isMultiFilter){
|
|
269
|
+
const selectAllText = options.selectAllLocaleText || "Select All";
|
|
270
|
+
toggleColumnCheckboxFilter(
|
|
271
|
+
agGridElement,
|
|
272
|
+
selectAllText,
|
|
273
|
+
false,
|
|
274
|
+
true
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Get the saved filter input and enter the search term
|
|
279
|
+
cy.get("@filterInput").then(($ele)=>{
|
|
280
|
+
cy.wrap($ele)
|
|
281
|
+
.eq(searchInputIndex)
|
|
282
|
+
.clear()
|
|
283
|
+
.type(filterValue)
|
|
284
|
+
.wait(500);
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
// Finally, if a multi-filter, select the filter value's checkbox
|
|
288
|
+
if(isMultiFilter){
|
|
289
|
+
toggleColumnCheckboxFilter(agGridElement, filterValue, true, true)
|
|
290
|
+
}
|
|
268
291
|
}
|
|
269
292
|
|
|
270
293
|
function applyColumnFilter(agGridElement, hasApplyButton, noMenuTabs) {
|
|
@@ -308,8 +331,9 @@ function toggleColumnCheckboxFilter(
|
|
|
308
331
|
function populateSearchCriteria(
|
|
309
332
|
searchCriteria,
|
|
310
333
|
hasApplyButton = false,
|
|
311
|
-
noMenuTabs = false
|
|
312
|
-
|
|
334
|
+
noMenuTabs = false,
|
|
335
|
+
selectAllLocaleText = 'Select All'
|
|
336
|
+
) {
|
|
313
337
|
const options = {};
|
|
314
338
|
//@ts-ignore
|
|
315
339
|
options.searchCriteria = {};
|
|
@@ -318,6 +342,10 @@ function populateSearchCriteria(
|
|
|
318
342
|
//@ts-ignore
|
|
319
343
|
options.searchCriteria.filterValue = searchCriteria.filterValue;
|
|
320
344
|
//@ts-ignore
|
|
345
|
+
options.searchCriteria.isMultiFilter = searchCriteria.isMultiFilter;
|
|
346
|
+
//@ts-ignore
|
|
347
|
+
options.selectAllLocaleText = selectAllLocaleText;
|
|
348
|
+
//@ts-ignore
|
|
321
349
|
options.hasApplyButton = hasApplyButton;
|
|
322
350
|
//@ts-ignore
|
|
323
351
|
options.noMenuTabs = noMenuTabs;
|
|
@@ -342,7 +370,8 @@ export function filterBySearchTextColumnMenu(agGridElement, options) {
|
|
|
342
370
|
const _options = populateSearchCriteria(
|
|
343
371
|
_searchCriteria,
|
|
344
372
|
options.hasApplyButton,
|
|
345
|
-
options.noMenuTabs
|
|
373
|
+
options.noMenuTabs,
|
|
374
|
+
options.isMultiFilter
|
|
346
375
|
);
|
|
347
376
|
_filterBySearchTextColumnMenu(agGridElement, _options);
|
|
348
377
|
});
|
|
@@ -367,14 +396,15 @@ function _filterBySearchTextColumnMenu(agGridElement, options) {
|
|
|
367
396
|
/**
|
|
368
397
|
* * Performs a filter operation on the specified column via the column's floating filter field using plain text search
|
|
369
398
|
* @param agGridElement The get() selector for which ag grid table you wish to retrieve.
|
|
370
|
-
* @param {{searchCriteria:[{columnName:string,filterValue:string,operator?:string}], hasApplyButton?:boolean}} options JSON with search properties
|
|
399
|
+
* @param {{searchCriteria:[{columnName:string,filterValue:string,operator?:string}], hasApplyButton?:boolean, noMenuTab?:boolean, selectAllLocaleText:string}} options JSON with search properties
|
|
371
400
|
* @param options.searchCriteria JSON with search properties and options
|
|
372
401
|
* @param options.searchCriteria.columnName name of the column to filter
|
|
373
402
|
* @param options.searchCriteria.filterValue value to input into the filter textbox
|
|
374
403
|
* @param options.searchCriteria.searchInputIndex [Optional] Uses 0 by default. Index of which filter box to use in event of having multiple search conditionals
|
|
375
404
|
* @param options.searchCriteria.operator [Optional] Use if using a search operator (i.e. Less Than, Equals, etc...use filterOperator.enum values).
|
|
376
405
|
* @param options.hasApplyButton [Optional] True if "Apply" button is used, false if filters by text input automatically.
|
|
377
|
-
* @param options.noMenuTabs [Optional] True if you use for example the community edition of ag-grid, which has no menu tabs
|
|
406
|
+
* @param options.noMenuTabs [Optional] True if you use, for example, the community edition of ag-grid, which has no menu tabs
|
|
407
|
+
* @param options.selectAllLocaleText [Optional] Pass in the locale text value of "Select All" for when you are filtering by checkbox - this wil first deselect the "Select All" option before selecting your filter value
|
|
378
408
|
*/
|
|
379
409
|
export function filterBySearchTextColumnFloatingFilter(agGridElement, options) {
|
|
380
410
|
// Check if there are multiple search criteria provided by attempting to access the columnName
|
package/src/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ declare namespace Cypress {
|
|
|
44
44
|
* @param options.searchCriteria.columnName name of the column to filter
|
|
45
45
|
* @param options.searchCriteria.filterValue value to input into the filter textbox
|
|
46
46
|
* @param options.searchCriteria.operator [Optional] Use if using a search operator (i.e. Less Than, Equals, etc...use filterOperator.enum values).
|
|
47
|
+
* @param options.searchCriteria.isMultiFilter [Optional] Use if floating filter is multiselect checkboxes vs free form input.
|
|
47
48
|
* @param options.hasApplyButton [Optional] True if "Apply" button is used, false if filters by text input automatically.
|
|
48
49
|
*/
|
|
49
50
|
agGridColumnFilterTextFloating<E extends Node = HTMLElement>(options: {}): Chainable<JQuery<E>>;
|