cypress-ag-grid 1.1.0 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-ag-grid",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Cypress plugin to interact with ag grid",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -24,6 +24,6 @@
24
24
  "author": "Kerry McKeever <kerry@kerrymckeever.com>",
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "cypress": "6.2.1"
27
+ "cypress": "^8.5.0"
28
28
  }
29
29
  }
@@ -5,13 +5,14 @@ import { filterTab } from "./menuTab.enum";
5
5
  /**
6
6
  * Uses the attribute value's index and sorts the data accordingly.
7
7
  * For our purposes, we are getting the attribute with the items' indices and sorting accordingly.
8
+ *
8
9
  * @param {*} index
9
10
  * @returns
10
11
  */
11
- function sortElementsByAttributeIndex(index) {
12
+ function sortElementsByAttributeValue(attribute) {
12
13
  return (a, b) => {
13
- const contentA = parseInt(a.attributes[index].nodeValue, 10).valueOf();
14
- const contentB = parseInt(b.attributes[index].nodeValue, 10).valueOf();
14
+ const contentA = parseInt(a.attributes[attribute].nodeValue, 10).valueOf();
15
+ const contentB = parseInt(b.attributes[attribute].nodeValue, 10).valueOf();
15
16
  return contentA < contentB ? -1 : contentA > contentB ? 1 : 0;
16
17
  };
17
18
  }
@@ -32,42 +33,47 @@ export const getAgGridData = (agGridElement, options = {}) => {
32
33
  const tableElement = agGridElement.get()[0].querySelectorAll(".ag-root")[0];
33
34
  const agGridSelectors = agGridColumnSelectors.split("^");
34
35
  const headers = [
35
- ...tableElement.querySelectorAll(".ag-header-cell-text")
36
- ].map((e) => e.textContent.trim());
36
+ ...tableElement.querySelectorAll('.ag-header-row-column .ag-header-cell')]
37
+ .sort(sortElementsByAttributeValue('aria-colindex'))
38
+ .map((headerElement) => {
39
+ return [...headerElement.querySelectorAll(".ag-header-cell-text")]
40
+ .map((e) => e.textContent.trim())
41
+ }).flat()
42
+
37
43
  let allRows = [];
38
44
  let rows = [];
39
45
 
40
46
  agGridSelectors.forEach((selector) => {
41
47
  const _rows = [...tableElement.querySelectorAll(`${selector}:not(.ag-hidden) .ag-row`)]
42
48
  // Sort rows by their row-index attribute value
43
- .sort(sortElementsByAttributeIndex(3))
49
+ .sort(sortElementsByAttributeValue("row-index"))
44
50
  .map((row) => {
45
51
  // Sort row cells by their aria-colindex attribute value
46
52
  return [...row.querySelectorAll(".ag-cell")]
47
- .sort(sortElementsByAttributeIndex(3))
53
+ .sort(sortElementsByAttributeValue("aria-colindex"))
48
54
  .map((e) => e.textContent.trim());
49
55
  });
50
56
  allRows.push(_rows);
51
57
  });
52
58
 
53
59
  // Remove any empty arrays before merging
54
- allRows = allRows.filter(function(ele){
60
+ allRows = allRows.filter(function (ele) {
55
61
  return ele.length
56
62
  })
57
63
 
58
- if(!allRows.length) rows = [];
59
- else{
60
- // Combine results from all specified tables (either single table, or all pinned columns) by index
61
- rows = allRows.reduce(function(a, b) {
62
- return a.map(function(v, i) {
63
- return v.concat(b[i]);
64
+ if (!allRows.length) rows = [];
65
+ else {
66
+ // Combine results from all specified tables (either single table, or all pinned columns) by index
67
+ rows = allRows.reduce(function (a, b) {
68
+ return a.map(function (v, i) {
69
+ return v.concat(b[i]);
70
+ });
64
71
  });
65
- });
66
- }
72
+ }
67
73
 
68
74
  // if options.rawValues = true, return headers & rows values as arrays instead of mapping as objects
69
75
  if (options.valuesArray) {
70
- return {headers, rows};
76
+ return { headers, rows };
71
77
  }
72
78
 
73
79
  // return structured object from headers and rows variables
@@ -170,7 +176,7 @@ function getFilterColumnButtonElement(
170
176
  .then(() => {
171
177
  cy.wrap($ele)
172
178
  .parents(".ag-header-row-column")
173
- .siblings(".ag-header-row-floating-filter")
179
+ .siblings(".ag-header-row-column-filter")
174
180
  .find(`.ag-header-cell[aria-colindex=${columnIndex}]`)
175
181
  .find(".ag-floating-filter-button");
176
182
  });
@@ -189,7 +195,7 @@ function getFilterColumnButtonElement(
189
195
  */
190
196
  function filterBySearchTerm(agGridElement, filterValue, operator, noMenuTabs) {
191
197
  // Navigate to the filter tab
192
- if (!noMenuTabs) {
198
+ if (!noMenuTabs) {
193
199
  selectMenuTab(agGridElement, filterTab.filter);
194
200
  }
195
201
  if (operator) {
@@ -223,9 +229,8 @@ function applyColumnFilter(agGridElement, hasApplyButton, noMenuTabs) {
223
229
  .click();
224
230
 
225
231
  }
226
- if (!noMenuTabs)
227
- {
228
- getMenuTabElement(agGridElement, filterTab.filter).click();
232
+ if (!noMenuTabs) {
233
+ getMenuTabElement(agGridElement, filterTab.filter).click();
229
234
  }
230
235
  }
231
236
 
@@ -241,9 +246,8 @@ function toggleColumnCheckboxFilter(
241
246
  doSelect,
242
247
  noMenuTabs = false
243
248
  ) {
244
- if (!noMenuTabs)
245
- {
246
- selectMenuTab(agGridElement, filterTab.filter);
249
+ if (!noMenuTabs) {
250
+ selectMenuTab(agGridElement, filterTab.filter);
247
251
  }
248
252
  cy.get(agGridElement)
249
253
  .find(".ag-input-field-label")