cypress-ag-grid 3.2.2 → 3.3.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/app/data.json CHANGED
@@ -18,6 +18,5 @@
18
18
  { "year": "1990", "make": "Ford", "model": "Taurus", "condition":"excellent","price": "900" },
19
19
  { "year": "2020", "make": "Hyundai", "model": "Elantra", "condition":"fair","price": "3000" },
20
20
  { "year": "2020", "make": "BMW", "model": "2002", "condition":"excellent","price": "88001" },
21
- { "year": "2023", "make": "Hyundai", "model": "Santa Fe", "condition":"excellent","price": "" },
22
- { "year": "2020", "make": "Toyota", "model": "Celica", "condition": "fair", "price": "35000" }
21
+ { "year": "2023", "make": "Hyundai", "model": "Santa Fe", "condition":"excellent","price": "" }
23
22
  ]
@@ -38,9 +38,6 @@ const expectedPaginatedTableData = [
38
38
  { Year: "2020", Make: "BMW", Model: "2002", Condition: "excellent", Price: "88001" },
39
39
  { Year: "2023", Make: "Hyundai", Model: "Santa Fe", Condition: "excellent", Price: "" },
40
40
  ],
41
- [
42
- { Year: "2020", Make: "Toyota", Model: "Celica", Condition: "fair", Price: "35000" },
43
- ]
44
41
  ];
45
42
 
46
43
  describe("ag-grid get data scenarios", () => {
@@ -49,31 +46,6 @@ describe("ag-grid get data scenarios", () => {
49
46
  cy.get(".ag-cell", { timeout: 10000 }).should("be.visible");
50
47
  });
51
48
 
52
- it("verify data when multiple rows are identical", ()=>{
53
-
54
- const expectedTableData =
55
- [
56
- { "Year": "2020", "Make": "Toyota", "Model": "Celica", "Condition": "fair", "Price": "35000" },
57
- { "Year": "2020", "Make": "Toyota", "Model": "Celica", "Condition": "poor", "Price": "5000" },
58
- { "Year": "2020", "Make": "Toyota", "Model": "Celica", "Condition": "fair", "Price": "35000" },
59
- ]
60
- cy.get(agGridSelector).agGridColumnFilterCheckboxMenu({
61
- searchCriteria: {
62
- columnName: "Model",
63
- filterValue: "Celica",
64
- },
65
- selectAllLocaleText: "Select All", // This is optional if you are using localText for ag grid
66
- hasApplyButton: true,
67
- });
68
-
69
- cy.get(agGridSelector)
70
- .getAgGridData()
71
- .then((actualTableData) => {
72
- cy.agGridValidateRowsExactOrder(actualTableData, expectedTableData);
73
- });
74
-
75
- })
76
-
77
49
  it("verify paginated table data - any order - include all columns", () => {
78
50
  cy.get(agGridSelector).agGridValidatePaginatedTable(
79
51
  expectedPaginatedTableData
@@ -17,6 +17,5 @@
17
17
  { "Year": "2020", "Make": "Honda", "Model": "Accord", "Condition": "good", "Price": "34000" },
18
18
  { "Year": "1990", "Make": "Ford", "Model": "Taurus", "Condition": "excellent", "Price": "900" },
19
19
  { "Year": "2020", "Make": "Hyundai", "Model": "Elantra", "Condition": "fair", "Price": "3000" },
20
- { "Year": "2020", "Make": "BMW", "Model": "2002", "Condition": "excellent", "Price": "88001" },
21
- { "Year": "2020", "Make": "Toyota", "Model": "Celica", "Condition": "fair", "Price": "35000" }
20
+ { "Year": "2020", "Make": "BMW", "Model": "2002", "Condition": "excellent", "Price": "88001" }
22
21
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-ag-grid",
3
- "version": "3.2.2",
3
+ "version": "3.3.1",
4
4
  "description": "Cypress plugin to interact with ag grid",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -1,7 +1,41 @@
1
1
  /// <reference types="cypress" />
2
- import { sort } from "./sort.enum";
3
- import { filterTab } from "./menuTab.enum";
4
2
  import { filterOperator } from "./filterOperator.enum";
3
+ import { filterTab } from "./menuTab.enum";
4
+ import { sort } from "./sort.enum";
5
+
6
+ function isRowNotDestroyed(rowElement) {
7
+ const rect = rowElement.getBoundingClientRect();
8
+ const viewPortRect = rowElement.parentElement.getBoundingClientRect();
9
+
10
+ return (
11
+ rect.top >= viewPortRect.top &&
12
+ rect.left >= viewPortRect.left &&
13
+ rect.bottom <= viewPortRect.bottom &&
14
+ rect.right <= viewPortRect.right
15
+ );
16
+ }
17
+
18
+ export const agGridWaitForAnimation = async (agGridElement) => {
19
+ if (agGridElement.get().length < 1) {
20
+ throw new Error(`Couldn't find the element ${agGridElement}`);
21
+ }
22
+
23
+ const animations = agGridElement.get()[0].getAnimations({ subtree: true });
24
+
25
+ await Promise.all(
26
+ animations.map(async (animation) => {
27
+ try {
28
+ await animation.finished;
29
+ } catch (error) {
30
+ if (error.name === "AbortError") return;
31
+ console.error("error", error, error.name);
32
+ throw error;
33
+ }
34
+ })
35
+ );
36
+
37
+ return agGridElement;
38
+ };
5
39
 
6
40
  /**
7
41
  * Uses the attribute value's index and sorts the data accordingly.
@@ -23,7 +57,8 @@ function sortElementsByAttributeValue(attribute) {
23
57
  * @param agGridElement The get() selector for which ag grid table you wish to retrieve.
24
58
  * @param options Provide an array of columns you wish to exclude from the table retrieval.
25
59
  */
26
- export const getAgGridData = (agGridElement, options = {}) => {
60
+ export const getAgGridData = async (agGridElement, options = {}) => {
61
+ await agGridWaitForAnimation(agGridElement);
27
62
  return _getAgGrid(agGridElement, options, false);
28
63
  };
29
64
 
@@ -32,7 +67,8 @@ export const getAgGridData = (agGridElement, options = {}) => {
32
67
  * @param agGridElement The get() selector for which ag grid table you wish to retrieve.
33
68
  * @param options Provide an array of columns you wish to exclude from the table retrieval.
34
69
  */
35
- export const getAgGridElements = (agGridElement, options = {}) => {
70
+ export const getAgGridElements = async (agGridElement, options = {}) => {
71
+ await agGridWaitForAnimation(agGridElement);
36
72
  return _getAgGrid(agGridElement, options, true);
37
73
  };
38
74
 
@@ -71,8 +107,18 @@ function _getAgGrid(agGridElement, options = {}, returnElements) {
71
107
 
72
108
  agGridSelectors.forEach((selector) => {
73
109
  const _rows = [
74
- ...tableElement.querySelectorAll(`${selector}:not(.ag-hidden) .ag-row`),
110
+ ...tableElement.querySelectorAll(
111
+ `${selector}:not(.ag-hidden) .ag-row:not(.ag-opacity-zero)`
112
+ ),
75
113
  ]
114
+ // When animation is enabled, ag-grid destroys rows in 2 phases,
115
+ // first it runs an animation to place rows to be destroyed just outside
116
+ // the viewport.
117
+ // In the second phase those rows are removed from the DOM.
118
+ // Because we get here AFTER all animations are finished, it is possible,
119
+ // those rows are still in the DOM, but are not visible.
120
+ // therefore those rows should be filtered out.
121
+ .filter(isRowNotDestroyed)
76
122
  // Sort rows by their row-index attribute value
77
123
  .sort(sortElementsByAttributeValue("row-index"))
78
124
  .map((row) => {
@@ -102,11 +148,11 @@ function _getAgGrid(agGridElement, options = {}, returnElements) {
102
148
 
103
149
  // Remove duplicate entries from allRows
104
150
  // In some instances we see cell duplication for non-unique rows
105
- allRows = allRows.map((row)=>{
106
- return row.filter((cell, index)=>{
151
+ allRows = allRows.map((row) => {
152
+ return row.filter((cell, index) => {
107
153
  return row.indexOf(cell) === index;
108
- })
109
- })
154
+ });
155
+ });
110
156
 
111
157
  if (!allRows.length) rows = [];
112
158
  else {
@@ -124,12 +170,10 @@ function _getAgGrid(agGridElement, options = {}, returnElements) {
124
170
  })
125
171
  );
126
172
  }
127
-
128
173
  // if options.rawValues = true, return headers & rows values as arrays instead of mapping as objects
129
174
  if (options.valuesArray) {
130
175
  return { headers, rows };
131
176
  }
132
-
133
177
  // return structured object from headers and rows variables
134
178
  return rows.map((row) =>
135
179
  row.reduce((acc, curr, idx) => {
@@ -178,11 +222,10 @@ export function sortColumnBy(agGridElement, columnName, sortDirection) {
178
222
  .then((value) => {
179
223
  cy.log(`sort: ${sortDirection}`);
180
224
  if (!value.includes(`ag-header-cell-sorted-${sortDirection}`)) {
181
- getColumnHeaderElement(agGridElement, columnName).click().wait(250);
225
+ getColumnHeaderElement(agGridElement, columnName).click();
182
226
  sortColumnBy(agGridElement, columnName, sortDirection);
183
227
  }
184
- })
185
- .wait(100);
228
+ });
186
229
  } else {
187
230
  throw new Error("sortDirection must be either 'asc' or 'desc'.");
188
231
  }
@@ -265,20 +308,19 @@ function filterBySearchTerm(agGridElement, options) {
265
308
  }
266
309
 
267
310
  if (operator) {
268
- cy.get(agGridElement)
311
+ const elem = cy
312
+ .get(agGridElement)
269
313
  .find(".ag-filter")
270
314
  .find(".ag-picker-field-wrapper")
271
315
  .filter(":visible")
272
- .eq(searchInputIndex)
273
- .click();
316
+ .eq(searchInputIndex);
317
+ cy.get(agGridElement).agGridWaitForAnimation();
318
+ elem.click();
274
319
  cy.get(agGridElement)
275
- .find(".ag-popup")
320
+ .find(".ag-popup .ag-list")
276
321
  .find("span")
277
322
  .contains(operator)
278
- .then(($ele) => {
279
- //Have to use the unwrapped element, since Cypress .click() event does not appropriately select the operator
280
- $ele.trigger("click");
281
- });
323
+ .click();
282
324
  }
283
325
  // Input filter term and allow grid a moment to render the results
284
326
  cy.get(agGridElement)
@@ -299,7 +341,7 @@ function filterBySearchTerm(agGridElement, options) {
299
341
  operator !== filterOperator.notBlank
300
342
  ) {
301
343
  cy.get("@filterInput").then(($ele) => {
302
- cy.wrap($ele).eq(searchInputIndex).clear().type(filterValue).wait(500);
344
+ cy.wrap($ele).eq(searchInputIndex).clear().type(filterValue);
303
345
  });
304
346
  }
305
347
 
@@ -314,11 +356,10 @@ function applyColumnFilter(agGridElement, hasApplyButton, noMenuTabs) {
314
356
  cy.get(agGridElement)
315
357
  .find(".ag-filter-apply-panel-button")
316
358
  .contains("Apply")
317
- .click()
318
- .wait(500);
359
+ .click();
319
360
  }
320
361
  if (!noMenuTabs) {
321
- getMenuTabElement(agGridElement, filterTab.filter).click().wait(500);
362
+ getMenuTabElement(agGridElement, filterTab.filter).click();
322
363
  }
323
364
  }
324
365
 
@@ -343,8 +384,8 @@ function toggleColumnCheckboxFilter(
343
384
  .siblings("div")
344
385
  .find("input")
345
386
  .then(($ele) => {
346
- if (doSelect) cy.wrap($ele).check().wait(500);
347
- else cy.wrap($ele).uncheck().wait(500);
387
+ if (doSelect) cy.wrap($ele).check();
388
+ else cy.wrap($ele).uncheck();
348
389
  });
349
390
  }
350
391
 
@@ -564,7 +605,8 @@ export function toggleColumnFromSideBar(agGridElement, columnName, doRemove) {
564
605
  if (!$columnFilterInputField.is(":visible")) {
565
606
  cy.get(".ag-side-buttons").find("span").contains("Columns").click();
566
607
  }
567
- cy.wrap($columnFilterInputField).clear().wait(250).type(columnName);
608
+ cy.get(agGridElement).agGridWaitForAnimation();
609
+ cy.wrap($columnFilterInputField).clear().type(columnName);
568
610
  cy.get(".ag-column-select-column-label")
569
611
  .contains(columnName)
570
612
  .parent()
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="cypress" />
2
2
 
3
- import {getAgGridData, getAgGridElements, sortColumnBy} from "./agGrid/agGridInteractions"
3
+ import {agGridWaitForAnimation, getAgGridData, getAgGridElements, sortColumnBy} from "./agGrid/agGridInteractions"
4
4
  import {validateTablePages, validateTableExactOrder, validateEmptyTable, validateTableRowSubset} from "./agGrid/agGridValidations"
5
5
  import {filterByCheckboxColumnMenu, filterBySearchTextColumnFloatingFilter, filterBySearchTextColumnMenu, toggleColumnFromSideBar, pinColumn} from "./agGrid/agGridInteractions";
6
6
 
@@ -17,4 +17,6 @@ Cypress.Commands.add('agGridValidateRowsSubset', {prevSubject: 'optional'}, vali
17
17
  Cypress.Commands.add('agGridValidateEmptyTable', {prevSubject: 'optional'}, validateEmptyTable)
18
18
 
19
19
  Cypress.Commands.add('agGridToggleColumnsSideBar', {prevSubject: true}, toggleColumnFromSideBar)
20
- Cypress.Commands.add('agGridPinColumn', {prevSubject: true}, pinColumn)
20
+ Cypress.Commands.add('agGridPinColumn', {prevSubject: true}, pinColumn)
21
+
22
+ Cypress.Commands.add('agGridWaitForAnimation', { prevSubject: 'element' }, agGridWaitForAnimation);