cypress-ag-grid 1.1.0 → 1.3.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.
|
@@ -128,7 +128,7 @@ describe("ag-grid scenarios", () => {
|
|
|
128
128
|
cy.get(agGridSelector)
|
|
129
129
|
.getAgGridData()
|
|
130
130
|
.then((actualTableData) => {
|
|
131
|
-
cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData);
|
|
131
|
+
cy.get(agGridSelector).agGridValidateRowsExactOrder(actualTableData, expectedTableData, true);
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
134
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-ag-grid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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": "
|
|
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
|
|
12
|
+
function sortElementsByAttributeValue(attribute) {
|
|
12
13
|
return (a, b) => {
|
|
13
|
-
const contentA = parseInt(a.attributes[
|
|
14
|
-
const contentB = parseInt(b.attributes[
|
|
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,59 @@ 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(
|
|
36
|
-
|
|
36
|
+
...tableElement.querySelectorAll('.ag-header-row-column [aria-colindex]')]
|
|
37
|
+
.sort(sortElementsByAttributeValue('aria-colindex'))
|
|
38
|
+
.map((headerElement) => {
|
|
39
|
+
// Check if the elements returned are already .ag-header-cell-text elements
|
|
40
|
+
// If not, query for that element and return the text content
|
|
41
|
+
let headerCells = [...headerElement.querySelectorAll(".ag-header-cell-text")]
|
|
42
|
+
if (headerCells.length === 0) {
|
|
43
|
+
return [headerElement].map((e) => e.textContent.trim())
|
|
44
|
+
} else {
|
|
45
|
+
return [...headerElement.querySelectorAll(".ag-header-cell-text")]
|
|
46
|
+
.map((e) => e.textContent.trim())
|
|
47
|
+
}
|
|
48
|
+
}).flat()
|
|
49
|
+
|
|
37
50
|
let allRows = [];
|
|
38
51
|
let rows = [];
|
|
39
52
|
|
|
40
53
|
agGridSelectors.forEach((selector) => {
|
|
41
54
|
const _rows = [...tableElement.querySelectorAll(`${selector}:not(.ag-hidden) .ag-row`)]
|
|
42
55
|
// Sort rows by their row-index attribute value
|
|
43
|
-
.sort(
|
|
56
|
+
.sort(sortElementsByAttributeValue("row-index"))
|
|
44
57
|
.map((row) => {
|
|
45
58
|
// Sort row cells by their aria-colindex attribute value
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
// First check if elements returned already contain the aria-colindex
|
|
60
|
+
// If not, just query for the .ag-cell
|
|
61
|
+
let rowCells = [...row.querySelectorAll(".ag-cell [aria-colindex]")]
|
|
62
|
+
if (rowCells.length === 0) {
|
|
63
|
+
rowCells = [...row.querySelectorAll(".ag-cell")]
|
|
64
|
+
}
|
|
65
|
+
return rowCells.sort(sortElementsByAttributeValue("aria-colindex"))
|
|
66
|
+
.map((e)=> e.textContent.trim())
|
|
49
67
|
});
|
|
50
68
|
allRows.push(_rows);
|
|
51
69
|
});
|
|
52
70
|
|
|
53
71
|
// Remove any empty arrays before merging
|
|
54
|
-
allRows = allRows.filter(function(ele){
|
|
72
|
+
allRows = allRows.filter(function (ele) {
|
|
55
73
|
return ele.length
|
|
56
74
|
})
|
|
57
75
|
|
|
58
|
-
if(!allRows.length) rows = [];
|
|
59
|
-
else{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
if (!allRows.length) rows = [];
|
|
77
|
+
else {
|
|
78
|
+
// Combine results from all specified tables (either single table, or all pinned columns) by index
|
|
79
|
+
rows = allRows.reduce(function (a, b) {
|
|
80
|
+
return a.map(function (v, i) {
|
|
81
|
+
return v.concat(b[i]);
|
|
82
|
+
});
|
|
64
83
|
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
84
|
+
}
|
|
67
85
|
|
|
68
86
|
// if options.rawValues = true, return headers & rows values as arrays instead of mapping as objects
|
|
69
87
|
if (options.valuesArray) {
|
|
70
|
-
return {headers, rows};
|
|
88
|
+
return { headers, rows };
|
|
71
89
|
}
|
|
72
90
|
|
|
73
91
|
// return structured object from headers and rows variables
|
|
@@ -170,7 +188,7 @@ function getFilterColumnButtonElement(
|
|
|
170
188
|
.then(() => {
|
|
171
189
|
cy.wrap($ele)
|
|
172
190
|
.parents(".ag-header-row-column")
|
|
173
|
-
.siblings(".ag-header-row-
|
|
191
|
+
.siblings(".ag-header-row-column-filter")
|
|
174
192
|
.find(`.ag-header-cell[aria-colindex=${columnIndex}]`)
|
|
175
193
|
.find(".ag-floating-filter-button");
|
|
176
194
|
});
|
|
@@ -189,7 +207,7 @@ function getFilterColumnButtonElement(
|
|
|
189
207
|
*/
|
|
190
208
|
function filterBySearchTerm(agGridElement, filterValue, operator, noMenuTabs) {
|
|
191
209
|
// Navigate to the filter tab
|
|
192
|
-
if (!noMenuTabs) {
|
|
210
|
+
if (!noMenuTabs) {
|
|
193
211
|
selectMenuTab(agGridElement, filterTab.filter);
|
|
194
212
|
}
|
|
195
213
|
if (operator) {
|
|
@@ -223,9 +241,8 @@ function applyColumnFilter(agGridElement, hasApplyButton, noMenuTabs) {
|
|
|
223
241
|
.click();
|
|
224
242
|
|
|
225
243
|
}
|
|
226
|
-
if (!noMenuTabs)
|
|
227
|
-
|
|
228
|
-
getMenuTabElement(agGridElement, filterTab.filter).click();
|
|
244
|
+
if (!noMenuTabs) {
|
|
245
|
+
getMenuTabElement(agGridElement, filterTab.filter).click();
|
|
229
246
|
}
|
|
230
247
|
}
|
|
231
248
|
|
|
@@ -241,9 +258,8 @@ function toggleColumnCheckboxFilter(
|
|
|
241
258
|
doSelect,
|
|
242
259
|
noMenuTabs = false
|
|
243
260
|
) {
|
|
244
|
-
if (!noMenuTabs)
|
|
245
|
-
|
|
246
|
-
selectMenuTab(agGridElement, filterTab.filter);
|
|
261
|
+
if (!noMenuTabs) {
|
|
262
|
+
selectMenuTab(agGridElement, filterTab.filter);
|
|
247
263
|
}
|
|
248
264
|
cy.get(agGridElement)
|
|
249
265
|
.find(".ag-input-field-label")
|
|
@@ -2,12 +2,24 @@ export function validateEmptyTable(agGridElement, actualTableData){
|
|
|
2
2
|
expect(actualTableData).to.be.empty;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function validateTableExactOrder(agGridElement, actualTableData,expectedTableData){
|
|
6
|
-
|
|
5
|
+
export function validateTableExactOrder(agGridElement, actualTableData,expectedTableData, showFullError = true){
|
|
6
|
+
let errorMessage = `The expected table data did not match the actual table data`
|
|
7
|
+
|
|
8
|
+
if(showFullError){
|
|
9
|
+
errorMessage = errorMessage + ` \r\nEXPECTED:\r\n${JSON.stringify(expectedTableData)}\r\nACTUAL:\r\n:${JSON.stringify(actualTableData)}`
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
expect(actualTableData, errorMessage).to.deep.equal(expectedTableData);
|
|
7
13
|
}
|
|
8
14
|
|
|
9
|
-
export function validateTableRowSubset(agGridElement, actualTableData,expectedTableData){
|
|
10
|
-
|
|
15
|
+
export function validateTableRowSubset(agGridElement, actualTableData,expectedTableData, showFullError = true){
|
|
16
|
+
let errorMessage = `The expected item does not exist in the actual table data`
|
|
17
|
+
|
|
18
|
+
if(showFullError){
|
|
19
|
+
errorMessage = errorMessage + ` \r\nEXPECTED:\r\n${JSON.stringify(expectedTableData)}\r\nACTUAL:\r\n:${JSON.stringify(actualTableData)}`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
expectedTableData.forEach((item)=> expect(actualTableData, errorMessage).to.deep.include(item));
|
|
11
23
|
}
|
|
12
24
|
|
|
13
25
|
export function validateTablePages(agGridElement,expectedPaginatedTableData, onlyColumns = {}) {
|
|
@@ -17,7 +29,7 @@ export function validateTablePages(agGridElement,expectedPaginatedTableData, onl
|
|
|
17
29
|
.getAgGridData(onlyColumns)
|
|
18
30
|
.then((table) => {
|
|
19
31
|
const actualPage = JSON.parse(JSON.stringify(table));
|
|
20
|
-
validateTableExactOrder(agGridElement, actualPage, expectedPage);
|
|
32
|
+
validateTableExactOrder(agGridElement, actualPage, expectedPage, true);
|
|
21
33
|
cy.get(".ag-icon-next").click();
|
|
22
34
|
iterator++;
|
|
23
35
|
});
|