Skip to content

Edit collect logs form cypress refactor #9516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

asirvadAbrahamVarghese
Copy link
Contributor

PR that refactors Cypress tests for Collect Logs edit form also include review comments changes from #9508

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

@asirvadAbrahamVarghese asirvadAbrahamVarghese requested a review from a team as a code owner July 9, 2025 13:52
@asirvadAbrahamVarghese asirvadAbrahamVarghese force-pushed the edit-collect-logs-form-cypress-refactor branch from df8d9be to b6be458 Compare July 10, 2025 05:38
@asirvadAbrahamVarghese
Copy link
Contributor Author

asirvadAbrahamVarghese commented Jul 10, 2025

This is also prone to sporadic server-related failures, as we’ve seen with the schedules form:
image

@asirvadAbrahamVarghese
Copy link
Contributor Author

asirvadAbrahamVarghese commented Jul 10, 2025

comment - When #9504 gets merged, we can use the helper function here.
comment - Note, checking for "saved" in the message is probably all we need.
comment - Also, we can merge this now and open a new PR to update to the helper function cy.expectFlash('success', 'saved')

comment - Note, the hardcoded 2 in these intercepts here and the tree select feel brittle to me. I wonder if we need to be this precise with the intercepts. Can we use glob pattern matching or are there similar POSTs that occur that we have to avoid intercept/waiting on?

* parentAccordId: Optional ID of the parent accordion to scope the search.
* If provided, the search will be limited to items within that accordion.
*/
Cypress.Commands.add('accordionItem', (name, partialMatch = false, parentAccordId) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be used to click:

  1. collapsed accordion (to expand it)
  2. expanded accordion (to collapse it)
  3. select any node in the accordion tree
  4. anything else?

Depending on how we intend to use it, we might want to give it a more intention revealing name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this be used to click:
collapsed accordion (to expand it)
expanded accordion (to collapse it)
select any node in the accordion tree
anything else?

So far, I haven't encountered a scenario where we need to collapse an already expanded accordion item. However, I've seen that behavior specifically with the heading accordions, which are already handled by the existing accordion command.

The intention of this command is:

  • To expand a collapsed accordion item by clicking on span.fa-angle-right, if it's present.
  • If span.fa-angle-right is not present (which means the item is either already expanded or doesn't have expandable content), then we simply select the list item.

Depending on how we intend to use it, we might want to give it a more intention revealing name.

Would toggleListItem be a better name? Given that it's not widely used, updating the name shouldn't be a problem.

Copy link
Member

Choose a reason for hiding this comment

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

This is specific to accordions so I think selectAccordionItem sounds good to me. Naming is hard but I took "select" from your description (expanding is a side effect you're not directly concerned with... only that it happens when you select). Accordion is generally what we call things here. I think we have lists in lots of places so accordion is a more specific name for it.

cy.get('.list-group-item').contains(name).click();
const selector = parentAccordId
? `.sidebar-pf-left #${parentAccordId} .list-group-item`
: '.sidebar-pf-left .list-group-item';
Copy link
Member

@jrafanie jrafanie Jul 10, 2025

Choose a reason for hiding this comment

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

Imagine a tree in an accordion with 200 nodes.

Depending on what we're able to click in the accordion (toplevel accordion, nodes in the tree), we might want to be able to scope things to any arbitrary place in the tree so we don't have to loop through 200 nodes to get to the last one. In other words, if we can select any node in the tree, can we provide a parent id to do the scoping and not just the parent accordion id?

This is a great idea and I can see us being able to do iterations of improvements as we find ways to normalize pages and traverse them consistently in cypress.

Copy link
Member

Choose a reason for hiding this comment

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

The looping looks like it could get expensive so I'm being overly cautious.

Copy link
Member

Choose a reason for hiding this comment

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

cc @GilbertCherrie @elsamaryv What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention with the parentAccordId parameter was to scope the search to a specific parent container (like the one shown in the image), and then iterate through the list items within that section to either expand or select the matching item.
image

we might want to be able to scope things to any arbitrary place in the tree so we don't have to loop through 200 nodes

Yes, as you mentioned, if the tree is large (as shown below), having to search through the entire structure could definitely become a pain point.
image

can we provide a parent id to do the scoping and not just the parent accordion id?

But in that case, we don’t really have a parent container to scope the iteration. Instead, we're mapping <li>elements with data-node-id, so I might need to figure out how to scope the search based on data-node-id. Do you think that would be a reliable approach?
image

Copy link
Contributor Author

@asirvadAbrahamVarghese asirvadAbrahamVarghese Jul 16, 2025

Choose a reason for hiding this comment

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

If we're okay using { force: true }, we could actually drop this change and stick with that approach. Once the heading accordion is expanded, all the child nodes are already in the DOM, they're just hidden.
image

So using { force: true } would still allow us to click the target element - cy.get('.list-group-item').contains(name).click({ force: true }); name can also be regex pattern, allowing for partial matching (e.g: cy.accordionItem(/^ManageIQ Region/);).
What do you all think?

If that's not the case, then instead of relying on data-node-id, we should consider implementing something similar to the menu command - where we pass an array representing the intended tree path(The array can include strings or regex patterns, allowing for partial matching as well)
In accordion list items case ['ManageIQ Region: Region 0 [0]', 'Roles', 'MainRole-user'], with 'MainRole-user' being the deepest child node we want to click.

Copy link
Member

Choose a reason for hiding this comment

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

Good question. I'm not sure. If there isn't a good selector we can use to find the right tree node by substring, we might need to change the code (if we can) to better select the correct node. I'm concerned with looping through all of them in the parent accordion. cc @GilbertCherrie @elsamaryv thoughts?

@jrafanie
Copy link
Member

This is also prone to sporadic server-related failures, as we’ve seen with the schedules form:

sorry, I can't read the error in the screenshot. Is that the session issue losing the tree info? undefined method to_sym for nil or undefined method split for nil: #9515?

@asirvadAbrahamVarghese
Copy link
Contributor Author

sorry, I can't read the error in the screenshot. Is that the session issue losing the tree info? undefined method to_sym for nil or undefined method split for nil

Yes a similar one, Data undefined method downcase' for nil [ops/accordion_select] (replaced the screenshot)

@asirvadAbrahamVarghese asirvadAbrahamVarghese force-pushed the edit-collect-logs-form-cypress-refactor branch from b6be458 to a5142fd Compare July 16, 2025 06:08
@miq-bot
Copy link
Member

miq-bot commented Jul 16, 2025

Checked commits asirvadAbrahamVarghese/manageiq-ui-classic@1d5b2a8~...a5142fd with ruby 3.1.7, rubocop 1.56.3, haml-lint 0.64.0, and yamllint
0 files checked, 0 offenses detected
Everything looks fine. 🍰

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.

3 participants