Skip to content

Conversation

@asirvadAbrahamVarghese
Copy link
Contributor

…de using a path array

Added new cypress command to select accordion item based on the given path to that node.

Implements full tree traversal in a single pass till the target node. Once the first matching node is found, subsequent searches continue from that point onward, avoiding redundant iteration from the beginning.

E.g: cy.selectAccordionItem([/^ManageIQ Region/, 'Tenants', 'My Company']);
As seen below, if the "Tenants" node is found at index 57 and it's not the target node, it will be expanded (if not already). The search for the next node, "My Company", will then begin from index 58 onward.
image

@miq-bot assign @elsamaryv
@miq-bot add-label cypress
@miq-bot add-label test

@asirvadAbrahamVarghese
Copy link
Contributor Author

asirvadAbrahamVarghese commented Jul 21, 2025

Checkout to this branch and run validate-select-accordion-item.cy.js to see the working

This test - a0a7779 - will be dropped before merge

@Fryguy
Copy link
Member

Fryguy commented Jul 21, 2025

@asirvadAbrahamVarghese Don't worry about it for this PR, but try to keep commit message titles 72 chars or less. This helps avoid the text being elided on GitHub. For example:

Add_cypress_command_select_accordion_item_by_asirvadAbrahamVarghese_·_Pull_Request__9522_·_ManageIQ_manageiq-ui-classic

(72 chars because on the CLI git log adds a tab character at 8 char width, and 72+8 = 80)

Copy link
Contributor

@elsamaryv elsamaryv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
@GilbertCherrie Looping you in to take a look as well.

message: `Matched "${liText}" at index ${i}`,
});

// Wrap the current li element in a jQuery object to per
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a typo in this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated - be6345


// Wrap the current li element in a jQuery object to per
const currentLiElement = Cypress.$(listItems[i]);
const hasAngleRight =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename hasAngleRight to isExpanded or something similar ? That would give better clarity about what this flag represents instead of focussing on the icon class used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about isExpandable, since the purpose of the variable is to determine whether the node can be expanded?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - be6345

// Exit the current function scope
return;
}
// Click the most child node and terminate
Copy link
Contributor

@elsamaryv elsamaryv Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you meant

Suggested change
// Click the most child node and terminate
// Click the last child node and terminate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated - be6345

@asirvadAbrahamVarghese asirvadAbrahamVarghese force-pushed the add-cypress-command-select-accordion-item branch from 5736237 to 70caab4 Compare July 22, 2025 09:51
]);
});

it('should not collpase already expanded node', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: collapse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated - a0a7779

Note: Added this test file just to check how the command works, will drop it before merging., I’ll likely remove these logs too (log1, log2)

}
// Click the node corresponding to the last label in the given path and terminate
cy.wrap(currentLiElement).click();
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a bit hard to follow.

These returns feel like guard clauses. Is the indentation correct here?

Would it be easier to read to do:

if (isClickableNode) {
          cy.wrap(currentLiElement).click();
          return;
}
... // rest of non-guard clauses

If we return early in guard clauses, we don't need to worry about if/else as we already returned if the guard clause was true/false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These returns feel like guard clauses. Is the indentation correct here?

Pretty sure the indentation is correct, since it's auto-formatted by Prettier 🤔

If we return early in guard clauses, we don't need to worry about if/else as we already returned if the guard clause was true/false

Agreed, changed the sequence - be6345

@asirvadAbrahamVarghese asirvadAbrahamVarghese force-pushed the add-cypress-command-select-accordion-item branch from bbaa961 to 0e8ec14 Compare July 23, 2025 08:44
@asirvadAbrahamVarghese asirvadAbrahamVarghese force-pushed the add-cypress-command-select-accordion-item branch from 0e8ec14 to a0a7779 Compare July 23, 2025 09:25
@@ -0,0 +1,50 @@
/* eslint-disable no-undef */

describe('Validate clickItem', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to name this but it should probably match the command name 'selectAccordionItem". That can be done later. I think we should get this in and see how we use it to help us better understand if the naming or structure could be improved.

* If the path is not found, it will throw an error.
*/
Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
cy.get('li.list-group-item').then(($items) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I'm curious if our other pages will be compatible with the selectors used here and below. As you use this shared command, make note of things that are different as we can change code to be more consistent or make different formats of the same command for different styles of pages that do things differently.

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging, I want to see how this looks as it's used.

@jrafanie jrafanie merged commit ef8fb4c into ManageIQ:master Jul 27, 2025
18 checks passed
@jrafanie jrafanie assigned jrafanie and unassigned elsamaryv Jul 27, 2025
@asirvadAbrahamVarghese asirvadAbrahamVarghese deleted the add-cypress-command-select-accordion-item branch August 7, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants