cypress-ag-grid 2.0.0-beta → 2.0.0

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 CHANGED
@@ -7,10 +7,12 @@ Cypress plugin for interacting with and validating against ag grid.
7
7
  + [Grid Interaction](#)
8
8
  - [Getting Data From the Grid](#getting-data-from-the-grid)
9
9
  - [Getting Select Row Data](#getting-select-row-data)
10
+ - [Getting Elements From the Grid](#getting-elements-from-the-grid)
10
11
  - [Sorting Columns](#sorting-columns)
11
12
  - [Filter by Text - Column Menu](#filter-by-text---column-menu)
12
13
  - [Filterby Text - Floating Filter](#filterby-text---floating-filter)
13
14
  - [Filter by Checkbox - Column Menu](#filter-by-checkbox---column-menu)
15
+ - [Filtering - Localization and Internationalization](#filtering---localization-and-internationalization)
14
16
  - [Add or Remove Columns](#add-or-remove-columns)
15
17
  + [Grid Validation](#)
16
18
  - [Validate Paginated Table](#validate-paginated-table)
@@ -86,6 +88,25 @@ The above command will return the follwoing:
86
88
  </br>
87
89
  </br>
88
90
 
91
+ ### Getting Elements From the Grid
92
+ To get the Ag Grid data as elements (if you want to interact with the cells themselves), you must chain `.getAgGridElements()` after the `cy.get()` command for the topmost level of the grid, including controls and headers (see selected DOM element in above image).
93
+ ```javascript
94
+ cy.get(agGridSelector)
95
+ .getAgGridElements()
96
+ .then((tableElements) => {
97
+ const porscheRow = tableElements.find(
98
+ (row) => row.Price.innerText === "72000"
99
+ );
100
+ const priceCell = porscheRow.Price;
101
+ cy.wrap(priceCell).dblclick().type("66000{enter}");
102
+ });
103
+
104
+ ```
105
+
106
+ The above example will grab the table as elements, finds the row whose `Price` equals `72000`. It then gets the `Price` cell for that row, double clicks on it to enable an editable input, and changes the value of the cell.
107
+ </br>
108
+ </br>
109
+
89
110
  ### Sorting Columns
90
111
  This command will sort the specified column by the sort direction specified.
91
112
 
@@ -128,13 +149,48 @@ The above command will filter the Model column for the value 'GLC300' and set th
128
149
  </br>
129
150
  </br>
130
151
  ### Filterby Text - Floating Filter
131
- This command will filter a column by a text value from its floating filter (if applicable).
152
+ This command will filter a column by a text value from its floating filter (if applicable). This command will filter a column by a text value from its floating menu. In the options, you must specify a `searchCriteria` object with `columnName`, `filterValue`, and optionally `operator` (i.e. Contains, Not contains, Equals, etc.) and `searchInputIndex` in the event you wish to apply multiple text conditions (see below for multi-condition example).
132
153
 
133
154
  ![alt text](./ag-grid-example-filter-text-floating.png "AG Grid Dom - Filter by Text Floating")
134
155
 
135
- <b>Definition:</b> .agGridColumnFilterTextMenu(options: {})
156
+ <b>Definition:</b> .agGridColumnFilterTextFloating(options: {})
157
+
158
+ Example:
159
+ ```
160
+ cy.get(agGridSelector).agGridColumnFilterTextFloating({
161
+ searchCriteria: {
162
+ columnName: "Make",
163
+ filterValue: "Ford",
164
+ },
165
+ hasApplyButton: true,
166
+ });
167
+ ```
168
+
169
+ The above example will search for the Make `Ford` from the floating text menu filter.
170
+
171
+ If you have the option for multiple conditions on the floating filter, you can do two searches, specifying the `searchInputIndex` parameter in the `searchCriteria` object. The below example will ssarch for any `Make` that contains `B` AND `MW`:
172
+
173
+ Example:
174
+ ```
175
+ cy.get(agGridSelector).agGridColumnFilterTextFloating({
176
+ searchCriteria: {
177
+ columnName: "Make",
178
+ filterValue: "B",
179
+ searchInputIndex: 0,
180
+ },
181
+ hasApplyButton: true,
182
+ });
183
+ cy.get(agGridSelector).agGridColumnFilterTextFloating({
184
+ searchCriteria: {
185
+ columnName: "Make",
186
+ filterValue: "MW",
187
+ searchInputIndex: 1,
188
+ },
189
+ hasApplyButton: true,
190
+ });
191
+ ```
192
+ ![alt text](./ag-grid-example-filter-text-floating-multi-condition.png "AG Grid Dom - Filter by Text Floating")
136
193
 
137
- See [Filter by Text - Column Menu](#filter-by-Text---Column-Menu) for example and usage.
138
194
  <br/>
139
195
  </br>
140
196
 
@@ -159,6 +215,20 @@ Example:
159
215
 
160
216
  ```
161
217
  </br>
218
+
219
+ ### Filtering - Localization and Internationalization
220
+ When we filter by checkbox, we first deselect the Select All checkbox to ensure we ONLY select the specified checkbox. Since AG grid allows for localization, we need a way to be able to pass in the localeText for Select All. This is the only area of this plugin that has a hard-coded value, so no other localization accommodations are needed.
221
+
222
+ ```
223
+ cy.get("#myGrid").agGridColumnFilterCheckboxMenu({
224
+ searchCriteria: {
225
+ columnName: "Model",
226
+ filterValue: "2002",
227
+ },
228
+ selectAllLocaleText: "Tout Sélectionner"
229
+ hasApplyButton: true,
230
+ });
231
+ ```
162
232
  </br>
163
233
 
164
234
  ### Add or Remove Columns
@@ -268,9 +338,9 @@ Example:
268
338
  * 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)
269
339
  * Example:
270
340
  ```javascript
271
- if(window.cypress){
341
+ if(window.Cypress){
272
342
  this.api.sizeColumnsToFit();
273
343
  }
274
344
  ```
275
345
  ## Credit
276
- 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).
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).
@@ -13,7 +13,7 @@ const agGridSelector = "#myGrid";
13
13
  describe("ag-grid get data scenarios", () => {
14
14
  beforeEach(() => {
15
15
  cy.visit("../app/index.html");
16
- cy.get(".ag-cell", {timeout: 10000}).should("be.visible");
16
+ cy.get(".ag-cell", { timeout: 10000 }).should("be.visible");
17
17
  });
18
18
 
19
19
  it("verify paginated table data - include all columns", () => {
@@ -98,7 +98,7 @@ describe("ag-grid get data scenarios", () => {
98
98
  columnName: "Model",
99
99
  filterValue: "2002",
100
100
  },
101
- selectAllLocaleText: 'Select All', // This is optional if you are using localText for ag grid
101
+ selectAllLocaleText: "Select All", // This is optional if you are using localText for ag grid
102
102
  hasApplyButton: true,
103
103
  });
104
104
  cy.get(agGridSelector)
@@ -110,20 +110,21 @@ describe("ag-grid get data scenarios", () => {
110
110
 
111
111
  it("able to filter by checkbox - multiple columns", () => {
112
112
  const expectedTableData = [
113
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "45000" },
114
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "32000" },
115
- { Year: "2020", Make: "BMW", Model: "2002", Price: "88001" },
113
+ { Year: "2020", Make: "BMW", Model: "3-series", Price: "45000" },
114
+ { Year: "2020", Make: "BMW", Model: "3-series", Price: "32000" },
115
+ { Year: "2020", Make: "BMW", Model: "2002", Price: "88001" },
116
116
  ];
117
117
  cy.get(agGridSelector).agGridColumnFilterCheckboxMenu({
118
- searchCriteria: [{
119
- columnName: "Model",
120
- filterValue: "2002",
121
- },
122
- {
123
- columnName: "Model",
124
- filterValue: "3-series",
125
- }
126
- ],
118
+ searchCriteria: [
119
+ {
120
+ columnName: "Model",
121
+ filterValue: "2002",
122
+ },
123
+ {
124
+ columnName: "Model",
125
+ filterValue: "3-series",
126
+ },
127
+ ],
127
128
  hasApplyButton: true,
128
129
  });
129
130
  cy.get(agGridSelector)
@@ -161,17 +162,18 @@ describe("ag-grid get data scenarios", () => {
161
162
  ];
162
163
  cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
163
164
  cy.get(agGridSelector).agGridColumnFilterTextMenu({
164
- searchCriteria: [{
165
- columnName: "Price",
166
- filterValue: "32000",
167
- operator: filterOperator.equals,
168
- },
169
- {
170
- columnName: "Make",
171
- filterValue: "BMW",
172
- operator: filterOperator.equals,
173
- }
174
- ],
165
+ searchCriteria: [
166
+ {
167
+ columnName: "Price",
168
+ filterValue: "32000",
169
+ operator: filterOperator.equals,
170
+ },
171
+ {
172
+ columnName: "Make",
173
+ filterValue: "BMW",
174
+ operator: filterOperator.equals,
175
+ },
176
+ ],
175
177
  hasApplyButton: true,
176
178
  });
177
179
  cy.get(agGridSelector)
@@ -203,21 +205,27 @@ describe("ag-grid get data scenarios", () => {
203
205
  });
204
206
  });
205
207
 
206
- it("able to filter by text - floating filter - multiple columns", () => {
208
+ it("able to filter by text - floating filter - multiple conditions", () => {
207
209
  const expectedTableData = [
208
- { Year: "1990", Make: "Ford", Model: "Taurus", Price: "900" },
210
+ { Year: "2020", Make: "BMW", Model: "2002", Price: "88001" },
211
+ { Year: "2020", Make: "BMW", Model: "3-series", Price: "45000" },
212
+ { Year: "2020", Make: "BMW", Model: "3-series", Price: "32000" },
209
213
  ];
210
214
  cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
211
215
  cy.get(agGridSelector).agGridColumnFilterTextFloating({
212
- searchCriteria: [{
216
+ searchCriteria: {
217
+ columnName: "Make",
218
+ filterValue: "B",
219
+ searchInputIndex: 0,
220
+ },
221
+ hasApplyButton: true,
222
+ });
223
+ cy.get(agGridSelector).agGridColumnFilterTextFloating({
224
+ searchCriteria: {
213
225
  columnName: "Make",
214
- filterValue: "Ford",
226
+ filterValue: "MW",
227
+ searchInputIndex: 1,
215
228
  },
216
- {
217
- columnName: "Year",
218
- filterValue: "1990",
219
- }
220
- ],
221
229
  hasApplyButton: true,
222
230
  });
223
231
  cy.get(agGridSelector)
@@ -225,7 +233,32 @@ describe("ag-grid get data scenarios", () => {
225
233
  .then((actualTableData) => {
226
234
  cy.agGridValidateRowsExactOrder(actualTableData, expectedTableData);
227
235
  });
228
- });
236
+ });
237
+
238
+ it("able to filter by text - floating filter - multiple columns", () => {
239
+ const expectedTableData = [
240
+ { Year: "1990", Make: "Ford", Model: "Taurus", Price: "900" },
241
+ ];
242
+ cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
243
+ cy.get(agGridSelector).agGridColumnFilterTextFloating({
244
+ searchCriteria: [
245
+ {
246
+ columnName: "Make",
247
+ filterValue: "Ford",
248
+ },
249
+ {
250
+ columnName: "Year",
251
+ filterValue: "1990",
252
+ },
253
+ ],
254
+ hasApplyButton: true,
255
+ });
256
+ cy.get(agGridSelector)
257
+ .getAgGridData()
258
+ .then((actualTableData) => {
259
+ cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
260
+ });
261
+ });
229
262
 
230
263
  it("able to validate empty table", () => {
231
264
  //Search for an entry that does not exist
@@ -447,4 +480,4 @@ function removePropertyFromCollection(expectedTableData, columnsToExclude) {
447
480
  // .then(() => {
448
481
  // return paginatedTableData;
449
482
  // });
450
- // }
483
+ // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-ag-grid",
3
- "version": "2.0.0-beta",
3
+ "version": "2.0.0",
4
4
  "description": "Cypress plugin to interact with ag grid",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -232,7 +232,12 @@ function getFilterColumnButtonElement(
232
232
  * @param operator (optional) use if using a search operator (i.e. Less Than, Equals, etc...use filterOperator.enum values)
233
233
  * @param noMenuTabs (optional) boolean indicating if the menu has tabs.
234
234
  */
235
- function filterBySearchTerm(agGridElement, filterValue, operator, noMenuTabs) {
235
+ function filterBySearchTerm(agGridElement, options) {
236
+ const filterValue = options.searchCriteria.filterValue;
237
+ const operator = options.searchCriteria.operator;
238
+ const searchInputIndex = options.searchCriteria.searchInputIndex || 0;
239
+ const noMenuTabs = options.noMenuTabs;
240
+
236
241
  // Navigate to the filter tab
237
242
  if (!noMenuTabs) {
238
243
  selectMenuTab(agGridElement, filterTab.filter);
@@ -256,6 +261,7 @@ function filterBySearchTerm(agGridElement, filterValue, operator, noMenuTabs) {
256
261
  .find(".ag-popup-child")
257
262
  .find("input")
258
263
  .filter(":visible")
264
+ .eq(searchInputIndex)
259
265
  .clear()
260
266
  .type(filterValue)
261
267
  .wait(500);
@@ -353,9 +359,7 @@ function _filterBySearchTextColumnMenu(agGridElement, options) {
353
359
  ).click();
354
360
  filterBySearchTerm(
355
361
  agGridElement,
356
- options.searchCriteria.filterValue,
357
- options.searchCriteria.operator,
358
- options.noMenuTabs
362
+ options
359
363
  );
360
364
  applyColumnFilter(agGridElement, options.hasApplyButton, options.noMenuTabs);
361
365
  }
@@ -367,6 +371,7 @@ function _filterBySearchTextColumnMenu(agGridElement, options) {
367
371
  * @param options.searchCriteria JSON with search properties and options
368
372
  * @param options.searchCriteria.columnName name of the column to filter
369
373
  * @param options.searchCriteria.filterValue value to input into the filter textbox
374
+ * @param options.searchCriteria.searchInputIndex [Optional] Uses 0 by default. Index of which filter box to use in event of having multiple search conditionals
370
375
  * @param options.searchCriteria.operator [Optional] Use if using a search operator (i.e. Less Than, Equals, etc...use filterOperator.enum values).
371
376
  * @param options.hasApplyButton [Optional] True if "Apply" button is used, false if filters by text input automatically.
372
377
  * @param options.noMenuTabs [Optional] True if you use for example the community edition of ag-grid, which has no menu tabs
@@ -396,9 +401,7 @@ function _filterBySearchTextColumnFloatingFilter(agGridElement, options) {
396
401
  ).click();
397
402
  filterBySearchTerm(
398
403
  agGridElement,
399
- options.searchCriteria.filterValue,
400
- options.searchCriteria.operator,
401
- options.noMenuTabs
404
+ options
402
405
  );
403
406
  applyColumnFilter(
404
407
  agGridElement,
@@ -1,450 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- import { sort } from "../../src/agGrid/sort.enum";
4
- import {
5
- deleteKey,
6
- sortedCollectionByProperty,
7
- } from "../../src/helpers/arrayHelpers";
8
- import { filterOperator } from "../../src/agGrid/filterOperator.enum";
9
-
10
- const _pageSize = 5;
11
- const agGridSelector = "#myGrid";
12
-
13
- describe("ag-grid scenarios", () => {
14
- beforeEach(() => {
15
- cy.visit("../app/index.html");
16
- cy.get(".ag-cell", {timeout: 10000}).should("be.visible");
17
- });
18
-
19
- it("verify paginated table data - include all columns", () => {
20
- const expectedPaginatedTableData = [
21
- [
22
- { Year: "2020", Make: "Toyota", Model: "Celica", Price: "35000" },
23
- { Year: "2020", Make: "Ford", Model: "Mondeo", Price: "32000" },
24
- { Year: "2020", Make: "Porsche", Model: "Boxter", Price: "72000" },
25
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "45000" },
26
- { Year: "2020", Make: "Mercedes", Model: "GLC300", Price: "53000" },
27
- ],
28
- [
29
- { Year: "2020", Make: "Honda", Model: "Civic", Price: "22000" },
30
- { Year: "2020", Make: "Honda", Model: "Accord", Price: "32000" },
31
- { Year: "2020", Make: "Ford", Model: "Taurus", Price: "19000" },
32
- { Year: "2020", Make: "Hyundai", Model: "Elantra", Price: "22000" },
33
- { Year: "2020", Make: "Toyota", Model: "Celica", Price: "5000" },
34
- ],
35
- [
36
- { Year: "2020", Make: "Ford", Model: "Mondeo", Price: "25000" },
37
- { Year: "2020", Make: "Porsche", Model: "Boxter", Price: "99000" },
38
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "32000" },
39
- { Year: "2020", Make: "Mercedes", Model: "GLC300", Price: "35000" },
40
- { Year: "2011", Make: "Honda", Model: "Civic", Price: "9000" },
41
- ],
42
- [
43
- { Year: "2020", Make: "Honda", Model: "Accord", Price: "34000" },
44
- { Year: "1990", Make: "Ford", Model: "Taurus", Price: "900" },
45
- { Year: "2020", Make: "Hyundai", Model: "Elantra", Price: "3000" },
46
- { Year: "2020", Make: "BMW", Model: "2002", Price: "88001" },
47
- ],
48
- ];
49
- cy.get(agGridSelector).agGridValidatePaginatedTable(
50
- expectedPaginatedTableData
51
- );
52
- });
53
-
54
- it("verify paginated table data - excluding columns", () => {
55
- const expectedPaginatedTableData = [
56
- [
57
- { Year: "2020", Make: "Toyota", Model: "Celica" },
58
- { Year: "2020", Make: "Ford", Model: "Mondeo" },
59
- { Year: "2020", Make: "Porsche", Model: "Boxter" },
60
- { Year: "2020", Make: "BMW", Model: "3-series" },
61
- { Year: "2020", Make: "Mercedes", Model: "GLC300" },
62
- ],
63
- [
64
- { Year: "2020", Make: "Honda", Model: "Civic" },
65
- { Year: "2020", Make: "Honda", Model: "Accord" },
66
- { Year: "2020", Make: "Ford", Model: "Taurus" },
67
- { Year: "2020", Make: "Hyundai", Model: "Elantra" },
68
- { Year: "2020", Make: "Toyota", Model: "Celica" },
69
- ],
70
- [
71
- { Year: "2020", Make: "Ford", Model: "Mondeo" },
72
- { Year: "2020", Make: "Porsche", Model: "Boxter" },
73
- { Year: "2020", Make: "BMW", Model: "3-series" },
74
- { Year: "2020", Make: "Mercedes", Model: "GLC300" },
75
- { Year: "2011", Make: "Honda", Model: "Civic" },
76
- ],
77
- [
78
- { Year: "2020", Make: "Honda", Model: "Accord" },
79
- { Year: "1990", Make: "Ford", Model: "Taurus" },
80
- { Year: "2020", Make: "Hyundai", Model: "Elantra" },
81
- { Year: "2020", Make: "BMW", Model: "2002" },
82
- ],
83
- ];
84
- cy.get(agGridSelector).agGridValidatePaginatedTable(
85
- expectedPaginatedTableData,
86
- {
87
- onlyColumns: ["Year", "Make", "Model"],
88
- }
89
- );
90
- });
91
-
92
- it("able to filter by checkbox", () => {
93
- const expectedTableData = [
94
- { Year: "2020", Make: "BMW", Model: "2002", Price: "88001" },
95
- ];
96
- cy.get(agGridSelector).agGridColumnFilterCheckboxMenu({
97
- searchCriteria: {
98
- columnName: "Model",
99
- filterValue: "2002",
100
- },
101
- selectAllLocaleText: 'Select All', // This is optional if you are using localText for ag grid
102
- hasApplyButton: true,
103
- });
104
- cy.get(agGridSelector)
105
- .getAgGridData()
106
- .then((actualTableData) => {
107
- cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
108
- });
109
- });
110
-
111
- it("able to filter by checkbox - multiple columns", () => {
112
- const expectedTableData = [
113
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "45000" },
114
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "32000" },
115
- { Year: "2020", Make: "BMW", Model: "2002", Price: "88001" },
116
- ];
117
- cy.get(agGridSelector).agGridColumnFilterCheckboxMenu({
118
- searchCriteria: [{
119
- columnName: "Model",
120
- filterValue: "2002",
121
- },
122
- {
123
- columnName: "Model",
124
- filterValue: "3-series",
125
- }
126
- ],
127
- hasApplyButton: true,
128
- });
129
- cy.get(agGridSelector)
130
- .getAgGridData()
131
- .then((actualTableData) => {
132
- cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData, true);
133
- });
134
- });
135
-
136
- it("able to filter by text - menu", () => {
137
- const expectedTableData = [
138
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "32000" },
139
- { Year: "2020", Make: "Honda", Model: "Accord", Price: "32000" },
140
- { Year: "2020", Make: "Ford", Model: "Mondeo", Price: "32000" },
141
- ];
142
- cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
143
- cy.get(agGridSelector).agGridColumnFilterTextMenu({
144
- searchCriteria: {
145
- columnName: "Price",
146
- filterValue: "32000",
147
- operator: filterOperator.equals,
148
- },
149
- hasApplyButton: true,
150
- });
151
- cy.get(agGridSelector)
152
- .getAgGridData()
153
- .then((actualTableData) => {
154
- cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
155
- });
156
- });
157
-
158
- it("able to filter by text - menu - multiple columns", () => {
159
- const expectedTableData = [
160
- { Year: "2020", Make: "BMW", Model: "3-series", Price: "32000" },
161
- ];
162
- cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
163
- cy.get(agGridSelector).agGridColumnFilterTextMenu({
164
- searchCriteria: [{
165
- columnName: "Price",
166
- filterValue: "32000",
167
- operator: filterOperator.equals,
168
- },
169
- {
170
- columnName: "Make",
171
- filterValue: "BMW",
172
- operator: filterOperator.equals,
173
- }
174
- ],
175
- hasApplyButton: true,
176
- });
177
- cy.get(agGridSelector)
178
- .getAgGridData()
179
- .then((actualTableData) => {
180
- cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
181
- });
182
- });
183
-
184
- it("able to filter by text - floating filter", () => {
185
- const expectedTableData = [
186
- { Year: "2020", Make: "Ford", Model: "Mondeo", Price: "32000" },
187
- { Year: "2020", Make: "Ford", Model: "Mondeo", Price: "25000" },
188
- { Year: "2020", Make: "Ford", Model: "Taurus", Price: "19000" },
189
- { Year: "1990", Make: "Ford", Model: "Taurus", Price: "900" },
190
- ];
191
- cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
192
- cy.get(agGridSelector).agGridColumnFilterTextFloating({
193
- searchCriteria: {
194
- columnName: "Make",
195
- filterValue: "Ford",
196
- },
197
- hasApplyButton: true,
198
- });
199
- cy.get(agGridSelector)
200
- .getAgGridData()
201
- .then((actualTableData) => {
202
- cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
203
- });
204
- });
205
-
206
- it("able to filter by text - floating filter - multiple columns", () => {
207
- const expectedTableData = [
208
- { Year: "1990", Make: "Ford", Model: "Taurus", Price: "900" },
209
- ];
210
- cy.get(agGridSelector).agGridSortColumn("Model", sort.ascending);
211
- cy.get(agGridSelector).agGridColumnFilterTextFloating({
212
- searchCriteria: [{
213
- columnName: "Make",
214
- filterValue: "Ford",
215
- },
216
- {
217
- columnName: "Year",
218
- filterValue: "1990",
219
- }
220
- ],
221
- hasApplyButton: true,
222
- });
223
- cy.get(agGridSelector)
224
- .getAgGridData()
225
- .then((actualTableData) => {
226
- cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
227
- });
228
- });
229
-
230
- it("able to validate empty table", () => {
231
- //Search for an entry that does not exist
232
- cy.get(agGridSelector).agGridColumnFilterTextMenu({
233
- searchCriteria: {
234
- columnName: "Price",
235
- filterValue: "0",
236
- operator: filterOperator.equals,
237
- },
238
- hasApplyButton: true,
239
- });
240
- cy.get(agGridSelector)
241
- .getAgGridData()
242
- .then((actualTableData) => {
243
- cy.get(agGridSelector).agGridValidateEmptyTable(actualTableData);
244
- });
245
- });
246
-
247
- it("able to sort by ascending order", () => {
248
- cy.get(agGridSelector).agGridSortColumn("Make", sort.ascending);
249
- cy.fixture("cardata").then((carData) => {
250
- // This will sort the entirety of our collection by the specified columnName and sort order
251
- // and will return only the # of records specified. In this example, I include only the first
252
- // page of data.
253
- const expectedData_sortedByAscending = sortedCollectionByProperty(
254
- carData,
255
- "Make",
256
- sort.ascending,
257
- _pageSize
258
- );
259
- cy.get(agGridSelector)
260
- .getAgGridData()
261
- .then((actualTableData) => {
262
- cy.get(agGridSelector).agGridValidateRowsExactOrder(
263
- actualTableData,
264
- expectedData_sortedByAscending
265
- );
266
- });
267
- });
268
- });
269
-
270
- it("able to sort by descending order", () => {
271
- cy.get(agGridSelector).agGridSortColumn("Make", sort.descending);
272
- cy.fixture("cardata").then((carData) => {
273
- // This will sort the entirety of our collection by the specified columnName and sort order
274
- // and will return only the # of records specified. In this example, I include only the first
275
- // page of data.
276
- const expectedData_sortedByDescending = sortedCollectionByProperty(
277
- carData,
278
- "Make",
279
- sort.descending,
280
- _pageSize
281
- );
282
- cy.get(agGridSelector)
283
- .getAgGridData()
284
- .then((actualTableData) => {
285
- cy.get(agGridSelector).agGridValidateRowsExactOrder(
286
- actualTableData,
287
- expectedData_sortedByDescending
288
- );
289
- });
290
- });
291
- });
292
-
293
- it("remove column from grid and verify select column data", () => {
294
- cy.get(agGridSelector).agGridToggleColumnsSideBar("Year", true);
295
- cy.fixture("cardata").then((expectedTableData) => {
296
- const expectedData_yearColumnRemoved = removePropertyFromCollection(
297
- expectedTableData,
298
- ["Year"]
299
- );
300
- cy.get(agGridSelector)
301
- .getAgGridData()
302
- .then((actualTableData) => {
303
- cy.get(agGridSelector).agGridValidateRowsExactOrder(
304
- actualTableData,
305
- expectedData_yearColumnRemoved.slice(0, _pageSize)
306
- );
307
- });
308
- });
309
- });
310
-
311
- it("remove single pinned column from grid and verify select column data", () => {
312
- cy.get(agGridSelector).agGridToggleColumnsSideBar("Price", true);
313
- cy.fixture("cardata").then((expectedTableData) => {
314
- const expectedData_priceColumnRemoved = removePropertyFromCollection(
315
- expectedTableData,
316
- ["Price"]
317
- );
318
-
319
- cy.get(agGridSelector)
320
- .getAgGridData()
321
- .then((actualTableData) => {
322
- cy.get(agGridSelector).agGridValidateRowsExactOrder(
323
- actualTableData,
324
- expectedData_priceColumnRemoved.slice(0, _pageSize)
325
- );
326
- });
327
- });
328
- });
329
-
330
- it("remove multiple columns from grid and verify select column data", () => {
331
- cy.get(agGridSelector).agGridToggleColumnsSideBar("Price", true);
332
- cy.get(agGridSelector).agGridToggleColumnsSideBar("Make", true);
333
- cy.fixture("cardata").then((expectedTableData) => {
334
- const expectedData_multipleColumnsRemoved = removePropertyFromCollection(
335
- expectedTableData,
336
- ["Price", "Make"]
337
- );
338
- cy.get(agGridSelector)
339
- .getAgGridData()
340
- .then((actualTableData) => {
341
- cy.get(agGridSelector).agGridValidateRowsExactOrder(
342
- actualTableData,
343
- expectedData_multipleColumnsRemoved.slice(0, _pageSize)
344
- );
345
- });
346
- });
347
- });
348
-
349
- it("only validate select column data", () => {
350
- const expectedTableData = [
351
- { Year: "2020", Make: "Toyota", Model: "Celica" },
352
- { Year: "2020", Make: "Ford", Model: "Mondeo" },
353
- { Year: "2020", Make: "Porsche", Model: "Boxter" },
354
- { Year: "2020", Make: "BMW", Model: "3-series" },
355
- { Year: "2020", Make: "Mercedes", Model: "GLC300" },
356
- ];
357
- cy.get(agGridSelector)
358
- .getAgGridData({ onlyColumns: ["Year", "Make", "Model"] })
359
- .then((actualTableData) => {
360
- cy.get(agGridSelector).agGridValidateRowsSubset(actualTableData, expectedTableData);
361
- });
362
- });
363
- });
364
-
365
- function removePropertyFromCollection(expectedTableData, columnsToExclude) {
366
- //Exclude any specified columns
367
- if (columnsToExclude) {
368
- columnsToExclude.forEach((excludedColumn) => {
369
- expectedTableData.forEach((obj) => deleteKey(obj, excludedColumn));
370
- });
371
- }
372
- return expectedTableData;
373
- }
374
-
375
- // /// THE BELOW METHODS SHOWCASE HOW TO DYNAMICALLY GET THE EXPECTED DATA AND MANIPULATE IT FOR VALIDATION
376
- // /// THIS INCLUDES PAGINATION, FILTERING, and COLUMN EXCLUSION
377
-
378
- // export const carColumns = {
379
- // year: "Year",
380
- // make: "Make",
381
- // model: "Model",
382
- // price: "Price",
383
- // };
384
-
385
- // /**
386
- // * Returns ALL expected table data populated from the expected test data call and does not factor in pagination
387
- // * @param columnsToExclude Provide an array of string values for columns to not return in the data set
388
- // * @param filters a "\^" delimited string of all columns and values to search for in the grid (i.e. "Name=John Smith^Rate Plan=Standard"
389
- // */
390
- // export function getExpectedTableData(columnsToExclude, filters) {
391
- // let table = [];
392
-
393
- // // Get the expected table data from the cardata fixture file and process it with columns exclusions and filters
394
- // return cy
395
- // .fixture("cardata")
396
- // .then((cars) => {
397
- // table = cars;
398
- // })
399
- // .then(() => {
400
- // // Iterate over all filter strings and filter table results in the order in which they are provided
401
- // if (filters) {
402
- // filters.split("^").forEach((filter) => {
403
- // const [key, value] = filter.split("=");
404
- // const getKey = getKeyByValue(carColumns, key);
405
- // table = table.filter((a) => a[getKey].includes(value));
406
- // });
407
- // }
408
- // })
409
- // .then(() => {
410
- // // Update the property key values to match what is represented in the grid for validation purposes
411
- // // (i.e. in this example, we change make to Make, model to Model, and price to Price to match
412
- // // what is shown in the grid headers exactly).
413
- // for (const key in carColumns)
414
- // table.forEach((obj) => renameKey(obj, key, carColumns[key]));
415
-
416
- // //Exclude any specified columns
417
- // if (columnsToExclude) {
418
- // columnsToExclude.forEach((excludedColumn) => {
419
- // table.forEach((obj) => deleteKey(obj, excludedColumn));
420
- // });
421
- // }
422
- // return table;
423
- // });
424
- // }
425
-
426
- // /**
427
- // * Returns ALL expected table data and paginates the data based on the pageSize
428
- // * @param columnsToExclude Provide an array of string values for columns to not return in the data set
429
- // * @param pageSize If no value is provided, default value of 5 items per page is used
430
- // */
431
- // function getExpectedPaginatedTableData(columnsToExclude, pageSize = 5) {
432
- // const paginatedTableData = [];
433
- // // paginates the expected table data, and removes specified column exclusions
434
- // return getExpectedTableData(columnsToExclude)
435
- // .then((tableData) => {
436
- // const pages = Math.floor(tableData.length / pageSize);
437
- // const finalPageCount = tableData.length % pageSize;
438
- // let iterator = 0;
439
- // for (let i = 0; i < pages; i++) {
440
- // paginatedTableData.push(tableData.slice(iterator, iterator + pageSize));
441
- // iterator += pageSize;
442
- // }
443
- // paginatedTableData.push(
444
- // tableData.slice(iterator, iterator + finalPageCount)
445
- // );
446
- // })
447
- // .then(() => {
448
- // return paginatedTableData;
449
- // });
450
- // }