Skip to content

Commit c2bd3bf

Browse files
authored
Merge pull request ManageIQ#9706 from asirvadAbrahamVarghese/enhance-select-accordion-item
Enhance select accordion item
2 parents 741093d + cefb19e commit c2bd3bf

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

cypress/support/commands/explorer.js

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
5858
const expandAndClickPath = (accordionPathIndex, searchStartIndex) => {
5959
/* TODO: Remove logger once the command is confirmed to be stable */
6060
Cypress.log({
61-
name: 'selectAccordionItem',
61+
name: '🟢 selectAccordionItem',
6262
message: `Found ${listItems.length} list items, searching from index ${searchStartIndex}`,
6363
});
6464

@@ -68,7 +68,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
6868
for (let i = searchStartIndex; i < listItems.length; i++) {
6969
/* TODO: Remove logger once the command is confirmed to be stable */
7070
Cypress.log({
71-
name: 'selectAccordionItem',
71+
name: '🟢 selectAccordionItem',
7272
message: `Loop index: ${i} & Searching for label: ${accordionLabel}`,
7373
});
7474

@@ -85,7 +85,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
8585
if (isMatch) {
8686
/* TODO: Remove logger once the command is confirmed to be stable */
8787
Cypress.log({
88-
name: 'selectAccordionItem',
88+
name: '🟢 selectAccordionItem',
8989
message: `Matched "${liText}" at index ${i}`,
9090
});
9191

@@ -104,6 +104,50 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
104104
return;
105105
}
106106

107+
// TODO: Once interceptApi is enhanced to handle mutiple aliases, instead of
108+
// depending on the spinner or angle-down spans, wait for tree_autoload to complete
109+
/* ===================================================================================== */
110+
const isStillLoading =
111+
currentLiElement.find('span.fa-spinner').length > 0;
112+
if (isStillLoading) {
113+
Cypress.log({
114+
name: '⚠️ selectAccordionItem',
115+
message: `Node "${liText}" is still loading - waiting for fa-angle-down to appear`,
116+
});
117+
118+
// Wait for fa-angle-down to appear (indicates loading is complete)
119+
cy.wrap(currentLiElement)
120+
.find('span.fa-angle-down')
121+
.should('exist')
122+
.then(() => {
123+
Cypress.log({
124+
name: '🟢 selectAccordionItem',
125+
message: `Node "${liText}" loading completed (fa-angle-down found)`,
126+
});
127+
cy.get('div.panel-collapse.collapse.in')
128+
.then((latestAccordionJqueryObject) => {
129+
// Update the expanded accordion reference to the latest one
130+
expandedAccordion = latestAccordionJqueryObject;
131+
const updatedListItems = [
132+
...expandedAccordion.find('li.list-group-item'),
133+
];
134+
Cypress.log({
135+
name: '🟢 selectAccordionItem',
136+
message: `Re-queried accordion - new list items count: ${updatedListItems.length}`,
137+
});
138+
// Update list items
139+
listItems = [...updatedListItems];
140+
})
141+
.then(() => {
142+
// Recurse to the next label in the given path array and
143+
// start iteration from the current index
144+
expandAndClickPath(accordionPathIndex + 1, i + 1);
145+
});
146+
});
147+
return;
148+
}
149+
/* ===================================================================================== */
150+
107151
const expandButton = currentLiElement.find('span.fa-angle-right');
108152
const isExpandable = expandButton.length > 0;
109153

@@ -113,7 +157,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
113157
// Expand the node
114158
/* TODO: Remove logger once the command is confirmed to be stable */
115159
Cypress.log({
116-
name: 'selectAccordionItem',
160+
name: '🟢 selectAccordionItem',
117161
message: `Expanding node "${liText}"`,
118162
});
119163
cy.interceptApi({
@@ -132,7 +176,7 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
132176
];
133177
/* TODO: Remove logger once the command is confirmed to be stable */
134178
Cypress.log({
135-
name: 'selectAccordionItem',
179+
name: '🟢 selectAccordionItem',
136180
message: `Re-queried accordion - new list items count: ${updatedListItems.length}`,
137181
});
138182
// Update list items

0 commit comments

Comments
 (0)